blob: 25635309c94a5bd4eb9ccc3387dafcba0270ebd0 [file] [log] [blame]
xingliuf61d39f2017-01-27 22:46:461// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_
6#define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_
7
8#include "base/macros.h"
9#include "base/time/time.h"
xingliu6719c202017-03-18 03:45:2110#include "content/browser/byte_stream.h"
xingliuf61d39f2017-01-27 22:46:4611#include "content/common/content_export.h"
12#include "content/public/browser/download_danger_type.h"
13#include "content/public/browser/download_interrupt_reasons.h"
14
15namespace content {
xingliu468824d2017-02-28 02:59:2516
17class DownloadItemImpl;
xingliuf61d39f2017-01-27 22:46:4618class WebContents;
19
xingliu468824d2017-02-28 02:59:2520// DownloadJob lives on UI thread and subclasses implement actual download logic
21// and interact with DownloadItemImpl.
22// The base class is a friend class of DownloadItemImpl.
xingliuf61d39f2017-01-27 22:46:4623class CONTENT_EXPORT DownloadJob {
24 public:
xingliu468824d2017-02-28 02:59:2525 explicit DownloadJob(DownloadItemImpl* download_item);
xingliuf61d39f2017-01-27 22:46:4626 virtual ~DownloadJob();
27
xingliuf61d39f2017-01-27 22:46:4628 // Download operations.
xingliu468824d2017-02-28 02:59:2529 virtual void Start() = 0;
xingliuf61d39f2017-01-27 22:46:4630 virtual void Cancel(bool user_cancel) = 0;
xingliu468824d2017-02-28 02:59:2531 virtual void Pause();
32 virtual void Resume(bool resume_request);
xingliuf61d39f2017-01-27 22:46:4633
xingliu468824d2017-02-28 02:59:2534 bool is_paused() const { return is_paused_; }
xingliuf61d39f2017-01-27 22:46:4635
36 // Return the WebContents associated with the download. Usually used to
37 // associate a browser window for any UI that needs to be displayed to the
38 // user.
39 // Or return nullptr if the download is not associated with an active
40 // WebContents.
41 virtual WebContents* GetWebContents() const = 0;
42
qinmin1c18f0d2017-03-23 02:01:0743 // Returns whether the download uses parallel requests.
44 virtual bool UsesParallelRequests() const;
45
xingliuf61d39f2017-01-27 22:46:4646 protected:
xingliu468824d2017-02-28 02:59:2547 void StartDownload() const;
xingliu391c49d742017-03-21 19:47:3748 void Interrupt(DownloadInterruptReason reason);
xingliuf61d39f2017-01-27 22:46:4649
xingliucca0315b2017-03-27 20:54:2350 // Add a byte stream to the download sink. Return false if we start to
51 // destroy download file.
52 bool AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader,
xingliu6719c202017-03-18 03:45:2153 int64_t offset,
54 int64_t length);
55
xingliu468824d2017-02-28 02:59:2556 DownloadItemImpl* download_item_;
xingliuf61d39f2017-01-27 22:46:4657
58 private:
xingliu468824d2017-02-28 02:59:2559 // If the download progress is paused by the user.
60 bool is_paused_;
61
xingliuf61d39f2017-01-27 22:46:4662 DISALLOW_COPY_AND_ASSIGN(DownloadJob);
63};
64
65} // namespace content
66
67#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_