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