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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 // exit to prevent this crash. This may result in a difference between the | 137 // exit to prevent this crash. This may result in a difference between the |
134 // downloaded file's size on disk, and what the history system's last record | 138 // downloaded file's size on disk, and what the history system's last record |
135 // of it is. At worst, we'll end up re-downloading a small portion of the file | 139 // of it is. At worst, we'll end up re-downloading a small portion of the file |
136 // when resuming a download (assuming the server supports byte ranges). | 140 // when resuming a download (assuming the server supports byte ranges). |
137 virtual void Cancel(bool user_cancel) = 0; | 141 virtual void Cancel(bool user_cancel) = 0; |
138 | 142 |
139 // Deletes the file from disk and removes the download from the views and | 143 // Deletes the file from disk and removes the download from the views and |
140 // history. | 144 // history. |
141 virtual void Delete(DeleteReason reason) = 0; | 145 virtual void Delete(DeleteReason reason) = 0; |
142 | 146 |
147 // Acquires the download file and deletes the download. Equivalent to calling | |
148 // |Delete(DELETE_DUE_TO_USER_DISCARD)| with the exception that the download | |
149 // file isn't deleted. The path to the file is passed to the |callback|. If | |
150 // the downloaded file is not available, then returned path will be empty. | |
151 virtual void AcquireFileAndDeleteDownload( | |
benjhayden
2013/05/14 20:48:05
Method names containing "And" generally signal to
asanka
2013/05/14 21:14:34
The intention is for this operation to be atomic.
| |
152 const AcquireFileCallback& callback) = 0; | |
153 | |
143 // Removes the download from the views and history. | 154 // Removes the download from the views and history. |
144 virtual void Remove() = 0; | 155 virtual void Remove() = 0; |
145 | 156 |
146 // Open the file associated with this download. If the download is | 157 // Open the file associated with this download. If the download is |
147 // still in progress, marks the download to be opened when it is complete. | 158 // still in progress, marks the download to be opened when it is complete. |
148 virtual void OpenDownload() = 0; | 159 virtual void OpenDownload() = 0; |
149 | 160 |
150 // Show the download via the OS shell. | 161 // Show the download via the OS shell. |
151 virtual void ShowDownloadInShell() = 0; | 162 virtual void ShowDownloadInShell() = 0; |
152 | 163 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 // return |name|. Has no effect on the final target filename. | 335 // return |name|. Has no effect on the final target filename. |
325 virtual void SetDisplayName(const base::FilePath& name) = 0; | 336 virtual void SetDisplayName(const base::FilePath& name) = 0; |
326 | 337 |
327 // Debug/testing ------------------------------------------------------------- | 338 // Debug/testing ------------------------------------------------------------- |
328 virtual std::string DebugString(bool verbose) const = 0; | 339 virtual std::string DebugString(bool verbose) const = 0; |
329 }; | 340 }; |
330 | 341 |
331 } // namespace content | 342 } // namespace content |
332 | 343 |
333 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ | 344 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_ITEM_H_ |
OLD | NEW |