| OLD | NEW |
| 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_service_factory.h" | 10 #include "chrome/browser/download/download_service_factory.h" |
| 11 #include "chrome/browser/download/download_status_updater.h" | 11 #include "chrome/browser/download/download_status_updater.h" |
| 12 #include "chrome/browser/net/chrome_net_log.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "content/public/browser/download_manager.h" | 15 #include "content/public/browser/download_manager.h" |
| 15 | 16 |
| 16 using content::DownloadManager; | 17 using content::DownloadManager; |
| 17 | 18 |
| 18 DownloadService::DownloadService(Profile* profile) | 19 DownloadService::DownloadService(Profile* profile) |
| 19 : download_manager_created_(false), | 20 : download_manager_created_(false), |
| 20 profile_(profile) { | 21 profile_(profile) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 DownloadService::~DownloadService() {} | 24 DownloadService::~DownloadService() {} |
| 24 | 25 |
| 25 void DownloadService::OnManagerCreated( | 26 void DownloadService::OnManagerCreated( |
| 26 const DownloadService::OnManagerCreatedCallback& cb) { | 27 const DownloadService::OnManagerCreatedCallback& cb) { |
| 27 if (download_manager_created_) { | 28 if (download_manager_created_) { |
| 28 cb.Run(manager_.get()); | 29 cb.Run(manager_.get()); |
| 29 } else { | 30 } else { |
| 30 on_manager_created_callbacks_.push_back(cb); | 31 on_manager_created_callbacks_.push_back(cb); |
| 31 } | 32 } |
| 32 } | 33 } |
| 33 | 34 |
| 34 DownloadManager* DownloadService::GetDownloadManager() { | 35 DownloadManager* DownloadService::GetDownloadManager() { |
| 35 if (!download_manager_created_) { | 36 if (!download_manager_created_) { |
| 36 // In case the delegate has already been set by | 37 // In case the delegate has already been set by |
| 37 // SetDownloadManagerDelegateForTesting. | 38 // SetDownloadManagerDelegateForTesting. |
| 38 if (!manager_delegate_.get()) | 39 if (!manager_delegate_.get()) |
| 39 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); | 40 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); |
| 40 manager_ = DownloadManager::Create(manager_delegate_.get()); | 41 manager_ = DownloadManager::Create(manager_delegate_.get(), |
| 42 g_browser_process->net_log()); |
| 41 manager_->Init(profile_); | 43 manager_->Init(profile_); |
| 42 manager_delegate_->SetDownloadManager(manager_); | 44 manager_delegate_->SetDownloadManager(manager_); |
| 43 | 45 |
| 44 // Include this download manager in the set monitored by the | 46 // Include this download manager in the set monitored by the |
| 45 // global status updater. | 47 // global status updater. |
| 46 g_browser_process->download_status_updater()->AddManager(manager_); | 48 g_browser_process->download_status_updater()->AddManager(manager_); |
| 47 | 49 |
| 48 download_manager_created_ = true; | 50 download_manager_created_ = true; |
| 49 for (std::vector<OnManagerCreatedCallback>::iterator cb | 51 for (std::vector<OnManagerCreatedCallback>::iterator cb |
| 50 = on_manager_created_callbacks_.begin(); | 52 = on_manager_created_callbacks_.begin(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 // Resetting here will guarantee that any attempts to get the | 103 // Resetting here will guarantee that any attempts to get the |
| 102 // DownloadManager after shutdown will return null. | 104 // DownloadManager after shutdown will return null. |
| 103 // | 105 // |
| 104 // TODO(rdsmith): Figure out how to guarantee when the last reference | 106 // TODO(rdsmith): Figure out how to guarantee when the last reference |
| 105 // will be released and make DownloadManager not RefCountedThreadSafe<>. | 107 // will be released and make DownloadManager not RefCountedThreadSafe<>. |
| 106 manager_.release(); | 108 manager_.release(); |
| 107 } | 109 } |
| 108 if (manager_delegate_.get()) | 110 if (manager_delegate_.get()) |
| 109 manager_delegate_.release(); | 111 manager_delegate_.release(); |
| 110 } | 112 } |
| OLD | NEW |