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 11 matching lines...) Expand all Loading... |
22 using AllowedInterfaces = std::set<std::string>; | 22 using AllowedInterfaces = std::set<std::string>; |
23 // A map of allowed applications to allowed interface sets. See shell.mojom for | 23 // A map of allowed applications to allowed interface sets. See shell.mojom for |
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(); | 30 ~ApplicationInfo(); |
31 | 31 |
32 GURL url; | |
33 std::string name; | 32 std::string name; |
| 33 std::string display_name; |
34 CapabilityFilter base_filter; | 34 CapabilityFilter base_filter; |
35 }; | 35 }; |
36 | 36 |
37 // Implemented by an object that provides storage for the application catalog | 37 // Implemented by an object that provides storage for the application catalog |
38 // (e.g. in Chrome, preferences). The PackageManagerImpl is the canonical owner | 38 // (e.g. in Chrome, preferences). The PackageManagerImpl is the canonical owner |
39 // of the contents of the store, so no one else must modify its contents. | 39 // of the contents of the store, so no one else must modify its contents. |
40 class ApplicationCatalogStore { | 40 class ApplicationCatalogStore { |
41 public: | 41 public: |
42 // Value is a string. | 42 // Value is a string. |
43 static const char kUrlKey[]; | 43 static const char kNameKey[]; |
44 // Value is a string. | 44 // Value is a string. |
45 static const char kNameKey[]; | 45 static const char kDisplayNameKey[]; |
46 // Value is a dictionary that maps from the filter to a list of string | 46 // Value is a dictionary that maps from the filter to a list of string |
47 // interfaces. | 47 // interfaces. |
48 static const char kCapabilitiesKey[]; | 48 static const char kCapabilitiesKey[]; |
49 | 49 |
50 virtual ~ApplicationCatalogStore() {} | 50 virtual ~ApplicationCatalogStore() {} |
51 | 51 |
52 // Called during initialization to construct the PackageManagerImpl's catalog. | 52 // Called during initialization to construct the PackageManagerImpl's catalog. |
53 // Returns a serialized list of the apps. Each entry in the returned list | 53 // Returns a serialized list of the apps. Each entry in the returned list |
54 // corresponds to an app (as a dictionary). Each dictionary has a url, name | 54 // corresponds to an app (as a dictionary). Each dictionary has a name, |
55 // and capabilities. The return value is owned by the caller. | 55 // display name and capabilities. The return value is owned by the caller. |
56 virtual const base::ListValue* GetStore() = 0; | 56 virtual const base::ListValue* GetStore() = 0; |
57 | 57 |
58 // Write the catalog to the store. Called when the PackageManagerImpl learns | 58 // Write the catalog to the store. Called when the PackageManagerImpl learns |
59 // of a newly encountered application. | 59 // of a newly encountered application. |
60 virtual void UpdateStore(scoped_ptr<base::ListValue> store) = 0; | 60 virtual void UpdateStore(scoped_ptr<base::ListValue> store) = 0; |
61 }; | 61 }; |
62 | 62 |
63 class PackageManager : public mojo::ShellClient, | 63 class PackageManager : public mojo::ShellClient, |
64 public mojo::InterfaceFactory<mojom::Resolver>, | 64 public mojo::InterfaceFactory<mojom::Resolver>, |
65 public mojo::InterfaceFactory<mojom::ShellResolver>, | 65 public mojo::InterfaceFactory<mojom::ShellResolver>, |
66 public mojo::InterfaceFactory<mojom::Catalog>, | 66 public mojo::InterfaceFactory<mojom::Catalog>, |
67 public mojom::Resolver, | 67 public mojom::Resolver, |
68 public mojom::ShellResolver, | 68 public mojom::ShellResolver, |
69 public mojom::Catalog { | 69 public mojom::Catalog { |
70 public: | 70 public: |
71 // If |register_schemes| is true, mojo: and exe: schemes are registered as | 71 // If |register_schemes| is true, mojo: and exe: schemes are registered as |
72 // "standard". | 72 // "standard". |
73 PackageManager(base::TaskRunner* blocking_pool, | 73 PackageManager(base::TaskRunner* blocking_pool, |
74 bool register_schemes, | |
75 scoped_ptr<ApplicationCatalogStore> catalog); | 74 scoped_ptr<ApplicationCatalogStore> catalog); |
76 ~PackageManager() override; | 75 ~PackageManager() override; |
77 | 76 |
78 private: | 77 private: |
79 using MojoURLAliasMap = std::map<GURL, std::pair<GURL, std::string>>; | 78 using MojoNameAliasMap = |
| 79 std::map<std::string, std::pair<std::string, std::string>>; |
80 | 80 |
81 // mojo::ShellClient: | 81 // mojo::ShellClient: |
82 bool AcceptConnection(mojo::Connection* connection) override; | 82 bool AcceptConnection(mojo::Connection* connection) override; |
83 | 83 |
84 // mojo::InterfaceFactory<mojom::Resolver>: | 84 // mojo::InterfaceFactory<mojom::Resolver>: |
85 void Create(mojo::Connection* connection, | 85 void Create(mojo::Connection* connection, |
86 mojom::ResolverRequest request) override; | 86 mojom::ResolverRequest request) override; |
87 | 87 |
88 // mojo::InterfaceFactory<mojom::ShellResolver>: | 88 // mojo::InterfaceFactory<mojom::ShellResolver>: |
89 void Create(mojo::Connection* connection, | 89 void Create(mojo::Connection* connection, |
90 mojom::ShellResolverRequest request) override; | 90 mojom::ShellResolverRequest request) override; |
91 | 91 |
92 // mojo::InterfaceFactory<mojom::Catalog>: | 92 // mojo::InterfaceFactory<mojom::Catalog>: |
93 void Create(mojo::Connection* connection, | 93 void Create(mojo::Connection* connection, |
94 mojom::CatalogRequest request) override; | 94 mojom::CatalogRequest request) override; |
95 | 95 |
96 // mojom::Resolver: | 96 // mojom::Resolver: |
97 void ResolveResponse( | 97 void ResolveResponse( |
98 mojo::URLResponsePtr response, | 98 mojo::URLResponsePtr response, |
99 const ResolveResponseCallback& callback) override; | 99 const ResolveResponseCallback& callback) override; |
100 void ResolveInterfaces(mojo::Array<mojo::String> interfaces, | 100 void ResolveInterfaces(mojo::Array<mojo::String> interfaces, |
101 const ResolveInterfacesCallback& callback) override; | 101 const ResolveInterfacesCallback& callback) override; |
102 void ResolveMIMEType(const mojo::String& mime_type, | 102 void ResolveMIMEType(const mojo::String& mime_type, |
103 const ResolveMIMETypeCallback& callback) override; | 103 const ResolveMIMETypeCallback& callback) override; |
104 void ResolveProtocolScheme( | 104 void ResolveProtocolScheme( |
105 const mojo::String& scheme, | 105 const mojo::String& scheme, |
106 const ResolveProtocolSchemeCallback& callback) override; | 106 const ResolveProtocolSchemeCallback& callback) override; |
107 | 107 |
108 // mojom::ShellResolver: | 108 // mojom::ShellResolver: |
109 void ResolveMojoURL(const mojo::String& mojo_url, | 109 void ResolveMojoName(const mojo::String& mojo_name, |
110 const ResolveMojoURLCallback& callback) override; | 110 const ResolveMojoNameCallback& callback) override; |
111 | 111 |
112 // mojom::Catalog: | 112 // mojom::Catalog: |
113 void GetEntries(mojo::Array<mojo::String> urls, | 113 void GetEntries(mojo::Array<mojo::String> names, |
114 const GetEntriesCallback& callback) override; | 114 const GetEntriesCallback& callback) override; |
115 | 115 |
116 // Completes resolving a Mojo URL from the Shell after the resolved URL has | 116 // Completes resolving a Mojo name from the Shell after the resolved name has |
117 // been added to the catalog and the manifest read. | 117 // been added to the catalog and the manifest read. |
118 void CompleteResolveMojoURL(const GURL& resolved_url, | 118 void CompleteResolveMojoName(const std::string& resolved_name, |
119 const std::string& qualifier, | 119 const std::string& qualifier, |
120 const ResolveMojoURLCallback& callback); | 120 const ResolveMojoNameCallback& callback); |
121 | 121 |
122 bool IsURLInCatalog(const GURL& url) const; | 122 bool IsNameInCatalog(const std::string& name) const; |
123 | 123 |
124 // Called from ResolveMojoURL(). | 124 // Called from ResolveMojoName(). |
125 // If |url| is not in the catalog, attempts to load a manifest for it. | 125 // If |name| is not in the catalog, attempts to load a manifest for it. |
126 void EnsureURLInCatalog(const GURL& url, | 126 void EnsureNameInCatalog(const std::string& name, |
127 const std::string& qualifier, | 127 const std::string& qualifier, |
128 const ResolveMojoURLCallback& callback); | 128 const ResolveMojoNameCallback& callback); |
129 | 129 |
130 // Populate/serialize the catalog from/to the supplied store. | 130 // Populate/serialize the catalog from/to the supplied store. |
131 void DeserializeCatalog(); | 131 void DeserializeCatalog(); |
132 void SerializeCatalog(); | 132 void SerializeCatalog(); |
133 | 133 |
134 // Construct a catalog entry from |dictionary|. | 134 // Construct a catalog entry from |dictionary|. |
135 const ApplicationInfo& DeserializeApplication( | 135 const ApplicationInfo& DeserializeApplication( |
136 const base::DictionaryValue* dictionary); | 136 const base::DictionaryValue* dictionary); |
137 | 137 |
138 GURL GetManifestURL(const GURL& url); | 138 GURL GetManifestURL(const std::string& name); |
139 | 139 |
140 // Called once the manifest has been read. |pm| may be null at this point, | 140 // Called once the manifest has been read. |pm| may be null at this point, |
141 // but |callback| must be run. | 141 // but |callback| must be run. |
142 static void OnReadManifest(base::WeakPtr<PackageManager> pm, | 142 static void OnReadManifest(base::WeakPtr<PackageManager> pm, |
143 const GURL& url, | 143 const std::string& name, |
144 const std::string& qualifier, | 144 const std::string& qualifier, |
145 const ResolveMojoURLCallback& callback, | 145 const ResolveMojoNameCallback& callback, |
146 scoped_ptr<base::Value> manifest); | 146 scoped_ptr<base::Value> manifest); |
147 | 147 |
148 // Called once the manifest is read and |this| hasn't been deleted. | 148 // Called once the manifest is read and |this| hasn't been deleted. |
149 void OnReadManifestImpl(const GURL& url, | 149 void OnReadManifestImpl(const std::string& name, |
150 const std::string& qualifier, | 150 const std::string& qualifier, |
151 const ResolveMojoURLCallback& callback, | 151 const ResolveMojoNameCallback& callback, |
152 scoped_ptr<base::Value> manifest); | 152 scoped_ptr<base::Value> manifest); |
153 | 153 |
154 base::TaskRunner* blocking_pool_; | 154 base::TaskRunner* blocking_pool_; |
155 GURL system_package_dir_; | 155 GURL system_package_dir_; |
156 | 156 |
157 mojo::BindingSet<mojom::Resolver> resolver_bindings_; | 157 mojo::BindingSet<mojom::Resolver> resolver_bindings_; |
158 mojo::BindingSet<mojom::ShellResolver> shell_resolver_bindings_; | 158 mojo::BindingSet<mojom::ShellResolver> shell_resolver_bindings_; |
159 mojo::BindingSet<mojom::Catalog> catalog_bindings_; | 159 mojo::BindingSet<mojom::Catalog> catalog_bindings_; |
160 | 160 |
161 scoped_ptr<ApplicationCatalogStore> catalog_store_; | 161 scoped_ptr<ApplicationCatalogStore> catalog_store_; |
162 std::map<GURL, ApplicationInfo> catalog_; | 162 std::map<std::string, ApplicationInfo> catalog_; |
163 | 163 |
164 // Used when an app handles multiple urls. Maps from app (as url) to url of | 164 // Used when an app handles multiple names. Maps from app (as name) to name of |
165 // app that is responsible for handling it. The value is a pair of the | 165 // app that is responsible for handling it. The value is a pair of the name of |
166 // url of the handler along with a qualifier. | 166 // the handler along with a qualifier. |
167 MojoURLAliasMap mojo_url_aliases_; | 167 MojoNameAliasMap mojo_name_aliases_; |
168 | 168 |
169 base::WeakPtrFactory<PackageManager> weak_factory_; | 169 base::WeakPtrFactory<PackageManager> weak_factory_; |
170 | 170 |
171 DISALLOW_COPY_AND_ASSIGN(PackageManager); | 171 DISALLOW_COPY_AND_ASSIGN(PackageManager); |
172 }; | 172 }; |
173 | 173 |
174 } // namespace package_manager | 174 } // namespace package_manager |
175 | 175 |
176 #endif // MOJO_SERVICES_PACKAGE_MANAGER_PACKAGE_MANAGER_H_ | 176 #endif // MOJO_SERVICES_PACKAGE_MANAGER_PACKAGE_MANAGER_H_ |
OLD | NEW |