OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/download/download_service.h" | 5 #include "chrome/browser/download/download_service.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 9 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
10 #include "chrome/browser/download/download_service_factory.h" | 10 #include "chrome/browser/download/download_service_factory.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 void DownloadService::OnManagerCreated( | 28 void DownloadService::OnManagerCreated( |
29 const DownloadService::OnManagerCreatedCallback& cb) { | 29 const DownloadService::OnManagerCreatedCallback& cb) { |
30 if (download_manager_created_) { | 30 if (download_manager_created_) { |
31 DownloadManager* dm = BrowserContext::GetDownloadManager(profile_); | 31 DownloadManager* dm = BrowserContext::GetDownloadManager(profile_); |
32 cb.Run(dm); | 32 cb.Run(dm); |
33 } else { | 33 } else { |
34 on_manager_created_callbacks_.push_back(cb); | 34 on_manager_created_callbacks_.push_back(cb); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 DownloadManagerDelegate* DownloadService::GetDownloadManagerDelegate() { | 38 ChromeDownloadManagerDelegate* DownloadService::GetDownloadManagerDelegate() { |
39 DCHECK(!download_manager_created_); | 39 DCHECK(!download_manager_created_); |
40 download_manager_created_ = true; | 40 download_manager_created_ = true; |
41 | 41 |
42 // In case the delegate has already been set by | 42 // In case the delegate has already been set by |
43 // SetDownloadManagerDelegateForTesting. | 43 // SetDownloadManagerDelegateForTesting. |
44 if (!manager_delegate_.get()) | 44 if (!manager_delegate_.get()) |
45 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); | 45 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); |
46 | 46 |
47 DownloadManager* dm = BrowserContext::GetDownloadManager(profile_); | 47 DownloadManager* dm = BrowserContext::GetDownloadManager(profile_); |
48 manager_delegate_->SetDownloadManager(dm); | 48 manager_delegate_->SetDownloadManager(dm); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 if ((*it)->HasOffTheRecordProfile()) | 84 if ((*it)->HasOffTheRecordProfile()) |
85 count += DownloadServiceFactory::GetForProfile( | 85 count += DownloadServiceFactory::GetForProfile( |
86 (*it)->GetOffTheRecordProfile())->DownloadCount(); | 86 (*it)->GetOffTheRecordProfile())->DownloadCount(); |
87 } | 87 } |
88 | 88 |
89 return count; | 89 return count; |
90 } | 90 } |
91 | 91 |
92 void DownloadService::SetDownloadManagerDelegateForTesting( | 92 void DownloadService::SetDownloadManagerDelegateForTesting( |
93 ChromeDownloadManagerDelegate* new_delegate) { | 93 ChromeDownloadManagerDelegate* new_delegate) { |
94 // Set the new delegate first so that if BrowserContext::GetDownloadManager() | |
95 // causes a new download manager to be created, we won't create a redundant | |
96 // ChromeDownloadManagerDelegate(). | |
97 manager_delegate_ = new_delegate; | |
94 // Guarantee everything is properly initialized. | 98 // Guarantee everything is properly initialized. |
95 DownloadManager* dm = BrowserContext::GetDownloadManager(profile_); | 99 DownloadManager* dm = BrowserContext::GetDownloadManager(profile_); |
96 dm->SetDelegate(new_delegate); | 100 if (dm->GetDelegate() != new_delegate) { |
97 new_delegate->SetDownloadManager(dm); | 101 dm->SetDelegate(new_delegate); |
98 manager_delegate_ = new_delegate; | 102 new_delegate->SetDownloadManager(dm); |
103 } | |
99 } | 104 } |
100 | 105 |
101 void DownloadService::Shutdown() { | 106 void DownloadService::Shutdown() { |
102 if (download_manager_created_) { | 107 if (download_manager_created_) { |
103 // Normally the DownloadManager would be shutdown later, after the Profile | 108 // Normally the DownloadManager would be shutdown later, after the Profile |
104 // goes away and BrowserContext's destructor runs. But that would be too | 109 // goes away and BrowserContext's destructor runs. But that would be too |
105 // late for us since we need to use the profile (indirectly through history | 110 // late for us since we need to use the profile (indirectly through history |
106 // code) when the DownloadManager is shutting down. So we shut it down | 111 // code) when the DownloadManager is shutting down. So we shut it down |
107 // manually earlier. See http://crbug.com/131692 | 112 // manually earlier. See http://crbug.com/131692 |
108 BrowserContext::GetDownloadManager(profile_)->Shutdown(); | 113 BrowserContext::GetDownloadManager(profile_)->Shutdown(); |
109 } | 114 } |
110 manager_delegate_.release(); | 115 manager_delegate_ = NULL; |
asanka
2012/07/23 19:47:11
Will wait for http://codereview.chromium.org/10808
| |
111 } | 116 } |
OLD | NEW |