Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1096)

Unified Diff: content/browser/download/download_job.h

Issue 2689373003: Introduce ParallelDownloadJob. (Closed)
Patch Set: nits. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_job.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/download/download_job.h
diff --git a/content/browser/download/download_job.h b/content/browser/download/download_job.h
index 2192d410c96d123fe93160aa69c24c9f1da55947..836cfdaa36679789b58188b2cded13af1f9c8d00 100644
--- a/content/browser/download/download_job.h
+++ b/content/browser/download/download_job.h
@@ -12,82 +12,25 @@
#include "content/public/browser/download_interrupt_reasons.h"
namespace content {
-class WebContents;
-
-// Unknown download progress.
-extern const int kDownloadProgressUnknown;
-// Unknown download speed.
-extern const int kDownloadSpeedUnknown;
+class DownloadItemImpl;
+class WebContents;
-// DownloadJob contains internal download logic.
-// The owner of DownloadJob(e.g DownloadItemImpl) should implement
-// DownloadJob::Manager to be informed with important changes from
-// DownloadJob and modify its states accordingly.
+// DownloadJob lives on UI thread and subclasses implement actual download logic
+// and interact with DownloadItemImpl.
+// The base class is a friend class of DownloadItemImpl.
class CONTENT_EXPORT DownloadJob {
public:
- // The interface used to interact with the owner of the download job.
- class CONTENT_EXPORT Manager {
- public:
- // Called when |download_job| becomes actively download data.
- virtual void OnSavingStarted(DownloadJob* download_job) = 0;
-
- // Called when |download_job| is interrupted.
- virtual void OnDownloadInterrupted(DownloadJob* download_job,
- DownloadInterruptReason reason) = 0;
-
- // Called when |download_job| is completed and inform the manager.
- virtual void OnDownloadComplete(DownloadJob* download_job) = 0;
-
- // Sets the download danger type.
- virtual void SetDangerType(DownloadDangerType danger_type) = 0;
- };
-
- DownloadJob();
+ explicit DownloadJob(DownloadItemImpl* download_item);
virtual ~DownloadJob();
- DownloadJob::Manager* manager() { return manager_; }
-
- // Called when DownloadJob is attached to DownloadJob::Manager.
- // |manager| can be nullptr.
- virtual void OnAttached(DownloadJob::Manager* manager);
-
- // Called before DownloadJob is detached from its manager.
- virtual void OnBeforeDetach();
-
// Download operations.
+ virtual void Start() = 0;
virtual void Cancel(bool user_cancel) = 0;
- virtual void Pause() = 0;
- virtual void Resume() = 0;
-
- // Return if the download file can be opened.
- // See |DownloadItem::CanOpenDownload|.
- virtual bool CanOpen() const = 0;
+ virtual void Pause();
+ virtual void Resume(bool resume_request);
- // Return if the download job can be resumed.
- virtual bool CanResume() const = 0;
-
- // See |DownloadItem::CanShowInFolder|.
- virtual bool CanShowInFolder() const = 0;
-
- // Return if the download job is actively downloading.
- virtual bool IsActive() const = 0;
-
- // Return if the download job is paused.
- virtual bool IsPaused() const = 0;
-
- // Return a number between 0 and 100 to represent the percentage progress of
- // the download. Return |kDownloadProgressUnknown| if the progress is
- // indeterminate.
- virtual int PercentComplete() const = 0;
-
- // Return the estimated current download speed in bytes per second.
- // Or return kDownloadSpeedUnknown if the download speed is not measurable.
- virtual int64_t CurrentSpeed() const = 0;
-
- // Set the estimated remaining time of the download to |remaining| and return
- // true if time remaining is available, otherwise return false.
- virtual bool TimeRemaining(base::TimeDelta* remaining) const = 0;
+ bool is_paused() const { return is_paused_; }
// Return the WebContents associated with the download. Usually used to
// associate a browser window for any UI that needs to be displayed to the
@@ -96,24 +39,15 @@ class CONTENT_EXPORT DownloadJob {
// WebContents.
virtual WebContents* GetWebContents() const = 0;
- // Print the debug string including internal states of the download job.
- virtual std::string DebugString(bool verbose) const = 0;
-
protected:
- // Mark the download as being active.
- void StartedSavingResponse();
-
- // Mark the download as interrupted.
- void Interrupt(DownloadInterruptReason reason);
+ void StartDownload() const;
- // Mark the download job as completed.
- void Complete();
-
- // Owner of this DownloadJob, Only valid between OnAttached() and
- // OnBeforeDetach(), inclusive. Otherwise set to nullptr.
- DownloadJob::Manager* manager_;
+ DownloadItemImpl* download_item_;
private:
+ // If the download progress is paused by the user.
+ bool is_paused_;
+
DISALLOW_COPY_AND_ASSIGN(DownloadJob);
};
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698