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 profile in Chrome. | 8 // active profile in Chrome. |
9 // | 9 // |
10 // Download observers: | 10 // Download observers: |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 bool Init(Profile* profile); | 115 bool Init(Profile* profile); |
116 | 116 |
117 // Notifications sent from the download thread to the UI thread | 117 // Notifications sent from the download thread to the UI thread |
118 void StartDownload(int32 id); | 118 void StartDownload(int32 id); |
119 void UpdateDownload(int32 download_id, int64 size); | 119 void UpdateDownload(int32 download_id, int64 size); |
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, int os_error, | 122 void OnResponseCompleted(int32 download_id, int64 size, int os_error, |
123 const std::string& hash); | 123 const std::string& hash); |
124 | 124 |
125 // Called from a view when a user clicks a UI button or link. | 125 // Called to initiate download cancel on behalf of an off-thread portion |
126 void DownloadCancelled(int32 download_id); | 126 // of the download system; redirects to DownloadItem. |
127 void RemoveDownload(int64 download_handle); | 127 void CancelDownload(int32 download_handle); |
128 | |
129 // This routine is called from the DownloadItem when a | |
130 // request is cancelled or interrupted. It removes the download | |
131 // from all internal queues, and takes care of the off-thread aspects | |
Randy Smith (Not in Mondays)
2011/06/30 23:05:13
Not all internal queues, just the ones representin
Randy Smith (Not in Mondays)
2011/07/05 20:28:44
Done.
| |
132 // of the cancel (stopping the request, cancelling the download on | |
133 // the file thread). | |
134 void DownloadStopped(int32 download_id); | |
135 | |
136 // Called from DownloadItem when the download is being removed. | |
Randy Smith (Not in Mondays)
2011/06/30 23:05:13
A bit more detail as to what it does.
Randy Smith (Not in Mondays)
2011/07/05 20:28:44
Done.
| |
137 void RemoveDownload(DownloadItem* download); | |
128 | 138 |
129 // Determine if the download is ready for completion, i.e. has had | 139 // Determine if the download is ready for completion, i.e. has had |
130 // all data saved, and completed the filename determination and | 140 // all data saved, and completed the filename determination and |
131 // history insertion. | 141 // history insertion. |
132 bool IsDownloadReadyForCompletion(DownloadItem* download); | 142 bool IsDownloadReadyForCompletion(DownloadItem* download); |
133 | 143 |
134 // If all pre-requisites have been met, complete download processing, i.e. | 144 // If all pre-requisites have been met, complete download processing, i.e. |
135 // do internal cleanup, file rename, and potentially auto-open. | 145 // do internal cleanup, file rename, and potentially auto-open. |
136 // (Dangerous downloads still may block on user acceptance after this | 146 // (Dangerous downloads still may block on user acceptance after this |
137 // point.) | 147 // point.) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 | 269 |
260 // Assert the named download item is on the correct queues | 270 // Assert the named download item is on the correct queues |
261 // in the DownloadManager. For debugging. | 271 // in the DownloadManager. For debugging. |
262 void AssertQueueStateConsistent(DownloadItem* download); | 272 void AssertQueueStateConsistent(DownloadItem* download); |
263 | 273 |
264 // Get the download item from the history map. Useful after the item has | 274 // Get the download item from the history map. Useful after the item has |
265 // been removed from the active map, or was retrieved from the history DB. | 275 // been removed from the active map, or was retrieved from the history DB. |
266 DownloadItem* GetDownloadItem(int id); | 276 DownloadItem* GetDownloadItem(int id); |
267 | 277 |
268 private: | 278 private: |
269 // For testing. | |
270 friend class DownloadManagerTest; | |
271 friend class MockDownloadManager; | |
272 | |
273 // This class is used to let an incognito DownloadManager observe changes to | 279 // This class is used to let an incognito DownloadManager observe changes to |
274 // a normal DownloadManager, to propagate ModelChanged() calls from the parent | 280 // a normal DownloadManager, to propagate ModelChanged() calls from the parent |
275 // DownloadManager to the observers of the incognito DownloadManager. | 281 // DownloadManager to the observers of the incognito DownloadManager. |
276 class OtherDownloadManagerObserver : public Observer { | 282 class OtherDownloadManagerObserver : public Observer { |
277 public: | 283 public: |
278 explicit OtherDownloadManagerObserver( | 284 explicit OtherDownloadManagerObserver( |
279 DownloadManager* observing_download_manager); | 285 DownloadManager* observing_download_manager); |
280 virtual ~OtherDownloadManagerObserver(); | 286 virtual ~OtherDownloadManagerObserver(); |
281 | 287 |
282 // Observer interface. | 288 // Observer interface. |
283 virtual void ModelChanged(); | 289 virtual void ModelChanged(); |
284 virtual void ManagerGoingDown(); | 290 virtual void ManagerGoingDown(); |
285 | 291 |
286 private: | 292 private: |
287 // The incognito download manager. | 293 // The incognito download manager. |
288 DownloadManager* observing_download_manager_; | 294 DownloadManager* observing_download_manager_; |
289 | 295 |
290 // The original profile's download manager. | 296 // The original profile's download manager. |
291 DownloadManager* observed_download_manager_; | 297 DownloadManager* observed_download_manager_; |
292 }; | 298 }; |
293 | 299 |
294 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 300 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
295 friend class DeleteTask<DownloadManager>; | 301 friend class DeleteTask<DownloadManager>; |
296 friend class OtherDownloadManagerObserver; | 302 friend class OtherDownloadManagerObserver; |
297 | 303 |
304 // For testing. | |
305 friend class DownloadManagerTest; | |
306 friend class MockDownloadManager; | |
307 FRIEND_TEST_ALL_PREFIXES(DownloadTest, CancelFromFileSelection); | |
308 FRIEND_TEST_ALL_PREFIXES(DownloadTest, RemoveFromFileSelection); | |
309 FRIEND_TEST_ALL_PREFIXES(DownloadTest, InterruptFromFileSelection); | |
310 | |
298 virtual ~DownloadManager(); | 311 virtual ~DownloadManager(); |
299 | 312 |
300 // Called on the FILE thread to check the existence of a downloaded file. | 313 // Called on the FILE thread to check the existence of a downloaded file. |
301 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); | 314 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); |
302 | 315 |
303 // Called on the UI thread if the FILE thread detects the removal of | 316 // Called on the UI thread if the FILE thread detects the removal of |
304 // the downloaded file. The UI thread updates the state of the file | 317 // the downloaded file. The UI thread updates the state of the file |
305 // and then notifies this update to the file's observer. | 318 // and then notifies this update to the file's observer. |
306 void OnFileRemovalDetected(int64 db_handle); | 319 void OnFileRemovalDetected(int64 db_handle); |
307 | 320 |
308 // Called on the download thread to check whether the suggested file path | 321 // Called on the download thread to check whether the suggested file path |
309 // exists. We don't check if the file exists on the UI thread to avoid UI | 322 // exists. We don't check if the file exists on the UI thread to avoid UI |
310 // stalls from interacting with the file system. | 323 // stalls from interacting with the file system. |
311 void CheckIfSuggestedPathExists(int32 download_id, | 324 void CheckIfSuggestedPathExists(int32 download_id, |
312 DownloadStateInfo state, | 325 DownloadStateInfo state, |
313 const FilePath& default_path); | 326 const FilePath& default_path); |
314 | 327 |
315 // Called on the UI thread once the DownloadManager has determined whether the | 328 // Called on the UI thread once the DownloadManager has determined whether the |
316 // suggested file path exists. | 329 // suggested file path exists. |
317 void OnPathExistenceAvailable(int32 download_id, | 330 void OnPathExistenceAvailable(int32 download_id, |
318 DownloadStateInfo new_state); | 331 DownloadStateInfo new_state); |
319 | 332 |
320 // Called back after a target path for the file to be downloaded to has been | 333 // Called back after a target path for the file to be downloaded to has been |
321 // determined, either automatically based on the suggested file name, or by | 334 // determined, either automatically based on the suggested file name, or by |
322 // the user in a Save As dialog box. | 335 // the user in a Save As dialog box. |
323 void ContinueDownloadWithPath(DownloadItem* download, | 336 void ContinueDownloadWithPath(DownloadItem* download, |
324 const FilePath& chosen_file); | 337 const FilePath& chosen_file); |
325 | 338 |
326 // Download cancel helper function. | |
327 // |request_handle| is passed by value because it is ultimately passed to | |
328 // other threads, and this way we don't have to worry about object lifetimes. | |
329 void DownloadCancelledInternal(int download_id, | |
330 DownloadRequestHandle request_handle); | |
331 | |
332 // All data has been downloaded. | 339 // All data has been downloaded. |
333 // |hash| is sha256 hash for the downloaded file. It is empty when the hash | 340 // |hash| is sha256 hash for the downloaded file. It is empty when the hash |
334 // is not available. | 341 // is not available. |
335 void OnAllDataSaved(int32 download_id, int64 size, const std::string& hash); | 342 void OnAllDataSaved(int32 download_id, int64 size, const std::string& hash); |
336 | 343 |
337 // An error occurred in the download. | 344 // An error occurred in the download. |
338 void OnDownloadError(int32 download_id, int64 size, int os_error); | 345 void OnDownloadError(int32 download_id, int64 size, int os_error); |
339 | 346 |
340 // Updates the app icon about the overall download progress. | 347 // Updates the app icon about the overall download progress. |
341 void UpdateAppIcon(); | 348 void UpdateAppIcon(); |
342 | 349 |
343 // Inform observers that the model has changed. | 350 // Inform observers that the model has changed. |
344 void NotifyModelChanged(); | 351 void NotifyModelChanged(); |
345 | 352 |
353 // Return all in progress downloads. This includes downloads that | |
354 // have not yet been entered into the history (all other accessors | |
355 // only return downloads that have been entered into the history). | |
356 // This is intended to be used for testing only. | |
357 void GetInProgressDownloads(std::vector<DownloadItem*>* result); | |
358 | |
346 // Get the download item from the active map. Useful when the item is not | 359 // Get the download item from the active map. Useful when the item is not |
347 // yet in the history map. | 360 // yet in the history map. |
348 DownloadItem* GetActiveDownloadItem(int id); | 361 DownloadItem* GetActiveDownloadItem(int id); |
349 | 362 |
350 // Debugging routine to confirm relationship between below | 363 // Debugging routine to confirm relationship between below |
351 // containers; no-op if NDEBUG. | 364 // containers; no-op if NDEBUG. |
352 void AssertContainersConsistent() const; | 365 void AssertContainersConsistent() const; |
353 | 366 |
354 // |downloads_| is the owning set for all downloads known to the | 367 // |downloads_| is the owning set for all downloads known to the |
355 // DownloadManager. This includes downloads started by the user in | 368 // DownloadManager. This includes downloads started by the user in |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 // The "Save As" dialog box used to ask the user where a file should be | 437 // The "Save As" dialog box used to ask the user where a file should be |
425 // saved. | 438 // saved. |
426 scoped_refptr<SelectFileDialog> select_file_dialog_; | 439 scoped_refptr<SelectFileDialog> select_file_dialog_; |
427 | 440 |
428 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; | 441 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; |
429 | 442 |
430 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 443 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
431 }; | 444 }; |
432 | 445 |
433 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 446 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |