| 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/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "components/filesystem/directory_impl.h" | 15 #include "components/filesystem/directory_impl.h" |
| 16 #include "components/filesystem/lock_table.h" | 16 #include "components/filesystem/lock_table.h" |
| 17 #include "components/filesystem/public/interfaces/types.mojom.h" | 17 #include "components/filesystem/public/interfaces/types.mojom.h" |
| 18 #include "mojo/public/cpp/bindings/strong_binding.h" | 18 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 19 #include "services/catalog/constants.h" | 19 #include "services/catalog/constants.h" |
| 20 #include "services/catalog/entry_cache.h" |
| 20 #include "services/catalog/instance.h" | 21 #include "services/catalog/instance.h" |
| 21 #include "services/catalog/reader.h" | 22 #include "services/catalog/reader.h" |
| 22 #include "services/service_manager/public/cpp/connection.h" | 23 #include "services/service_manager/public/cpp/connection.h" |
| 23 #include "services/service_manager/public/cpp/interface_registry.h" | 24 #include "services/service_manager/public/cpp/interface_registry.h" |
| 24 #include "services/service_manager/public/cpp/service_context.h" | 25 #include "services/service_manager/public/cpp/service_context.h" |
| 25 | 26 |
| 26 namespace catalog { | 27 namespace catalog { |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 bool IsPathNameValid(const std::string& name) { | 30 bool IsPathNameValid(const std::string& name) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return true; | 81 return true; |
| 81 } | 82 } |
| 82 | 83 |
| 83 private: | 84 private: |
| 84 Catalog* const catalog_; | 85 Catalog* const catalog_; |
| 85 | 86 |
| 86 DISALLOW_COPY_AND_ASSIGN(ServiceImpl); | 87 DISALLOW_COPY_AND_ASSIGN(ServiceImpl); |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 Catalog::Catalog(std::unique_ptr<base::Value> static_manifest) : Catalog() { | 90 Catalog::Catalog(std::unique_ptr<base::Value> static_manifest) : Catalog() { |
| 90 system_reader_.reset(new Reader(std::move(static_manifest), &system_cache_)); | 91 system_reader_.reset(new Reader(std::move(static_manifest), |
| 92 system_cache_.get())); |
| 91 loaded_ = true; | 93 loaded_ = true; |
| 92 } | 94 } |
| 93 | 95 |
| 94 Catalog::Catalog(base::SequencedWorkerPool* worker_pool, | 96 Catalog::Catalog(base::SequencedWorkerPool* worker_pool, |
| 95 ManifestProvider* manifest_provider) : Catalog() { | 97 ManifestProvider* manifest_provider) : Catalog() { |
| 96 system_reader_.reset(new Reader(worker_pool, manifest_provider)); | 98 system_reader_.reset(new Reader(worker_pool, manifest_provider)); |
| 97 ScanSystemPackageDir(); | 99 ScanSystemPackageDir(); |
| 98 } | 100 } |
| 99 | 101 |
| 100 Catalog::Catalog(base::SingleThreadTaskRunner* task_runner, | 102 Catalog::Catalog(base::SingleThreadTaskRunner* task_runner, |
| 101 ManifestProvider* manifest_provider) : Catalog() { | 103 ManifestProvider* manifest_provider) : Catalog() { |
| 102 system_reader_.reset(new Reader(task_runner, manifest_provider)); | 104 system_reader_.reset(new Reader(task_runner, manifest_provider)); |
| 103 ScanSystemPackageDir(); | 105 ScanSystemPackageDir(); |
| 104 } | 106 } |
| 105 | 107 |
| 106 Catalog::~Catalog() {} | 108 Catalog::~Catalog() {} |
| 107 | 109 |
| 108 void Catalog::OverridePackageName(const std::string& service_name, | 110 void Catalog::OverridePackageName(const std::string& service_name, |
| 109 const std::string& package_name) { | 111 const std::string& package_name) { |
| 110 system_reader_->OverridePackageName(service_name, package_name); | 112 system_reader_->OverridePackageName(service_name, package_name); |
| 111 } | 113 } |
| 112 | 114 |
| 113 service_manager::mojom::ServicePtr Catalog::TakeService() { | 115 service_manager::mojom::ServicePtr Catalog::TakeService() { |
| 114 return std::move(service_); | 116 return std::move(service_); |
| 115 } | 117 } |
| 116 | 118 |
| 117 Catalog::Catalog() : weak_factory_(this) { | 119 Catalog::Catalog() : system_cache_(new EntryCache), weak_factory_(this) { |
| 118 service_context_.reset(new service_manager::ServiceContext( | 120 service_context_.reset(new service_manager::ServiceContext( |
| 119 base::MakeUnique<ServiceImpl>(this), | 121 base::MakeUnique<ServiceImpl>(this), |
| 120 service_manager::mojom::ServiceRequest(&service_))); | 122 service_manager::mojom::ServiceRequest(&service_))); |
| 121 } | 123 } |
| 122 | 124 |
| 123 void Catalog::ScanSystemPackageDir() { | 125 void Catalog::ScanSystemPackageDir() { |
| 124 base::FilePath system_package_dir; | 126 base::FilePath system_package_dir; |
| 125 PathService::Get(base::DIR_MODULE, &system_package_dir); | 127 PathService::Get(base::DIR_MODULE, &system_package_dir); |
| 126 system_package_dir = system_package_dir.AppendASCII(kPackagesDirName); | 128 system_package_dir = system_package_dir.AppendASCII(kPackagesDirName); |
| 127 system_reader_->Read(system_package_dir, &system_cache_, | 129 system_reader_->Read(system_package_dir, system_cache_.get(), |
| 128 base::Bind(&Catalog::SystemPackageDirScanned, | 130 base::Bind(&Catalog::SystemPackageDirScanned, |
| 129 weak_factory_.GetWeakPtr())); | 131 weak_factory_.GetWeakPtr())); |
| 130 } | 132 } |
| 131 | 133 |
| 132 void Catalog::Create(const service_manager::Identity& remote_identity, | 134 void Catalog::Create(const service_manager::Identity& remote_identity, |
| 133 service_manager::mojom::ResolverRequest request) { | 135 service_manager::mojom::ResolverRequest request) { |
| 134 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); | 136 Instance* instance = GetInstanceForUserId(remote_identity.user_id()); |
| 135 instance->BindResolver(std::move(request)); | 137 instance->BindResolver(std::move(request)); |
| 136 } | 138 } |
| 137 | 139 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 168 } | 170 } |
| 169 | 171 |
| 170 Instance* Catalog::GetInstanceForUserId(const std::string& user_id) { | 172 Instance* Catalog::GetInstanceForUserId(const std::string& user_id) { |
| 171 auto it = instances_.find(user_id); | 173 auto it = instances_.find(user_id); |
| 172 if (it != instances_.end()) | 174 if (it != instances_.end()) |
| 173 return it->second.get(); | 175 return it->second.get(); |
| 174 | 176 |
| 175 Instance* instance = new Instance(system_reader_.get()); | 177 Instance* instance = new Instance(system_reader_.get()); |
| 176 instances_[user_id] = base::WrapUnique(instance); | 178 instances_[user_id] = base::WrapUnique(instance); |
| 177 if (loaded_) | 179 if (loaded_) |
| 178 instance->CacheReady(&system_cache_); | 180 instance->CacheReady(system_cache_.get()); |
| 179 | 181 |
| 180 return instance; | 182 return instance; |
| 181 } | 183 } |
| 182 | 184 |
| 183 void Catalog::SystemPackageDirScanned() { | 185 void Catalog::SystemPackageDirScanned() { |
| 184 loaded_ = true; | 186 loaded_ = true; |
| 185 for (auto& instance : instances_) | 187 for (auto& instance : instances_) |
| 186 instance.second->CacheReady(&system_cache_); | 188 instance.second->CacheReady(system_cache_.get()); |
| 187 } | 189 } |
| 188 | 190 |
| 189 } // namespace catalog | 191 } // namespace catalog |
| OLD | NEW |