OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Each download is represented by a DownloadItem, and all DownloadItems | 5 // Each download is represented by a DownloadItem, and all DownloadItems |
6 // are owned by the DownloadManager which maintains a global list of all | 6 // are owned by the DownloadManager which maintains a global list of all |
7 // downloads. DownloadItems are created when a user initiates a download, | 7 // downloads. DownloadItems are created when a user initiates a download, |
8 // and exist for the duration of the browser life time. | 8 // and exist for the duration of the browser life time. |
9 // | 9 // |
10 // Download observers: | 10 // Download observers: |
11 // DownloadItem::Observer: | 11 // DownloadItem::Observer: |
12 // - allows observers to receive notifications about one download from start | 12 // - allows observers to receive notifications about one download from start |
13 // to completion | 13 // to completion |
14 // Use AddObserver() / RemoveObserver() on the appropriate download object to | 14 // Use AddObserver() / RemoveObserver() on the appropriate download object to |
15 // receive state updates. | 15 // receive state updates. |
16 | 16 |
17 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ | 17 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ |
18 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ | 18 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ |
19 | 19 |
20 #include <map> | 20 #include <map> |
21 #include <string> | 21 #include <string> |
22 #include <vector> | 22 #include <vector> |
23 | 23 |
| 24 #include "base/callback_forward.h" |
24 #include "base/files/file_path.h" | 25 #include "base/files/file_path.h" |
25 #include "base/string16.h" | 26 #include "base/string16.h" |
26 #include "base/supports_user_data.h" | 27 #include "base/supports_user_data.h" |
27 #include "content/public/browser/download_danger_type.h" | 28 #include "content/public/browser/download_danger_type.h" |
28 #include "content/public/browser/download_interrupt_reasons.h" | 29 #include "content/public/browser/download_interrupt_reasons.h" |
29 #include "content/public/common/page_transition_types.h" | 30 #include "content/public/common/page_transition_types.h" |
30 | 31 |
31 class GURL; | 32 class GURL; |
32 | 33 |
33 namespace base { | 34 namespace base { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 }; | 75 }; |
75 | 76 |
76 // How the final target path should be used. | 77 // How the final target path should be used. |
77 enum TargetDisposition { | 78 enum TargetDisposition { |
78 TARGET_DISPOSITION_OVERWRITE, // Overwrite if the target already exists. | 79 TARGET_DISPOSITION_OVERWRITE, // Overwrite if the target already exists. |
79 TARGET_DISPOSITION_PROMPT // Prompt the user for the actual | 80 TARGET_DISPOSITION_PROMPT // Prompt the user for the actual |
80 // target. Implies | 81 // target. Implies |
81 // TARGET_DISPOSITION_OVERWRITE. | 82 // TARGET_DISPOSITION_OVERWRITE. |
82 }; | 83 }; |
83 | 84 |
| 85 // Callback used with AcquireFileAndDeleteDownload(). |
| 86 typedef base::Callback<void(const base::FilePath&)> AcquireFileCallback; |
| 87 |
84 static const char kEmptyFileHash[]; | 88 static const char kEmptyFileHash[]; |
85 | 89 |
86 // Interface that observers of a particular download must implement in order | 90 // Interface that observers of a particular download must implement in order |
87 // to receive updates to the download's status. | 91 // to receive updates to the download's status. |
88 class CONTENT_EXPORT Observer { | 92 class CONTENT_EXPORT Observer { |
89 public: | 93 public: |
90 virtual void OnDownloadUpdated(DownloadItem* download) {} | 94 virtual void OnDownloadUpdated(DownloadItem* download) {} |
91 virtual void OnDownloadOpened(DownloadItem* download) {} | 95 virtual void OnDownloadOpened(DownloadItem* download) {} |
92 virtual void OnDownloadRemoved(DownloadItem* download) {} | 96 virtual void OnDownloadRemoved(DownloadItem* download) {} |
93 | 97 |
(...skipping 10 matching lines...) Expand all Loading... |
104 | 108 |
105 // Observation --------------------------------------------------------------- | 109 // Observation --------------------------------------------------------------- |
106 | 110 |
107 virtual void AddObserver(DownloadItem::Observer* observer) = 0; | 111 virtual void AddObserver(DownloadItem::Observer* observer) = 0; |
108 virtual void RemoveObserver(DownloadItem::Observer* observer) = 0; | 112 virtual void RemoveObserver(DownloadItem::Observer* observer) = 0; |
109 virtual void UpdateObservers() = 0; | 113 virtual void UpdateObservers() = 0; |
110 | 114 |
111 // User Actions -------------------------------------------------------------- | 115 // User Actions -------------------------------------------------------------- |
112 | 116 |
113 // Called when the user has validated the download of a dangerous file. | 117 // Called when the user has validated the download of a dangerous file. |
114 virtual void DangerousDownloadValidated() = 0; | 118 virtual void ValidateDangerousDownload() = 0; |
115 | 119 |
116 // Pause a download. Will have no effect if the download is already | 120 // Pause a download. Will have no effect if the download is already |
117 // paused. | 121 // paused. |
118 virtual void Pause() = 0; | 122 virtual void Pause() = 0; |
119 | 123 |
120 // Resume a download that has been paused or interrupted. Will have no effect | 124 // Resume a download that has been paused or interrupted. Will have no effect |
121 // if the download is neither. | 125 // if the download is neither. |
122 virtual void Resume() = 0; | 126 virtual void Resume() = 0; |
123 | 127 |
124 // Cancel the download operation. We need to distinguish between cancels at | 128 // Cancel the download operation. We need to distinguish between cancels at |
125 // exit (DownloadManager destructor) from user interface initiated cancels | 129 // exit (DownloadManager destructor) from user interface initiated cancels |
126 // because at exit, the history system may not exist, and any updates to it | 130 // because at exit, the history system may not exist, and any updates to it |
127 // require AddRef'ing the DownloadManager in the destructor which results in | 131 // require AddRef'ing the DownloadManager in the destructor which results in |
128 // a DCHECK failure. Set |user_cancel| to false when canceling from at | 132 // a DCHECK failure. Set |user_cancel| to false when canceling from at |
129 // exit to prevent this crash. This may result in a difference between the | 133 // exit to prevent this crash. This may result in a difference between the |
130 // downloaded file's size on disk, and what the history system's last record | 134 // downloaded file's size on disk, and what the history system's last record |
131 // of it is. At worst, we'll end up re-downloading a small portion of the file | 135 // of it is. At worst, we'll end up re-downloading a small portion of the file |
132 // when resuming a download (assuming the server supports byte ranges). | 136 // when resuming a download (assuming the server supports byte ranges). |
133 virtual void Cancel(bool user_cancel) = 0; | 137 virtual void Cancel(bool user_cancel) = 0; |
134 | 138 |
135 // Deletes the file from disk and removes the download from the views and | 139 // Deletes the file from disk and removes the download from the views and |
136 // history. | 140 // history. If |callback| is not empty, then the downloaded file will not be |
137 virtual void Delete(DeleteReason reason) = 0; | 141 // deleted. Instead, the path of the file will be passed into |callback|. If |
| 142 // the intermediate file is not available, then the returned path will be |
| 143 // empty. |
| 144 virtual void DiscardDangerousDownload( |
| 145 DeleteReason reason, |
| 146 const AcquireFileCallback& callback) = 0; |
138 | 147 |
139 // Removes the download from the views and history. | 148 // Removes the download from the views and history. |
140 virtual void Remove() = 0; | 149 virtual void Remove() = 0; |
141 | 150 |
142 // Open the file associated with this download. If the download is | 151 // Open the file associated with this download. If the download is |
143 // still in progress, marks the download to be opened when it is complete. | 152 // still in progress, marks the download to be opened when it is complete. |
144 virtual void OpenDownload() = 0; | 153 virtual void OpenDownload() = 0; |
145 | 154 |
146 // Show the download via the OS shell. | 155 // Show the download via the OS shell. |
147 virtual void ShowDownloadInShell() = 0; | 156 virtual void ShowDownloadInShell() = 0; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 virtual const std::string& GetHash() const = 0; | 248 virtual const std::string& GetHash() const = 0; |
240 | 249 |
241 // Intermediate hash state, for persisting partial downloads. | 250 // Intermediate hash state, for persisting partial downloads. |
242 virtual const std::string& GetHashState() const = 0; | 251 virtual const std::string& GetHashState() const = 0; |
243 | 252 |
244 // True if the file associated with the download has been removed by | 253 // True if the file associated with the download has been removed by |
245 // external action. | 254 // external action. |
246 virtual bool GetFileExternallyRemoved() const = 0; | 255 virtual bool GetFileExternallyRemoved() const = 0; |
247 | 256 |
248 // True if the file that will be written by the download is dangerous | 257 // True if the file that will be written by the download is dangerous |
249 // and we will require a call to DangerousDownloadValidated() to complete. | 258 // and we will require a call to ValidateDangerousDownload() to complete. |
250 // False if the download is safe or that function has been called. | 259 // False if the download is safe or that function has been called. |
251 virtual bool IsDangerous() const = 0; | 260 virtual bool IsDangerous() const = 0; |
252 | 261 |
253 // Why |safety_state_| is not SAFE. | 262 // Why |safety_state_| is not SAFE. |
254 virtual DownloadDangerType GetDangerType() const = 0; | 263 virtual DownloadDangerType GetDangerType() const = 0; |
255 | 264 |
256 // Progress State accessors ----------------------------------------------- | 265 // Progress State accessors ----------------------------------------------- |
257 | 266 |
258 // Simple calculation of the amount of time remaining to completion. Fills | 267 // Simple calculation of the amount of time remaining to completion. Fills |
259 // |*remaining| with the amount of time remaining if successful. Fails and | 268 // |*remaining| with the amount of time remaining if successful. Fails and |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // return |name|. Has no effect on the final target filename. | 334 // return |name|. Has no effect on the final target filename. |
326 virtual void SetDisplayName(const base::FilePath& name) = 0; | 335 virtual void SetDisplayName(const base::FilePath& name) = 0; |
327 | 336 |
328 // Debug/testing ------------------------------------------------------------- | 337 // Debug/testing ------------------------------------------------------------- |
329 virtual std::string DebugString(bool verbose) const = 0; | 338 virtual std::string DebugString(bool verbose) const = 0; |
330 }; | 339 }; |
331 | 340 |
332 } // namespace content | 341 } // namespace content |
333 | 342 |
334 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ | 343 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ |
OLD | NEW |