Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 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" | |
| 10 #include "content/common/content_export.h" | |
| 11 #include "content/public/browser/download_danger_type.h" | |
| 12 #include "content/public/browser/download_interrupt_reasons.h" | |
| 13 | |
| 14 namespace content { | |
| 15 class WebContents; | |
| 16 | |
| 17 // Unknown download progress. | |
| 18 extern const int kDownloadProgressUnknown; | |
| 19 | |
| 20 // Unknown download speed. | |
| 21 extern const int kDownloadSpeedUnknown; | |
| 22 | |
| 23 // DownloadJob contains internal download logic. | |
| 24 // The owner of DownloadJob(e.g DownloadItemImpl) should implement | |
| 25 // DownloadJob::Manager to be informed with important changes from | |
| 26 // DownloadJob and modify its states accordingly. | |
| 27 class CONTENT_EXPORT DownloadJob { | |
| 28 public: | |
| 29 // The interface used to interact with the owner of the download job. | |
| 30 class CONTENT_EXPORT Manager { | |
| 31 public: | |
| 32 // Called when |download_job| becomes actively download data. | |
| 33 virtual void OnSavingStarted(DownloadJob* download_job) = 0; | |
| 34 | |
| 35 // Called when |download_job| is interrupted. | |
| 36 virtual void OnDownloadInterrupted(DownloadJob* download_job, | |
| 37 DownloadInterruptReason reason) = 0; | |
| 38 | |
| 39 // Called when |download_job| is completed and inform the manager. | |
| 40 virtual void OnDownloadComplete(DownloadJob* download_job) = 0; | |
| 41 | |
| 42 // Sets the download danger type. | |
| 43 virtual void SetDangerType(DownloadDangerType danger_type) = 0; | |
| 44 }; | |
| 45 | |
| 46 DownloadJob(); | |
| 47 virtual ~DownloadJob(); | |
| 48 | |
| 49 DownloadJob::Manager* manager() { return manager_; } | |
| 50 | |
| 51 // Called when DownloadJob is attached to DownloadJob::Manager. | |
| 52 virtual void OnAttached(DownloadJob::Manager* manager); | |
| 53 | |
| 54 // Called before DownloadJob is detached from its manager. | |
| 55 virtual void OnBeforeDetach(); | |
| 56 | |
| 57 // Download operations. | |
| 58 virtual void Cancel(bool user_cancel) = 0; | |
| 59 virtual void Pause() = 0; | |
| 60 virtual void Resume() = 0; | |
| 61 | |
| 62 // Return if the download file can be opened. | |
| 63 // See |DownloadItem:: CanOpenDownload|. | |
|
David Trainor- moved to gerrit
2017/01/25 03:46:09
remove space after ::
| |
| 64 virtual bool CanOpen() const = 0; | |
| 65 | |
| 66 // Return if the download job can be resumed. | |
| 67 virtual bool CanResume() const = 0; | |
| 68 | |
| 69 // See |DownloadItem::CanShowInFolder|. | |
| 70 virtual bool CanShowInFolder() const = 0; | |
| 71 | |
| 72 // Return if the download job is actively downloading. | |
| 73 virtual bool IsActive() const = 0; | |
| 74 | |
| 75 // Return if the download job is paused. | |
| 76 virtual bool IsPause() const = 0; | |
|
David Trainor- moved to gerrit
2017/01/25 03:46:09
s/Pause/Paused?
| |
| 77 | |
| 78 // Return a number between 0 and 100 to represent the percentage progress of | |
| 79 // the download. Return |kDownloadProgressUnknown| if the progress is | |
| 80 // indeterminate. | |
| 81 virtual int PercentComplete() const = 0; | |
| 82 | |
| 83 // Return the estimated current download speed in bytes per second. | |
| 84 // Or return kDownloadSpeedUnknown if the download speed is not measurable. | |
| 85 virtual int64_t CurrentSpeed() const = 0; | |
| 86 | |
| 87 // Set the estimated remaining time of the download to |remaining| and return | |
| 88 // true if time remaining is available, otherwise return false. | |
| 89 virtual bool TimeRemaining(base::TimeDelta* remaining) const = 0; | |
| 90 | |
| 91 // Return the WebContents associated with the download. Usually used to | |
| 92 // associate a browser window for any UI that needs to be displayed to the | |
| 93 // user. | |
| 94 // Or return nullptr if the download is not associated with an active | |
| 95 // WebContents. | |
| 96 virtual WebContents* GetWebContents() const = 0; | |
| 97 | |
| 98 // Print the debug string including internal states of the download job. | |
| 99 virtual std::string DebugString(bool verbose) const = 0; | |
| 100 | |
| 101 protected: | |
| 102 // Mark the download as being active. | |
| 103 void StartedSavingResponse(); | |
| 104 | |
| 105 // Mark the download as interrupted. | |
| 106 void Interrupt(DownloadInterruptReason reason); | |
| 107 | |
| 108 // Mark the download job as completed. | |
| 109 void Complete(); | |
| 110 | |
| 111 // Owner of this DownloadJob, Only valid between OnAttached() and | |
| 112 // OnBeforeDetach(), inclusive. Otherwise set to nullptr. | |
| 113 DownloadJob::Manager* manager_; | |
| 114 | |
| 115 private: | |
| 116 DISALLOW_COPY_AND_ASSIGN(DownloadJob); | |
| 117 }; | |
| 118 | |
| 119 } // namespace content | |
| 120 | |
| 121 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_ | |
| OLD | NEW |