| 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" |
| 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 #include "url/gurl.h" | |
| 20 | 20 |
| 21 namespace catalog { | 21 namespace catalog { |
| 22 | 22 |
| 23 class Store; | 23 class Store; |
| 24 | 24 |
| 25 class Catalog : public mojom::Resolver, | 25 class Catalog : public mojom::Resolver, |
| 26 public mojo::shell::mojom::ShellResolver, | 26 public mojo::shell::mojom::ShellResolver, |
| 27 public mojom::Catalog { | 27 public mojom::Catalog { |
| 28 public: | 28 public: |
| 29 Catalog(base::TaskRunner* blocking_pool, scoped_ptr<Store> store); | 29 Catalog(base::TaskRunner* blocking_pool, scoped_ptr<Store> store); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 58 const GetEntriesCallback& callback) override; | 58 const GetEntriesCallback& callback) override; |
| 59 | 59 |
| 60 // Completes resolving a Mojo name from the Shell after the resolved name has | 60 // Completes resolving a Mojo name from the Shell after the resolved name has |
| 61 // been added to the catalog and the manifest read. | 61 // been added to the catalog and the manifest read. |
| 62 void CompleteResolveMojoName(const std::string& resolved_name, | 62 void CompleteResolveMojoName(const std::string& resolved_name, |
| 63 const std::string& qualifier, | 63 const std::string& qualifier, |
| 64 const ResolveMojoNameCallback& callback); | 64 const ResolveMojoNameCallback& callback); |
| 65 | 65 |
| 66 bool IsNameInCatalog(const std::string& name) const; | 66 bool IsNameInCatalog(const std::string& name) const; |
| 67 | 67 |
| 68 // Called from ResolveMojoName(). | |
| 69 // Attempts to load a manifest for |name|, reads it and adds its metadata to | |
| 70 // the catalog. | |
| 71 void AddNameToCatalog(const std::string& name, | |
| 72 const ResolveMojoNameCallback& callback); | |
| 73 | |
| 74 // Populate/serialize the catalog from/to the supplied store. | 68 // Populate/serialize the catalog from/to the supplied store. |
| 75 void DeserializeCatalog(); | 69 void DeserializeCatalog(); |
| 76 void SerializeCatalog(); | 70 void SerializeCatalog(); |
| 77 | 71 |
| 72 // Callback for Reader, receives an Entry constructed from the manifest for |
| 73 // |name|. |
| 74 static void OnReadEntry(base::WeakPtr<Catalog> catalog, |
| 75 const std::string& name, |
| 76 const ResolveMojoNameCallback& callback, |
| 77 scoped_ptr<Entry> entry); |
| 78 void OnReadEntryImpl(const std::string& name, |
| 79 const ResolveMojoNameCallback& callback, |
| 80 scoped_ptr<Entry> entry); |
| 81 |
| 78 // Construct a catalog entry from |dictionary|. | 82 // Construct a catalog entry from |dictionary|. |
| 79 scoped_ptr<Entry> DeserializeApplication( | 83 scoped_ptr<Entry> DeserializeApplication( |
| 80 const base::DictionaryValue* dictionary); | 84 const base::DictionaryValue* dictionary); |
| 81 | 85 |
| 82 GURL GetManifestURL(const std::string& name); | 86 scoped_ptr<Reader> reader_; |
| 83 | 87 base::FilePath package_path_; |
| 84 // Called once the manifest has been read. |pm| may be null at this point, | |
| 85 // but |callback| must be run. | |
| 86 static void OnReadManifest(base::WeakPtr<Catalog> catalog, | |
| 87 const std::string& name, | |
| 88 const ResolveMojoNameCallback& callback, | |
| 89 scoped_ptr<base::Value> manifest); | |
| 90 | |
| 91 // Called once the manifest is read and |this| hasn't been deleted. | |
| 92 void OnReadManifestImpl(const std::string& name, | |
| 93 const ResolveMojoNameCallback& callback, | |
| 94 scoped_ptr<base::Value> manifest); | |
| 95 | |
| 96 base::TaskRunner* blocking_pool_; | |
| 97 GURL system_package_dir_; | |
| 98 | 88 |
| 99 mojo::BindingSet<mojom::Resolver> resolver_bindings_; | 89 mojo::BindingSet<mojom::Resolver> resolver_bindings_; |
| 100 mojo::BindingSet<mojo::shell::mojom::ShellResolver> shell_resolver_bindings_; | 90 mojo::BindingSet<mojo::shell::mojom::ShellResolver> shell_resolver_bindings_; |
| 101 mojo::BindingSet<mojom::Catalog> catalog_bindings_; | 91 mojo::BindingSet<mojom::Catalog> catalog_bindings_; |
| 102 | 92 |
| 103 scoped_ptr<Store> store_; | 93 scoped_ptr<Store> store_; |
| 104 std::map<std::string, Entry> catalog_; | 94 std::map<std::string, Entry> catalog_; |
| 105 | 95 |
| 106 // Used when an app handles multiple names. Maps from app (as name) to name of | 96 // Used when an app handles multiple names. Maps from app (as name) to name of |
| 107 // app that is responsible for handling it. The value is a pair of the name of | 97 // app that is responsible for handling it. The value is a pair of the name of |
| 108 // the handler along with a qualifier. | 98 // the handler along with a qualifier. |
| 109 MojoNameAliasMap mojo_name_aliases_; | 99 MojoNameAliasMap mojo_name_aliases_; |
| 110 | 100 |
| 111 std::map<std::string, std::string> qualifiers_; | 101 std::map<std::string, std::string> qualifiers_; |
| 112 | 102 |
| 113 base::WeakPtrFactory<Catalog> weak_factory_; | 103 base::WeakPtrFactory<Catalog> weak_factory_; |
| 114 | 104 |
| 115 DISALLOW_COPY_AND_ASSIGN(Catalog); | 105 DISALLOW_COPY_AND_ASSIGN(Catalog); |
| 116 }; | 106 }; |
| 117 | 107 |
| 118 } // namespace catalog | 108 } // namespace catalog |
| 119 | 109 |
| 120 #endif // MOJO_SERVICES_CATALOG_CATALOG_H_ | 110 #endif // MOJO_SERVICES_CATALOG_CATALOG_H_ |
| OLD | NEW |