OLD | NEW |
---|---|
1 // Copyright (c) 2011 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" |
11 #include "chrome/browser/net/chrome_net_log.h" | |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "content/public/browser/download_manager.h" | 14 #include "content/public/browser/download_manager.h" |
14 | 15 |
15 using content::DownloadManager; | 16 using content::DownloadManager; |
16 | 17 |
17 DownloadService::DownloadService(Profile* profile) | 18 DownloadService::DownloadService(Profile* profile) |
18 : download_manager_created_(false), | 19 : download_manager_created_(false), |
19 profile_(profile) { | 20 profile_(profile) { |
20 } | 21 } |
21 | 22 |
22 DownloadService::~DownloadService() {} | 23 DownloadService::~DownloadService() {} |
23 | 24 |
24 void DownloadService::OnManagerCreated( | 25 void DownloadService::OnManagerCreated( |
25 const DownloadService::OnManagerCreatedCallback& cb) { | 26 const DownloadService::OnManagerCreatedCallback& cb) { |
26 if (download_manager_created_) { | 27 if (download_manager_created_) { |
27 cb.Run(manager_.get()); | 28 cb.Run(manager_.get()); |
28 } else { | 29 } else { |
29 on_manager_created_callbacks_.push_back(cb); | 30 on_manager_created_callbacks_.push_back(cb); |
30 } | 31 } |
31 } | 32 } |
32 | 33 |
33 DownloadManager* DownloadService::GetDownloadManager() { | 34 DownloadManager* DownloadService::GetDownloadManager() { |
34 if (!download_manager_created_) { | 35 if (!download_manager_created_) { |
35 // In case the delegate has already been set by | 36 // In case the delegate has already been set by |
36 // SetDownloadManagerDelegateForTesting. | 37 // SetDownloadManagerDelegateForTesting. |
37 if (!manager_delegate_.get()) | 38 if (!manager_delegate_.get()) |
38 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); | 39 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); |
39 manager_ = DownloadManager::Create( | 40 manager_ = DownloadManager::Create( |
40 manager_delegate_.get(), g_browser_process->download_status_updater()); | 41 manager_delegate_.get(), |
42 g_browser_process->download_status_updater(), | |
43 g_browser_process->net_log()); | |
Randy Smith (Not in Mondays)
2012/02/03 19:36:41
Remind me: Is there a global from which we can gra
ahendrickson
2012/02/05 05:06:53
There is:
content::GetContentClient()->browser()-
Randy Smith (Not in Mondays)
2012/02/06 00:37:49
I'm torn--I can see arguments in both directions.
| |
41 manager_->Init(profile_); | 44 manager_->Init(profile_); |
42 manager_delegate_->SetDownloadManager(manager_); | 45 manager_delegate_->SetDownloadManager(manager_); |
43 download_manager_created_ = true; | 46 download_manager_created_ = true; |
44 for (std::vector<OnManagerCreatedCallback>::iterator cb | 47 for (std::vector<OnManagerCreatedCallback>::iterator cb |
45 = on_manager_created_callbacks_.begin(); | 48 = on_manager_created_callbacks_.begin(); |
46 cb != on_manager_created_callbacks_.end(); ++cb) { | 49 cb != on_manager_created_callbacks_.end(); ++cb) { |
47 cb->Run(manager_.get()); | 50 cb->Run(manager_.get()); |
48 } | 51 } |
49 on_manager_created_callbacks_.clear(); | 52 on_manager_created_callbacks_.clear(); |
50 } | 53 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 // Resetting here will guarantee that any attempts to get the | 99 // Resetting here will guarantee that any attempts to get the |
97 // DownloadManager after shutdown will return null. | 100 // DownloadManager after shutdown will return null. |
98 // | 101 // |
99 // TODO(rdsmith): Figure out how to guarantee when the last reference | 102 // TODO(rdsmith): Figure out how to guarantee when the last reference |
100 // will be released and make DownloadManager not RefCountedThreadSafe<>. | 103 // will be released and make DownloadManager not RefCountedThreadSafe<>. |
101 manager_.release(); | 104 manager_.release(); |
102 } | 105 } |
103 if (manager_delegate_.get()) | 106 if (manager_delegate_.get()) |
104 manager_delegate_.release(); | 107 manager_delegate_.release(); |
105 } | 108 } |
OLD | NEW |