| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_impl.h" | 5 #include "chrome/browser/download/download_service_impl.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 10 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 11 #include "chrome/browser/download/download_history.h" | 11 #include "chrome/browser/download/download_history.h" |
| 12 #include "chrome/browser/download/download_status_updater.h" | 12 #include "chrome/browser/download/download_status_updater.h" |
| 13 #include "chrome/browser/download/download_ui_controller.h" | 13 #include "chrome/browser/download/download_ui_controller.h" |
| 14 #include "chrome/browser/history/history_service_factory.h" | 14 #include "chrome/browser/history/history_service_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "components/history/core/browser/history_service.h" | 16 #include "components/history/core/browser/history_service.h" |
| 17 #include "content/public/browser/download_manager.h" | 17 #include "content/public/browser/download_manager.h" |
| 18 #include "extensions/features/features.h" |
| 18 | 19 |
| 19 #if defined(ENABLE_EXTENSIONS) | 20 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 20 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 21 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 using content::BrowserContext; | 24 using content::BrowserContext; |
| 24 using content::DownloadManager; | 25 using content::DownloadManager; |
| 25 using content::DownloadManagerDelegate; | 26 using content::DownloadManagerDelegate; |
| 26 | 27 |
| 27 DownloadServiceImpl::DownloadServiceImpl(Profile* profile) | 28 DownloadServiceImpl::DownloadServiceImpl(Profile* profile) |
| 28 : download_manager_created_(false), profile_(profile) { | 29 : download_manager_created_(false), profile_(profile) { |
| 29 } | 30 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 42 } | 43 } |
| 43 download_manager_created_ = true; | 44 download_manager_created_ = true; |
| 44 | 45 |
| 45 // In case the delegate has already been set by | 46 // In case the delegate has already been set by |
| 46 // SetDownloadManagerDelegateForTesting. | 47 // SetDownloadManagerDelegateForTesting. |
| 47 if (!manager_delegate_.get()) | 48 if (!manager_delegate_.get()) |
| 48 manager_delegate_.reset(new ChromeDownloadManagerDelegate(profile_)); | 49 manager_delegate_.reset(new ChromeDownloadManagerDelegate(profile_)); |
| 49 | 50 |
| 50 manager_delegate_->SetDownloadManager(manager); | 51 manager_delegate_->SetDownloadManager(manager); |
| 51 | 52 |
| 52 #if defined(ENABLE_EXTENSIONS) | 53 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 53 extension_event_router_.reset( | 54 extension_event_router_.reset( |
| 54 new extensions::ExtensionDownloadsEventRouter(profile_, manager)); | 55 new extensions::ExtensionDownloadsEventRouter(profile_, manager)); |
| 55 #endif | 56 #endif |
| 56 | 57 |
| 57 if (!profile_->IsOffTheRecord()) { | 58 if (!profile_->IsOffTheRecord()) { |
| 58 history::HistoryService* history = HistoryServiceFactory::GetForProfile( | 59 history::HistoryService* history = HistoryServiceFactory::GetForProfile( |
| 59 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 60 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 60 history->GetNextDownloadId( | 61 history->GetNextDownloadId( |
| 61 manager_delegate_->GetDownloadIdReceiverCallback()); | 62 manager_delegate_->GetDownloadIdReceiverCallback()); |
| 62 download_history_.reset(new DownloadHistory( | 63 download_history_.reset(new DownloadHistory( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 77 } | 78 } |
| 78 | 79 |
| 79 DownloadHistory* DownloadServiceImpl::GetDownloadHistory() { | 80 DownloadHistory* DownloadServiceImpl::GetDownloadHistory() { |
| 80 if (!download_manager_created_) { | 81 if (!download_manager_created_) { |
| 81 GetDownloadManagerDelegate(); | 82 GetDownloadManagerDelegate(); |
| 82 } | 83 } |
| 83 DCHECK(download_manager_created_); | 84 DCHECK(download_manager_created_); |
| 84 return download_history_.get(); | 85 return download_history_.get(); |
| 85 } | 86 } |
| 86 | 87 |
| 87 #if defined(ENABLE_EXTENSIONS) | 88 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 88 extensions::ExtensionDownloadsEventRouter* | 89 extensions::ExtensionDownloadsEventRouter* |
| 89 DownloadServiceImpl::GetExtensionEventRouter() { | 90 DownloadServiceImpl::GetExtensionEventRouter() { |
| 90 return extension_event_router_.get(); | 91 return extension_event_router_.get(); |
| 91 } | 92 } |
| 92 #endif | 93 #endif |
| 93 | 94 |
| 94 bool DownloadServiceImpl::HasCreatedDownloadManager() { | 95 bool DownloadServiceImpl::HasCreatedDownloadManager() { |
| 95 return download_manager_created_; | 96 return download_manager_created_; |
| 96 } | 97 } |
| 97 | 98 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 138 |
| 138 void DownloadServiceImpl::Shutdown() { | 139 void DownloadServiceImpl::Shutdown() { |
| 139 if (download_manager_created_) { | 140 if (download_manager_created_) { |
| 140 // Normally the DownloadManager would be shutdown later, after the Profile | 141 // Normally the DownloadManager would be shutdown later, after the Profile |
| 141 // goes away and BrowserContext's destructor runs. But that would be too | 142 // goes away and BrowserContext's destructor runs. But that would be too |
| 142 // late for us since we need to use the profile (indirectly through history | 143 // late for us since we need to use the profile (indirectly through history |
| 143 // code) when the DownloadManager is shutting down. So we shut it down | 144 // code) when the DownloadManager is shutting down. So we shut it down |
| 144 // manually earlier. See http://crbug.com/131692 | 145 // manually earlier. See http://crbug.com/131692 |
| 145 BrowserContext::GetDownloadManager(profile_)->Shutdown(); | 146 BrowserContext::GetDownloadManager(profile_)->Shutdown(); |
| 146 } | 147 } |
| 147 #if defined(ENABLE_EXTENSIONS) | 148 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 148 extension_event_router_.reset(); | 149 extension_event_router_.reset(); |
| 149 #endif | 150 #endif |
| 150 manager_delegate_.reset(); | 151 manager_delegate_.reset(); |
| 151 download_history_.reset(); | 152 download_history_.reset(); |
| 152 } | 153 } |
| OLD | NEW |