| 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/file_path.h" | 24 #include "base/file_path.h" |
| 25 #include "base/string16.h" | 25 #include "base/string16.h" |
| 26 #include "base/supports_user_data.h" |
| 26 #include "content/public/browser/download_danger_type.h" | 27 #include "content/public/browser/download_danger_type.h" |
| 27 #include "content/public/browser/download_interrupt_reasons.h" | 28 #include "content/public/browser/download_interrupt_reasons.h" |
| 28 #include "content/public/common/page_transition_types.h" | 29 #include "content/public/common/page_transition_types.h" |
| 29 | 30 |
| 30 class FilePath; | 31 class FilePath; |
| 31 class GURL; | 32 class GURL; |
| 32 struct DownloadCreateInfo; | 33 struct DownloadCreateInfo; |
| 33 | 34 |
| 34 namespace base { | 35 namespace base { |
| 35 class Time; | 36 class Time; |
| 36 class TimeDelta; | 37 class TimeDelta; |
| 37 } | 38 } |
| 38 | 39 |
| 39 namespace content { | 40 namespace content { |
| 40 | 41 |
| 41 class BrowserContext; | 42 class BrowserContext; |
| 42 class DownloadId; | 43 class DownloadId; |
| 43 class DownloadManager; | 44 class DownloadManager; |
| 44 class WebContents; | 45 class WebContents; |
| 45 struct DownloadPersistentStoreInfo; | 46 struct DownloadPersistentStoreInfo; |
| 46 | 47 |
| 47 // One DownloadItem per download. This is the model class that stores all the | 48 // One DownloadItem per download. This is the model class that stores all the |
| 48 // state for a download. Multiple views, such as a tab's download shelf and the | 49 // state for a download. Multiple views, such as a tab's download shelf and the |
| 49 // Destination tab's download view, may refer to a given DownloadItem. | 50 // Destination tab's download view, may refer to a given DownloadItem. |
| 50 // | 51 // |
| 51 // This is intended to be used only on the UI thread. | 52 // This is intended to be used only on the UI thread. |
| 52 class CONTENT_EXPORT DownloadItem { | 53 class CONTENT_EXPORT DownloadItem : public base::SupportsUserData { |
| 53 public: | 54 public: |
| 54 enum DownloadState { | 55 enum DownloadState { |
| 55 // Download is actively progressing. | 56 // Download is actively progressing. |
| 56 IN_PROGRESS = 0, | 57 IN_PROGRESS = 0, |
| 57 | 58 |
| 58 // Download is completely finished. | 59 // Download is completely finished. |
| 59 COMPLETE, | 60 COMPLETE, |
| 60 | 61 |
| 61 // Download has been cancelled. | 62 // Download has been cancelled. |
| 62 CANCELLED, | 63 CANCELLED, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 public: | 105 public: |
| 105 virtual void OnDownloadUpdated(DownloadItem* download) = 0; | 106 virtual void OnDownloadUpdated(DownloadItem* download) = 0; |
| 106 | 107 |
| 107 // Called when a downloaded file has been opened. | 108 // Called when a downloaded file has been opened. |
| 108 virtual void OnDownloadOpened(DownloadItem* download) = 0; | 109 virtual void OnDownloadOpened(DownloadItem* download) = 0; |
| 109 | 110 |
| 110 protected: | 111 protected: |
| 111 virtual ~Observer() {} | 112 virtual ~Observer() {} |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 // Interface for data that can be stored associated with (and owned | |
| 115 // by) an object of this class via GetExternalData/SetExternalData. | |
| 116 class ExternalData { | |
| 117 public: | |
| 118 virtual ~ExternalData() {}; | |
| 119 }; | |
| 120 | |
| 121 virtual ~DownloadItem() {} | 115 virtual ~DownloadItem() {} |
| 122 | 116 |
| 123 virtual void AddObserver(DownloadItem::Observer* observer) = 0; | 117 virtual void AddObserver(DownloadItem::Observer* observer) = 0; |
| 124 virtual void RemoveObserver(DownloadItem::Observer* observer) = 0; | 118 virtual void RemoveObserver(DownloadItem::Observer* observer) = 0; |
| 125 | 119 |
| 126 // Notifies our observers periodically. | 120 // Notifies our observers periodically. |
| 127 virtual void UpdateObservers() = 0; | 121 virtual void UpdateObservers() = 0; |
| 128 | 122 |
| 129 // Returns true if it is OK to open a folder which this file is inside. | 123 // Returns true if it is OK to open a folder which this file is inside. |
| 130 virtual bool CanShowInFolder() = 0; | 124 virtual bool CanShowInFolder() = 0; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 // Set a display name for the download that will be independent of the target | 278 // Set a display name for the download that will be independent of the target |
| 285 // filename. If |name| is not empty, then GetFileNameToReportUser() will | 279 // filename. If |name| is not empty, then GetFileNameToReportUser() will |
| 286 // return |name|. Has no effect on the final target filename. | 280 // return |name|. Has no effect on the final target filename. |
| 287 virtual void SetDisplayName(const FilePath& name) = 0; | 281 virtual void SetDisplayName(const FilePath& name) = 0; |
| 288 | 282 |
| 289 // Returns the user-verified target file path for the download. | 283 // Returns the user-verified target file path for the download. |
| 290 // This returns the same path as GetTargetFilePath() for safe downloads | 284 // This returns the same path as GetTargetFilePath() for safe downloads |
| 291 // but does not for dangerous downloads until the name is verified. | 285 // but does not for dangerous downloads until the name is verified. |
| 292 virtual FilePath GetUserVerifiedFilePath() const = 0; | 286 virtual FilePath GetUserVerifiedFilePath() const = 0; |
| 293 | 287 |
| 294 // Manage data owned by other subsystems associated with the | |
| 295 // DownloadItem. By custom, key is the address of a | |
| 296 // static char subsystem_specific_string[] = ".."; defined | |
| 297 // in the subsystem, but the only requirement of this interface | |
| 298 // is that the key be unique over all data stored with this | |
| 299 // DownloadItem. | |
| 300 // | |
| 301 // Note that SetExternalData takes ownership of the | |
| 302 // passed object; it will be destroyed when the DownloadItem is. | |
| 303 // If an object is already held by the DownloadItem associated with | |
| 304 // the passed key, it will be destroyed if overwriten by a new pointer | |
| 305 // (overwrites by the same pointer are ignored). | |
| 306 virtual ExternalData* GetExternalData(const void* key) = 0; | |
| 307 virtual const ExternalData* GetExternalData(const void* key) const = 0; | |
| 308 virtual void SetExternalData(const void* key, ExternalData* data) = 0; | |
| 309 | |
| 310 virtual std::string DebugString(bool verbose) const = 0; | 288 virtual std::string DebugString(bool verbose) const = 0; |
| 311 | 289 |
| 312 virtual void MockDownloadOpenForTesting() = 0; | 290 virtual void MockDownloadOpenForTesting() = 0; |
| 313 }; | 291 }; |
| 314 | 292 |
| 315 } // namespace content | 293 } // namespace content |
| 316 | 294 |
| 317 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ | 295 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ |
| OLD | NEW |