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 16 matching lines...) Expand all Loading... | |
| 27 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 27 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
| 28 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 28 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
| 29 #pragma once | 29 #pragma once |
| 30 | 30 |
| 31 #include <map> | 31 #include <map> |
| 32 #include <set> | 32 #include <set> |
| 33 #include <string> | 33 #include <string> |
| 34 #include <vector> | 34 #include <vector> |
| 35 | 35 |
| 36 #include "base/basictypes.h" | 36 #include "base/basictypes.h" |
| 37 #include "base/callback.h" | |
| 37 #include "base/file_path.h" | 38 #include "base/file_path.h" |
| 38 #include "base/gtest_prod_util.h" | 39 #include "base/gtest_prod_util.h" |
| 39 #include "base/hash_tables.h" | 40 #include "base/hash_tables.h" |
| 40 #include "base/memory/ref_counted.h" | 41 #include "base/memory/ref_counted.h" |
| 41 #include "base/memory/scoped_ptr.h" | 42 #include "base/memory/scoped_ptr.h" |
| 42 #include "base/memory/weak_ptr.h" | 43 #include "base/memory/weak_ptr.h" |
| 43 #include "base/observer_list.h" | 44 #include "base/observer_list.h" |
| 44 #include "base/time.h" | 45 #include "base/time.h" |
| 45 #include "chrome/browser/download/download_item.h" | 46 #include "chrome/browser/download/download_item.h" |
| 46 #include "chrome/browser/download/download_request_handle.h" | 47 #include "chrome/browser/download/download_request_handle.h" |
| 48 #include "chrome/browser/download/download_state_info.h" | |
| 47 #include "chrome/browser/download/download_status_updater_delegate.h" | 49 #include "chrome/browser/download/download_status_updater_delegate.h" |
| 48 #include "chrome/browser/ui/shell_dialogs.h" | 50 #include "chrome/browser/ui/shell_dialogs.h" |
| 49 #include "content/browser/browser_thread.h" | 51 #include "content/browser/browser_thread.h" |
| 50 | 52 |
| 51 class DownloadFileManager; | 53 class DownloadFileManager; |
| 52 class DownloadHistory; | 54 class DownloadHistory; |
| 53 class DownloadPrefs; | 55 class DownloadPrefs; |
| 54 class DownloadStatusUpdater; | 56 class DownloadStatusUpdater; |
| 55 class GURL; | 57 class GURL; |
| 56 class Profile; | 58 class Profile; |
| 57 class ResourceDispatcherHost; | 59 class ResourceDispatcherHost; |
| 58 class TabContents; | 60 class TabContents; |
| 59 struct DownloadCreateInfo; | 61 struct DownloadCreateInfo; |
| 60 struct DownloadHistoryInfo; | 62 struct DownloadHistoryInfo; |
| 61 struct DownloadSaveInfo; | 63 struct DownloadSaveInfo; |
| 64 namespace base { | |
| 65 class Lock; | |
| 66 } // namespace base | |
|
Randy Smith (Not in Mondays)
2011/07/28 21:03:16
I'm having a "I don't think this can work" reactio
benjhayden
2011/08/03 17:44:46
Done.
| |
| 62 | 67 |
| 63 // Browser's download manager: manages all downloads and destination view. | 68 // Browser's download manager: manages all downloads and destination view. |
| 64 class DownloadManager | 69 class DownloadManager |
| 65 : public base::RefCountedThreadSafe<DownloadManager, | 70 : public base::RefCountedThreadSafe<DownloadManager, |
| 66 BrowserThread::DeleteOnUIThread>, | 71 BrowserThread::DeleteOnUIThread>, |
| 67 public DownloadStatusUpdaterDelegate, | 72 public DownloadStatusUpdaterDelegate, |
| 68 public SelectFileDialog::Listener { | 73 public SelectFileDialog::Listener { |
| 69 public: | 74 public: |
| 70 explicit DownloadManager(DownloadStatusUpdater* status_updater); | 75 explicit DownloadManager(DownloadStatusUpdater* status_updater); |
| 71 | 76 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 // Return all non-temporary downloads in the specified directory that are | 110 // Return all non-temporary downloads in the specified directory that are |
| 106 // in-progress (including dangerous downloads waiting for user confirmation). | 111 // in-progress (including dangerous downloads waiting for user confirmation). |
| 107 void GetCurrentDownloads(const FilePath& dir_path, | 112 void GetCurrentDownloads(const FilePath& dir_path, |
| 108 std::vector<DownloadItem*>* result); | 113 std::vector<DownloadItem*>* result); |
| 109 | 114 |
| 110 // Returns all non-temporary downloads matching |query|. Empty query matches | 115 // Returns all non-temporary downloads matching |query|. Empty query matches |
| 111 // everything. | 116 // everything. |
| 112 void SearchDownloads(const string16& query, | 117 void SearchDownloads(const string16& query, |
| 113 std::vector<DownloadItem*>* result); | 118 std::vector<DownloadItem*>* result); |
| 114 | 119 |
| 120 // Returns the next download id in a DownloadId and increments the counter. | |
| 121 // May be called on any thread. The incremented counter is not persisted, but | |
| 122 // the base counter for this accessor is initialized from the largest id | |
| 123 // actually saved to the download history database. | |
| 124 DownloadId GetNextId(); | |
| 125 | |
| 126 // Instead of passing a DownloadManager* between threads and hoping users only | |
| 127 // call GetNextId(), you can pass this thunk around instead. Pass the thunk | |
| 128 // around by const ref and store it by copy per the base::Callback interface. | |
| 129 // The thunk may be copied, including between threads. If you change | |
| 130 // GetNextIdThunkType from base::Callback, then you should think about how | |
| 131 // you're changing the ref-count of DownloadManager. Use it like: | |
| 132 // const DownloadManager::GetNextIdThunkType& next_id_thunk = | |
| 133 // download_manager->GetNextIdThunk(); | |
| 134 // id = next_id_thunk.Run(); | |
| 135 typedef base::Callback<DownloadId(void)> GetNextIdThunkType; | |
| 136 GetNextIdThunkType GetNextIdThunk(); | |
| 137 | |
| 115 // Returns true if initialized properly. | 138 // Returns true if initialized properly. |
| 116 bool Init(Profile* profile); | 139 bool Init(Profile* profile); |
| 117 | 140 |
| 118 // Notifications sent from the download thread to the UI thread | 141 // Notifications sent from the download thread to the UI thread |
| 119 void StartDownload(int32 id); | 142 void StartDownload(int32 id); |
| 120 void UpdateDownload(int32 download_id, int64 size); | 143 void UpdateDownload(int32 download_id, int64 size); |
| 121 // |hash| is sha256 hash for the downloaded file. It is empty when the hash | 144 // |hash| is sha256 hash for the downloaded file. It is empty when the hash |
| 122 // is not available. | 145 // is not available. |
| 123 void OnResponseCompleted(int32 download_id, int64 size, int os_error, | 146 void OnResponseCompleted(int32 download_id, int64 size, int os_error, |
| 124 const std::string& hash); | 147 const std::string& hash); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 // yet in the history map. | 366 // yet in the history map. |
| 344 DownloadItem* GetActiveDownloadItem(int id); | 367 DownloadItem* GetActiveDownloadItem(int id); |
| 345 | 368 |
| 346 // Debugging routine to confirm relationship between below | 369 // Debugging routine to confirm relationship between below |
| 347 // containers; no-op if NDEBUG. | 370 // containers; no-op if NDEBUG. |
| 348 void AssertContainersConsistent() const; | 371 void AssertContainersConsistent() const; |
| 349 | 372 |
| 350 // Add a DownloadItem to history_downloads_. | 373 // Add a DownloadItem to history_downloads_. |
| 351 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); | 374 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); |
| 352 | 375 |
| 376 // The DownloadHistory grabbed the next_id counter from the sql MetaTable. | |
| 377 void OnHistoryGetNextId(int next_id); | |
|
Randy Smith (Not in Mondays)
2011/07/28 21:03:16
For the next CL: Consider making the next_id field
benjhayden
2011/08/03 17:44:46
So, Profile will use its HistoryService directly a
Randy Smith (Not in Mondays)
2011/08/03 21:10:29
Yep. Or if there's some reason to, it can constru
benjhayden
2011/08/04 17:15:00
Done.
| |
| 378 | |
| 353 // |downloads_| is the owning set for all downloads known to the | 379 // |downloads_| is the owning set for all downloads known to the |
| 354 // DownloadManager. This includes downloads started by the user in | 380 // DownloadManager. This includes downloads started by the user in |
| 355 // this session, downloads initialized from the history system, and | 381 // this session, downloads initialized from the history system, and |
| 356 // "save page as" downloads. All other DownloadItem containers in | 382 // "save page as" downloads. All other DownloadItem containers in |
| 357 // the DownloadManager are maps; they do not own the DownloadItems. | 383 // the DownloadManager are maps; they do not own the DownloadItems. |
| 358 // Note that this is the only place (with any functional implications; | 384 // Note that this is the only place (with any functional implications; |
| 359 // see save_page_as_downloads_ below) that "save page as" downloads are | 385 // 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 | 386 // kept, as the DownloadManager's only job is to hold onto those |
| 361 // until destruction. | 387 // until destruction. |
| 362 // | 388 // |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 #if !defined(NDEBUG) | 422 #if !defined(NDEBUG) |
| 397 DownloadSet save_page_as_downloads_; | 423 DownloadSet save_page_as_downloads_; |
| 398 #endif | 424 #endif |
| 399 | 425 |
| 400 // True if the download manager has been initialized and requires a shutdown. | 426 // True if the download manager has been initialized and requires a shutdown. |
| 401 bool shutdown_needed_; | 427 bool shutdown_needed_; |
| 402 | 428 |
| 403 // Observers that want to be notified of changes to the set of downloads. | 429 // Observers that want to be notified of changes to the set of downloads. |
| 404 ObserverList<Observer> observers_; | 430 ObserverList<Observer> observers_; |
| 405 | 431 |
| 432 base::Lock next_id_lock_; | |
| 433 int next_id_; | |
| 434 | |
| 406 // The current active profile. | 435 // The current active profile. |
| 407 Profile* profile_; | 436 Profile* profile_; |
| 408 | 437 |
| 409 scoped_ptr<DownloadHistory> download_history_; | 438 scoped_ptr<DownloadHistory> download_history_; |
| 410 | 439 |
| 411 scoped_ptr<DownloadPrefs> download_prefs_; | 440 scoped_ptr<DownloadPrefs> download_prefs_; |
| 412 | 441 |
| 413 // Non-owning pointer for handling file writing on the download_thread_. | 442 // Non-owning pointer for handling file writing on the download_thread_. |
| 414 DownloadFileManager* file_manager_; | 443 DownloadFileManager* file_manager_; |
| 415 | 444 |
| 416 // Non-owning pointer for updating the download status. | 445 // Non-owning pointer for updating the download status. |
| 417 base::WeakPtr<DownloadStatusUpdater> status_updater_; | 446 base::WeakPtr<DownloadStatusUpdater> status_updater_; |
| 418 | 447 |
| 419 // The user's last choice for download directory. This is only used when the | 448 // 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. | 449 // user wants us to prompt for a save location for each download. |
| 421 FilePath last_download_path_; | 450 FilePath last_download_path_; |
| 422 | 451 |
| 423 // The "Save As" dialog box used to ask the user where a file should be | 452 // The "Save As" dialog box used to ask the user where a file should be |
| 424 // saved. | 453 // saved. |
| 425 scoped_refptr<SelectFileDialog> select_file_dialog_; | 454 scoped_refptr<SelectFileDialog> select_file_dialog_; |
| 426 | 455 |
| 427 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; | 456 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; |
| 428 | 457 |
| 429 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 458 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
| 430 }; | 459 }; |
| 431 | 460 |
| 432 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 461 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
| OLD | NEW |