| 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 #ifndef SERVICES_CATALOG_INSTANCE_H_ | 5 #ifndef SERVICES_CATALOG_INSTANCE_H_ |
| 6 #define SERVICES_CATALOG_INSTANCE_H_ | 6 #define SERVICES_CATALOG_INSTANCE_H_ |
| 7 | 7 |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 11 #include "base/values.h" | 10 #include "base/values.h" |
| 12 #include "mojo/public/cpp/bindings/binding_set.h" | 11 #include "mojo/public/cpp/bindings/binding_set.h" |
| 13 #include "services/catalog/entry.h" | 12 #include "services/catalog/entry.h" |
| 14 #include "services/catalog/public/interfaces/catalog.mojom.h" | 13 #include "services/catalog/public/interfaces/catalog.mojom.h" |
| 15 #include "services/catalog/store.h" | 14 #include "services/catalog/store.h" |
| 16 #include "services/catalog/types.h" | 15 #include "services/catalog/types.h" |
| 17 #include "services/service_manager/public/cpp/interface_factory.h" | 16 #include "services/service_manager/public/cpp/interface_factory.h" |
| 18 #include "services/service_manager/public/interfaces/resolver.mojom.h" | 17 #include "services/service_manager/public/interfaces/resolver.mojom.h" |
| 19 | 18 |
| 20 namespace catalog { | 19 namespace catalog { |
| 21 | 20 |
| 22 class Reader; | 21 class Reader; |
| 23 class Store; | |
| 24 | 22 |
| 25 class Instance : public service_manager::mojom::Resolver, | 23 class Instance : public service_manager::mojom::Resolver, |
| 26 public mojom::Catalog { | 24 public mojom::Catalog { |
| 27 public: | 25 public: |
| 28 // |manifest_provider| may be null. | 26 // |manifest_provider| may be null. |
| 29 Instance(std::unique_ptr<Store> store, Reader* system_reader); | 27 explicit Instance(Reader* system_reader); |
| 30 ~Instance() override; | 28 ~Instance() override; |
| 31 | 29 |
| 32 void BindResolver(service_manager::mojom::ResolverRequest request); | 30 void BindResolver(service_manager::mojom::ResolverRequest request); |
| 33 void BindCatalog(mojom::CatalogRequest request); | 31 void BindCatalog(mojom::CatalogRequest request); |
| 34 | 32 |
| 35 // Called when |cache| has been populated by a directory scan. | 33 // Called when |cache| has been populated by a directory scan. |
| 36 void CacheReady(EntryCache* cache); | 34 void CacheReady(EntryCache* cache); |
| 37 | 35 |
| 38 private: | 36 private: |
| 39 // service_manager::mojom::Resolver: | 37 // service_manager::mojom::Resolver: |
| 40 void ResolveMojoName(const std::string& service_name, | 38 void ResolveServiceName(const std::string& service_name, |
| 41 const ResolveMojoNameCallback& callback) override; | 39 const ResolveServiceNameCallback& callback) override; |
| 42 | 40 |
| 43 // mojom::Catalog: | 41 // mojom::Catalog: |
| 44 void GetEntries(const base::Optional<std::vector<std::string>>& names, | 42 void GetEntries(const base::Optional<std::vector<std::string>>& names, |
| 45 const GetEntriesCallback& callback) override; | 43 const GetEntriesCallback& callback) override; |
| 46 void GetEntriesProvidingCapability( | 44 void GetEntriesProvidingCapability( |
| 47 const std::string& capability, | 45 const std::string& capability, |
| 48 const GetEntriesProvidingCapabilityCallback& callback) override; | 46 const GetEntriesProvidingCapabilityCallback& callback) override; |
| 49 void GetEntriesConsumingMIMEType( | 47 void GetEntriesConsumingMIMEType( |
| 50 const std::string& mime_type, | 48 const std::string& mime_type, |
| 51 const GetEntriesConsumingMIMETypeCallback& callback) override; | 49 const GetEntriesConsumingMIMETypeCallback& callback) override; |
| 52 void GetEntriesSupportingScheme( | 50 void GetEntriesSupportingScheme( |
| 53 const std::string& scheme, | 51 const std::string& scheme, |
| 54 const GetEntriesSupportingSchemeCallback& callback) override; | 52 const GetEntriesSupportingSchemeCallback& callback) override; |
| 55 | 53 |
| 56 // Populate/serialize the cache from/to the supplied store. | |
| 57 void DeserializeCatalog(); | |
| 58 void SerializeCatalog(); | |
| 59 | |
| 60 // Receives the result of manifest parsing, may be received after the | |
| 61 // catalog object that issued the request is destroyed. | |
| 62 static void OnReadManifest(base::WeakPtr<Instance> instance, | |
| 63 const std::string& service_name, | |
| 64 const ResolveMojoNameCallback& callback, | |
| 65 service_manager::mojom::ResolveResultPtr result); | |
| 66 | |
| 67 // User-specific persistent storage of package manifests and other settings. | |
| 68 std::unique_ptr<Store> store_; | |
| 69 | |
| 70 mojo::BindingSet<service_manager::mojom::Resolver> resolver_bindings_; | 54 mojo::BindingSet<service_manager::mojom::Resolver> resolver_bindings_; |
| 71 mojo::BindingSet<mojom::Catalog> catalog_bindings_; | 55 mojo::BindingSet<mojom::Catalog> catalog_bindings_; |
| 72 | 56 |
| 73 Reader* system_reader_; | 57 Reader* system_reader_; |
| 74 | 58 |
| 75 // A map of name -> Entry data structure for system-level packages (i.e. those | 59 // A map of name -> Entry data structure for system-level packages (i.e. those |
| 76 // that are visible to all users). | 60 // that are visible to all users). |
| 77 // TODO(beng): eventually add per-user applications. | 61 // TODO(beng): eventually add per-user applications. |
| 78 EntryCache* system_cache_ = nullptr; | 62 EntryCache* system_cache_ = nullptr; |
| 79 | 63 |
| 80 // We only bind requests for these interfaces once the catalog has been | 64 // We only bind requests for these interfaces once the catalog has been |
| 81 // populated. These data structures queue requests until that happens. | 65 // populated. These data structures queue requests until that happens. |
| 82 std::vector<service_manager::mojom::ResolverRequest> | 66 std::vector<service_manager::mojom::ResolverRequest> |
| 83 pending_resolver_requests_; | 67 pending_resolver_requests_; |
| 84 std::vector<mojom::CatalogRequest> pending_catalog_requests_; | 68 std::vector<mojom::CatalogRequest> pending_catalog_requests_; |
| 85 | 69 |
| 86 base::WeakPtrFactory<Instance> weak_factory_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(Instance); | 70 DISALLOW_COPY_AND_ASSIGN(Instance); |
| 89 }; | 71 }; |
| 90 | 72 |
| 91 } // namespace catalog | 73 } // namespace catalog |
| 92 | 74 |
| 93 #endif // SERVICES_CATALOG_INSTANCE_H_ | 75 #endif // SERVICES_CATALOG_INSTANCE_H_ |
| OLD | NEW |