Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1153)

Side by Side Diff: chrome/browser/download/download_service.cc

Issue 214523003: Before deleting a profile, cancel all in-progress downloads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/download/download_service.h ('k') | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return download_manager_created_; 88 return download_manager_created_;
89 } 89 }
90 90
91 int DownloadService::NonMaliciousDownloadCount() const { 91 int DownloadService::NonMaliciousDownloadCount() const {
92 if (!download_manager_created_) 92 if (!download_manager_created_)
93 return 0; 93 return 0;
94 return BrowserContext::GetDownloadManager(profile_)-> 94 return BrowserContext::GetDownloadManager(profile_)->
95 NonMaliciousInProgressCount(); 95 NonMaliciousInProgressCount();
96 } 96 }
97 97
98 void DownloadService::CancelDownloads() {
99 if (!download_manager_created_)
100 return;
101
102 DownloadManager* download_manager =
103 BrowserContext::GetDownloadManager(profile_);
104 DownloadManager::DownloadVector downloads;
105 download_manager->GetAllDownloads(&downloads);
106 for (DownloadManager::DownloadVector::iterator it = downloads.begin();
107 it != downloads.end();
108 ++it) {
109 if ((*it)->GetState() == content::DownloadItem::IN_PROGRESS)
110 (*it)->Cancel(false);
111 }
112 }
113
98 // static 114 // static
99 int DownloadService::NonMaliciousDownloadCountAllProfiles() { 115 int DownloadService::NonMaliciousDownloadCountAllProfiles() {
100 std::vector<Profile*> profiles( 116 std::vector<Profile*> profiles(
101 g_browser_process->profile_manager()->GetLoadedProfiles()); 117 g_browser_process->profile_manager()->GetLoadedProfiles());
102 118
103 int count = 0; 119 int count = 0;
104 for (std::vector<Profile*>::iterator it = profiles.begin(); 120 for (std::vector<Profile*>::iterator it = profiles.begin();
105 it < profiles.end(); ++it) { 121 it < profiles.end(); ++it) {
106 count += DownloadServiceFactory::GetForBrowserContext(*it)-> 122 count += DownloadServiceFactory::GetForBrowserContext(*it)->
107 NonMaliciousDownloadCount(); 123 NonMaliciousDownloadCount();
108 if ((*it)->HasOffTheRecordProfile()) 124 if ((*it)->HasOffTheRecordProfile())
109 count += DownloadServiceFactory::GetForBrowserContext( 125 count += DownloadServiceFactory::GetForBrowserContext(
110 (*it)->GetOffTheRecordProfile())->NonMaliciousDownloadCount(); 126 (*it)->GetOffTheRecordProfile())->NonMaliciousDownloadCount();
111 } 127 }
112 128
113 return count; 129 return count;
114 } 130 }
115 131
116 // static 132 // static
117 void DownloadService::CancelAllDownloads() { 133 void DownloadService::CancelAllDownloads() {
118 std::vector<Profile*> profiles( 134 std::vector<Profile*> profiles(
119 g_browser_process->profile_manager()->GetLoadedProfiles()); 135 g_browser_process->profile_manager()->GetLoadedProfiles());
120 for (std::vector<Profile*>::iterator it = profiles.begin(); 136 for (std::vector<Profile*>::iterator it = profiles.begin();
121 it < profiles.end(); 137 it < profiles.end();
122 ++it) { 138 ++it) {
123 content::DownloadManager* download_manager = 139 DownloadService* service =
124 content::BrowserContext::GetDownloadManager(*it); 140 DownloadServiceFactory::GetForBrowserContext(*it);
125 content::DownloadManager::DownloadVector downloads; 141 service->CancelDownloads();
126 download_manager->GetAllDownloads(&downloads);
127 for (content::DownloadManager::DownloadVector::iterator it =
128 downloads.begin();
129 it != downloads.end();
130 ++it) {
131 if ((*it)->GetState() == content::DownloadItem::IN_PROGRESS)
132 (*it)->Cancel(false);
133 }
134 } 142 }
135 } 143 }
136 144
137 void DownloadService::SetDownloadManagerDelegateForTesting( 145 void DownloadService::SetDownloadManagerDelegateForTesting(
138 scoped_ptr<ChromeDownloadManagerDelegate> new_delegate) { 146 scoped_ptr<ChromeDownloadManagerDelegate> new_delegate) {
139 manager_delegate_.swap(new_delegate); 147 manager_delegate_.swap(new_delegate);
140 DownloadManager* dm = BrowserContext::GetDownloadManager(profile_); 148 DownloadManager* dm = BrowserContext::GetDownloadManager(profile_);
141 dm->SetDelegate(manager_delegate_.get()); 149 dm->SetDelegate(manager_delegate_.get());
142 manager_delegate_->SetDownloadManager(dm); 150 manager_delegate_->SetDownloadManager(dm);
143 if (new_delegate) 151 if (new_delegate)
(...skipping 17 matching lines...) Expand all
161 // code) when the DownloadManager is shutting down. So we shut it down 169 // code) when the DownloadManager is shutting down. So we shut it down
162 // manually earlier. See http://crbug.com/131692 170 // manually earlier. See http://crbug.com/131692
163 BrowserContext::GetDownloadManager(profile_)->Shutdown(); 171 BrowserContext::GetDownloadManager(profile_)->Shutdown();
164 } 172 }
165 #if !defined(OS_ANDROID) 173 #if !defined(OS_ANDROID)
166 extension_event_router_.reset(); 174 extension_event_router_.reset();
167 #endif 175 #endif
168 manager_delegate_.reset(); 176 manager_delegate_.reset();
169 download_history_.reset(); 177 download_history_.reset();
170 } 178 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_service.h ('k') | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698