| 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/instance.h" | 5 #include "services/catalog/instance.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "services/catalog/entry.h" | 8 #include "services/catalog/entry.h" |
| 9 #include "services/catalog/manifest_provider.h" | 9 #include "services/catalog/manifest_provider.h" |
| 10 #include "services/catalog/reader.h" | 10 #include "services/catalog/reader.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 //////////////////////////////////////////////////////////////////////////////// | 26 //////////////////////////////////////////////////////////////////////////////// |
| 27 // Instance, public: | 27 // Instance, public: |
| 28 | 28 |
| 29 Instance::Instance(std::unique_ptr<Store> store, Reader* system_reader) | 29 Instance::Instance(std::unique_ptr<Store> store, Reader* system_reader) |
| 30 : store_(std::move(store)), | 30 : store_(std::move(store)), |
| 31 system_reader_(system_reader), | 31 system_reader_(system_reader), |
| 32 weak_factory_(this) {} | 32 weak_factory_(this) {} |
| 33 Instance::~Instance() {} | 33 Instance::~Instance() {} |
| 34 | 34 |
| 35 void Instance::BindResolver(shell::mojom::ResolverRequest request) { | 35 void Instance::BindResolver(service_manager::mojom::ResolverRequest request) { |
| 36 if (system_cache_) | 36 if (system_cache_) |
| 37 resolver_bindings_.AddBinding(this, std::move(request)); | 37 resolver_bindings_.AddBinding(this, std::move(request)); |
| 38 else | 38 else |
| 39 pending_resolver_requests_.push_back(std::move(request)); | 39 pending_resolver_requests_.push_back(std::move(request)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void Instance::BindCatalog(mojom::CatalogRequest request) { | 42 void Instance::BindCatalog(mojom::CatalogRequest request) { |
| 43 if (system_cache_) | 43 if (system_cache_) |
| 44 catalog_bindings_.AddBinding(this, std::move(request)); | 44 catalog_bindings_.AddBinding(this, std::move(request)); |
| 45 else | 45 else |
| 46 pending_catalog_requests_.push_back(std::move(request)); | 46 pending_catalog_requests_.push_back(std::move(request)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void Instance::CacheReady(EntryCache* cache) { | 49 void Instance::CacheReady(EntryCache* cache) { |
| 50 system_cache_ = cache; | 50 system_cache_ = cache; |
| 51 DeserializeCatalog(); | 51 DeserializeCatalog(); |
| 52 for (auto& request : pending_resolver_requests_) | 52 for (auto& request : pending_resolver_requests_) |
| 53 BindResolver(std::move(request)); | 53 BindResolver(std::move(request)); |
| 54 for (auto& request : pending_catalog_requests_) | 54 for (auto& request : pending_catalog_requests_) |
| 55 BindCatalog(std::move(request)); | 55 BindCatalog(std::move(request)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 //////////////////////////////////////////////////////////////////////////////// | 58 //////////////////////////////////////////////////////////////////////////////// |
| 59 // Instance, shell::mojom::Resolver: | 59 // Instance, service_manager::mojom::Resolver: |
| 60 | 60 |
| 61 void Instance::ResolveMojoName(const std::string& mojo_name, | 61 void Instance::ResolveMojoName(const std::string& mojo_name, |
| 62 const ResolveMojoNameCallback& callback) { | 62 const ResolveMojoNameCallback& callback) { |
| 63 DCHECK(system_cache_); | 63 DCHECK(system_cache_); |
| 64 | 64 |
| 65 std::string type = shell::GetNameType(mojo_name); | 65 std::string type = service_manager::GetNameType(mojo_name); |
| 66 if (type != shell::kNameType_Service && type != shell::kNameType_Exe) { | 66 if (type != service_manager::kNameType_Service && |
| 67 type != service_manager::kNameType_Exe) { |
| 67 std::unique_ptr<Entry> entry(new Entry(mojo_name)); | 68 std::unique_ptr<Entry> entry(new Entry(mojo_name)); |
| 68 shell::mojom::ResolveResultPtr result = | 69 service_manager::mojom::ResolveResultPtr result = |
| 69 shell::mojom::ResolveResult::From(*entry); | 70 service_manager::mojom::ResolveResult::From(*entry); |
| 70 result->capabilities = base::nullopt; | 71 result->capabilities = base::nullopt; |
| 71 callback.Run(std::move(result)); | 72 callback.Run(std::move(result)); |
| 72 return; | 73 return; |
| 73 } | 74 } |
| 74 | 75 |
| 75 // TODO(beng): per-user catalogs. | 76 // TODO(beng): per-user catalogs. |
| 76 auto entry = system_cache_->find(mojo_name); | 77 auto entry = system_cache_->find(mojo_name); |
| 77 if (entry != system_cache_->end()) { | 78 if (entry != system_cache_->end()) { |
| 78 callback.Run(shell::mojom::ResolveResult::From(*entry->second)); | 79 callback.Run(service_manager::mojom::ResolveResult::From(*entry->second)); |
| 79 return; | 80 return; |
| 80 } | 81 } |
| 81 | 82 |
| 82 // Manifests for mojo: names should always be in the catalog by this point. | 83 // Manifests for mojo: names should always be in the catalog by this point. |
| 83 //DCHECK(type == shell::kNameType_Exe); | 84 // DCHECK(type == service_manager::kNameType_Exe); |
| 84 system_reader_->CreateEntryForName( | 85 system_reader_->CreateEntryForName( |
| 85 mojo_name, system_cache_, | 86 mojo_name, system_cache_, |
| 86 base::Bind(&Instance::OnReadManifest, weak_factory_.GetWeakPtr(), | 87 base::Bind(&Instance::OnReadManifest, weak_factory_.GetWeakPtr(), |
| 87 mojo_name, callback)); | 88 mojo_name, callback)); |
| 88 } | 89 } |
| 89 | 90 |
| 90 //////////////////////////////////////////////////////////////////////////////// | 91 //////////////////////////////////////////////////////////////////////////////// |
| 91 // Instance, mojom::Catalog: | 92 // Instance, mojom::Catalog: |
| 92 | 93 |
| 93 void Instance::GetEntries(const base::Optional<std::vector<std::string>>& names, | 94 void Instance::GetEntries(const base::Optional<std::vector<std::string>>& names, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 for (const auto& entry : *system_cache_) | 164 for (const auto& entry : *system_cache_) |
| 164 catalog->Append(entry.second->Serialize()); | 165 catalog->Append(entry.second->Serialize()); |
| 165 if (store_) | 166 if (store_) |
| 166 store_->UpdateStore(std::move(catalog)); | 167 store_->UpdateStore(std::move(catalog)); |
| 167 } | 168 } |
| 168 | 169 |
| 169 // static | 170 // static |
| 170 void Instance::OnReadManifest(base::WeakPtr<Instance> instance, | 171 void Instance::OnReadManifest(base::WeakPtr<Instance> instance, |
| 171 const std::string& mojo_name, | 172 const std::string& mojo_name, |
| 172 const ResolveMojoNameCallback& callback, | 173 const ResolveMojoNameCallback& callback, |
| 173 shell::mojom::ResolveResultPtr result) { | 174 service_manager::mojom::ResolveResultPtr result) { |
| 174 callback.Run(std::move(result)); | 175 callback.Run(std::move(result)); |
| 175 if (instance) | 176 if (instance) |
| 176 instance->SerializeCatalog(); | 177 instance->SerializeCatalog(); |
| 177 } | 178 } |
| 178 | 179 |
| 179 } // namespace catalog | 180 } // namespace catalog |
| OLD | NEW |