| 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_CATALOG_H_ | 5 #ifndef SERVICES_CATALOG_CATALOG_H_ |
| 6 #define SERVICES_CATALOG_CATALOG_H_ | 6 #define SERVICES_CATALOG_CATALOG_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "components/filesystem/public/interfaces/directory.mojom.h" | 14 #include "components/filesystem/public/interfaces/directory.mojom.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
| 16 #include "mojo/public/cpp/bindings/binding_set.h" | 16 #include "mojo/public/cpp/bindings/binding_set.h" |
| 17 #include "services/catalog/entry_cache.h" | |
| 18 #include "services/catalog/public/interfaces/catalog.mojom.h" | 17 #include "services/catalog/public/interfaces/catalog.mojom.h" |
| 19 #include "services/service_manager/public/cpp/interface_factory.h" | 18 #include "services/service_manager/public/cpp/interface_factory.h" |
| 20 #include "services/service_manager/public/cpp/service.h" | 19 #include "services/service_manager/public/cpp/service.h" |
| 21 #include "services/service_manager/public/interfaces/resolver.mojom.h" | 20 #include "services/service_manager/public/interfaces/resolver.mojom.h" |
| 22 #include "services/service_manager/public/interfaces/service.mojom.h" | 21 #include "services/service_manager/public/interfaces/service.mojom.h" |
| 23 | 22 |
| 24 namespace base { | 23 namespace base { |
| 25 class FilePath; | 24 class SequencedWorkerPool; |
| 25 class SingleThreadTaskRunner; |
| 26 class Value; | 26 class Value; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace filesystem { | 29 namespace filesystem { |
| 30 class LockTable; | 30 class LockTable; |
| 31 } | 31 } |
| 32 | 32 |
| 33 namespace service_manager { | 33 namespace service_manager { |
| 34 class ServiceContext; | 34 class ServiceContext; |
| 35 } | 35 } |
| 36 | 36 |
| 37 namespace catalog { | 37 namespace catalog { |
| 38 | 38 |
| 39 class EntryCache; |
| 39 class Instance; | 40 class Instance; |
| 40 class ManifestProvider; | 41 class ManifestProvider; |
| 42 class Reader; |
| 41 | 43 |
| 42 // Creates and owns an instance of the catalog. Exposes a ServicePtr that | 44 // Creates and owns an instance of the catalog. Exposes a ServicePtr that |
| 43 // can be passed to the service manager, potentially in a different process. | 45 // can be passed to the service manager, potentially in a different process. |
| 44 class Catalog | 46 class Catalog |
| 45 : public service_manager::InterfaceFactory<mojom::Catalog>, | 47 : public service_manager::InterfaceFactory<mojom::Catalog>, |
| 46 public service_manager::InterfaceFactory<filesystem::mojom::Directory>, | 48 public service_manager::InterfaceFactory<filesystem::mojom::Directory>, |
| 47 public service_manager::InterfaceFactory< | 49 public service_manager::InterfaceFactory< |
| 48 service_manager::mojom::Resolver> { | 50 service_manager::mojom::Resolver>, |
| 51 public service_manager::InterfaceFactory<mojom::CatalogControl>, |
| 52 public mojom::CatalogControl { |
| 49 public: | 53 public: |
| 50 // Constructs a catalog over a static manifest. This catalog never performs | 54 // Constructs a catalog over a static manifest. This catalog never performs |
| 51 // file I/O. Note that either |static_manifest| or |service_manifest_provider| | 55 // file I/O. |
| 52 // may be null. If both are null, no service names will be resolved. | 56 explicit Catalog(std::unique_ptr<base::Value> static_manifest); |
| 53 explicit Catalog(std::unique_ptr<base::Value> static_manifest, | 57 |
| 54 ManifestProvider* service_manifest_provider = nullptr); | 58 // |manifest_provider| may be null. |
| 59 Catalog(base::SequencedWorkerPool* worker_pool, |
| 60 ManifestProvider* manifest_provider); |
| 61 Catalog(base::SingleThreadTaskRunner* task_runner, |
| 62 ManifestProvider* manifest_provider); |
| 55 | 63 |
| 56 ~Catalog() override; | 64 ~Catalog() override; |
| 57 | 65 |
| 66 // By default, "foo" resolves to a package named "foo". This allows |
| 67 // an embedder to override that behavior for specific service names. Must be |
| 68 // called before the catalog is connected to the ServiceManager. |
| 69 void OverridePackageName(const std::string& service_name, |
| 70 const std::string& package_name); |
| 71 |
| 58 service_manager::mojom::ServicePtr TakeService(); | 72 service_manager::mojom::ServicePtr TakeService(); |
| 59 | 73 |
| 60 // Allows an embedder to override the default static manifest contents for | |
| 61 // Catalog instances which are constructed with a null static manifest. | |
| 62 static void SetDefaultCatalogManifest( | |
| 63 std::unique_ptr<base::Value> static_manifest); | |
| 64 | |
| 65 // Loads a default catalog manifest from the given FilePath. |path| is taken | |
| 66 // to be relative to the current executable's path. | |
| 67 static void LoadDefaultCatalogManifest(const base::FilePath& path); | |
| 68 | |
| 69 private: | 74 private: |
| 70 class ServiceImpl; | 75 class ServiceImpl; |
| 71 | 76 |
| 77 Catalog(); |
| 78 |
| 79 // Starts a scane for system packages. |
| 80 void ScanSystemPackageDir(); |
| 81 |
| 72 // service_manager::InterfaceFactory<service_manager::mojom::Resolver>: | 82 // service_manager::InterfaceFactory<service_manager::mojom::Resolver>: |
| 73 void Create(const service_manager::Identity& remote_identity, | 83 void Create(const service_manager::Identity& remote_identity, |
| 74 service_manager::mojom::ResolverRequest request) override; | 84 service_manager::mojom::ResolverRequest request) override; |
| 75 | 85 |
| 76 // service_manager::InterfaceFactory<mojom::Catalog>: | 86 // service_manager::InterfaceFactory<mojom::Catalog>: |
| 77 void Create(const service_manager::Identity& remote_identity, | 87 void Create(const service_manager::Identity& remote_identity, |
| 78 mojom::CatalogRequest request) override; | 88 mojom::CatalogRequest request) override; |
| 79 | 89 |
| 80 // service_manager::InterfaceFactory<filesystem::mojom::Directory>: | 90 // service_manager::InterfaceFactory<filesystem::mojom::Directory>: |
| 81 void Create(const service_manager::Identity& remote_identity, | 91 void Create(const service_manager::Identity& remote_identity, |
| 82 filesystem::mojom::DirectoryRequest request) override; | 92 filesystem::mojom::DirectoryRequest request) override; |
| 83 | 93 |
| 94 // service_manager::InterfaceFactory<mojom::CatalogControl>: |
| 95 void Create(const service_manager::Identity& remote_identity, |
| 96 mojom::CatalogControlRequest request) override; |
| 97 |
| 98 // mojom::CatalogControl: |
| 99 void OverrideManifestPath( |
| 100 const std::string& service_name, |
| 101 const base::FilePath& path, |
| 102 const OverrideManifestPathCallback& callback) override; |
| 103 |
| 84 Instance* GetInstanceForUserId(const std::string& user_id); | 104 Instance* GetInstanceForUserId(const std::string& user_id); |
| 85 | 105 |
| 106 void SystemPackageDirScanned(); |
| 107 |
| 86 service_manager::mojom::ServicePtr service_; | 108 service_manager::mojom::ServicePtr service_; |
| 87 std::unique_ptr<service_manager::ServiceContext> service_context_; | 109 std::unique_ptr<service_manager::ServiceContext> service_context_; |
| 88 ManifestProvider* service_manifest_provider_; | 110 |
| 89 EntryCache system_cache_; | |
| 90 std::map<std::string, std::unique_ptr<Instance>> instances_; | 111 std::map<std::string, std::unique_ptr<Instance>> instances_; |
| 91 | 112 |
| 113 std::unique_ptr<Reader> system_reader_; |
| 114 const std::unique_ptr<EntryCache> system_cache_; |
| 115 bool loaded_ = false; |
| 116 |
| 92 scoped_refptr<filesystem::LockTable> lock_table_; | 117 scoped_refptr<filesystem::LockTable> lock_table_; |
| 93 | 118 |
| 119 mojo::BindingSet<mojom::CatalogControl> control_bindings_; |
| 120 |
| 94 base::WeakPtrFactory<Catalog> weak_factory_; | 121 base::WeakPtrFactory<Catalog> weak_factory_; |
| 95 | 122 |
| 96 DISALLOW_COPY_AND_ASSIGN(Catalog); | 123 DISALLOW_COPY_AND_ASSIGN(Catalog); |
| 97 }; | 124 }; |
| 98 | 125 |
| 99 } // namespace catalog | 126 } // namespace catalog |
| 100 | 127 |
| 101 #endif // SERVICES_CATALOG_CATALOG_H_ | 128 #endif // SERVICES_CATALOG_CATALOG_H_ |
| OLD | NEW |