OLD | NEW |
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/download/download_service_factory.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "content/browser/download/download_id_factory.h" | 12 #include "content/browser/download/download_id_factory.h" |
13 #include "content/browser/download/download_manager.h" | 13 #include "content/browser/download/download_manager_impl.h" |
14 | 14 |
15 DownloadService::DownloadService(Profile* profile) | 15 DownloadService::DownloadService(Profile* profile) |
16 : download_manager_created_(false), | 16 : download_manager_created_(false), |
17 profile_(profile) { | 17 profile_(profile) { |
18 if (profile_->IsOffTheRecord()) { | 18 if (profile_->IsOffTheRecord()) { |
19 id_factory_ = DownloadServiceFactory::GetForProfile( | 19 id_factory_ = DownloadServiceFactory::GetForProfile( |
20 profile_->GetOriginalProfile())->GetDownloadIdFactory(); | 20 profile_->GetOriginalProfile())->GetDownloadIdFactory(); |
21 } else { | 21 } else { |
22 id_factory_ = new DownloadIdFactory(this); | 22 id_factory_ = new DownloadIdFactory(this); |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 DownloadService::~DownloadService() {} | 26 DownloadService::~DownloadService() {} |
27 | 27 |
28 DownloadIdFactory* DownloadService::GetDownloadIdFactory() const { | 28 DownloadIdFactory* DownloadService::GetDownloadIdFactory() const { |
29 return id_factory_.get(); | 29 return id_factory_.get(); |
30 } | 30 } |
31 | 31 |
32 DownloadManager* DownloadService::GetDownloadManager() { | 32 DownloadManager* DownloadService::GetDownloadManager() { |
33 if (!download_manager_created_) { | 33 if (!download_manager_created_) { |
34 // In case the delegate has already been set by | 34 // In case the delegate has already been set by |
35 // SetDownloadManagerDelegateForTesting. | 35 // SetDownloadManagerDelegateForTesting. |
36 if (!manager_delegate_.get()) | 36 if (!manager_delegate_.get()) |
37 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); | 37 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); |
38 manager_ = new DownloadManager( | 38 manager_ = new DownloadManagerImpl( |
39 manager_delegate_.get(), | 39 manager_delegate_.get(), |
40 id_factory_.get(), | 40 id_factory_.get(), |
41 g_browser_process->download_status_updater()); | 41 g_browser_process->download_status_updater()); |
42 manager_->Init(profile_); | 42 manager_->Init(profile_); |
43 manager_delegate_->SetDownloadManager(manager_); | 43 manager_delegate_->SetDownloadManager(manager_); |
44 download_manager_created_ = true; | 44 download_manager_created_ = true; |
45 } | 45 } |
46 return manager_.get(); | 46 return manager_.get(); |
47 } | 47 } |
48 | 48 |
49 bool DownloadService::HasCreatedDownloadManager() { | 49 bool DownloadService::HasCreatedDownloadManager() { |
50 return download_manager_created_; | 50 return download_manager_created_; |
51 } | 51 } |
52 | 52 |
53 int DownloadService::DownloadCount() const { | 53 int DownloadService::DownloadCount() const { |
54 return download_manager_created_ ? manager_->in_progress_count() : 0; | 54 return download_manager_created_ ? manager_->InProgressCount() : 0; |
55 } | 55 } |
56 | 56 |
57 // static | 57 // static |
58 int DownloadService::DownloadCountAllProfiles() { | 58 int DownloadService::DownloadCountAllProfiles() { |
59 std::vector<Profile*> profiles( | 59 std::vector<Profile*> profiles( |
60 g_browser_process->profile_manager()->GetLoadedProfiles()); | 60 g_browser_process->profile_manager()->GetLoadedProfiles()); |
61 | 61 |
62 int count = 0; | 62 int count = 0; |
63 for (std::vector<Profile*>::iterator it = profiles.begin(); | 63 for (std::vector<Profile*>::iterator it = profiles.begin(); |
64 it < profiles.end(); ++it) { | 64 it < profiles.end(); ++it) { |
(...skipping 26 matching lines...) Expand all Loading... |
91 // Resetting here will guarantee that any attempts to get the | 91 // Resetting here will guarantee that any attempts to get the |
92 // DownloadManager after shutdown will return null. | 92 // DownloadManager after shutdown will return null. |
93 // | 93 // |
94 // TODO(rdsmith): Figure out how to guarantee when the last reference | 94 // TODO(rdsmith): Figure out how to guarantee when the last reference |
95 // will be released and make DownloadManager not RefCountedThreadSafe<>. | 95 // will be released and make DownloadManager not RefCountedThreadSafe<>. |
96 manager_.release(); | 96 manager_.release(); |
97 } | 97 } |
98 if (manager_delegate_.get()) | 98 if (manager_delegate_.get()) |
99 manager_delegate_.release(); | 99 manager_delegate_.release(); |
100 } | 100 } |
OLD | NEW |