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 "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/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "content/browser/download/download_id_factory.h" | 13 #include "content/browser/download/download_id_factory.h" |
14 #include "content/browser/download/download_manager_impl.h" | 14 #include "content/public/browser/download_manager.h" |
15 | 15 |
16 using content::DownloadManager; | 16 using content::DownloadManager; |
17 | 17 |
18 DownloadService::DownloadService(Profile* profile) | 18 DownloadService::DownloadService(Profile* profile) |
19 : download_manager_created_(false), | 19 : download_manager_created_(false), |
20 profile_(profile) { | 20 profile_(profile) { |
21 if (profile_->IsOffTheRecord()) { | 21 if (profile_->IsOffTheRecord()) { |
22 id_factory_ = DownloadServiceFactory::GetForProfile( | 22 id_factory_ = DownloadServiceFactory::GetForProfile( |
23 profile_->GetOriginalProfile())->GetDownloadIdFactory(); | 23 profile_->GetOriginalProfile())->GetDownloadIdFactory(); |
24 } else { | 24 } else { |
(...skipping 15 matching lines...) Expand all Loading... |
40 on_manager_created_callbacks_.push_back(cb); | 40 on_manager_created_callbacks_.push_back(cb); |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 DownloadManager* DownloadService::GetDownloadManager() { | 44 DownloadManager* DownloadService::GetDownloadManager() { |
45 if (!download_manager_created_) { | 45 if (!download_manager_created_) { |
46 // In case the delegate has already been set by | 46 // In case the delegate has already been set by |
47 // SetDownloadManagerDelegateForTesting. | 47 // SetDownloadManagerDelegateForTesting. |
48 if (!manager_delegate_.get()) | 48 if (!manager_delegate_.get()) |
49 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); | 49 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); |
50 manager_ = new DownloadManagerImpl( | 50 manager_ = DownloadManager::Create( |
51 manager_delegate_.get(), | 51 manager_delegate_.get(), |
52 id_factory_.get(), | 52 id_factory_.get(), |
53 g_browser_process->download_status_updater()); | 53 g_browser_process->download_status_updater()); |
54 manager_->Init(profile_); | 54 manager_->Init(profile_); |
55 manager_delegate_->SetDownloadManager(manager_); | 55 manager_delegate_->SetDownloadManager(manager_); |
56 download_manager_created_ = true; | 56 download_manager_created_ = true; |
57 for (std::vector<OnManagerCreatedCallback>::iterator cb | 57 for (std::vector<OnManagerCreatedCallback>::iterator cb |
58 = on_manager_created_callbacks_.begin(); | 58 = on_manager_created_callbacks_.begin(); |
59 cb != on_manager_created_callbacks_.end(); ++cb) { | 59 cb != on_manager_created_callbacks_.end(); ++cb) { |
60 cb->Run(manager_.get()); | 60 cb->Run(manager_.get()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // Resetting here will guarantee that any attempts to get the | 109 // Resetting here will guarantee that any attempts to get the |
110 // DownloadManager after shutdown will return null. | 110 // DownloadManager after shutdown will return null. |
111 // | 111 // |
112 // TODO(rdsmith): Figure out how to guarantee when the last reference | 112 // TODO(rdsmith): Figure out how to guarantee when the last reference |
113 // will be released and make DownloadManager not RefCountedThreadSafe<>. | 113 // will be released and make DownloadManager not RefCountedThreadSafe<>. |
114 manager_.release(); | 114 manager_.release(); |
115 } | 115 } |
116 if (manager_delegate_.get()) | 116 if (manager_delegate_.get()) |
117 manager_delegate_.release(); | 117 manager_delegate_.release(); |
118 } | 118 } |
OLD | NEW |