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

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

Issue 2645133003: Introduce DownloadJob for DownloadItem refactoring. (Closed)
Patch Set: Comments change. 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 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 // 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 // Types of download jobs.
30 enum Type {
31 URL_DOWNLOAD = 0, // Normal download.
qinmin 2017/01/24 23:57:49 this can be removed now
xingliu 2017/01/25 01:18:07 Done.
32 };
33
34 // The interface used to interact with the owner of the download job.
35 class CONTENT_EXPORT Manager {
36 public:
37 // Called when |download_job| starts, and pass the ResponseInfo to the
38 // manager.
39 virtual void OnSavingStarted(DownloadJob* download_job) = 0;
qinmin 2017/01/24 23:57:49 should there be a responseInfo param?
xingliu 2017/01/25 01:18:07 In the current DownloadItemImpl code, the Response
40
41 // Called when |download_job| is interrupted.
42 virtual void OnDownloadInterrupted(DownloadJob* download_job,
43 DownloadInterruptReason reason) = 0;
44
45 // Called when |download_job| is completed and inform the manager.
46 virtual void OnDownloadComplete(DownloadJob* download_job) = 0;
47
48 // Sets the download danger type.
49 virtual void SetDangerType(DownloadDangerType danger_type) = 0;
50 };
51
52 DownloadJob();
53 virtual ~DownloadJob();
54
55 DownloadJob::Manager* manager() { return manager_; }
56
57 Type type() const { return type_; }
58
59 // Called when DownloadJob is attached to DownloadJob::Manager.
60 virtual void OnAttached(DownloadJob::Manager* manager);
61
62 // Called before DownloadJob is detached from its manager.
63 virtual void OnBeforeDetach();
64
65 // Download operations.
66 virtual void Cancel(bool user_cancel) = 0;
67 virtual void Pause() = 0;
68 virtual void Resume() = 0;
69
70 // Return if the download file can be opened.
71 // See |DownloadItem:: CanOpenDownload|.
72 virtual bool CanOpen() const = 0;
73
74 // Return if the download job can be resumed.
75 virtual bool CanResume() const = 0;
76
77 // See |DownloadItem::CanShowInFolder|.
78 virtual bool CanShowInFolder() const = 0;
79
80 // Return if the download job is actively downloading.
81 virtual bool IsActive() const = 0;
82
83 // Return if the download job is paused.
84 virtual bool IsPause() const = 0;
85
86 // Return a number between 0 and 100 to represent the percentage progress of
87 // the download. Return |kDownloadProgressUnknown| if the progress is
88 // indeterminate.
89 virtual int PercentComplete() const = 0;
90
91 // Return the estimated current download speed in bytes per second.
92 // Or return kDownloadSpeedUnknown if the download speed is not measurable.
93 virtual int64_t CurrentSpeed() const = 0;
94
95 // Set the estimated remaining time of the download to |remaining| and return
96 // true if time remaining is available, otherwise return false.
97 virtual bool TimeRemaining(base::TimeDelta* remaining) const = 0;
98
99 // Return the WebContents associated with the download. Usually used to
100 // associate a browser window for any UI that needs to be displayed to the
101 // user.
102 // Or return nullptr if the download is not associated with an active
103 // WebContents.
104 virtual WebContents* GetWebContents() const = 0;
105
106 // Print the debug string including internal states of the download job.
107 virtual std::string DebugString(bool verbose) const = 0;
108
109 protected:
110 // Mark the download as being active.
111 void StartedSavingResponse();
112
113 // Mark the download as interrupted.
114 void Interrupt(DownloadInterruptReason reason);
115
116 // Mark the download job as completed.
117 void Complete();
118
119 // Owner of this DownloadJob, Only valid between OnAttached() and
120 // OnBeforeDetach(), inclusive. Otherwise set to nullptr.
121 DownloadJob::Manager* manager_;
122
123 // The type of the download.
124 DownloadJob::Type type_;
125
126 private:
127 DISALLOW_COPY_AND_ASSIGN(DownloadJob);
128 };
129
130 } // namespace content
131
132 #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