OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/catalog/catalog.h" | 5 #include "services/catalog/catalog.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "services/catalog/constants.h" | 9 #include "services/catalog/constants.h" |
10 #include "services/catalog/instance.h" | 10 #include "services/catalog/instance.h" |
11 #include "services/catalog/reader.h" | 11 #include "services/catalog/reader.h" |
12 #include "services/shell/public/cpp/connection.h" | 12 #include "services/shell/public/cpp/connection.h" |
13 #include "services/shell/public/cpp/shell_connection.h" | 13 #include "services/shell/public/cpp/shell_connection.h" |
14 | 14 |
15 namespace catalog { | 15 namespace catalog { |
16 | 16 |
17 Catalog::Catalog(base::TaskRunner* file_task_runner, | 17 Catalog::Catalog(base::SequencedWorkerPool* worker_pool, |
18 std::unique_ptr<Store> store, | 18 std::unique_ptr<Store> store, |
19 ManifestProvider* manifest_provider) | 19 ManifestProvider* manifest_provider) |
20 : file_task_runner_(file_task_runner), | 20 : Catalog(std::move(store)) { |
21 store_(std::move(store)), | 21 system_reader_.reset(new Reader(worker_pool, manifest_provider)); |
22 weak_factory_(this) { | 22 ScanSystemPackageDir(); |
23 shell::mojom::ShellClientRequest request = GetProxy(&shell_client_); | 23 } |
24 shell_connection_.reset(new shell::ShellConnection(this, std::move(request))); | |
25 | 24 |
26 base::FilePath system_package_dir; | 25 Catalog::Catalog(base::SingleThreadTaskRunner* task_runner, |
27 PathService::Get(base::DIR_MODULE, &system_package_dir); | 26 std::unique_ptr<Store> store, |
28 system_package_dir = system_package_dir.AppendASCII(kMojoApplicationsDirName); | 27 ManifestProvider* manifest_provider) |
29 system_reader_.reset(new Reader(file_task_runner, manifest_provider)); | 28 : Catalog(std::move(store)) { |
30 system_reader_->Read(system_package_dir, &system_cache_, | 29 system_reader_.reset(new Reader(task_runner, manifest_provider)); |
31 base::Bind(&Catalog::SystemPackageDirScanned, | 30 ScanSystemPackageDir(); |
32 weak_factory_.GetWeakPtr())); | |
33 } | 31 } |
34 | 32 |
35 Catalog::~Catalog() {} | 33 Catalog::~Catalog() {} |
36 | 34 |
37 shell::mojom::ShellClientPtr Catalog::TakeShellClient() { | 35 shell::mojom::ShellClientPtr Catalog::TakeShellClient() { |
38 return std::move(shell_client_); | 36 return std::move(shell_client_); |
39 } | 37 } |
40 | 38 |
| 39 Catalog::Catalog(std::unique_ptr<Store> store) |
| 40 : store_(std::move(store)), weak_factory_(this) { |
| 41 shell::mojom::ShellClientRequest request = GetProxy(&shell_client_); |
| 42 shell_connection_.reset(new shell::ShellConnection(this, std::move(request))); |
| 43 } |
| 44 |
| 45 void Catalog::ScanSystemPackageDir() { |
| 46 base::FilePath system_package_dir; |
| 47 PathService::Get(base::DIR_MODULE, &system_package_dir); |
| 48 system_package_dir = system_package_dir.AppendASCII(kMojoApplicationsDirName); |
| 49 system_reader_->Read(system_package_dir, &system_cache_, |
| 50 base::Bind(&Catalog::SystemPackageDirScanned, |
| 51 weak_factory_.GetWeakPtr())); |
| 52 } |
| 53 |
41 bool Catalog::AcceptConnection(shell::Connection* connection) { | 54 bool Catalog::AcceptConnection(shell::Connection* connection) { |
42 connection->AddInterface<mojom::Catalog>(this); | 55 connection->AddInterface<mojom::Catalog>(this); |
43 connection->AddInterface<shell::mojom::ShellResolver>(this); | 56 connection->AddInterface<shell::mojom::ShellResolver>(this); |
44 return true; | 57 return true; |
45 } | 58 } |
46 | 59 |
47 void Catalog::Create(shell::Connection* connection, | 60 void Catalog::Create(shell::Connection* connection, |
48 shell::mojom::ShellResolverRequest request) { | 61 shell::mojom::ShellResolverRequest request) { |
49 Instance* instance = | 62 Instance* instance = |
50 GetInstanceForUserId(connection->GetRemoteIdentity().user_id()); | 63 GetInstanceForUserId(connection->GetRemoteIdentity().user_id()); |
(...skipping 21 matching lines...) Expand all Loading... |
72 return instance; | 85 return instance; |
73 } | 86 } |
74 | 87 |
75 void Catalog::SystemPackageDirScanned() { | 88 void Catalog::SystemPackageDirScanned() { |
76 loaded_ = true; | 89 loaded_ = true; |
77 for (auto& instance : instances_) | 90 for (auto& instance : instances_) |
78 instance.second->CacheReady(&system_cache_); | 91 instance.second->CacheReady(&system_cache_); |
79 } | 92 } |
80 | 93 |
81 } // namespace catalog | 94 } // namespace catalog |
OLD | NEW |