| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/download/internal/download_service_impl.h" | 5 #include "components/download/internal/download_service_impl.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "components/download/internal/client_set.h" |
| 11 #include "components/download/internal/config.h" |
| 12 #include "components/download/internal/controller_impl.h" |
| 13 #include "components/download/internal/download_driver.h" |
| 14 #include "components/download/internal/model_impl.h" |
| 15 #include "components/download/internal/noop_store.h" |
| 16 #include "components/download/internal/stats.h" |
| 17 |
| 7 namespace download { | 18 namespace download { |
| 8 | 19 |
| 9 // static | 20 // static |
| 10 DownloadService* DownloadService::Create( | 21 DownloadService* DownloadService::Create( |
| 22 std::unique_ptr<DownloadClientMap> clients, |
| 11 const base::FilePath& storage_dir, | 23 const base::FilePath& storage_dir, |
| 12 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner) { | 24 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner) { |
| 13 return new DownloadServiceImpl(Configuration::CreateFromFinch()); | 25 auto client_set = base::MakeUnique<ClientSet>(std::move(clients)); |
| 26 auto config = Configuration::CreateFromFinch(); |
| 27 auto driver = base::WrapUnique<DownloadDriver>(nullptr); |
| 28 auto model = base::MakeUnique<ModelImpl>(base::MakeUnique<NoopStore>()); |
| 29 |
| 30 std::unique_ptr<Controller> controller = |
| 31 base::MakeUnique<ControllerImpl>(std::move(client_set), std::move(config), |
| 32 std::move(driver), std::move(model)); |
| 33 |
| 34 return new DownloadServiceImpl(std::move(controller)); |
| 14 } | 35 } |
| 15 | 36 |
| 16 DownloadServiceImpl::DownloadServiceImpl(std::unique_ptr<Configuration> config) | 37 DownloadServiceImpl::DownloadServiceImpl(std::unique_ptr<Controller> controller) |
| 17 : config_(std::move(config)) {} | 38 : controller_(std::move(controller)) { |
| 39 controller_->Initialize(); |
| 40 } |
| 18 | 41 |
| 19 DownloadServiceImpl::~DownloadServiceImpl() = default; | 42 DownloadServiceImpl::~DownloadServiceImpl() = default; |
| 20 | 43 |
| 44 DownloadService::ServiceStatus DownloadServiceImpl::GetStatus() { |
| 45 if (!controller_->GetStartupStatus().Complete()) |
| 46 return DownloadService::ServiceStatus::STARTING_UP; |
| 47 |
| 48 if (!controller_->GetStartupStatus().Ok()) |
| 49 return DownloadService::ServiceStatus::UNAVAILABLE; |
| 50 |
| 51 return DownloadService::ServiceStatus::READY; |
| 52 } |
| 53 |
| 21 void DownloadServiceImpl::StartDownload(const DownloadParams& download_params) { | 54 void DownloadServiceImpl::StartDownload(const DownloadParams& download_params) { |
| 55 stats::LogServiceApiAction(download_params.client, |
| 56 stats::ServiceApiAction::START_DOWNLOAD); |
| 57 controller_->StartDownload(download_params); |
| 22 } | 58 } |
| 23 void DownloadServiceImpl::PauseDownload(const std::string& guid) {} | 59 |
| 24 void DownloadServiceImpl::ResumeDownload(const std::string& guid) {} | 60 void DownloadServiceImpl::PauseDownload(const std::string& guid) { |
| 25 void DownloadServiceImpl::CancelDownload(const std::string& guid) {} | 61 stats::LogServiceApiAction(controller_->GetOwnerOfDownload(guid), |
| 62 stats::ServiceApiAction::PAUSE_DOWNLOAD); |
| 63 controller_->PauseDownload(guid); |
| 64 } |
| 65 |
| 66 void DownloadServiceImpl::ResumeDownload(const std::string& guid) { |
| 67 stats::LogServiceApiAction(controller_->GetOwnerOfDownload(guid), |
| 68 stats::ServiceApiAction::RESUME_DOWNLOAD); |
| 69 controller_->ResumeDownload(guid); |
| 70 } |
| 71 |
| 72 void DownloadServiceImpl::CancelDownload(const std::string& guid) { |
| 73 stats::LogServiceApiAction(controller_->GetOwnerOfDownload(guid), |
| 74 stats::ServiceApiAction::CANCEL_DOWNLOAD); |
| 75 controller_->CancelDownload(guid); |
| 76 } |
| 77 |
| 26 void DownloadServiceImpl::ChangeDownloadCriteria( | 78 void DownloadServiceImpl::ChangeDownloadCriteria( |
| 27 const std::string& guid, | 79 const std::string& guid, |
| 28 const SchedulingParams& params) {} | 80 const SchedulingParams& params) { |
| 81 stats::LogServiceApiAction(controller_->GetOwnerOfDownload(guid), |
| 82 stats::ServiceApiAction::CHANGE_CRITERIA); |
| 83 controller_->ChangeDownloadCriteria(guid, params); |
| 84 } |
| 29 | 85 |
| 30 } // namespace download | 86 } // namespace download |
| OLD | NEW |