| 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_history.h" | 10 #include "chrome/browser/download/download_history.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 bool DownloadService::HasCreatedDownloadManager() { | 87 bool DownloadService::HasCreatedDownloadManager() { |
| 88 return download_manager_created_; | 88 return download_manager_created_; |
| 89 } | 89 } |
| 90 | 90 |
| 91 int DownloadService::DownloadCount() const { | 91 int DownloadService::DownloadCount() const { |
| 92 if (!download_manager_created_) | 92 if (!download_manager_created_) |
| 93 return 0; | 93 return 0; |
| 94 return BrowserContext::GetDownloadManager(profile_)->InProgressCount(); | 94 return BrowserContext::GetDownloadManager(profile_)->InProgressCount(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 int DownloadService::NonDangerousDownloadCount() const { |
| 98 if (!download_manager_created_) |
| 99 return 0; |
| 100 return BrowserContext::GetDownloadManager(profile_)-> |
| 101 NonDangerousInProgressCount(); |
| 102 } |
| 103 |
| 97 // static | 104 // static |
| 98 int DownloadService::DownloadCountAllProfiles() { | 105 int DownloadService::DownloadCountAllProfiles() { |
| 99 std::vector<Profile*> profiles( | 106 std::vector<Profile*> profiles( |
| 100 g_browser_process->profile_manager()->GetLoadedProfiles()); | 107 g_browser_process->profile_manager()->GetLoadedProfiles()); |
| 101 | 108 |
| 102 int count = 0; | 109 int count = 0; |
| 103 for (std::vector<Profile*>::iterator it = profiles.begin(); | 110 for (std::vector<Profile*>::iterator it = profiles.begin(); |
| 104 it < profiles.end(); ++it) { | 111 it < profiles.end(); ++it) { |
| 105 count += DownloadServiceFactory::GetForBrowserContext(*it)->DownloadCount(); | 112 count += DownloadServiceFactory::GetForBrowserContext(*it)->DownloadCount(); |
| 106 if ((*it)->HasOffTheRecordProfile()) | 113 if ((*it)->HasOffTheRecordProfile()) |
| 107 count += DownloadServiceFactory::GetForBrowserContext( | 114 count += DownloadServiceFactory::GetForBrowserContext( |
| 108 (*it)->GetOffTheRecordProfile())->DownloadCount(); | 115 (*it)->GetOffTheRecordProfile())->DownloadCount(); |
| 109 } | 116 } |
| 110 | 117 |
| 111 return count; | 118 return count; |
| 112 } | 119 } |
| 113 | 120 |
| 121 // static |
| 122 int DownloadService::NonDangerousDownloadCountAllProfiles() { |
| 123 std::vector<Profile*> profiles( |
| 124 g_browser_process->profile_manager()->GetLoadedProfiles()); |
| 125 |
| 126 int count = 0; |
| 127 for (std::vector<Profile*>::iterator it = profiles.begin(); |
| 128 it < profiles.end(); ++it) { |
| 129 count += DownloadServiceFactory::GetForBrowserContext(*it)-> |
| 130 NonDangerousDownloadCount(); |
| 131 if ((*it)->HasOffTheRecordProfile()) |
| 132 count += DownloadServiceFactory::GetForBrowserContext( |
| 133 (*it)->GetOffTheRecordProfile())->NonDangerousDownloadCount(); |
| 134 } |
| 135 |
| 136 return count; |
| 137 } |
| 138 |
| 114 void DownloadService::SetDownloadManagerDelegateForTesting( | 139 void DownloadService::SetDownloadManagerDelegateForTesting( |
| 115 ChromeDownloadManagerDelegate* new_delegate) { | 140 ChromeDownloadManagerDelegate* new_delegate) { |
| 116 // Set the new delegate first so that if BrowserContext::GetDownloadManager() | 141 // Set the new delegate first so that if BrowserContext::GetDownloadManager() |
| 117 // causes a new download manager to be created, we won't create a redundant | 142 // causes a new download manager to be created, we won't create a redundant |
| 118 // ChromeDownloadManagerDelegate(). | 143 // ChromeDownloadManagerDelegate(). |
| 119 manager_delegate_ = new_delegate; | 144 manager_delegate_ = new_delegate; |
| 120 // Guarantee everything is properly initialized. | 145 // Guarantee everything is properly initialized. |
| 121 DownloadManager* dm = BrowserContext::GetDownloadManager(profile_); | 146 DownloadManager* dm = BrowserContext::GetDownloadManager(profile_); |
| 122 if (dm->GetDelegate() != new_delegate) { | 147 if (dm->GetDelegate() != new_delegate) { |
| 123 dm->SetDelegate(new_delegate); | 148 dm->SetDelegate(new_delegate); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 142 // code) when the DownloadManager is shutting down. So we shut it down | 167 // code) when the DownloadManager is shutting down. So we shut it down |
| 143 // manually earlier. See http://crbug.com/131692 | 168 // manually earlier. See http://crbug.com/131692 |
| 144 BrowserContext::GetDownloadManager(profile_)->Shutdown(); | 169 BrowserContext::GetDownloadManager(profile_)->Shutdown(); |
| 145 } | 170 } |
| 146 #if !defined(OS_ANDROID) | 171 #if !defined(OS_ANDROID) |
| 147 extension_event_router_.reset(); | 172 extension_event_router_.reset(); |
| 148 #endif | 173 #endif |
| 149 manager_delegate_ = NULL; | 174 manager_delegate_ = NULL; |
| 150 download_history_.reset(); | 175 download_history_.reset(); |
| 151 } | 176 } |
| OLD | NEW |