Chromium Code Reviews| Index: chrome/browser/download/download_service.cc |
| diff --git a/chrome/browser/download/download_service.cc b/chrome/browser/download/download_service.cc |
| index a9d401756ef0c1a6a6b3feb14428ca55e4b6f7da..378b92ae3d0d3830ad9e6e7f8cfcdda0186374c0 100644 |
| --- a/chrome/browser/download/download_service.cc |
| +++ b/chrome/browser/download/download_service.cc |
| @@ -35,7 +35,7 @@ void DownloadService::OnManagerCreated( |
| } |
| } |
| -DownloadManagerDelegate* DownloadService::GetDownloadManagerDelegate() { |
| +ChromeDownloadManagerDelegate* DownloadService::GetDownloadManagerDelegate() { |
| DCHECK(!download_manager_created_); |
| download_manager_created_ = true; |
| @@ -91,11 +91,16 @@ int DownloadService::DownloadCountAllProfiles() { |
| void DownloadService::SetDownloadManagerDelegateForTesting( |
| ChromeDownloadManagerDelegate* new_delegate) { |
| + // Set the new delegate first so that if BrowserContext::GetDownloadManager() |
| + // causes a new download manager to be created, we won't create a redundant |
| + // ChromeDownloadManagerDelegate(). |
| + manager_delegate_ = new_delegate; |
| // Guarantee everything is properly initialized. |
| DownloadManager* dm = BrowserContext::GetDownloadManager(profile_); |
| - dm->SetDelegate(new_delegate); |
| - new_delegate->SetDownloadManager(dm); |
| - manager_delegate_ = new_delegate; |
| + if (dm->GetDelegate() != new_delegate) { |
| + dm->SetDelegate(new_delegate); |
| + new_delegate->SetDownloadManager(dm); |
| + } |
| } |
| void DownloadService::Shutdown() { |
| @@ -107,5 +112,5 @@ void DownloadService::Shutdown() { |
| // manually earlier. See http://crbug.com/131692 |
| BrowserContext::GetDownloadManager(profile_)->Shutdown(); |
| } |
| - manager_delegate_.release(); |
| + manager_delegate_ = NULL; |
|
asanka
2012/07/23 19:47:11
Will wait for http://codereview.chromium.org/10808
|
| } |