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 | |
| 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 until | |
| 122 // your new DownloadItem is stored in the history. | |
|
Randy Smith (Not in Mondays)
2011/07/25 20:20:12
nit: It's not really the incremented counter that'
benjhayden
2011/07/27 19:40:54
Done.
| |
| 123 DownloadId GetNextId(); | |
| 124 | |
| 125 // Instead of passing a DownloadManager* between threads and hoping users only | |
| 126 // call GetNextId(), you can pass this thunk around instead. Use it like "id | |
| 127 // = next_id_thunk.Run();" Pass the thunk around by const ref and store it by | |
|
Randy Smith (Not in Mondays)
2011/07/25 20:20:12
nit: I may be targeting a less-smart class of deve
Randy Smith (Not in Mondays)
2011/07/25 20:20:12
I'm a bit worried by this. My understanding was t
benjhayden
2011/07/27 19:40:54
Done.
benjhayden
2011/07/27 19:40:54
I'm not sure exactly what you're asking.
If you're
Randy Smith (Not in Mondays)
2011/07/28 21:03:16
I think I wasn't understanding how base::Callback
benjhayden
2011/08/03 17:44:46
Done.
| |
| 128 // copy per the base::Callback interface. If you change GetNextIdThunkType | |
| 129 // from base::Callback, then you should think about how you're changing the | |
| 130 // ref-count of DownloadManager. | |
| 131 typedef base::Callback<DownloadId(void)> GetNextIdThunkType; | |
| 132 GetNextIdThunkType GetNextIdThunk(); | |
|
Randy Smith (Not in Mondays)
2011/07/25 20:20:12
If you want to pass it around by const ref, is the
benjhayden
2011/07/27 19:40:54
Error: returning reference to temporary.
| |
| 133 | |
| 115 // Returns true if initialized properly. | 134 // Returns true if initialized properly. |
| 116 bool Init(Profile* profile); | 135 bool Init(Profile* profile); |
| 117 | 136 |
| 118 // Notifications sent from the download thread to the UI thread | 137 // Notifications sent from the download thread to the UI thread |
| 119 void StartDownload(int32 id); | 138 void StartDownload(int32 id); |
| 120 void UpdateDownload(int32 download_id, int64 size); | 139 void UpdateDownload(int32 download_id, int64 size); |
| 121 // |hash| is sha256 hash for the downloaded file. It is empty when the hash | 140 // |hash| is sha256 hash for the downloaded file. It is empty when the hash |
| 122 // is not available. | 141 // is not available. |
| 123 void OnResponseCompleted(int32 download_id, int64 size, int os_error, | 142 void OnResponseCompleted(int32 download_id, int64 size, int os_error, |
| 124 const std::string& hash); | 143 const std::string& hash); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 // yet in the history map. | 362 // yet in the history map. |
| 344 DownloadItem* GetActiveDownloadItem(int id); | 363 DownloadItem* GetActiveDownloadItem(int id); |
| 345 | 364 |
| 346 // Debugging routine to confirm relationship between below | 365 // Debugging routine to confirm relationship between below |
| 347 // containers; no-op if NDEBUG. | 366 // containers; no-op if NDEBUG. |
| 348 void AssertContainersConsistent() const; | 367 void AssertContainersConsistent() const; |
| 349 | 368 |
| 350 // Add a DownloadItem to history_downloads_. | 369 // Add a DownloadItem to history_downloads_. |
| 351 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); | 370 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); |
| 352 | 371 |
| 372 // The DownloadHistory grabbed the next_id counter from the sql MetaTable. | |
| 373 void OnHistoryGetNextId(int next_id); | |
| 374 | |
| 353 // |downloads_| is the owning set for all downloads known to the | 375 // |downloads_| is the owning set for all downloads known to the |
| 354 // DownloadManager. This includes downloads started by the user in | 376 // DownloadManager. This includes downloads started by the user in |
| 355 // this session, downloads initialized from the history system, and | 377 // this session, downloads initialized from the history system, and |
| 356 // "save page as" downloads. All other DownloadItem containers in | 378 // "save page as" downloads. All other DownloadItem containers in |
| 357 // the DownloadManager are maps; they do not own the DownloadItems. | 379 // the DownloadManager are maps; they do not own the DownloadItems. |
| 358 // Note that this is the only place (with any functional implications; | 380 // Note that this is the only place (with any functional implications; |
| 359 // see save_page_as_downloads_ below) that "save page as" downloads are | 381 // 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 | 382 // kept, as the DownloadManager's only job is to hold onto those |
| 361 // until destruction. | 383 // until destruction. |
| 362 // | 384 // |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 #if !defined(NDEBUG) | 418 #if !defined(NDEBUG) |
| 397 DownloadSet save_page_as_downloads_; | 419 DownloadSet save_page_as_downloads_; |
| 398 #endif | 420 #endif |
| 399 | 421 |
| 400 // True if the download manager has been initialized and requires a shutdown. | 422 // True if the download manager has been initialized and requires a shutdown. |
| 401 bool shutdown_needed_; | 423 bool shutdown_needed_; |
| 402 | 424 |
| 403 // Observers that want to be notified of changes to the set of downloads. | 425 // Observers that want to be notified of changes to the set of downloads. |
| 404 ObserverList<Observer> observers_; | 426 ObserverList<Observer> observers_; |
| 405 | 427 |
| 428 base::Lock next_id_lock_; | |
| 429 int next_id_; | |
| 430 | |
| 406 // The current active profile. | 431 // The current active profile. |
| 407 Profile* profile_; | 432 Profile* profile_; |
| 408 | 433 |
| 409 scoped_ptr<DownloadHistory> download_history_; | 434 scoped_ptr<DownloadHistory> download_history_; |
| 410 | 435 |
| 411 scoped_ptr<DownloadPrefs> download_prefs_; | 436 scoped_ptr<DownloadPrefs> download_prefs_; |
| 412 | 437 |
| 413 // Non-owning pointer for handling file writing on the download_thread_. | 438 // Non-owning pointer for handling file writing on the download_thread_. |
| 414 DownloadFileManager* file_manager_; | 439 DownloadFileManager* file_manager_; |
| 415 | 440 |
| 416 // Non-owning pointer for updating the download status. | 441 // Non-owning pointer for updating the download status. |
| 417 base::WeakPtr<DownloadStatusUpdater> status_updater_; | 442 base::WeakPtr<DownloadStatusUpdater> status_updater_; |
| 418 | 443 |
| 419 // The user's last choice for download directory. This is only used when the | 444 // 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. | 445 // user wants us to prompt for a save location for each download. |
| 421 FilePath last_download_path_; | 446 FilePath last_download_path_; |
| 422 | 447 |
| 423 // The "Save As" dialog box used to ask the user where a file should be | 448 // The "Save As" dialog box used to ask the user where a file should be |
| 424 // saved. | 449 // saved. |
| 425 scoped_refptr<SelectFileDialog> select_file_dialog_; | 450 scoped_refptr<SelectFileDialog> select_file_dialog_; |
| 426 | 451 |
| 427 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; | 452 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; |
| 428 | 453 |
| 429 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 454 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
| 430 }; | 455 }; |
| 431 | 456 |
| 432 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 457 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
| OLD | NEW |