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

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

Issue 7466033: Fix warning prompting on closing a window that will cancel downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make sure to use temporary download directory Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/download/chrome_download_manager_delegate.h" 8 #include "chrome/browser/download/chrome_download_manager_delegate.h"
9 #include "chrome/browser/download/download_service_factory.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h"
10 #include "content/browser/download/download_manager.h" 12 #include "content/browser/download/download_manager.h"
11 13
12 DownloadService::DownloadService(Profile* profile) 14 DownloadService::DownloadService(Profile* profile)
13 : download_manager_created_(false), 15 : download_manager_created_(false),
14 profile_(profile) {} 16 profile_(profile) {}
15 17
16 DownloadService::~DownloadService() {} 18 DownloadService::~DownloadService() {}
17 19
18 DownloadManager* DownloadService::GetDownloadManager() { 20 DownloadManager* DownloadService::GetDownloadManager() {
19 if (!download_manager_created_) { 21 if (!download_manager_created_) {
20 // In case the delegate has already been set by 22 // In case the delegate has already been set by
21 // SetDownloadManagerDelegateForTesting. 23 // SetDownloadManagerDelegateForTesting.
22 if (!manager_delegate_.get()) 24 if (!manager_delegate_.get())
23 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); 25 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_);
24 manager_ = new DownloadManager( 26 manager_ = new DownloadManager(
25 manager_delegate_.get(), g_browser_process->download_status_updater()); 27 manager_delegate_.get(), g_browser_process->download_status_updater());
26 manager_->Init(profile_); 28 manager_->Init(profile_);
27 manager_delegate_->SetDownloadManager(manager_); 29 manager_delegate_->SetDownloadManager(manager_);
28 download_manager_created_ = true; 30 download_manager_created_ = true;
29 } 31 }
30 return manager_.get(); 32 return manager_.get();
31 } 33 }
32 34
33 bool DownloadService::HasCreatedDownloadManager() { 35 bool DownloadService::HasCreatedDownloadManager() {
34 return download_manager_created_; 36 return download_manager_created_;
35 } 37 }
36 38
39 int DownloadService::DownloadCount() const {
40 return download_manager_created_ ? manager_->in_progress_count() : 0;
41 }
42
43 // static
44 int DownloadService::DownloadCountAllProfiles() {
45 std::vector<Profile*> profiles(
46 g_browser_process->profile_manager()->GetLoadedProfiles());
47
48 int count = 0;
49 for (std::vector<Profile*>::iterator it = profiles.begin();
50 it < profiles.end(); ++it) {
51 count += DownloadServiceFactory::GetForProfile(*it)->DownloadCount();
52 if ((*it)->HasOffTheRecordProfile())
53 count += DownloadServiceFactory::GetForProfile(
54 (*it)->GetOffTheRecordProfile())->DownloadCount();
55 }
56
57 return count;
58 }
59
37 void DownloadService::SetDownloadManagerDelegateForTesting( 60 void DownloadService::SetDownloadManagerDelegateForTesting(
38 ChromeDownloadManagerDelegate* new_delegate) { 61 ChromeDownloadManagerDelegate* new_delegate) {
39 // Guarantee everything is properly initialized. 62 // Guarantee everything is properly initialized.
40 GetDownloadManager(); 63 GetDownloadManager();
41 64
42 manager_->SetDownloadManagerDelegate(new_delegate); 65 manager_->SetDownloadManagerDelegate(new_delegate);
43 new_delegate->SetDownloadManager(manager_); 66 new_delegate->SetDownloadManager(manager_);
44 manager_delegate_ = new_delegate; 67 manager_delegate_ = new_delegate;
45 } 68 }
46 69
47 void DownloadService::Shutdown() { 70 void DownloadService::Shutdown() {
48 if (manager_.get()) { 71 if (manager_.get()) {
49 manager_->Shutdown(); 72 manager_->Shutdown();
50 73
51 // The manager reference can be released any time after shutdown; 74 // The manager reference can be released any time after shutdown;
52 // it will be destroyed when the last reference is released on the 75 // it will be destroyed when the last reference is released on the
53 // FILE thread. 76 // FILE thread.
54 // Resetting here will guarantee that any attempts to get the 77 // Resetting here will guarantee that any attempts to get the
55 // DownloadManager after shutdown will return null. 78 // DownloadManager after shutdown will return null.
56 // 79 //
57 // TODO(rdsmith): Figure out how to guarantee when the last reference 80 // TODO(rdsmith): Figure out how to guarantee when the last reference
58 // will be released and make DownloadManager not RefCountedThreadSafe<>. 81 // will be released and make DownloadManager not RefCountedThreadSafe<>.
59 manager_.release(); 82 manager_.release();
60 } 83 }
61 if (manager_delegate_.get()) 84 if (manager_delegate_.get())
62 manager_delegate_.release(); 85 manager_delegate_.release();
63 } 86 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_service.h ('k') | chrome/browser/download/download_test_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698