Chromium Code Reviews| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 | 86 |
| 87 // Called immediately after the DownloadManager puts up a select file | 87 // Called immediately after the DownloadManager puts up a select file |
| 88 // dialog. | 88 // dialog. |
| 89 // |id| indicates which download opened the dialog. | 89 // |id| indicates which download opened the dialog. |
| 90 virtual void SelectFileDialogDisplayed(int32 id) {} | 90 virtual void SelectFileDialogDisplayed(int32 id) {} |
| 91 | 91 |
| 92 protected: | 92 protected: |
| 93 virtual ~Observer() {} | 93 virtual ~Observer() {} |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 typedef std::vector<DownloadItem*> DownloadVector; | |
|
Paweł Hajdan Jr.
2011/07/29 18:03:30
nit: Add empty line below.
| |
| 96 // Return all temporary downloads that reside in the specified directory. | 97 // Return all temporary downloads that reside in the specified directory. |
| 97 void GetTemporaryDownloads(const FilePath& dir_path, | 98 void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result); |
| 98 std::vector<DownloadItem*>* result); | |
| 99 | 99 |
| 100 // Return all non-temporary downloads in the specified directory that are | 100 // Return all non-temporary downloads in the specified directory that are |
| 101 // are in progress or have completed. | 101 // are in progress or have completed. |
| 102 void GetAllDownloads(const FilePath& dir_path, | 102 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); |
| 103 std::vector<DownloadItem*>* result); | |
| 104 | 103 |
| 105 // Return all non-temporary downloads in the specified directory that are | 104 // Return all non-temporary downloads in the specified directory that are |
| 106 // in-progress (including dangerous downloads waiting for user confirmation). | 105 // in-progress (including dangerous downloads waiting for user confirmation). |
| 107 void GetCurrentDownloads(const FilePath& dir_path, | 106 void GetCurrentDownloads(const FilePath& dir_path, DownloadVector* result); |
| 108 std::vector<DownloadItem*>* result); | |
| 109 | 107 |
| 110 // Returns all non-temporary downloads matching |query|. Empty query matches | 108 // Returns all non-temporary downloads matching |query|. Empty query matches |
| 111 // everything. | 109 // everything. |
| 112 void SearchDownloads(const string16& query, | 110 void SearchDownloads(const string16& query, DownloadVector* result); |
| 113 std::vector<DownloadItem*>* result); | |
| 114 | 111 |
| 115 // Returns true if initialized properly. | 112 // Returns true if initialized properly. |
| 116 bool Init(Profile* profile); | 113 bool Init(Profile* profile); |
| 117 | 114 |
| 118 // Notifications sent from the download thread to the UI thread | 115 // Notifications sent from the download thread to the UI thread |
| 119 void StartDownload(int32 id); | 116 void StartDownload(int32 id); |
| 120 void UpdateDownload(int32 download_id, int64 size); | 117 void UpdateDownload(int32 download_id, int64 size); |
| 121 // |hash| is sha256 hash for the downloaded file. It is empty when the hash | 118 // |hash| is sha256 hash for the downloaded file. It is empty when the hash |
| 122 // is not available. | 119 // is not available. |
| 123 void OnResponseCompleted(int32 download_id, int64 size, int os_error, | 120 void OnResponseCompleted(int32 download_id, int64 size, int os_error, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 int RemoveDownloads(const base::Time remove_begin); | 154 int RemoveDownloads(const base::Time remove_begin); |
| 158 | 155 |
| 159 // Remove all downloads will delete all downloads. The number of downloads | 156 // Remove all downloads will delete all downloads. The number of downloads |
| 160 // deleted is returned back to the caller. | 157 // deleted is returned back to the caller. |
| 161 int RemoveAllDownloads(); | 158 int RemoveAllDownloads(); |
| 162 | 159 |
| 163 // Final download manager transition for download: Update the download | 160 // Final download manager transition for download: Update the download |
| 164 // history and remove the download from |active_downloads_|. | 161 // history and remove the download from |active_downloads_|. |
| 165 void DownloadCompleted(int32 download_id); | 162 void DownloadCompleted(int32 download_id); |
| 166 | 163 |
| 167 // Called when a Save Page As download is started. Transfers ownership | |
| 168 // of |download_item| to the DownloadManager. | |
| 169 void SavePageAsDownloadStarted(DownloadItem* download_item); | |
| 170 | |
| 171 // Download the object at the URL. Used in cases such as "Save Link As..." | 164 // Download the object at the URL. Used in cases such as "Save Link As..." |
| 172 void DownloadUrl(const GURL& url, | 165 void DownloadUrl(const GURL& url, |
| 173 const GURL& referrer, | 166 const GURL& referrer, |
| 174 const std::string& referrer_encoding, | 167 const std::string& referrer_encoding, |
| 175 TabContents* tab_contents); | 168 TabContents* tab_contents); |
| 176 | 169 |
| 177 // Download the object at the URL and save it to the specified path. The | 170 // Download the object at the URL and save it to the specified path. The |
| 178 // download is treated as the temporary download and thus will not appear | 171 // download is treated as the temporary download and thus will not appear |
| 179 // in the download history. Used in cases such as drag and drop. | 172 // in the download history. Used in cases such as drag and drop. |
| 180 void DownloadUrlToFile(const GURL& url, | 173 void DownloadUrlToFile(const GURL& url, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); | 249 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); |
| 257 | 250 |
| 258 // Assert the named download item is on the correct queues | 251 // Assert the named download item is on the correct queues |
| 259 // in the DownloadManager. For debugging. | 252 // in the DownloadManager. For debugging. |
| 260 void AssertQueueStateConsistent(DownloadItem* download); | 253 void AssertQueueStateConsistent(DownloadItem* download); |
| 261 | 254 |
| 262 // Get the download item from the history map. Useful after the item has | 255 // Get the download item from the history map. Useful after the item has |
| 263 // been removed from the active map, or was retrieved from the history DB. | 256 // been removed from the active map, or was retrieved from the history DB. |
| 264 DownloadItem* GetDownloadItem(int id); | 257 DownloadItem* GetDownloadItem(int id); |
| 265 | 258 |
| 259 // Called when Save Page download starts. Transfers ownership of |download| | |
| 260 // to the DownloadManager. | |
| 261 void SavePageDownloadStarted(DownloadItem* download); | |
| 262 | |
| 263 // Callback when Save Page As entry is commited to the history system. | |
| 264 void OnSavePageDownloadEntryAdded(int32 download_id, int64 db_handle); | |
| 265 | |
| 266 // Called when Save Page download is done. | |
| 267 void SavePageDownloadFinished(DownloadItem* download); | |
| 268 | |
| 269 // Save Page Ids. | |
| 270 int32 GetNextSavePageId(); | |
| 271 | |
| 266 private: | 272 private: |
| 267 // For testing. | 273 // For testing. |
| 268 friend class DownloadManagerTest; | 274 friend class DownloadManagerTest; |
| 269 friend class MockDownloadManager; | 275 friend class MockDownloadManager; |
| 276 friend class SavePageBrowserTest; | |
| 270 | 277 |
| 271 // This class is used to let an incognito DownloadManager observe changes to | 278 // This class is used to let an incognito DownloadManager observe changes to |
| 272 // a normal DownloadManager, to propagate ModelChanged() calls from the parent | 279 // a normal DownloadManager, to propagate ModelChanged() calls from the parent |
| 273 // DownloadManager to the observers of the incognito DownloadManager. | 280 // DownloadManager to the observers of the incognito DownloadManager. |
| 274 class OtherDownloadManagerObserver : public Observer { | 281 class OtherDownloadManagerObserver : public Observer { |
| 275 public: | 282 public: |
| 276 explicit OtherDownloadManagerObserver( | 283 explicit OtherDownloadManagerObserver( |
| 277 DownloadManager* observing_download_manager); | 284 DownloadManager* observing_download_manager); |
| 278 virtual ~OtherDownloadManagerObserver(); | 285 virtual ~OtherDownloadManagerObserver(); |
| 279 | 286 |
| 280 // Observer interface. | 287 // Observer interface. |
| 281 virtual void ModelChanged(); | 288 virtual void ModelChanged(); |
| 282 virtual void ManagerGoingDown(); | 289 virtual void ManagerGoingDown(); |
| 283 | 290 |
| 284 private: | 291 private: |
| 285 // The incognito download manager. | 292 // The incognito download manager. |
| 286 DownloadManager* observing_download_manager_; | 293 DownloadManager* observing_download_manager_; |
| 287 | 294 |
| 288 // The original profile's download manager. | 295 // The original profile's download manager. |
| 289 DownloadManager* observed_download_manager_; | 296 DownloadManager* observed_download_manager_; |
| 290 }; | 297 }; |
| 291 | 298 |
| 292 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 299 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 293 friend class DeleteTask<DownloadManager>; | 300 friend class DeleteTask<DownloadManager>; |
| 294 friend class OtherDownloadManagerObserver; | 301 friend class OtherDownloadManagerObserver; |
| 295 | 302 |
| 296 virtual ~DownloadManager(); | 303 virtual ~DownloadManager(); |
| 297 | 304 |
| 305 DownloadHistory* download_history() const { return download_history_.get(); } | |
|
Paweł Hajdan Jr.
2011/07/29 18:03:30
My earlier comment about non-const return from con
achuithb
2011/07/30 01:56:47
Done.
| |
| 306 | |
| 298 // Called on the FILE thread to check the existence of a downloaded file. | 307 // Called on the FILE thread to check the existence of a downloaded file. |
| 299 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); | 308 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); |
| 300 | 309 |
| 301 // Called on the UI thread if the FILE thread detects the removal of | 310 // Called on the UI thread if the FILE thread detects the removal of |
| 302 // the downloaded file. The UI thread updates the state of the file | 311 // the downloaded file. The UI thread updates the state of the file |
| 303 // and then notifies this update to the file's observer. | 312 // and then notifies this update to the file's observer. |
| 304 void OnFileRemovalDetected(int64 db_handle); | 313 void OnFileRemovalDetected(int64 db_handle); |
| 305 | 314 |
| 306 // Called on the download thread to check whether the suggested file path | 315 // Called on the download thread to check whether the suggested file path |
| 307 // exists. We don't check if the file exists on the UI thread to avoid UI | 316 // exists. We don't check if the file exists on the UI thread to avoid UI |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 // yet in the history map. | 352 // yet in the history map. |
| 344 DownloadItem* GetActiveDownloadItem(int id); | 353 DownloadItem* GetActiveDownloadItem(int id); |
| 345 | 354 |
| 346 // Debugging routine to confirm relationship between below | 355 // Debugging routine to confirm relationship between below |
| 347 // containers; no-op if NDEBUG. | 356 // containers; no-op if NDEBUG. |
| 348 void AssertContainersConsistent() const; | 357 void AssertContainersConsistent() const; |
| 349 | 358 |
| 350 // Add a DownloadItem to history_downloads_. | 359 // Add a DownloadItem to history_downloads_. |
| 351 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); | 360 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); |
| 352 | 361 |
| 362 typedef std::set<DownloadItem*> DownloadSet; | |
|
Paweł Hajdan Jr.
2011/07/29 18:03:30
nit: Follow the style-guide ordering of class decl
achuithb
2011/07/30 01:56:47
Done.
| |
| 363 typedef base::hash_map<int64, DownloadItem*> DownloadMap; | |
| 364 | |
| 365 // Remove from internal maps. | |
| 366 int RemoveDownloadItems(const DownloadVector& pending_deletes); | |
| 367 | |
| 353 // |downloads_| is the owning set for all downloads known to the | 368 // |downloads_| is the owning set for all downloads known to the |
| 354 // DownloadManager. This includes downloads started by the user in | 369 // DownloadManager. This includes downloads started by the user in |
| 355 // this session, downloads initialized from the history system, and | 370 // this session, downloads initialized from the history system, and |
| 356 // "save page as" downloads. All other DownloadItem containers in | 371 // "save page as" downloads. All other DownloadItem containers in |
| 357 // the DownloadManager are maps; they do not own the DownloadItems. | 372 // the DownloadManager are maps; they do not own the DownloadItems. |
| 358 // Note that this is the only place (with any functional implications; | 373 // Note that this is the only place (with any functional implications; |
| 359 // see save_page_as_downloads_ below) that "save page as" downloads are | 374 // see save_page_as_downloads_ below) that "save page as" downloads are |
| 360 // kept, as the DownloadManager's only job is to hold onto those | 375 // kept, as the DownloadManager's only job is to hold onto those |
| 361 // until destruction. | 376 // until destruction. |
| 362 // | 377 // |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 379 // When a download is created through a user action, the corresponding | 394 // When a download is created through a user action, the corresponding |
| 380 // DownloadItem* is placed in |active_downloads_| and remains there until the | 395 // DownloadItem* is placed in |active_downloads_| and remains there until the |
| 381 // download is in a terminal state (COMPLETE or CANCELLED). It is also | 396 // download is in a terminal state (COMPLETE or CANCELLED). It is also |
| 382 // placed in |in_progress_| and remains there until it has received a | 397 // placed in |in_progress_| and remains there until it has received a |
| 383 // valid handle from the history system. Once it has a valid handle, the | 398 // valid handle from the history system. Once it has a valid handle, the |
| 384 // DownloadItem* is placed in the |history_downloads_| map. When the | 399 // DownloadItem* is placed in the |history_downloads_| map. When the |
| 385 // download reaches a terminal state, it is removed from |in_progress_|. | 400 // download reaches a terminal state, it is removed from |in_progress_|. |
| 386 // Downloads from past sessions read from a persisted state from the | 401 // Downloads from past sessions read from a persisted state from the |
| 387 // history system are placed directly into |history_downloads_| since | 402 // history system are placed directly into |history_downloads_| since |
| 388 // they have valid handles in the history system. | 403 // they have valid handles in the history system. |
| 389 typedef std::set<DownloadItem*> DownloadSet; | |
| 390 typedef base::hash_map<int64, DownloadItem*> DownloadMap; | |
| 391 | 404 |
| 392 DownloadSet downloads_; | 405 DownloadSet downloads_; |
| 393 DownloadMap history_downloads_; | 406 DownloadMap history_downloads_; |
| 394 DownloadMap in_progress_; | 407 DownloadMap in_progress_; |
| 395 DownloadMap active_downloads_; | 408 DownloadMap active_downloads_; |
| 396 #if !defined(NDEBUG) | 409 DownloadMap save_page_downloads_; |
| 397 DownloadSet save_page_as_downloads_; | |
| 398 #endif | |
| 399 | 410 |
| 400 // True if the download manager has been initialized and requires a shutdown. | 411 // True if the download manager has been initialized and requires a shutdown. |
| 401 bool shutdown_needed_; | 412 bool shutdown_needed_; |
| 402 | 413 |
| 403 // Observers that want to be notified of changes to the set of downloads. | 414 // Observers that want to be notified of changes to the set of downloads. |
| 404 ObserverList<Observer> observers_; | 415 ObserverList<Observer> observers_; |
| 405 | 416 |
| 406 // The current active profile. | 417 // The current active profile. |
| 407 Profile* profile_; | 418 Profile* profile_; |
| 408 | 419 |
| 409 scoped_ptr<DownloadHistory> download_history_; | 420 scoped_ptr<DownloadHistory> download_history_; |
| 410 | 421 |
| 411 scoped_ptr<DownloadPrefs> download_prefs_; | 422 scoped_ptr<DownloadPrefs> download_prefs_; |
| 412 | 423 |
| 413 // Non-owning pointer for handling file writing on the download_thread_. | 424 // Non-owning pointer for handling file writing on the download_thread_. |
| 414 DownloadFileManager* file_manager_; | 425 DownloadFileManager* file_manager_; |
| 415 | 426 |
| 416 // Non-owning pointer for updating the download status. | 427 // Non-owning pointer for updating the download status. |
| 417 base::WeakPtr<DownloadStatusUpdater> status_updater_; | 428 base::WeakPtr<DownloadStatusUpdater> status_updater_; |
| 418 | 429 |
| 419 // The user's last choice for download directory. This is only used when the | 430 // The user's last choice for download directory. This is only used when the |
| 420 // user wants us to prompt for a save location for each download. | 431 // user wants us to prompt for a save location for each download. |
| 421 FilePath last_download_path_; | 432 FilePath last_download_path_; |
| 422 | 433 |
| 434 // Save Page Ids. | |
|
Paweł Hajdan Jr.
2011/07/29 18:03:30
This is so vague. How about "The ID to be used for
achuithb
2011/07/30 01:56:47
Done.
| |
| 435 int32 next_save_page_id_; | |
| 436 | |
| 423 // 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 |
| 424 // saved. | 438 // saved. |
| 425 scoped_refptr<SelectFileDialog> select_file_dialog_; | 439 scoped_refptr<SelectFileDialog> select_file_dialog_; |
| 426 | 440 |
| 427 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; | 441 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; |
| 428 | 442 |
| 429 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 443 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
| 430 }; | 444 }; |
| 431 | 445 |
| 432 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 446 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
| OLD | NEW |