| 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 MOJO_SERVICES_CATALOG_CATALOG_H_ | 5 #ifndef MOJO_SERVICES_CATALOG_CATALOG_H_ |
| 6 #define MOJO_SERVICES_CATALOG_CATALOG_H_ | 6 #define MOJO_SERVICES_CATALOG_CATALOG_H_ |
| 7 | 7 |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/strings/string_piece.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "mojo/public/cpp/bindings/binding_set.h" | 13 #include "mojo/public/cpp/bindings/binding_set.h" |
| 13 #include "mojo/services/catalog/entry.h" | 14 #include "mojo/services/catalog/entry.h" |
| 14 #include "mojo/services/catalog/public/interfaces/catalog.mojom.h" | 15 #include "mojo/services/catalog/public/interfaces/catalog.mojom.h" |
| 15 #include "mojo/services/catalog/public/interfaces/resolver.mojom.h" | 16 #include "mojo/services/catalog/public/interfaces/resolver.mojom.h" |
| 16 #include "mojo/services/catalog/store.h" | 17 #include "mojo/services/catalog/store.h" |
| 17 #include "mojo/shell/public/cpp/interface_factory.h" | 18 #include "mojo/shell/public/cpp/interface_factory.h" |
| 18 #include "mojo/shell/public/interfaces/shell_resolver.mojom.h" | 19 #include "mojo/shell/public/interfaces/shell_resolver.mojom.h" |
| 19 | 20 |
| 20 namespace catalog { | 21 namespace catalog { |
| 21 | 22 |
| 22 class Store; | 23 class Store; |
| 23 | 24 |
| 24 struct ReadManifestResult { | 25 struct ReadManifestResult { |
| 25 ReadManifestResult(); | 26 ReadManifestResult(); |
| 26 ~ReadManifestResult(); | 27 ~ReadManifestResult(); |
| 27 scoped_ptr<base::Value> manifest_root; | 28 scoped_ptr<base::Value> manifest_root; |
| 28 base::FilePath package_dir; | 29 base::FilePath package_dir; |
| 29 }; | 30 }; |
| 30 | 31 |
| 31 class Catalog : public mojom::Resolver, | 32 class Catalog : public mojom::Resolver, |
| 32 public mojo::shell::mojom::ShellResolver, | 33 public mojo::shell::mojom::ShellResolver, |
| 33 public mojom::Catalog { | 34 public mojom::Catalog { |
| 34 public: | 35 public: |
| 35 Catalog(scoped_ptr<Store> store, base::TaskRunner* file_task_runner); | 36 class Delegate { |
| 37 public: |
| 38 virtual ~Delegate() {} |
| 39 virtual bool GetApplicationManifest(const base::StringPiece& name, |
| 40 std::string* manifest_contents) = 0; |
| 41 }; |
| 42 |
| 43 // |delegate| may be null. |
| 44 Catalog(scoped_ptr<Store> store, |
| 45 base::TaskRunner* file_task_runner, |
| 46 Delegate* delegate); |
| 36 ~Catalog() override; | 47 ~Catalog() override; |
| 37 | 48 |
| 38 void BindResolver(mojom::ResolverRequest request); | 49 void BindResolver(mojom::ResolverRequest request); |
| 39 void BindShellResolver(mojo::shell::mojom::ShellResolverRequest request); | 50 void BindShellResolver(mojo::shell::mojom::ShellResolverRequest request); |
| 40 void BindCatalog(mojom::CatalogRequest request); | 51 void BindCatalog(mojom::CatalogRequest request); |
| 41 | 52 |
| 42 private: | 53 private: |
| 43 using MojoNameAliasMap = | 54 using MojoNameAliasMap = |
| 44 std::map<std::string, std::pair<std::string, std::string>>; | 55 std::map<std::string, std::pair<std::string, std::string>>; |
| 45 | 56 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 71 // received after the catalog object that issued the request is destroyed. | 82 // received after the catalog object that issued the request is destroyed. |
| 72 static void OnReadManifest(base::WeakPtr<Catalog> catalog, | 83 static void OnReadManifest(base::WeakPtr<Catalog> catalog, |
| 73 const std::string& name, | 84 const std::string& name, |
| 74 const ResolveMojoNameCallback& callback, | 85 const ResolveMojoNameCallback& callback, |
| 75 scoped_ptr<ReadManifestResult> result); | 86 scoped_ptr<ReadManifestResult> result); |
| 76 | 87 |
| 77 // Populate the catalog with data from |entry|, and pass it to the client | 88 // Populate the catalog with data from |entry|, and pass it to the client |
| 78 // via callback. | 89 // via callback. |
| 79 void AddEntryToCatalog(scoped_ptr<Entry> entry); | 90 void AddEntryToCatalog(scoped_ptr<Entry> entry); |
| 80 | 91 |
| 92 Delegate* delegate_; |
| 93 |
| 81 // Directory that contains packages and executables visible to all users. | 94 // Directory that contains packages and executables visible to all users. |
| 82 base::FilePath system_package_dir_; | 95 base::FilePath system_package_dir_; |
| 83 | 96 |
| 84 // TODO(beng): add user package dir. | 97 // TODO(beng): add user package dir. |
| 85 | 98 |
| 86 // User-specific persistent storage of package manifests and other settings. | 99 // User-specific persistent storage of package manifests and other settings. |
| 87 scoped_ptr<Store> store_; | 100 scoped_ptr<Store> store_; |
| 88 | 101 |
| 89 // Task runner for performing file operations. | 102 // Task runner for performing file operations. |
| 90 base::TaskRunner* file_task_runner_; | 103 base::TaskRunner* file_task_runner_; |
| 91 | 104 |
| 92 mojo::BindingSet<mojom::Resolver> resolver_bindings_; | 105 mojo::BindingSet<mojom::Resolver> resolver_bindings_; |
| 93 mojo::BindingSet<mojo::shell::mojom::ShellResolver> shell_resolver_bindings_; | 106 mojo::BindingSet<mojo::shell::mojom::ShellResolver> shell_resolver_bindings_; |
| 94 mojo::BindingSet<mojom::Catalog> catalog_bindings_; | 107 mojo::BindingSet<mojom::Catalog> catalog_bindings_; |
| 95 | 108 |
| 96 // Mojo name -> Entry storage, constructed from Store/package manifests. | 109 // Mojo name -> Entry storage, constructed from Store/package manifests. |
| 97 std::map<std::string, scoped_ptr<Entry>> catalog_; | 110 std::map<std::string, scoped_ptr<Entry>> catalog_; |
| 98 | 111 |
| 99 base::WeakPtrFactory<Catalog> weak_factory_; | 112 base::WeakPtrFactory<Catalog> weak_factory_; |
| 100 | 113 |
| 101 DISALLOW_COPY_AND_ASSIGN(Catalog); | 114 DISALLOW_COPY_AND_ASSIGN(Catalog); |
| 102 }; | 115 }; |
| 103 | 116 |
| 104 } // namespace catalog | 117 } // namespace catalog |
| 105 | 118 |
| 106 #endif // MOJO_SERVICES_CATALOG_CATALOG_H_ | 119 #endif // MOJO_SERVICES_CATALOG_CATALOG_H_ |
| OLD | NEW |