Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Side by Side Diff: components/download/internal/download_service_impl.cc

Issue 2895953004: Add initial Controller to DownloadService (Closed)
Patch Set: Rebased Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_path.h"
10 #include "base/memory/ptr_util.h"
11 #include "components/download/internal/client_set.h"
12 #include "components/download/internal/config.h"
13 #include "components/download/internal/controller_impl.h"
14 #include "components/download/internal/download_driver.h"
15 #include "components/download/internal/download_store.h"
16 #include "components/download/internal/model_impl.h"
17 #include "components/download/internal/proto/entry.pb.h"
18 #include "components/download/internal/stats.h"
19 #include "components/leveldb_proto/proto_database_impl.h"
20
7 namespace download { 21 namespace download {
22 namespace {
23 const char kEntryDBStorageDir[] = "EntryDB";
24 } // namespace
8 25
9 // static 26 // static
10 DownloadService* DownloadService::Create( 27 DownloadService* DownloadService::Create(
28 std::unique_ptr<DownloadClientMap> clients,
11 const base::FilePath& storage_dir, 29 const base::FilePath& storage_dir,
12 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner) { 30 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner) {
13 return new DownloadServiceImpl(Configuration::CreateFromFinch()); 31 auto entry_db_storage_dir = storage_dir.AppendASCII(kEntryDBStorageDir);
32 auto entry_db =
33 base::MakeUnique<leveldb_proto::ProtoDatabaseImpl<protodb::Entry>>(
34 background_task_runner);
35
36 auto store = base::MakeUnique<DownloadStore>(entry_db_storage_dir,
37 std::move(entry_db));
38 auto client_set = base::MakeUnique<ClientSet>(std::move(clients));
39 auto config = Configuration::CreateFromFinch();
40 auto driver = base::WrapUnique<DownloadDriver>(nullptr);
41 auto model = base::MakeUnique<ModelImpl>(std::move(store));
42
43 std::unique_ptr<Controller> controller =
44 base::MakeUnique<ControllerImpl>(std::move(client_set), std::move(config),
45 std::move(driver), std::move(model));
46
47 return new DownloadServiceImpl(std::move(controller));
14 } 48 }
15 49
16 DownloadServiceImpl::DownloadServiceImpl(std::unique_ptr<Configuration> config) 50 DownloadServiceImpl::DownloadServiceImpl(std::unique_ptr<Controller> controller)
17 : config_(std::move(config)) {} 51 : controller_(std::move(controller)) {
52 controller_->Initialize();
53 }
18 54
19 DownloadServiceImpl::~DownloadServiceImpl() = default; 55 DownloadServiceImpl::~DownloadServiceImpl() = default;
20 56
57 DownloadService::ServiceStatus DownloadServiceImpl::GetStatus() {
58 if (!controller_->GetStartupStatus().Complete())
59 return DownloadService::ServiceStatus::STARTING_UP;
60
61 if (!controller_->GetStartupStatus().Ok())
62 return DownloadService::ServiceStatus::UNAVAILABLE;
63
64 return DownloadService::ServiceStatus::READY;
65 }
66
21 void DownloadServiceImpl::StartDownload(const DownloadParams& download_params) { 67 void DownloadServiceImpl::StartDownload(const DownloadParams& download_params) {
68 stats::LogServiceApiAction(download_params.client,
69 stats::ServiceApiAction::START_DOWNLOAD);
70 controller_->StartDownload(download_params);
22 } 71 }
23 void DownloadServiceImpl::PauseDownload(const std::string& guid) {} 72
24 void DownloadServiceImpl::ResumeDownload(const std::string& guid) {} 73 void DownloadServiceImpl::PauseDownload(const std::string& guid) {
25 void DownloadServiceImpl::CancelDownload(const std::string& guid) {} 74 stats::LogServiceApiAction(controller_->GetOwnerOfDownload(guid),
75 stats::ServiceApiAction::PAUSE_DOWNLOAD);
76 controller_->PauseDownload(guid);
77 }
78
79 void DownloadServiceImpl::ResumeDownload(const std::string& guid) {
80 stats::LogServiceApiAction(controller_->GetOwnerOfDownload(guid),
81 stats::ServiceApiAction::RESUME_DOWNLOAD);
82 controller_->ResumeDownload(guid);
83 }
84
85 void DownloadServiceImpl::CancelDownload(const std::string& guid) {
86 stats::LogServiceApiAction(controller_->GetOwnerOfDownload(guid),
87 stats::ServiceApiAction::CANCEL_DOWNLOAD);
88 controller_->CancelDownload(guid);
89 }
90
26 void DownloadServiceImpl::ChangeDownloadCriteria( 91 void DownloadServiceImpl::ChangeDownloadCriteria(
27 const std::string& guid, 92 const std::string& guid,
28 const SchedulingParams& params) {} 93 const SchedulingParams& params) {
94 stats::LogServiceApiAction(controller_->GetOwnerOfDownload(guid),
95 stats::ServiceApiAction::CHANGE_CRITERIA);
96 controller_->ChangeDownloadCriteria(guid, params);
97 }
29 98
30 } // namespace download 99 } // namespace download
OLDNEW
« no previous file with comments | « components/download/internal/download_service_impl.h ('k') | components/download/internal/download_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698