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 // The DownloadManager object manages the process of downloading, including | 5 // The DownloadManager object manages the process of downloading, including |
6 // updates to the history system and providing the information for displaying | 6 // updates to the history system and providing the information for displaying |
7 // the downloads view in the Destinations tab. There is one DownloadManager per | 7 // the downloads view in the Destinations tab. There is one DownloadManager per |
8 // active browser context in Chrome. | 8 // active browser context in Chrome. |
9 // | 9 // |
10 // Download observers: | 10 // Download observers: |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 // Offthread target for cancelling a particular download. Will be a no-op | 118 // Offthread target for cancelling a particular download. Will be a no-op |
119 // if the download has already been cancelled. | 119 // if the download has already been cancelled. |
120 virtual void CancelDownload(int32 download_id) = 0; | 120 virtual void CancelDownload(int32 download_id) = 0; |
121 | 121 |
122 // Called when there is an error in the download. | 122 // Called when there is an error in the download. |
123 // |download_id| is the ID of the download. | 123 // |download_id| is the ID of the download. |
124 // |size| is the number of bytes that are currently downloaded. | 124 // |size| is the number of bytes that are currently downloaded. |
125 // |reason| is a download interrupt reason code. | 125 // |reason| is a download interrupt reason code. |
126 virtual void OnDownloadInterrupted(int32 download_id, int64 size, | 126 virtual void OnDownloadInterrupted(int32 download_id, int64 size, |
127 InterruptReason reason) = 0; | 127 InterruptReason reason) = 0; |
128 | |
129 // Called from DownloadItem to handle the DownloadManager portion of a | |
130 // Cancel; should not be called from other locations. | |
131 virtual void DownloadCancelledInternal(DownloadItem* download) = 0; | |
132 | |
133 // Called from a view when a user clicks a UI button or link. | |
134 virtual void RemoveDownload(int64 download_handle) = 0; | |
135 | |
136 // Determine if the download is ready for completion, i.e. has had | |
137 // all data saved, and completed the filename determination and | |
138 // history insertion. | |
139 virtual bool IsDownloadReadyForCompletion(DownloadItem* download) = 0; | |
140 | |
141 // If all pre-requisites have been met, complete download processing, i.e. | |
142 // do internal cleanup, file rename, and potentially auto-open. | |
143 // (Dangerous downloads still may block on user acceptance after this | |
144 // point.) | |
145 virtual void MaybeCompleteDownload(DownloadItem* download) = 0; | |
146 | 128 |
147 // Called when the download is renamed to its final name. | 129 // Called when the download is renamed to its final name. |
148 // |uniquifier| is a number used to make unique names for the file. It is | 130 // |uniquifier| is a number used to make unique names for the file. It is |
149 // only valid for the DANGEROUS_BUT_VALIDATED state of the download item. | 131 // only valid for the DANGEROUS_BUT_VALIDATED state of the download item. |
150 virtual void OnDownloadRenamedToFinalName(int download_id, | 132 virtual void OnDownloadRenamedToFinalName(int download_id, |
151 const FilePath& full_path, | 133 const FilePath& full_path, |
152 int uniquifier) = 0; | 134 int uniquifier) = 0; |
153 | 135 |
154 // Remove downloads after remove_begin (inclusive) and before remove_end | 136 // Remove downloads after remove_begin (inclusive) and before remove_end |
155 // (exclusive). You may pass in null Time values to do an unbounded delete | 137 // (exclusive). You may pass in null Time values to do an unbounded delete |
156 // in either direction. | 138 // in either direction. |
157 virtual int RemoveDownloadsBetween(const base::Time remove_begin, | 139 virtual int RemoveDownloadsBetween(const base::Time remove_begin, |
158 const base::Time remove_end) = 0; | 140 const base::Time remove_end) = 0; |
159 | 141 |
160 // Remove downloads will delete all downloads that have a timestamp that is | 142 // Remove downloads will delete all downloads that have a timestamp that is |
161 // the same or more recent than |remove_begin|. The number of downloads | 143 // the same or more recent than |remove_begin|. The number of downloads |
162 // deleted is returned back to the caller. | 144 // deleted is returned back to the caller. |
163 virtual int RemoveDownloads(const base::Time remove_begin) = 0; | 145 virtual int RemoveDownloads(const base::Time remove_begin) = 0; |
164 | 146 |
165 // Remove all downloads will delete all downloads. The number of downloads | 147 // Remove all downloads will delete all downloads. The number of downloads |
166 // deleted is returned back to the caller. | 148 // deleted is returned back to the caller. |
167 virtual int RemoveAllDownloads() = 0; | 149 virtual int RemoveAllDownloads() = 0; |
168 | 150 |
169 // Final download manager transition for download: Update the download | |
170 // history and remove the download from |active_downloads_|. | |
171 virtual void DownloadCompleted(int32 download_id) = 0; | |
172 | |
173 // Download the object at the URL. Used in cases such as "Save Link As..." | 151 // Download the object at the URL. Used in cases such as "Save Link As..." |
174 virtual void DownloadUrl(const GURL& url, | 152 virtual void DownloadUrl(const GURL& url, |
175 const GURL& referrer, | 153 const GURL& referrer, |
176 const std::string& referrer_encoding, | 154 const std::string& referrer_encoding, |
177 TabContents* tab_contents) = 0; | 155 TabContents* tab_contents) = 0; |
178 | 156 |
179 // Download the object at the URL and save it to the specified path. The | 157 // Download the object at the URL and save it to the specified path. The |
180 // download is treated as the temporary download and thus will not appear | 158 // download is treated as the temporary download and thus will not appear |
181 // in the download history. Used in cases such as drag and drop. | 159 // in the download history. Used in cases such as drag and drop. |
182 virtual void DownloadUrlToFile(const GURL& url, | 160 virtual void DownloadUrlToFile(const GURL& url, |
(...skipping 11 matching lines...) Expand all Loading... |
194 // Called by the embedder, after creating the download manager, to let it know | 172 // Called by the embedder, after creating the download manager, to let it know |
195 // about downloads from previous runs of the browser. | 173 // about downloads from previous runs of the browser. |
196 virtual void OnPersistentStoreQueryComplete( | 174 virtual void OnPersistentStoreQueryComplete( |
197 std::vector<DownloadPersistentStoreInfo>* entries) = 0; | 175 std::vector<DownloadPersistentStoreInfo>* entries) = 0; |
198 | 176 |
199 // Called by the embedder, in response to | 177 // Called by the embedder, in response to |
200 // DownloadManagerDelegate::AddItemToPersistentStore. | 178 // DownloadManagerDelegate::AddItemToPersistentStore. |
201 virtual void OnItemAddedToPersistentStore(int32 download_id, | 179 virtual void OnItemAddedToPersistentStore(int32 download_id, |
202 int64 db_handle) = 0; | 180 int64 db_handle) = 0; |
203 | 181 |
204 // Display a new download in the appropriate browser UI. | |
205 virtual void ShowDownloadInBrowser(DownloadItem* download) = 0; | |
206 | |
207 // The number of in progress (including paused) downloads. | 182 // The number of in progress (including paused) downloads. |
208 virtual int InProgressCount() const = 0; | 183 virtual int InProgressCount() const = 0; |
209 | 184 |
210 virtual content::BrowserContext* BrowserContext() = 0; | 185 virtual content::BrowserContext* BrowserContext() const = 0; |
211 | 186 |
212 virtual FilePath LastDownloadPath() = 0; | 187 virtual FilePath LastDownloadPath() = 0; |
213 | 188 |
214 // Creates the download item. Must be called on the UI thread. | 189 // Creates the download item. Must be called on the UI thread. |
215 virtual void CreateDownloadItem(DownloadCreateInfo* info, | 190 virtual void CreateDownloadItem( |
216 const DownloadRequestHandle& request_handle) = 0; | 191 DownloadCreateInfo* info, |
| 192 const DownloadRequestHandle& request_handle) = 0; |
| 193 |
| 194 // Creates a download item for the SavePackage system. |
| 195 // Must be called on the UI thread. Note that the DownloadManager |
| 196 // retains ownership. |
| 197 virtual DownloadItem* CreateSavePackageDownloadItem( |
| 198 const FilePath& main_file_path, |
| 199 const GURL& page_url, |
| 200 bool is_otr, |
| 201 DownloadItem::Observer* observer) = 0; |
217 | 202 |
218 // Clears the last download path, used to initialize "save as" dialogs. | 203 // Clears the last download path, used to initialize "save as" dialogs. |
219 virtual void ClearLastDownloadPath() = 0; | 204 virtual void ClearLastDownloadPath() = 0; |
220 | 205 |
221 // Called by the delegate after the save as dialog is closed. | 206 // Called by the delegate after the save as dialog is closed. |
222 virtual void FileSelected(const FilePath& path, void* params) = 0; | 207 virtual void FileSelected(const FilePath& path, void* params) = 0; |
223 virtual void FileSelectionCanceled(void* params) = 0; | 208 virtual void FileSelectionCanceled(void* params) = 0; |
224 | 209 |
225 // Called by the delegate if it delayed the download in | 210 // Called by the delegate if it delayed the download in |
226 // DownloadManagerDelegate::ShouldStartDownload and now is ready. | 211 // DownloadManagerDelegate::ShouldStartDownload and now is ready. |
227 virtual void RestartDownload(int32 download_id) = 0; | 212 virtual void RestartDownload(int32 download_id) = 0; |
228 | 213 |
229 // Mark the download opened in the persistent store. | |
230 virtual void MarkDownloadOpened(DownloadItem* download) = 0; | |
231 | |
232 // Checks whether downloaded files still exist. Updates state of downloads | 214 // Checks whether downloaded files still exist. Updates state of downloads |
233 // that refer to removed files. The check runs in the background and may | 215 // that refer to removed files. The check runs in the background and may |
234 // finish asynchronously after this method returns. | 216 // finish asynchronously after this method returns. |
235 virtual void CheckForHistoryFilesRemoval() = 0; | 217 virtual void CheckForHistoryFilesRemoval() = 0; |
236 | 218 |
237 // Checks whether a downloaded file still exists and updates the file's state | |
238 // if the file is already removed. The check runs in the background and may | |
239 // finish asynchronously after this method returns. | |
240 virtual void CheckForFileRemoval(DownloadItem* download_item) = 0; | |
241 | |
242 // Assert the named download item is on the correct queues | |
243 // in the DownloadManager. For debugging. | |
244 virtual void AssertQueueStateConsistent(DownloadItem* download) = 0; | |
245 | |
246 // Get the download item from the history map. Useful after the item has | 219 // Get the download item from the history map. Useful after the item has |
247 // been removed from the active map, or was retrieved from the history DB. | 220 // been removed from the active map, or was retrieved from the history DB. |
248 virtual DownloadItem* GetDownloadItem(int id) = 0; | 221 virtual DownloadItem* GetDownloadItem(int id) = 0; |
249 | 222 |
250 // Called when Save Page download starts. Transfers ownership of |download| | |
251 // to the DownloadManager. | |
252 virtual void SavePageDownloadStarted(DownloadItem* download) = 0; | |
253 | |
254 // Called when Save Page download is done. | 223 // Called when Save Page download is done. |
255 virtual void SavePageDownloadFinished(DownloadItem* download) = 0; | 224 virtual void SavePageDownloadFinished(DownloadItem* download) = 0; |
256 | 225 |
257 // Get the download item from the active map. Useful when the item is not | 226 // Get the download item from the active map. Useful when the item is not |
258 // yet in the history map. | 227 // yet in the history map. |
259 virtual DownloadItem* GetActiveDownloadItem(int id) = 0; | 228 virtual DownloadItem* GetActiveDownloadItem(int id) = 0; |
260 | 229 |
261 virtual content::DownloadManagerDelegate* delegate() const = 0; | 230 virtual content::DownloadManagerDelegate* delegate() const = 0; |
262 | 231 |
263 // For testing only. May be called from tests indirectly (through | 232 // For testing only. May be called from tests indirectly (through |
264 // other for testing only methods). | 233 // other for testing only methods). |
265 virtual void SetDownloadManagerDelegate( | 234 virtual void SetDownloadManagerDelegate( |
266 content::DownloadManagerDelegate* delegate) = 0; | 235 content::DownloadManagerDelegate* delegate) = 0; |
267 | 236 |
268 virtual DownloadId GetNextId() = 0; | |
269 | |
270 protected: | 237 protected: |
271 // These functions are here for unit tests. | 238 // These functions are here for unit tests. |
272 | 239 |
273 // Called back after a target path for the file to be downloaded to has been | 240 // Called back after a target path for the file to be downloaded to has been |
274 // determined, either automatically based on the suggested file name, or by | 241 // determined, either automatically based on the suggested file name, or by |
275 // the user in a Save As dialog box. | 242 // the user in a Save As dialog box. |
276 virtual void ContinueDownloadWithPath(DownloadItem* download, | 243 virtual void ContinueDownloadWithPath(DownloadItem* download, |
277 const FilePath& chosen_file) = 0; | 244 const FilePath& chosen_file) = 0; |
278 | 245 |
279 // Retrieves the download from the |download_id|. | 246 // Retrieves the download from the |download_id|. |
280 // Returns NULL if the download is not active. | 247 // Returns NULL if the download is not active. |
281 virtual DownloadItem* GetActiveDownload(int32 download_id) = 0; | 248 virtual DownloadItem* GetActiveDownload(int32 download_id) = 0; |
282 | 249 |
283 virtual void SetFileManager(DownloadFileManager* file_manager) = 0; | 250 virtual void SetFileManager(DownloadFileManager* file_manager) = 0; |
284 | 251 |
285 private: | 252 private: |
286 // For testing. | 253 // For testing. |
287 friend class DownloadManagerTest; | 254 friend class DownloadManagerTest; |
288 | 255 |
289 friend class base::RefCountedThreadSafe< | 256 friend class base::RefCountedThreadSafe< |
290 DownloadManager, content::BrowserThread::DeleteOnUIThread>; | 257 DownloadManager, content::BrowserThread::DeleteOnUIThread>; |
291 friend struct content::BrowserThread::DeleteOnThread< | 258 friend struct content::BrowserThread::DeleteOnThread< |
292 content::BrowserThread::UI>; | 259 content::BrowserThread::UI>; |
293 friend class DeleteTask<DownloadManager>; | 260 friend class DeleteTask<DownloadManager>; |
294 }; | 261 }; |
295 | 262 |
296 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 263 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |