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