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 <map> | |
21 #include <string> | 22 #include <string> |
22 | 23 |
23 #include "base/string16.h" | 24 #include "base/string16.h" |
24 #include "content/browser/download/download_state_info.h" | 25 #include "content/browser/download/download_state_info.h" |
25 #include "content/browser/download/interrupt_reasons.h" | 26 #include "content/browser/download/interrupt_reasons.h" |
26 | 27 |
27 class DownloadId; | 28 class DownloadId; |
28 class DownloadFileManager; | 29 class DownloadFileManager; |
29 class DownloadManager; | 30 class DownloadManager; |
30 class FilePath; | 31 class FilePath; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 public: | 94 public: |
94 virtual void OnDownloadUpdated(DownloadItem* download) = 0; | 95 virtual void OnDownloadUpdated(DownloadItem* download) = 0; |
95 | 96 |
96 // Called when a downloaded file has been opened. | 97 // Called when a downloaded file has been opened. |
97 virtual void OnDownloadOpened(DownloadItem* download) = 0; | 98 virtual void OnDownloadOpened(DownloadItem* download) = 0; |
98 | 99 |
99 protected: | 100 protected: |
100 virtual ~Observer() {} | 101 virtual ~Observer() {} |
101 }; | 102 }; |
102 | 103 |
104 // Interface for data that can be stored associated with (and owned | |
105 // by) an object of this class via GetExternalData/SetExternalData. | |
106 class ExternalData { | |
107 public: | |
108 virtual ~ExternalData() {}; | |
109 }; | |
110 | |
103 virtual ~DownloadItem(); | 111 virtual ~DownloadItem(); |
104 | 112 |
105 virtual void AddObserver(DownloadItem::Observer* observer) = 0; | 113 virtual void AddObserver(DownloadItem::Observer* observer) = 0; |
106 virtual void RemoveObserver(DownloadItem::Observer* observer) = 0; | 114 virtual void RemoveObserver(DownloadItem::Observer* observer) = 0; |
107 | 115 |
108 // Notifies our observers periodically. | 116 // Notifies our observers periodically. |
109 virtual void UpdateObservers() = 0; | 117 virtual void UpdateObservers() = 0; |
110 | 118 |
111 // Returns true if it is OK to open a folder which this file is inside. | 119 // Returns true if it is OK to open a folder which this file is inside. |
112 virtual bool CanShowInFolder() = 0; | 120 virtual bool CanShowInFolder() = 0; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 virtual bool NeedsRename() const = 0; | 309 virtual bool NeedsRename() const = 0; |
302 | 310 |
303 // Cancels the off-thread aspects of the download. | 311 // Cancels the off-thread aspects of the download. |
304 // TODO(rdsmith): This should be private and only called from | 312 // TODO(rdsmith): This should be private and only called from |
305 // DownloadItem::Cancel/Interrupt; it isn't now because we can't | 313 // DownloadItem::Cancel/Interrupt; it isn't now because we can't |
306 // call those functions from | 314 // call those functions from |
307 // DownloadManager::FileSelectionCancelled() without doing some | 315 // DownloadManager::FileSelectionCancelled() without doing some |
308 // rewrites of the DownloadManager queues. | 316 // rewrites of the DownloadManager queues. |
309 virtual void OffThreadCancel(DownloadFileManager* file_manager) = 0; | 317 virtual void OffThreadCancel(DownloadFileManager* file_manager) = 0; |
310 | 318 |
319 // Manage data owned by other subsystems associated with the | |
320 // DownloadItem. By custom, key is the address of a | |
321 // static char subsystem_specific_string[] = ".."; defined | |
322 // in the subsystem, but the only requirement of this interface | |
323 // is that the key be unique over all data stored with this | |
324 // DownloadItem. | |
325 // | |
326 // Note that SetExternalData takes ownership of the | |
327 // passed object; it will be destroyed when the DownloadItem is. | |
328 // If an object is already held by the DownloadItem associated with | |
329 // the passed key, it will be destroyed on overwrite. | |
asanka
2011/12/07 04:10:57
Nit: Should this mention the behavior when the obj
Randy Smith (Not in Mondays)
2011/12/07 18:36:12
Done.
| |
330 virtual ExternalData* GetExternalData(const void* key) = 0; | |
331 virtual void SetExternalData(const void* key, ExternalData* data) = 0; | |
332 | |
311 virtual std::string DebugString(bool verbose) const = 0; | 333 virtual std::string DebugString(bool verbose) const = 0; |
312 | 334 |
313 virtual void MockDownloadOpenForTesting() = 0; | 335 virtual void MockDownloadOpenForTesting() = 0; |
314 }; | 336 }; |
315 | 337 |
316 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 338 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
OLD | NEW |