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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 void StartDownload(int32 id); | 115 void StartDownload(int32 id); |
116 void UpdateDownload(int32 download_id, int64 size); | 116 void UpdateDownload(int32 download_id, int64 size); |
117 | 117 |
118 // |download_id| is the ID of the download. | 118 // |download_id| is the ID of the download. |
119 // |size| is the number of bytes that have been downloaded. | 119 // |size| is the number of bytes that have been downloaded. |
120 // |hash| is sha256 hash for the downloaded file. It is empty when the hash | 120 // |hash| is sha256 hash for the downloaded file. It is empty when the hash |
121 // is not available. | 121 // is not available. |
122 void OnResponseCompleted(int32 download_id, int64 size, | 122 void OnResponseCompleted(int32 download_id, int64 size, |
123 const std::string& hash); | 123 const std::string& hash); |
124 | 124 |
125 // Offthread target for cancelling a particular download. Will be a no-op | |
126 // if the download has already been cancelled. | |
127 void CancelDownload(int32 download_id); | |
128 | |
129 // Called when there is an error in the download. | 125 // Called when there is an error in the download. |
130 // |download_id| is the ID of the download. | 126 // |download_id| is the ID of the download. |
131 // |size| is the number of bytes that are currently downloaded. | 127 // |size| is the number of bytes that are currently downloaded. |
132 // |error| is a download error code. Indicates what caused the interruption. | 128 // |error| is a download error code. Indicates what caused the interruption. |
133 void OnDownloadError(int32 download_id, int64 size, net::Error error); | 129 void OnDownloadError(int32 download_id, int64 size, net::Error error); |
134 | 130 |
135 // Called from DownloadItem to handle the DownloadManager portion of a | 131 // This routine is called from the DownloadItem when a |
136 // Cancel; should not be called from other locations. | 132 // request is cancelled or interrupted. It removes the download |
137 void DownloadCancelledInternal(DownloadItem* download); | 133 // from all internal queues holding in-progress work, and takes care |
| 134 // of the off-thread aspects of the cancel (stopping the request, |
| 135 // cancelling the download on the file thread). |
| 136 void DownloadStopped(DownloadItem* download); |
138 | 137 |
139 // Called from a view when a user clicks a UI button or link. | 138 // Called from DownloadItem when the download is being removed. |
140 void RemoveDownload(int64 download_handle); | 139 // Takes care of all history operations, modifying internal queues, |
| 140 // and notifying DownloadManager observers, and actually deletes |
| 141 // the DownloadItem. |
| 142 void RemoveDownload(DownloadItem* download); |
141 | 143 |
142 // Determine if the download is ready for completion, i.e. has had | 144 // Determine if the download is ready for completion, i.e. has had |
143 // all data saved, and completed the filename determination and | 145 // all data saved, and completed the filename determination and |
144 // history insertion. | 146 // history insertion. |
145 bool IsDownloadReadyForCompletion(DownloadItem* download); | 147 bool IsDownloadReadyForCompletion(DownloadItem* download); |
146 | 148 |
147 // If all pre-requisites have been met, complete download processing, i.e. | 149 // If all pre-requisites have been met, complete download processing, i.e. |
148 // do internal cleanup, file rename, and potentially auto-open. | 150 // do internal cleanup, file rename, and potentially auto-open. |
149 // (Dangerous downloads still may block on user acceptance after this | 151 // (Dangerous downloads still may block on user acceptance after this |
150 // point.) | 152 // point.) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 DownloadItem* GetDownloadItem(int id); | 259 DownloadItem* GetDownloadItem(int id); |
258 | 260 |
259 // Called when Save Page download starts. Transfers ownership of |download| | 261 // Called when Save Page download starts. Transfers ownership of |download| |
260 // to the DownloadManager. | 262 // to the DownloadManager. |
261 void SavePageDownloadStarted(DownloadItem* download); | 263 void SavePageDownloadStarted(DownloadItem* download); |
262 | 264 |
263 // Called when Save Page download is done. | 265 // Called when Save Page download is done. |
264 void SavePageDownloadFinished(DownloadItem* download); | 266 void SavePageDownloadFinished(DownloadItem* download); |
265 | 267 |
266 // Get the download item from the active map. Useful when the item is not | 268 // Get the download item from the active map. Useful when the item is not |
267 // yet in the history map. | 269 // yet in the history map. Returns NULL if no such active download. |
268 DownloadItem* GetActiveDownloadItem(int id); | 270 DownloadItem* GetActiveDownloadItem(int id); |
269 | 271 |
270 DownloadManagerDelegate* delegate() const { return delegate_; } | 272 DownloadManagerDelegate* delegate() const { return delegate_; } |
271 | 273 |
272 private: | 274 private: |
273 typedef std::set<DownloadItem*> DownloadSet; | 275 typedef std::set<DownloadItem*> DownloadSet; |
274 typedef base::hash_map<int64, DownloadItem*> DownloadMap; | 276 typedef base::hash_map<int64, DownloadItem*> DownloadMap; |
275 | 277 |
| 278 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 279 friend class DeleteTask<DownloadManager>; |
| 280 friend class base::RefCountedThreadSafe<DownloadManager, |
| 281 BrowserThread::DeleteOnUIThread>; |
| 282 |
276 // For testing. | 283 // For testing. |
277 friend class DownloadManagerTest; | 284 friend class DownloadManagerTest; |
278 friend class MockDownloadManager; | 285 friend class MockDownloadManager; |
279 friend class DownloadTest; | 286 friend class DownloadTest; |
280 | 287 |
281 friend class base::RefCountedThreadSafe<DownloadManager, | |
282 BrowserThread::DeleteOnUIThread>; | |
283 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | |
284 friend class DeleteTask<DownloadManager>; | |
285 | |
286 void set_delegate(DownloadManagerDelegate* delegate) { delegate_ = delegate; } | 288 void set_delegate(DownloadManagerDelegate* delegate) { delegate_ = delegate; } |
287 | 289 |
288 virtual ~DownloadManager(); | 290 virtual ~DownloadManager(); |
289 | 291 |
290 // Called on the FILE thread to check the existence of a downloaded file. | 292 // Called on the FILE thread to check the existence of a downloaded file. |
291 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); | 293 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); |
292 | 294 |
293 // Called on the UI thread if the FILE thread detects the removal of | 295 // Called on the UI thread if the FILE thread detects the removal of |
294 // the downloaded file. The UI thread updates the state of the file | 296 // the downloaded file. The UI thread updates the state of the file |
295 // and then notifies this update to the file's observer. | 297 // and then notifies this update to the file's observer. |
296 void OnFileRemovalDetected(int64 db_handle); | 298 void OnFileRemovalDetected(int64 db_handle); |
297 | 299 |
298 // Called back after a target path for the file to be downloaded to has been | 300 // Called back after a target path for the file to be downloaded to has been |
299 // determined, either automatically based on the suggested file name, or by | 301 // determined, either automatically based on the suggested file name, or by |
300 // the user in a Save As dialog box. | 302 // the user in a Save As dialog box. |
301 void ContinueDownloadWithPath(DownloadItem* download, | 303 void ContinueDownloadWithPath(DownloadItem* download, |
302 const FilePath& chosen_file); | 304 const FilePath& chosen_file); |
303 | 305 |
304 // Retrieves the download from the |download_id|. | 306 // Retrieves the download from the |download_id|. |
305 // Returns NULL if the download is not active. | 307 // Returns NULL if the download is not active. |
306 DownloadItem* GetActiveDownload(int32 download_id); | 308 DownloadItem* GetActiveDownload(int32 download_id); |
307 | 309 |
308 // Removes |download| from the active and in progress maps. | |
309 // Called when the download is cancelled or has an error. | |
310 // Does nothing if the download is not in the history DB. | |
311 void RemoveFromActiveList(DownloadItem* download); | |
312 | |
313 // Updates the delegate about the overall download progress. | 310 // Updates the delegate about the overall download progress. |
314 void UpdateDownloadProgress(); | 311 void UpdateDownloadProgress(); |
315 | 312 |
316 // Inform observers that the model has changed. | 313 // Inform observers that the model has changed. |
317 void NotifyModelChanged(); | 314 void NotifyModelChanged(); |
318 | 315 |
| 316 // Return all in progress downloads. This includes downloads that |
| 317 // have not yet been entered into the history (all other accessors |
| 318 // only return downloads that have been entered into the history). |
| 319 // This is intended to be used for testing only. |
| 320 void GetInProgressDownloads(std::vector<DownloadItem*>* result); |
| 321 |
319 // Debugging routine to confirm relationship between below | 322 // Debugging routine to confirm relationship between below |
320 // containers; no-op if NDEBUG. | 323 // containers; no-op if NDEBUG. |
321 void AssertContainersConsistent() const; | 324 void AssertContainersConsistent() const; |
322 | 325 |
323 // Add a DownloadItem to history_downloads_. | 326 // Add a DownloadItem to history_downloads_. |
324 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); | 327 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); |
325 | 328 |
326 // Remove from internal maps. | 329 // Remove from internal maps. |
327 int RemoveDownloadItems(const DownloadVector& pending_deletes); | 330 int RemoveDownloadItems(const DownloadVector& pending_deletes); |
328 | 331 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 DownloadManagerDelegate* delegate_; | 402 DownloadManagerDelegate* delegate_; |
400 | 403 |
401 // TODO(rdsmith): Remove when http://crbug.com/84508 is fixed. | 404 // TODO(rdsmith): Remove when http://crbug.com/84508 is fixed. |
402 // For debugging only. | 405 // For debugging only. |
403 int64 largest_db_handle_in_history_; | 406 int64 largest_db_handle_in_history_; |
404 | 407 |
405 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 408 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
406 }; | 409 }; |
407 | 410 |
408 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 411 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |