OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 17 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
18 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 18 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
19 #pragma once | 19 #pragma once |
20 | 20 |
21 #include <string> | 21 #include <string> |
22 | 22 |
23 #include "base/string16.h" | 23 #include "base/string16.h" |
24 #include "content/browser/download/download_state_info.h" | 24 #include "content/browser/download/download_state_info.h" |
25 #include "content/browser/download/interrupt_reasons.h" | 25 #include "content/browser/download/interrupt_reasons.h" |
26 | 26 |
| 27 class DownloadFileManager; |
27 class DownloadId; | 28 class DownloadId; |
28 class DownloadFileManager; | |
29 class DownloadManager; | 29 class DownloadManager; |
30 class FilePath; | 30 class FilePath; |
31 class GURL; | 31 class GURL; |
32 class TabContents; | 32 class TabContents; |
33 struct DownloadCreateInfo; | 33 struct DownloadCreateInfo; |
34 struct DownloadPersistentStoreInfo; | 34 struct DownloadPersistentStoreInfo; |
35 namespace base { | 35 namespace base { |
36 class Time; | 36 class Time; |
37 class TimeDelta; | 37 class TimeDelta; |
38 } | 38 } |
39 | 39 |
40 namespace content { | |
41 class BrowserContext; | |
42 } | |
43 | |
44 // One DownloadItem per download. This is the model class that stores all the | 40 // One DownloadItem per download. This is the model class that stores all the |
45 // state for a download. Multiple views, such as a tab's download shelf and the | 41 // state for a download. Multiple views, such as a tab's download shelf and the |
46 // Destination tab's download view, may refer to a given DownloadItem. | 42 // Destination tab's download view, may refer to a given DownloadItem. |
47 // | 43 // |
48 // This is intended to be used only on the UI thread. | 44 // This is intended to be used only on the UI thread. |
49 class CONTENT_EXPORT DownloadItem { | 45 class CONTENT_EXPORT DownloadItem { |
50 public: | 46 public: |
51 enum DownloadState { | 47 enum DownloadState { |
52 // Download is actively progressing. | 48 // Download is actively progressing. |
53 IN_PROGRESS = 0, | 49 IN_PROGRESS = 0, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // Called by the delegate after it delayed opening the download in | 146 // Called by the delegate after it delayed opening the download in |
151 // DownloadManagerDelegate::ShouldOpenDownload. | 147 // DownloadManagerDelegate::ShouldOpenDownload. |
152 virtual void DelayedDownloadOpened() = 0; | 148 virtual void DelayedDownloadOpened() = 0; |
153 | 149 |
154 // Called when all data has been saved. Only has display effects. | 150 // Called when all data has been saved. Only has display effects. |
155 virtual void OnAllDataSaved(int64 size, const std::string& final_hash) = 0; | 151 virtual void OnAllDataSaved(int64 size, const std::string& final_hash) = 0; |
156 | 152 |
157 // Called when the downloaded file is removed. | 153 // Called when the downloaded file is removed. |
158 virtual void OnDownloadedFileRemoved() = 0; | 154 virtual void OnDownloadedFileRemoved() = 0; |
159 | 155 |
160 // If all pre-requisites have been met, complete download processing, i.e. | |
161 // do internal cleanup, file rename, and potentially auto-open. | |
162 // (Dangerous downloads still may block on user acceptance after this | |
163 // point.) | |
164 virtual void MaybeCompleteDownload() = 0; | |
165 | |
166 // Download operation had an error. | 156 // Download operation had an error. |
167 // |size| is the amount of data received at interruption. | 157 // |size| is the amount of data received at interruption. |
168 // |reason| is the download interrupt reason code that the operation received. | 158 // |reason| is the download interrupt reason code that the operation received. |
169 virtual void Interrupted(int64 size, InterruptReason reason) = 0; | 159 virtual void Interrupted(int64 size, InterruptReason reason) = 0; |
170 | 160 |
171 // Deletes the file from disk and removes the download from the views and | 161 // Deletes the file from disk and removes the download from the views and |
172 // history. |user| should be true if this is the result of the user clicking | 162 // history. |user| should be true if this is the result of the user clicking |
173 // the discard button, and false if it is being deleted for other reasons like | 163 // the discard button, and false if it is being deleted for other reasons like |
174 // browser shutdown. | 164 // browser shutdown. |
175 virtual void Delete(DeleteReason reason) = 0; | 165 virtual void Delete(DeleteReason reason) = 0; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 virtual std::string GetReferrerCharset() const = 0; | 240 virtual std::string GetReferrerCharset() const = 0; |
251 virtual int64 GetTotalBytes() const = 0; | 241 virtual int64 GetTotalBytes() const = 0; |
252 virtual void SetTotalBytes(int64 total_bytes) = 0; | 242 virtual void SetTotalBytes(int64 total_bytes) = 0; |
253 virtual int64 GetReceivedBytes() const = 0; | 243 virtual int64 GetReceivedBytes() const = 0; |
254 virtual int32 GetId() const = 0; | 244 virtual int32 GetId() const = 0; |
255 virtual DownloadId GetGlobalId() const = 0; | 245 virtual DownloadId GetGlobalId() const = 0; |
256 virtual base::Time GetStartTime() const = 0; | 246 virtual base::Time GetStartTime() const = 0; |
257 virtual base::Time GetEndTime() const = 0; | 247 virtual base::Time GetEndTime() const = 0; |
258 virtual void SetDbHandle(int64 handle) = 0; | 248 virtual void SetDbHandle(int64 handle) = 0; |
259 virtual int64 GetDbHandle() const = 0; | 249 virtual int64 GetDbHandle() const = 0; |
| 250 virtual DownloadManager* GetDownloadManager() = 0; |
260 virtual bool IsPaused() const = 0; | 251 virtual bool IsPaused() const = 0; |
261 virtual bool GetOpenWhenComplete() const = 0; | 252 virtual bool GetOpenWhenComplete() const = 0; |
262 virtual void SetOpenWhenComplete(bool open) = 0; | 253 virtual void SetOpenWhenComplete(bool open) = 0; |
263 virtual bool GetFileExternallyRemoved() const = 0; | 254 virtual bool GetFileExternallyRemoved() const = 0; |
264 virtual SafetyState GetSafetyState() const = 0; | 255 virtual SafetyState GetSafetyState() const = 0; |
265 // Why |safety_state_| is not SAFE. | 256 // Why |safety_state_| is not SAFE. |
266 virtual DownloadStateInfo::DangerType GetDangerType() const = 0; | 257 virtual DownloadStateInfo::DangerType GetDangerType() const = 0; |
267 virtual bool IsDangerous() const = 0; | 258 virtual bool IsDangerous() const = 0; |
268 virtual void MarkContentDangerous() = 0; | 259 virtual void MarkContentDangerous() = 0; |
269 virtual void MarkFileDangerous() = 0; | 260 virtual void MarkFileDangerous() = 0; |
270 virtual void MarkUrlDangerous() = 0; | 261 virtual void MarkUrlDangerous() = 0; |
271 | 262 |
272 virtual bool GetAutoOpened() = 0; | 263 virtual bool GetAutoOpened() = 0; |
273 virtual const FilePath& GetTargetName() const = 0; | 264 virtual const FilePath& GetTargetName() const = 0; |
274 virtual bool PromptUserForSaveLocation() const = 0; | 265 virtual bool PromptUserForSaveLocation() const = 0; |
275 virtual bool IsOtr() const = 0; | 266 virtual bool IsOtr() const = 0; |
276 virtual const FilePath& GetSuggestedPath() const = 0; | 267 virtual const FilePath& GetSuggestedPath() const = 0; |
277 virtual bool IsTemporary() const = 0; | 268 virtual bool IsTemporary() const = 0; |
278 virtual void SetOpened(bool opened) = 0; | 269 virtual void SetOpened(bool opened) = 0; |
279 virtual bool GetOpened() const = 0; | 270 virtual bool GetOpened() const = 0; |
280 | 271 |
281 virtual InterruptReason GetLastReason() const = 0; | 272 virtual InterruptReason GetLastReason() const = 0; |
282 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const = 0; | 273 virtual DownloadPersistentStoreInfo GetPersistentStoreInfo() const = 0; |
283 virtual DownloadStateInfo GetStateInfo() const = 0; | 274 virtual DownloadStateInfo GetStateInfo() const = 0; |
284 virtual content::BrowserContext* BrowserContext() const = 0; | |
285 virtual TabContents* GetTabContents() const = 0; | 275 virtual TabContents* GetTabContents() const = 0; |
286 | 276 |
287 // Returns the final target file path for the download. | 277 // Returns the final target file path for the download. |
288 virtual FilePath GetTargetFilePath() const = 0; | 278 virtual FilePath GetTargetFilePath() const = 0; |
289 | 279 |
290 // Returns the file-name that should be reported to the user, which is | 280 // Returns the file-name that should be reported to the user, which is |
291 // target_name possibly with the uniquifier number. | 281 // target_name possibly with the uniquifier number. |
292 virtual FilePath GetFileNameToReportUser() const = 0; | 282 virtual FilePath GetFileNameToReportUser() const = 0; |
293 | 283 |
294 // Returns the user-verified target file path for the download. | 284 // Returns the user-verified target file path for the download. |
(...skipping 11 matching lines...) Expand all Loading... |
306 // DownloadManager::FileSelectionCancelled() without doing some | 296 // DownloadManager::FileSelectionCancelled() without doing some |
307 // rewrites of the DownloadManager queues. | 297 // rewrites of the DownloadManager queues. |
308 virtual void OffThreadCancel(DownloadFileManager* file_manager) = 0; | 298 virtual void OffThreadCancel(DownloadFileManager* file_manager) = 0; |
309 | 299 |
310 virtual std::string DebugString(bool verbose) const = 0; | 300 virtual std::string DebugString(bool verbose) const = 0; |
311 | 301 |
312 virtual void MockDownloadOpenForTesting() = 0; | 302 virtual void MockDownloadOpenForTesting() = 0; |
313 }; | 303 }; |
314 | 304 |
315 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 305 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
OLD | NEW |