| 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/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 12 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 14 #include "components/filesystem/directory_impl.h" | 15 #include "components/filesystem/directory_impl.h" |
| 15 #include "components/filesystem/lock_table.h" | 16 #include "components/filesystem/lock_table.h" |
| 16 #include "components/filesystem/public/interfaces/types.mojom.h" | 17 #include "components/filesystem/public/interfaces/types.mojom.h" |
| 17 #include "mojo/public/cpp/bindings/strong_binding.h" | 18 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 18 #include "services/catalog/constants.h" | 19 #include "services/catalog/constants.h" |
| 19 #include "services/catalog/instance.h" | 20 #include "services/catalog/instance.h" |
| 20 #include "services/catalog/reader.h" | 21 #include "services/catalog/reader.h" |
| 21 #include "services/service_manager/public/cpp/connection.h" | 22 #include "services/service_manager/public/cpp/connection.h" |
| 23 #include "services/service_manager/public/cpp/interface_registry.h" |
| 22 #include "services/service_manager/public/cpp/names.h" | 24 #include "services/service_manager/public/cpp/names.h" |
| 23 #include "services/service_manager/public/cpp/service_context.h" | 25 #include "services/service_manager/public/cpp/service_context.h" |
| 24 | 26 |
| 25 namespace catalog { | 27 namespace catalog { |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 bool IsPathNameValid(const std::string& name) { | 30 bool IsPathNameValid(const std::string& name) { |
| 29 if (name.empty() || name == "." || name == "..") | 31 if (name.empty() || name == "." || name == "..") |
| 30 return false; | 32 return false; |
| 31 | 33 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 67 |
| 66 base::FilePath base_path; | 68 base::FilePath base_path; |
| 67 PathService::Get(base::DIR_EXE, &base_path); | 69 PathService::Get(base::DIR_EXE, &base_path); |
| 68 // TODO(beng): this won't handle user-specific components. | 70 // TODO(beng): this won't handle user-specific components. |
| 69 return base_path.AppendASCII(kPackagesDirName).AppendASCII(path). | 71 return base_path.AppendASCII(kPackagesDirName).AppendASCII(path). |
| 70 AppendASCII("resources"); | 72 AppendASCII("resources"); |
| 71 } | 73 } |
| 72 | 74 |
| 73 } // namespace | 75 } // namespace |
| 74 | 76 |
| 77 class Catalog::ServiceImpl : public service_manager::Service { |
| 78 public: |
| 79 explicit ServiceImpl(Catalog* catalog) : catalog_(catalog) {} |
| 80 ~ServiceImpl() override {} |
| 81 |
| 82 // service_manager::Service: |
| 83 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
| 84 service_manager::InterfaceRegistry* registry) override { |
| 85 registry->AddInterface<mojom::Catalog>(catalog_); |
| 86 registry->AddInterface<mojom::CatalogControl>(catalog_); |
| 87 registry->AddInterface<filesystem::mojom::Directory>(catalog_); |
| 88 registry->AddInterface<service_manager::mojom::Resolver>(catalog_); |
| 89 return true; |
| 90 } |
| 91 |
| 92 private: |
| 93 Catalog* const catalog_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(ServiceImpl); |
| 96 }; |
| 97 |
| 75 Catalog::Catalog(base::SequencedWorkerPool* worker_pool, | 98 Catalog::Catalog(base::SequencedWorkerPool* worker_pool, |
| 76 std::unique_ptr<Store> store, | 99 std::unique_ptr<Store> store, |
| 77 ManifestProvider* manifest_provider) | 100 ManifestProvider* manifest_provider) |
| 78 : Catalog(std::move(store)) { | 101 : Catalog(std::move(store)) { |
| 79 system_reader_.reset(new Reader(worker_pool, manifest_provider)); | 102 system_reader_.reset(new Reader(worker_pool, manifest_provider)); |
| 80 ScanSystemPackageDir(); | 103 ScanSystemPackageDir(); |
| 81 } | 104 } |
| 82 | 105 |
| 83 Catalog::Catalog(base::SingleThreadTaskRunner* task_runner, | 106 Catalog::Catalog(base::SingleThreadTaskRunner* task_runner, |
| 84 std::unique_ptr<Store> store, | 107 std::unique_ptr<Store> store, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 95 system_reader_->OverridePackageName(service_name, package_name); | 118 system_reader_->OverridePackageName(service_name, package_name); |
| 96 } | 119 } |
| 97 | 120 |
| 98 service_manager::mojom::ServicePtr Catalog::TakeService() { | 121 service_manager::mojom::ServicePtr Catalog::TakeService() { |
| 99 return std::move(service_); | 122 return std::move(service_); |
| 100 } | 123 } |
| 101 | 124 |
| 102 Catalog::Catalog(std::unique_ptr<Store> store) | 125 Catalog::Catalog(std::unique_ptr<Store> store) |
| 103 : store_(std::move(store)), weak_factory_(this) { | 126 : store_(std::move(store)), weak_factory_(this) { |
| 104 service_manager::mojom::ServiceRequest request = GetProxy(&service_); | 127 service_manager::mojom::ServiceRequest request = GetProxy(&service_); |
| 105 service_manager_connection_.reset( | 128 service_context_.reset(new service_manager::ServiceContext( |
| 106 new service_manager::ServiceContext(this, std::move(request))); | 129 base::MakeUnique<ServiceImpl>(this), std::move(request))); |
| 107 } | 130 } |
| 108 | 131 |
| 109 void Catalog::ScanSystemPackageDir() { | 132 void Catalog::ScanSystemPackageDir() { |
| 110 base::FilePath system_package_dir; | 133 base::FilePath system_package_dir; |
| 111 PathService::Get(base::DIR_MODULE, &system_package_dir); | 134 PathService::Get(base::DIR_MODULE, &system_package_dir); |
| 112 system_package_dir = system_package_dir.AppendASCII(kPackagesDirName); | 135 system_package_dir = system_package_dir.AppendASCII(kPackagesDirName); |
| 113 system_reader_->Read(system_package_dir, &system_cache_, | 136 system_reader_->Read(system_package_dir, &system_cache_, |
| 114 base::Bind(&Catalog::SystemPackageDirScanned, | 137 base::Bind(&Catalog::SystemPackageDirScanned, |
| 115 weak_factory_.GetWeakPtr())); | 138 weak_factory_.GetWeakPtr())); |
| 116 } | 139 } |
| 117 | 140 |
| 118 bool Catalog::OnConnect(const service_manager::ServiceInfo& remote_info, | |
| 119 service_manager::InterfaceRegistry* registry) { | |
| 120 registry->AddInterface<mojom::Catalog>(this); | |
| 121 registry->AddInterface<mojom::CatalogControl>(this); | |
| 122 registry->AddInterface<filesystem::mojom::Directory>(this); | |
| 123 registry->AddInterface<service_manager::mojom::Resolver>(this); | |
| 124 return true; | |
| 125 } | |
| 126 | |
| 127 void Catalog::Create(const service_manager::Identity& remote_identity, | 141 void Catalog::Create(const service_manager::Identity& remote_identity, |
| 128 service_manager::mojom::ResolverRequest request) { | 142 service_manager::mojom::ResolverRequest request) { |
| 129 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); | 143 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); |
| 130 instance->BindResolver(std::move(request)); | 144 instance->BindResolver(std::move(request)); |
| 131 } | 145 } |
| 132 | 146 |
| 133 void Catalog::Create(const service_manager::Identity& remote_identity, | 147 void Catalog::Create(const service_manager::Identity& remote_identity, |
| 134 mojom::CatalogRequest request) { | 148 mojom::CatalogRequest request) { |
| 135 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); | 149 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); |
| 136 instance->BindCatalog(std::move(request)); | 150 instance->BindCatalog(std::move(request)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 return instance; | 190 return instance; |
| 177 } | 191 } |
| 178 | 192 |
| 179 void Catalog::SystemPackageDirScanned() { | 193 void Catalog::SystemPackageDirScanned() { |
| 180 loaded_ = true; | 194 loaded_ = true; |
| 181 for (auto& instance : instances_) | 195 for (auto& instance : instances_) |
| 182 instance.second->CacheReady(&system_cache_); | 196 instance.second->CacheReady(&system_cache_); |
| 183 } | 197 } |
| 184 | 198 |
| 185 } // namespace catalog | 199 } // namespace catalog |
| OLD | NEW |