| Index: chrome/browser/download/download_service.cc
|
| ===================================================================
|
| --- chrome/browser/download/download_service.cc (revision 140592)
|
| +++ chrome/browser/download/download_service.cc (working copy)
|
| @@ -14,7 +14,9 @@
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "content/public/browser/download_manager.h"
|
|
|
| +using content::BrowserContext;
|
| using content::DownloadManager;
|
| +using content::DownloadManagerDelegate;
|
|
|
| DownloadService::DownloadService(Profile* profile)
|
| : download_manager_created_(false),
|
| @@ -25,37 +27,38 @@
|
|
|
| void DownloadService::OnManagerCreated(
|
| const DownloadService::OnManagerCreatedCallback& cb) {
|
| + DownloadManager* dm = BrowserContext::GetDownloadManager(profile_);
|
| if (download_manager_created_) {
|
| - cb.Run(manager_.get());
|
| + cb.Run(dm);
|
| } else {
|
| on_manager_created_callbacks_.push_back(cb);
|
| }
|
| }
|
|
|
| -DownloadManager* DownloadService::GetDownloadManager() {
|
| - if (!download_manager_created_) {
|
| - // In case the delegate has already been set by
|
| - // SetDownloadManagerDelegateForTesting.
|
| - if (!manager_delegate_.get())
|
| - manager_delegate_ = new ChromeDownloadManagerDelegate(profile_);
|
| - manager_ = DownloadManager::Create(manager_delegate_.get(),
|
| - g_browser_process->net_log());
|
| - manager_->Init(profile_);
|
| - manager_delegate_->SetDownloadManager(manager_);
|
| +DownloadManagerDelegate* DownloadService::GetDownloadManagerDelegate() {
|
| + DCHECK(!download_manager_created_);
|
| + download_manager_created_ = true;
|
|
|
| - // Include this download manager in the set monitored by the
|
| - // global status updater.
|
| - g_browser_process->download_status_updater()->AddManager(manager_);
|
| + // In case the delegate has already been set by
|
| + // SetDownloadManagerDelegateForTesting.
|
| + if (!manager_delegate_.get()) {
|
| + manager_delegate_ = new ChromeDownloadManagerDelegate(profile_);
|
| + }
|
|
|
| - download_manager_created_ = true;
|
| - for (std::vector<OnManagerCreatedCallback>::iterator cb
|
| - = on_manager_created_callbacks_.begin();
|
| - cb != on_manager_created_callbacks_.end(); ++cb) {
|
| - cb->Run(manager_.get());
|
| - }
|
| - on_manager_created_callbacks_.clear();
|
| + DownloadManager* dm = BrowserContext::GetDownloadManager(profile_);
|
| + // Include this download manager in the set monitored by the
|
| + // global status updater.
|
| + g_browser_process->download_status_updater()->AddManager(dm);
|
| +
|
| + download_manager_created_ = true;
|
| + for (std::vector<OnManagerCreatedCallback>::iterator cb
|
| + = on_manager_created_callbacks_.begin();
|
| + cb != on_manager_created_callbacks_.end(); ++cb) {
|
| + cb->Run(dm);
|
| }
|
| - return manager_.get();
|
| + on_manager_created_callbacks_.clear();
|
| +
|
| + return manager_delegate_.get();
|
| }
|
|
|
| bool DownloadService::HasCreatedDownloadManager() {
|
| @@ -63,7 +66,8 @@
|
| }
|
|
|
| int DownloadService::DownloadCount() const {
|
| - return download_manager_created_ ? manager_->InProgressCount() : 0;
|
| + DownloadManager* dm = BrowserContext::GetDownloadManager(profile_);
|
| + return download_manager_created_ ? dm->InProgressCount() : 0;
|
| }
|
|
|
| // static
|
| @@ -86,26 +90,15 @@
|
| void DownloadService::SetDownloadManagerDelegateForTesting(
|
| ChromeDownloadManagerDelegate* new_delegate) {
|
| // Guarantee everything is properly initialized.
|
| - GetDownloadManager();
|
| -
|
| - manager_->SetDownloadManagerDelegate(new_delegate);
|
| - new_delegate->SetDownloadManager(manager_);
|
| + DownloadManager* dm = BrowserContext::GetDownloadManager(profile_);
|
| + dm->SetDownloadManagerDelegate(new_delegate);
|
| manager_delegate_ = new_delegate;
|
| }
|
|
|
| void DownloadService::Shutdown() {
|
| - if (manager_.get()) {
|
| - manager_->Shutdown();
|
| -
|
| - // The manager reference can be released any time after shutdown;
|
| - // it will be destroyed when the last reference is released on the
|
| - // FILE thread.
|
| - // Resetting here will guarantee that any attempts to get the
|
| - // DownloadManager after shutdown will return null.
|
| - //
|
| - // TODO(rdsmith): Figure out how to guarantee when the last reference
|
| - // will be released and make DownloadManager not RefCountedThreadSafe<>.
|
| - manager_.release();
|
| + if (download_manager_created_) {
|
| + DownloadManager* dm = BrowserContext::GetDownloadManager(profile_);
|
| + dm->Shutdown();
|
| }
|
| if (manager_delegate_.get())
|
| manager_delegate_.release();
|
|
|