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

Side by Side Diff: content/browser/download/download_job.h

Issue 2645133003: Introduce DownloadJob for DownloadItem refactoring. (Closed)
Patch Set: Small tweak to inline getter. Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « content/browser/BUILD.gn ('k') | content/browser/download/download_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // 1. DownloadJob contains internal download logic. Subclasses should implement
24 // their own state machine.
25 // 2. The DownloadJob::Manager(e.g DownloadItemImpl) may provide content public
26 // api to the embedder backed by different implementation of DownloadJob
27 // internally.
28 // 3. The DownloadJob::Manager may maintain multiple DownloadJobs.
29 class CONTENT_EXPORT DownloadJob {
30 public:
31 // Types of download jobs.
32 enum Type {
33 FILE = 0, // Normal download.
34 SAVE_PAGE, // Save page download.
35 };
36
37 // The owner of DownloadJob(e.g DownloadItemImpl or parallel download job)
38 // should implement this to be informed with important changes from
39 // DownloadJob and modify its states accordingly.
40 class CONTENT_EXPORT Manager {
41 public:
42 // Called when |download_job| starts, and pass the ResponseInfo to the
43 // manager.
44 // TODO(xingliu): Pass ResponseInfo to the manager.
45 virtual void StartSaving(DownloadJob* download_job) = 0;
qinmin 2017/01/23 21:46:35 Shouldn't the manager just call download_job_->Sta
xingliu 2017/01/23 22:59:09 These are the callbacks to DownloadItemImpl which
qinmin 2017/01/23 23:03:15 Then shouldn't the function name be OnSavingStarte
xingliu 2017/01/23 23:26:08 Done, changed to OnSavingStarted aligned with othe
46
47 // Called when |download_job| is interrupted.
48 virtual void OnDownloadInterrupted(DownloadJob* download_job,
49 DownloadInterruptReason reason) = 0;
50
51 // Called when |download_job| is completed and inform the manager.
52 virtual void OnDownloadComplete(DownloadJob* download_job) = 0;
53
54 // Sets the download danger type.
55 virtual void SetDangerType(DownloadDangerType danger_type) = 0;
56 };
57
58 DownloadJob();
59 virtual ~DownloadJob();
60
61 DownloadJob::Manager* manager() { return manager_; }
62
63 Type type() const { return type_; }
64
65 // Called when DownloadJob is attached to DownloadJob::Manager.
66 virtual void OnAttached(DownloadJob::Manager* manager);
67
68 // Called before DownloadJob is detached from its manager.
69 virtual void OnBeforeDetach();
70
71 // Download operations.
72 virtual void Cancel(bool user_cancel) = 0;
73 virtual void Pause() = 0;
74 virtual void Resume() = 0;
75
76 // Return if the download file can be opened.
77 // See |DownloadItem:: CanOpenDownload|.
78 virtual bool CanOpen() const = 0;
79
80 // Return if the download job can be resumed.
81 virtual bool CanResume() const = 0;
82
83 // See |DownloadItem::CanShowInFolder|.
84 virtual bool CanShowInFolder() const = 0;
85
86 // Return if the download job is actively downloading.
87 virtual bool IsActive() const = 0;
88
89 // Return if the download job is paused.
90 virtual bool IsPause() const = 0;
91
92 // Return a number between 0 and 100 to represent the percentage progress of
93 // the download. Return |kDownloadProgressUnknown| if the progress is
94 // indeterminate.
95 virtual int PercentComplete() const = 0;
96
97 // Return the estimated current download speed in bytes per second.
98 // Or return kDownloadSpeedUnknown if the download speed is not measurable.
99 virtual int64_t CurrentSpeed() const = 0;
100
101 // Set the estimated remaining time of the download to |remaining| and return
102 // true if time remaining is available, otherwise return false.
103 virtual bool TimeRemaining(base::TimeDelta* remaining) const = 0;
104
105 // Return the WebContents associated with the download. Usually used to
106 // associate a browser window for any UI that needs to be displayed to the
107 // user.
108 // Or return nullptr if the download is not associated with an active
109 // WebContents.
110 virtual WebContents* GetWebContents() const = 0;
111
112 // Print the debug string including internal states of the download job.
113 virtual std::string DebugString(bool verbose) const = 0;
114
115 protected:
116 // Mark the download as being in-progress.
117 // TODO(xingliu): Pass ResponseInfo to the manager here.
118 void StartedSavingResponse();
119
120 // Mark the download as interrupted.
121 void Interrupt(DownloadInterruptReason reason);
122
123 // Mark the download job as completed.
124 void Complete();
125
126 // Owner of this DownloadJob, Only valid between OnAttached() and
127 // OnBeforeDetach(), inclusive. Otherwise set to nullptr.
128 DownloadJob::Manager* manager_;
129
130 // The type of the download.
131 DownloadJob::Type type_;
132
133 private:
134 DISALLOW_COPY_AND_ASSIGN(DownloadJob);
135 };
136
137 } // namespace content
138
139 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_JOB_H_
OLDNEW
« no previous file with comments | « content/browser/BUILD.gn ('k') | content/browser/download/download_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698