| 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_PACKAGE_MANAGER_PACKAGE_MANAGER_H_ | 5 #ifndef MOJO_SERVICES_PACKAGE_MANAGER_PACKAGE_MANAGER_H_ |
| 6 #define MOJO_SERVICES_PACKAGE_MANAGER_PACKAGE_MANAGER_H_ | 6 #define MOJO_SERVICES_PACKAGE_MANAGER_PACKAGE_MANAGER_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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // more details. | 24 // more details. |
| 25 using CapabilityFilter = std::map<std::string, AllowedInterfaces>; | 25 using CapabilityFilter = std::map<std::string, AllowedInterfaces>; |
| 26 | 26 |
| 27 // Static information about an application package known to the PackageManager. | 27 // Static information about an application package known to the PackageManager. |
| 28 struct ApplicationInfo { | 28 struct ApplicationInfo { |
| 29 ApplicationInfo(); | 29 ApplicationInfo(); |
| 30 ApplicationInfo(const ApplicationInfo& other); | 30 ApplicationInfo(const ApplicationInfo& other); |
| 31 ~ApplicationInfo(); | 31 ~ApplicationInfo(); |
| 32 | 32 |
| 33 std::string name; | 33 std::string name; |
| 34 std::string qualifier; |
| 34 std::string display_name; | 35 std::string display_name; |
| 35 CapabilityFilter base_filter; | 36 CapabilityFilter base_filter; |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 // Implemented by an object that provides storage for the application catalog | 39 // Implemented by an object that provides storage for the application catalog |
| 39 // (e.g. in Chrome, preferences). The PackageManagerImpl is the canonical owner | 40 // (e.g. in Chrome, preferences). The PackageManagerImpl is the canonical owner |
| 40 // of the contents of the store, so no one else must modify its contents. | 41 // of the contents of the store, so no one else must modify its contents. |
| 41 class ApplicationCatalogStore { | 42 class ApplicationCatalogStore { |
| 42 public: | 43 public: |
| 43 // Value is a string. | 44 // Value is a string. |
| 44 static const char kNameKey[]; | 45 static const char kNameKey[]; |
| 45 // Value is a string. | 46 // Value is a string. |
| 47 static const char kQualifierKey[]; |
| 48 // Value is a string. |
| 46 static const char kDisplayNameKey[]; | 49 static const char kDisplayNameKey[]; |
| 47 // Value is a dictionary that maps from the filter to a list of string | 50 // Value is a dictionary that maps from the filter to a list of string |
| 48 // interfaces. | 51 // interfaces. |
| 49 static const char kCapabilitiesKey[]; | 52 static const char kCapabilitiesKey[]; |
| 50 | 53 |
| 51 virtual ~ApplicationCatalogStore() {} | 54 virtual ~ApplicationCatalogStore() {} |
| 52 | 55 |
| 53 // Called during initialization to construct the PackageManagerImpl's catalog. | 56 // Called during initialization to construct the PackageManagerImpl's catalog. |
| 54 // Returns a serialized list of the apps. Each entry in the returned list | 57 // Returns a serialized list of the apps. Each entry in the returned list |
| 55 // corresponds to an app (as a dictionary). Each dictionary has a name, | 58 // corresponds to an app (as a dictionary). Each dictionary has a name, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 119 |
| 117 // Completes resolving a Mojo name from the Shell after the resolved name has | 120 // Completes resolving a Mojo name from the Shell after the resolved name has |
| 118 // been added to the catalog and the manifest read. | 121 // been added to the catalog and the manifest read. |
| 119 void CompleteResolveMojoName(const std::string& resolved_name, | 122 void CompleteResolveMojoName(const std::string& resolved_name, |
| 120 const std::string& qualifier, | 123 const std::string& qualifier, |
| 121 const ResolveMojoNameCallback& callback); | 124 const ResolveMojoNameCallback& callback); |
| 122 | 125 |
| 123 bool IsNameInCatalog(const std::string& name) const; | 126 bool IsNameInCatalog(const std::string& name) const; |
| 124 | 127 |
| 125 // Called from ResolveMojoName(). | 128 // Called from ResolveMojoName(). |
| 126 // If |name| is not in the catalog, attempts to load a manifest for it. | 129 // Attempts to load a manifest for |name|, reads it and adds its metadata to |
| 127 void EnsureNameInCatalog(const std::string& name, | 130 // the catalog. |
| 128 const std::string& qualifier, | 131 void AddNameToCatalog(const std::string& name, |
| 129 const ResolveMojoNameCallback& callback); | 132 const ResolveMojoNameCallback& callback); |
| 130 | 133 |
| 131 // Populate/serialize the catalog from/to the supplied store. | 134 // Populate/serialize the catalog from/to the supplied store. |
| 132 void DeserializeCatalog(); | 135 void DeserializeCatalog(); |
| 133 void SerializeCatalog(); | 136 void SerializeCatalog(); |
| 134 | 137 |
| 135 // Construct a catalog entry from |dictionary|. | 138 // Construct a catalog entry from |dictionary|. |
| 136 const ApplicationInfo& DeserializeApplication( | 139 const ApplicationInfo& DeserializeApplication( |
| 137 const base::DictionaryValue* dictionary); | 140 const base::DictionaryValue* dictionary); |
| 138 | 141 |
| 139 GURL GetManifestURL(const std::string& name); | 142 GURL GetManifestURL(const std::string& name); |
| 140 | 143 |
| 141 // Called once the manifest has been read. |pm| may be null at this point, | 144 // Called once the manifest has been read. |pm| may be null at this point, |
| 142 // but |callback| must be run. | 145 // but |callback| must be run. |
| 143 static void OnReadManifest(base::WeakPtr<PackageManager> pm, | 146 static void OnReadManifest(base::WeakPtr<PackageManager> pm, |
| 144 const std::string& name, | 147 const std::string& name, |
| 145 const std::string& qualifier, | |
| 146 const ResolveMojoNameCallback& callback, | 148 const ResolveMojoNameCallback& callback, |
| 147 scoped_ptr<base::Value> manifest); | 149 scoped_ptr<base::Value> manifest); |
| 148 | 150 |
| 149 // Called once the manifest is read and |this| hasn't been deleted. | 151 // Called once the manifest is read and |this| hasn't been deleted. |
| 150 void OnReadManifestImpl(const std::string& name, | 152 void OnReadManifestImpl(const std::string& name, |
| 151 const std::string& qualifier, | |
| 152 const ResolveMojoNameCallback& callback, | 153 const ResolveMojoNameCallback& callback, |
| 153 scoped_ptr<base::Value> manifest); | 154 scoped_ptr<base::Value> manifest); |
| 154 | 155 |
| 155 base::TaskRunner* blocking_pool_; | 156 base::TaskRunner* blocking_pool_; |
| 156 GURL system_package_dir_; | 157 GURL system_package_dir_; |
| 157 | 158 |
| 158 mojo::BindingSet<mojom::Resolver> resolver_bindings_; | 159 mojo::BindingSet<mojom::Resolver> resolver_bindings_; |
| 159 mojo::BindingSet<mojom::ShellResolver> shell_resolver_bindings_; | 160 mojo::BindingSet<mojom::ShellResolver> shell_resolver_bindings_; |
| 160 mojo::BindingSet<mojom::Catalog> catalog_bindings_; | 161 mojo::BindingSet<mojom::Catalog> catalog_bindings_; |
| 161 | 162 |
| 162 scoped_ptr<ApplicationCatalogStore> catalog_store_; | 163 scoped_ptr<ApplicationCatalogStore> catalog_store_; |
| 163 std::map<std::string, ApplicationInfo> catalog_; | 164 std::map<std::string, ApplicationInfo> catalog_; |
| 164 | 165 |
| 165 // Used when an app handles multiple names. Maps from app (as name) to name of | 166 // Used when an app handles multiple names. Maps from app (as name) to name of |
| 166 // app that is responsible for handling it. The value is a pair of the name of | 167 // app that is responsible for handling it. The value is a pair of the name of |
| 167 // the handler along with a qualifier. | 168 // the handler along with a qualifier. |
| 168 MojoNameAliasMap mojo_name_aliases_; | 169 MojoNameAliasMap mojo_name_aliases_; |
| 169 | 170 |
| 171 std::map<std::string, std::string> qualifiers_; |
| 172 |
| 170 base::WeakPtrFactory<PackageManager> weak_factory_; | 173 base::WeakPtrFactory<PackageManager> weak_factory_; |
| 171 | 174 |
| 172 DISALLOW_COPY_AND_ASSIGN(PackageManager); | 175 DISALLOW_COPY_AND_ASSIGN(PackageManager); |
| 173 }; | 176 }; |
| 174 | 177 |
| 175 } // namespace package_manager | 178 } // namespace package_manager |
| 176 | 179 |
| 177 #endif // MOJO_SERVICES_PACKAGE_MANAGER_PACKAGE_MANAGER_H_ | 180 #endif // MOJO_SERVICES_PACKAGE_MANAGER_PACKAGE_MANAGER_H_ |
| OLD | NEW |