Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/byte_stream.h" | 10 #include "content/browser/byte_stream.h" |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "content/public/browser/download_danger_type.h" | 12 #include "content/public/browser/download_danger_type.h" |
| 13 #include "content/public/browser/download_interrupt_reasons.h" | 13 #include "content/public/browser/download_interrupt_reasons.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 class DownloadItemImpl; | 17 class DownloadItemImpl; |
| 18 class WebContents; | 18 class WebContents; |
| 19 | 19 |
| 20 // DownloadJob lives on UI thread and subclasses implement actual download logic | 20 // DownloadJob lives on UI thread and subclasses implement actual download logic |
| 21 // and interact with DownloadItemImpl. | 21 // and interact with DownloadItemImpl. |
| 22 // The base class is a friend class of DownloadItemImpl. | 22 // The base class is a friend class of DownloadItemImpl. |
| 23 class CONTENT_EXPORT DownloadJob { | 23 class CONTENT_EXPORT DownloadJob { |
| 24 public: | 24 public: |
| 25 explicit DownloadJob(DownloadItemImpl* download_item); | 25 explicit DownloadJob(DownloadItemImpl* download_item); |
| 26 virtual ~DownloadJob(); | 26 virtual ~DownloadJob(); |
| 27 | 27 |
| 28 // Download operations. | 28 // Download operations. |
| 29 virtual void Start() = 0; | 29 virtual void Start() = 0; |
| 30 virtual void Cancel(bool user_cancel) = 0; | 30 virtual void Cancel(bool user_cancel); |
| 31 virtual void Pause(); | 31 virtual void Pause(); |
| 32 virtual void Resume(bool resume_request); | 32 virtual void Resume(bool resume_request); |
| 33 | 33 |
| 34 bool is_paused() const { return is_paused_; } | 34 bool is_paused() const { return is_paused_; } |
| 35 bool is_canceled() const { return is_canceled_; } | |
|
qinmin
2017/03/26 05:01:00
nit: these functions and the private member variab
xingliu
2017/03/27 17:29:33
We actually added an is_canceled check in BuildPar
| |
| 35 | 36 |
| 36 // Return the WebContents associated with the download. Usually used to | 37 // 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 // associate a browser window for any UI that needs to be displayed to the |
| 38 // user. | 39 // user. |
| 39 // Or return nullptr if the download is not associated with an active | 40 // Or return nullptr if the download is not associated with an active |
| 40 // WebContents. | 41 // WebContents. |
| 41 virtual WebContents* GetWebContents() const = 0; | 42 virtual WebContents* GetWebContents() const = 0; |
| 42 | 43 |
| 43 // Returns whether the download uses parallel requests. | 44 // Returns whether the download uses parallel requests. |
| 44 virtual bool UsesParallelRequests() const; | 45 virtual bool UsesParallelRequests() const; |
| 45 | 46 |
| 46 protected: | 47 protected: |
| 47 void StartDownload() const; | 48 void StartDownload() const; |
| 48 void Interrupt(DownloadInterruptReason reason); | 49 void Interrupt(DownloadInterruptReason reason); |
| 49 | 50 |
| 50 // Add a byte stream to the download sink. | 51 // Add a byte stream to the download sink. Return false if we start to |
| 51 void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, | 52 // destroy download file. |
| 53 bool AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, | |
| 52 int64_t offset, | 54 int64_t offset, |
| 53 int64_t length); | 55 int64_t length); |
| 54 | 56 |
| 55 DownloadItemImpl* download_item_; | 57 DownloadItemImpl* download_item_; |
| 56 | 58 |
| 57 private: | 59 private: |
| 58 // If the download progress is paused by the user. | 60 // If the download progress is paused by the user. |
| 59 bool is_paused_; | 61 bool is_paused_; |
| 60 | 62 |
| 63 // If the download progress is canceled. | |
| 64 bool is_canceled_; | |
| 65 | |
| 61 DISALLOW_COPY_AND_ASSIGN(DownloadJob); | 66 DISALLOW_COPY_AND_ASSIGN(DownloadJob); |
| 62 }; | 67 }; |
| 63 | 68 |
| 64 } // namespace content | 69 } // namespace content |
| 65 | 70 |
| 66 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_ | 71 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_ |
| OLD | NEW |