| 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" |
| 45 #include "base/synchronization/lock.h" |
| 44 #include "base/time.h" | 46 #include "base/time.h" |
| 45 #include "chrome/browser/download/download_item.h" | 47 #include "chrome/browser/download/download_item.h" |
| 46 #include "chrome/browser/download/download_request_handle.h" | 48 #include "chrome/browser/download/download_request_handle.h" |
| 49 #include "chrome/browser/download/download_state_info.h" |
| 47 #include "chrome/browser/download/download_status_updater_delegate.h" | 50 #include "chrome/browser/download/download_status_updater_delegate.h" |
| 48 #include "content/browser/browser_thread.h" | 51 #include "content/browser/browser_thread.h" |
| 49 | 52 |
| 50 class DownloadFileManager; | 53 class DownloadFileManager; |
| 51 class DownloadHistory; | 54 class DownloadHistory; |
| 52 class DownloadManagerDelegate; | 55 class DownloadManagerDelegate; |
| 53 class DownloadPrefs; | 56 class DownloadPrefs; |
| 54 class DownloadStatusUpdater; | 57 class DownloadStatusUpdater; |
| 55 class GURL; | 58 class GURL; |
| 56 class Profile; | 59 class Profile; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); | 106 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); |
| 104 | 107 |
| 105 // Return all non-temporary downloads in the specified directory that are | 108 // Return all non-temporary downloads in the specified directory that are |
| 106 // in-progress (including dangerous downloads waiting for user confirmation). | 109 // in-progress (including dangerous downloads waiting for user confirmation). |
| 107 void GetCurrentDownloads(const FilePath& dir_path, DownloadVector* result); | 110 void GetCurrentDownloads(const FilePath& dir_path, DownloadVector* result); |
| 108 | 111 |
| 109 // Returns all non-temporary downloads matching |query|. Empty query matches | 112 // Returns all non-temporary downloads matching |query|. Empty query matches |
| 110 // everything. | 113 // everything. |
| 111 void SearchDownloads(const string16& query, DownloadVector* result); | 114 void SearchDownloads(const string16& query, DownloadVector* result); |
| 112 | 115 |
| 116 // Returns the next download id in a DownloadId and increments the counter. |
| 117 // May be called on any thread. The incremented counter is not persisted, but |
| 118 // the base counter for this accessor is initialized from the largest id |
| 119 // actually saved to the download history database. |
| 120 DownloadId GetNextId(); |
| 121 |
| 122 // Instead of passing a DownloadManager* between threads and hoping users only |
| 123 // call GetNextId(), you can pass this thunk around instead. Pass the thunk |
| 124 // around by const ref and store it by copy per the base::Callback interface. |
| 125 // The thunk may be copied, including between threads. If you change |
| 126 // GetNextIdThunkType from base::Callback, then you should think about how |
| 127 // you're changing the ref-count of DownloadManager. Use it like: |
| 128 // const DownloadManager::GetNextIdThunkType& next_id_thunk = |
| 129 // download_manager->GetNextIdThunk(); |
| 130 // id = next_id_thunk.Run(); |
| 131 typedef base::Callback<DownloadId(void)> GetNextIdThunkType; |
| 132 GetNextIdThunkType GetNextIdThunk(); |
| 133 |
| 113 // Returns true if initialized properly. | 134 // Returns true if initialized properly. |
| 114 bool Init(Profile* profile); | 135 bool Init(Profile* profile); |
| 115 | 136 |
| 116 // Notifications sent from the download thread to the UI thread | 137 // Notifications sent from the download thread to the UI thread |
| 117 void StartDownload(int32 id); | 138 void StartDownload(int32 id); |
| 118 void UpdateDownload(int32 download_id, int64 size); | 139 void UpdateDownload(int32 download_id, int64 size); |
| 119 // |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 |
| 120 // is not available. | 141 // is not available. |
| 121 void OnResponseCompleted(int32 download_id, int64 size, int os_error, | 142 void OnResponseCompleted(int32 download_id, int64 size, int os_error, |
| 122 const std::string& hash); | 143 const std::string& hash); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // Debugging routine to confirm relationship between below | 383 // Debugging routine to confirm relationship between below |
| 363 // containers; no-op if NDEBUG. | 384 // containers; no-op if NDEBUG. |
| 364 void AssertContainersConsistent() const; | 385 void AssertContainersConsistent() const; |
| 365 | 386 |
| 366 // Add a DownloadItem to history_downloads_. | 387 // Add a DownloadItem to history_downloads_. |
| 367 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); | 388 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); |
| 368 | 389 |
| 369 // Remove from internal maps. | 390 // Remove from internal maps. |
| 370 int RemoveDownloadItems(const DownloadVector& pending_deletes); | 391 int RemoveDownloadItems(const DownloadVector& pending_deletes); |
| 371 | 392 |
| 393 // The DownloadHistory grabbed the next_id counter from the sql MetaTable. |
| 394 // TODO(benjhayden) Make ProfileImpl pass this into DownloadManager's |
| 395 // constructor. |
| 396 void OnHistoryGetNextId(int next_id); |
| 397 |
| 372 // |downloads_| is the owning set for all downloads known to the | 398 // |downloads_| is the owning set for all downloads known to the |
| 373 // DownloadManager. This includes downloads started by the user in | 399 // DownloadManager. This includes downloads started by the user in |
| 374 // this session, downloads initialized from the history system, and | 400 // this session, downloads initialized from the history system, and |
| 375 // "save page as" downloads. All other DownloadItem containers in | 401 // "save page as" downloads. All other DownloadItem containers in |
| 376 // the DownloadManager are maps; they do not own the DownloadItems. | 402 // the DownloadManager are maps; they do not own the DownloadItems. |
| 377 // Note that this is the only place (with any functional implications; | 403 // Note that this is the only place (with any functional implications; |
| 378 // see save_page_as_downloads_ below) that "save page as" downloads are | 404 // see save_page_as_downloads_ below) that "save page as" downloads are |
| 379 // kept, as the DownloadManager's only job is to hold onto those | 405 // kept, as the DownloadManager's only job is to hold onto those |
| 380 // until destruction. | 406 // until destruction. |
| 381 // | 407 // |
| (...skipping 29 matching lines...) Expand all Loading... |
| 411 DownloadMap in_progress_; | 437 DownloadMap in_progress_; |
| 412 DownloadMap active_downloads_; | 438 DownloadMap active_downloads_; |
| 413 DownloadMap save_page_downloads_; | 439 DownloadMap save_page_downloads_; |
| 414 | 440 |
| 415 // True if the download manager has been initialized and requires a shutdown. | 441 // True if the download manager has been initialized and requires a shutdown. |
| 416 bool shutdown_needed_; | 442 bool shutdown_needed_; |
| 417 | 443 |
| 418 // Observers that want to be notified of changes to the set of downloads. | 444 // Observers that want to be notified of changes to the set of downloads. |
| 419 ObserverList<Observer> observers_; | 445 ObserverList<Observer> observers_; |
| 420 | 446 |
| 447 base::Lock next_id_lock_; |
| 448 int next_id_; |
| 449 |
| 421 // The current active profile. | 450 // The current active profile. |
| 422 Profile* profile_; | 451 Profile* profile_; |
| 423 | 452 |
| 424 scoped_ptr<DownloadHistory> download_history_; | 453 scoped_ptr<DownloadHistory> download_history_; |
| 425 | 454 |
| 426 scoped_ptr<DownloadPrefs> download_prefs_; | 455 scoped_ptr<DownloadPrefs> download_prefs_; |
| 427 | 456 |
| 428 // Non-owning pointer for handling file writing on the download_thread_. | 457 // Non-owning pointer for handling file writing on the download_thread_. |
| 429 DownloadFileManager* file_manager_; | 458 DownloadFileManager* file_manager_; |
| 430 | 459 |
| 431 // Non-owning pointer for updating the download status. | 460 // Non-owning pointer for updating the download status. |
| 432 base::WeakPtr<DownloadStatusUpdater> status_updater_; | 461 base::WeakPtr<DownloadStatusUpdater> status_updater_; |
| 433 | 462 |
| 434 // The user's last choice for download directory. This is only used when the | 463 // The user's last choice for download directory. This is only used when the |
| 435 // user wants us to prompt for a save location for each download. | 464 // user wants us to prompt for a save location for each download. |
| 436 FilePath last_download_path_; | 465 FilePath last_download_path_; |
| 437 | 466 |
| 438 // Download Id for next Save Page. | 467 // Download Id for next Save Page. |
| 439 int32 next_save_page_id_; | 468 int32 next_save_page_id_; |
| 440 | 469 |
| 441 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; | 470 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; |
| 442 | 471 |
| 443 // Allows an embedder to control behavior. Guaranteed to outlive this object. | 472 // Allows an embedder to control behavior. Guaranteed to outlive this object. |
| 444 DownloadManagerDelegate* delegate_; | 473 DownloadManagerDelegate* delegate_; |
| 445 | 474 |
| 446 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 475 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
| 447 }; | 476 }; |
| 448 | 477 |
| 449 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 478 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
| OLD | NEW |