| 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/values.h" | 11 #include "base/values.h" |
| 12 #include "mojo/public/cpp/bindings/binding_set.h" | 12 #include "mojo/public/cpp/bindings/binding_set.h" |
| 13 #include "mojo/services/catalog/entry.h" | 13 #include "mojo/services/catalog/entry.h" |
| 14 #include "mojo/services/catalog/public/interfaces/catalog.mojom.h" | 14 #include "mojo/services/catalog/public/interfaces/catalog.mojom.h" |
| 15 #include "mojo/services/catalog/public/interfaces/resolver.mojom.h" | 15 #include "mojo/services/catalog/public/interfaces/resolver.mojom.h" |
| 16 #include "mojo/services/catalog/reader.h" | |
| 17 #include "mojo/services/catalog/store.h" | 16 #include "mojo/services/catalog/store.h" |
| 18 #include "mojo/shell/public/cpp/interface_factory.h" | 17 #include "mojo/shell/public/cpp/interface_factory.h" |
| 19 #include "mojo/shell/public/interfaces/shell_resolver.mojom.h" | 18 #include "mojo/shell/public/interfaces/shell_resolver.mojom.h" |
| 20 | 19 |
| 21 namespace catalog { | 20 namespace catalog { |
| 22 | 21 |
| 23 class Store; | 22 class Store; |
| 24 | 23 |
| 24 struct ReadManifestResult { |
| 25 ReadManifestResult(); |
| 26 ~ReadManifestResult(); |
| 27 scoped_ptr<base::Value> manifest_root; |
| 28 base::FilePath package_dir; |
| 29 }; |
| 30 |
| 25 class Catalog : public mojom::Resolver, | 31 class Catalog : public mojom::Resolver, |
| 26 public mojo::shell::mojom::ShellResolver, | 32 public mojo::shell::mojom::ShellResolver, |
| 27 public mojom::Catalog { | 33 public mojom::Catalog { |
| 28 public: | 34 public: |
| 29 Catalog(base::TaskRunner* blocking_pool, scoped_ptr<Store> store); | 35 Catalog(scoped_ptr<Store> store, base::TaskRunner* file_task_runner); |
| 30 ~Catalog() override; | 36 ~Catalog() override; |
| 31 | 37 |
| 32 void BindResolver(mojom::ResolverRequest request); | 38 void BindResolver(mojom::ResolverRequest request); |
| 33 void BindShellResolver(mojo::shell::mojom::ShellResolverRequest request); | 39 void BindShellResolver(mojo::shell::mojom::ShellResolverRequest request); |
| 34 void BindCatalog(mojom::CatalogRequest request); | 40 void BindCatalog(mojom::CatalogRequest request); |
| 35 | 41 |
| 36 private: | 42 private: |
| 37 using MojoNameAliasMap = | 43 using MojoNameAliasMap = |
| 38 std::map<std::string, std::pair<std::string, std::string>>; | 44 std::map<std::string, std::pair<std::string, std::string>>; |
| 39 | 45 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 const ResolveProtocolSchemeCallback& callback) override; | 56 const ResolveProtocolSchemeCallback& callback) override; |
| 51 | 57 |
| 52 // mojo::shell::mojom::ShellResolver: | 58 // mojo::shell::mojom::ShellResolver: |
| 53 void ResolveMojoName(const mojo::String& mojo_name, | 59 void ResolveMojoName(const mojo::String& mojo_name, |
| 54 const ResolveMojoNameCallback& callback) override; | 60 const ResolveMojoNameCallback& callback) override; |
| 55 | 61 |
| 56 // mojom::Catalog: | 62 // mojom::Catalog: |
| 57 void GetEntries(mojo::Array<mojo::String> names, | 63 void GetEntries(mojo::Array<mojo::String> names, |
| 58 const GetEntriesCallback& callback) override; | 64 const GetEntriesCallback& callback) override; |
| 59 | 65 |
| 60 // Completes resolving a Mojo name from the Shell after the resolved name has | |
| 61 // been added to the catalog and the manifest read. | |
| 62 void CompleteResolveMojoName(const std::string& resolved_name, | |
| 63 const std::string& qualifier, | |
| 64 const ResolveMojoNameCallback& callback); | |
| 65 | |
| 66 bool IsNameInCatalog(const std::string& name) const; | |
| 67 | |
| 68 // Populate/serialize the catalog from/to the supplied store. | 66 // Populate/serialize the catalog from/to the supplied store. |
| 69 void DeserializeCatalog(); | 67 void DeserializeCatalog(); |
| 70 void SerializeCatalog(); | 68 void SerializeCatalog(); |
| 71 | 69 |
| 72 // Callback for Reader, receives an Entry constructed from the manifest for | 70 // Receives the result of manifest parsing on |file_task_runner_|, may be |
| 73 // |name|. | 71 // received after the catalog object that issued the request is destroyed. |
| 74 static void OnReadEntry(base::WeakPtr<Catalog> catalog, | 72 static void OnReadManifest(base::WeakPtr<Catalog> catalog, |
| 75 const std::string& name, | 73 const std::string& name, |
| 76 const ResolveMojoNameCallback& callback, | 74 const ResolveMojoNameCallback& callback, |
| 77 scoped_ptr<Entry> entry); | 75 scoped_ptr<ReadManifestResult> result); |
| 78 void OnReadEntryImpl(const std::string& name, | |
| 79 const ResolveMojoNameCallback& callback, | |
| 80 scoped_ptr<Entry> entry); | |
| 81 | 76 |
| 82 // Construct a catalog entry from |dictionary|. | 77 // Populate the catalog with data from |entry|, and pass it to the client |
| 83 scoped_ptr<Entry> DeserializeApplication( | 78 // via callback. |
| 84 const base::DictionaryValue* dictionary); | 79 void AddEntryToCatalog(scoped_ptr<Entry> entry); |
| 85 | 80 |
| 86 scoped_ptr<Reader> reader_; | 81 // Directory that contains packages and executables visible to all users. |
| 87 base::FilePath package_path_; | 82 base::FilePath system_package_dir_; |
| 83 |
| 84 // TODO(beng): add user package dir. |
| 85 |
| 86 // User-specific persistent storage of package manifests and other settings. |
| 87 scoped_ptr<Store> store_; |
| 88 |
| 89 // Task runner for performing file operations. |
| 90 base::TaskRunner* file_task_runner_; |
| 88 | 91 |
| 89 mojo::BindingSet<mojom::Resolver> resolver_bindings_; | 92 mojo::BindingSet<mojom::Resolver> resolver_bindings_; |
| 90 mojo::BindingSet<mojo::shell::mojom::ShellResolver> shell_resolver_bindings_; | 93 mojo::BindingSet<mojo::shell::mojom::ShellResolver> shell_resolver_bindings_; |
| 91 mojo::BindingSet<mojom::Catalog> catalog_bindings_; | 94 mojo::BindingSet<mojom::Catalog> catalog_bindings_; |
| 92 | 95 |
| 93 scoped_ptr<Store> store_; | 96 // Mojo name -> Entry storage, constructed from Store/package manifests. |
| 94 std::map<std::string, Entry> catalog_; | 97 std::map<std::string, scoped_ptr<Entry>> catalog_; |
| 95 | |
| 96 // Used when an app handles multiple names. Maps from app (as name) to name of | |
| 97 // app that is responsible for handling it. The value is a pair of the name of | |
| 98 // the handler along with a qualifier. | |
| 99 MojoNameAliasMap mojo_name_aliases_; | |
| 100 | |
| 101 std::map<std::string, std::string> qualifiers_; | |
| 102 | 98 |
| 103 base::WeakPtrFactory<Catalog> weak_factory_; | 99 base::WeakPtrFactory<Catalog> weak_factory_; |
| 104 | 100 |
| 105 DISALLOW_COPY_AND_ASSIGN(Catalog); | 101 DISALLOW_COPY_AND_ASSIGN(Catalog); |
| 106 }; | 102 }; |
| 107 | 103 |
| 108 } // namespace catalog | 104 } // namespace catalog |
| 109 | 105 |
| 110 #endif // MOJO_SERVICES_CATALOG_CATALOG_H_ | 106 #endif // MOJO_SERVICES_CATALOG_CATALOG_H_ |
| OLD | NEW |