OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SHELL_APPLICATION_MANAGER_H_ | 5 #ifndef MOJO_SHELL_APPLICATION_MANAGER_H_ |
6 #define MOJO_SHELL_APPLICATION_MANAGER_H_ | 6 #define MOJO_SHELL_APPLICATION_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "mojo/application/public/interfaces/application.mojom.h" | 14 #include "mojo/application/public/interfaces/application.mojom.h" |
15 #include "mojo/application/public/interfaces/service_provider.mojom.h" | 15 #include "mojo/application/public/interfaces/service_provider.mojom.h" |
16 #include "mojo/application/public/interfaces/shell.mojom.h" | 16 #include "mojo/application/public/interfaces/shell.mojom.h" |
17 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 17 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
18 #include "mojo/public/cpp/bindings/interface_request.h" | 18 #include "mojo/public/cpp/bindings/interface_request.h" |
19 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | |
20 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h" | |
21 #include "mojo/services/updater/updater.mojom.h" | 19 #include "mojo/services/updater/updater.mojom.h" |
22 #include "mojo/shell/application_loader.h" | 20 #include "mojo/shell/application_loader.h" |
23 #include "mojo/shell/capability_filter.h" | 21 #include "mojo/shell/capability_filter.h" |
24 #include "mojo/shell/connect_to_application_params.h" | 22 #include "mojo/shell/connect_to_application_params.h" |
25 #include "mojo/shell/fetcher.h" | 23 #include "mojo/shell/fetcher.h" |
26 #include "mojo/shell/identity.h" | 24 #include "mojo/shell/identity.h" |
27 #include "mojo/shell/native_runner.h" | 25 #include "mojo/shell/native_runner.h" |
28 #include "url/gurl.h" | 26 #include "url/gurl.h" |
29 | 27 |
30 namespace base { | 28 namespace base { |
31 class FilePath; | 29 class FilePath; |
32 class SequencedWorkerPool; | 30 class SequencedWorkerPool; |
33 } | 31 } |
34 | 32 |
35 namespace mojo { | 33 namespace mojo { |
36 namespace shell { | 34 namespace shell { |
37 | 35 |
| 36 class ApplicationFetcher; |
38 class ApplicationInstance; | 37 class ApplicationInstance; |
39 class ContentHandlerConnection; | 38 class ContentHandlerConnection; |
40 | 39 |
41 class ApplicationManager { | 40 class ApplicationManager { |
42 public: | 41 public: |
43 class Delegate { | |
44 public: | |
45 // Gives the delegate a chance to apply any mappings for the specified url. | |
46 // This should not resolve 'mojo' urls, that is done by ResolveMojoURL(). | |
47 virtual GURL ResolveMappings(const GURL& url) = 0; | |
48 | |
49 // Used to map a url with the scheme 'mojo' to the appropriate url. Return | |
50 // |url| if the scheme is not 'mojo'. | |
51 virtual GURL ResolveMojoURL(const GURL& url) = 0; | |
52 | |
53 // Asks the delegate to create a Fetcher for the specified url. Return | |
54 // true on success, false if the default fetcher should be created. | |
55 virtual bool CreateFetcher( | |
56 const GURL& url, | |
57 const Fetcher::FetchCallback& loader_callback) = 0; | |
58 | |
59 protected: | |
60 virtual ~Delegate() {} | |
61 }; | |
62 | |
63 // API for testing. | 42 // API for testing. |
64 class TestAPI { | 43 class TestAPI { |
65 public: | 44 public: |
66 explicit TestAPI(ApplicationManager* manager); | 45 explicit TestAPI(ApplicationManager* manager); |
67 ~TestAPI(); | 46 ~TestAPI(); |
68 | 47 |
69 // Returns true if the shared instance has been created. | 48 // Returns true if the shared instance has been created. |
70 static bool HasCreatedInstance(); | 49 static bool HasCreatedInstance(); |
71 // Returns true if there is a ApplicationInstance for this URL. | 50 // Returns true if there is a ApplicationInstance for this URL. |
72 bool HasRunningInstanceForURL(const GURL& url) const; | 51 bool HasRunningInstanceForURL(const GURL& url) const; |
73 | 52 |
74 private: | 53 private: |
75 ApplicationManager* manager_; | 54 ApplicationManager* manager_; |
76 | 55 |
77 DISALLOW_COPY_AND_ASSIGN(TestAPI); | 56 DISALLOW_COPY_AND_ASSIGN(TestAPI); |
78 }; | 57 }; |
79 | 58 |
80 explicit ApplicationManager(Delegate* delegate); | 59 explicit ApplicationManager(scoped_ptr<ApplicationFetcher> fetcher); |
81 ~ApplicationManager(); | 60 ~ApplicationManager(); |
82 | 61 |
83 // Loads a service if necessary and establishes a new client connection. | 62 // Loads a service if necessary and establishes a new client connection. |
84 // |originator| can be NULL (e.g. for the first application or in tests), but | 63 // |originator| can be NULL (e.g. for the first application or in tests), but |
85 // typically is non-NULL and identifies the instance initiating the | 64 // typically is non-NULL and identifies the instance initiating the |
86 // connection. | 65 // connection. |
87 // Please see the comments in connect_to_application_params.h for more details | 66 // Please see the comments in connect_to_application_params.h for more details |
88 // about the parameters. | 67 // about the parameters. |
89 void ConnectToApplication( | 68 void ConnectToApplication( |
90 ApplicationInstance* originator, | 69 ApplicationInstance* originator, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { | 105 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { |
127 default_loader_ = loader.Pass(); | 106 default_loader_ = loader.Pass(); |
128 } | 107 } |
129 void set_native_runner_factory( | 108 void set_native_runner_factory( |
130 scoped_ptr<NativeRunnerFactory> runner_factory) { | 109 scoped_ptr<NativeRunnerFactory> runner_factory) { |
131 native_runner_factory_ = runner_factory.Pass(); | 110 native_runner_factory_ = runner_factory.Pass(); |
132 } | 111 } |
133 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { | 112 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { |
134 blocking_pool_ = blocking_pool; | 113 blocking_pool_ = blocking_pool; |
135 } | 114 } |
136 void set_disable_cache(bool disable_cache) { disable_cache_ = disable_cache; } | |
137 // Sets a Loader to be used for a specific url. | 115 // Sets a Loader to be used for a specific url. |
138 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); | 116 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); |
139 // Sets a Loader to be used for a specific url scheme. | 117 // Sets a Loader to be used for a specific url scheme. |
140 void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader, | 118 void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader, |
141 const std::string& scheme); | 119 const std::string& scheme); |
142 // These options will be used in running any native application at |url| | 120 // These options will be used in running any native application at |url| |
143 // (which shouldn't contain a query string). (|url| will be mapped and | 121 // (which shouldn't contain a query string). (|url| will be mapped and |
144 // resolved, and any application whose base resolved URL matches it will have | 122 // resolved, and any application whose base resolved URL matches it will have |
145 // |options| applied.) | 123 // |options| applied.) |
146 // TODO(vtl): This may not do what's desired if the resolved URL results in an | 124 // TODO(vtl): This may not do what's desired if the resolved URL results in an |
(...skipping 27 matching lines...) Expand all Loading... |
174 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; | 152 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; |
175 using URLToNativeOptionsMap = std::map<GURL, NativeRunnerFactory::Options>; | 153 using URLToNativeOptionsMap = std::map<GURL, NativeRunnerFactory::Options>; |
176 | 154 |
177 // Takes the contents of |params| only when it returns true. | 155 // Takes the contents of |params| only when it returns true. |
178 bool ConnectToRunningApplication( | 156 bool ConnectToRunningApplication( |
179 scoped_ptr<ConnectToApplicationParams>* params); | 157 scoped_ptr<ConnectToApplicationParams>* params); |
180 // |resolved_url| is the URL to load by |loader| (if loader is not null). It | 158 // |resolved_url| is the URL to load by |loader| (if loader is not null). It |
181 // may be different from |(*params)->app_url()| because of mappings and | 159 // may be different from |(*params)->app_url()| because of mappings and |
182 // resolution rules. | 160 // resolution rules. |
183 // Takes the contents of |params| only when it returns true. | 161 // Takes the contents of |params| only when it returns true. |
184 bool ConnectToApplicationWithLoader( | 162 void ConnectToApplicationWithLoader( |
185 scoped_ptr<ConnectToApplicationParams>* params, | 163 scoped_ptr<ConnectToApplicationParams>* params, |
186 const GURL& resolved_url, | 164 const GURL& resolved_url, |
187 ApplicationLoader* loader); | 165 ApplicationLoader* loader); |
188 | 166 |
189 InterfaceRequest<Application> RegisterInstance( | 167 InterfaceRequest<Application> RegisterInstance( |
190 scoped_ptr<ConnectToApplicationParams> params, | 168 scoped_ptr<ConnectToApplicationParams> params, |
191 ApplicationInstance** resulting_instance); | 169 ApplicationInstance** resulting_instance); |
192 | 170 |
193 // Called once |fetcher| has found app. |params->app_url()| is the url of | 171 // Called once |fetcher| has found app. |params->app_url()| is the url of |
194 // the requested application before any mappings/resolution have been applied. | 172 // the requested application before any mappings/resolution have been applied. |
195 // The corresponding URLRequest struct in |params| has been taken. | 173 // The corresponding URLRequest struct in |params| has been taken. |
196 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params, | 174 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params, |
197 NativeApplicationCleanup cleanup, | |
198 scoped_ptr<Fetcher> fetcher); | 175 scoped_ptr<Fetcher> fetcher); |
199 | 176 |
200 void RunNativeApplication(InterfaceRequest<Application> application_request, | 177 void RunNativeApplication(InterfaceRequest<Application> application_request, |
201 bool start_sandboxed, | 178 bool start_sandboxed, |
202 const NativeRunnerFactory::Options& options, | 179 const NativeRunnerFactory::Options& options, |
203 NativeApplicationCleanup cleanup, | |
204 scoped_ptr<Fetcher> fetcher, | 180 scoped_ptr<Fetcher> fetcher, |
205 const base::FilePath& file_path, | 181 const base::FilePath& file_path, |
206 bool path_exists); | 182 bool path_exists); |
207 | 183 |
208 void LoadWithContentHandler( | 184 void LoadWithContentHandler( |
209 const Identity& originator_identity, | 185 const Identity& originator_identity, |
210 const CapabilityFilter& originator_filter, | 186 const CapabilityFilter& originator_filter, |
211 const GURL& content_handler_url, | 187 const GURL& content_handler_url, |
212 const std::string& qualifier, | 188 const std::string& qualifier, |
213 const CapabilityFilter& filter, | 189 const CapabilityFilter& filter, |
214 const Shell::ConnectToApplicationCallback& connect_callback, | 190 const Shell::ConnectToApplicationCallback& connect_callback, |
215 ApplicationInstance* app, | 191 ApplicationInstance* app, |
216 InterfaceRequest<Application> application_request, | 192 InterfaceRequest<Application> application_request, |
217 URLResponsePtr url_response); | 193 URLResponsePtr url_response); |
218 | 194 |
219 // Returns the appropriate loader for |url|, or null if there is no loader | 195 // Returns the appropriate loader for |url|, or the default loader if there is |
220 // configured for the URL. | 196 // no loader configured for the URL. |
221 ApplicationLoader* GetLoaderForURL(const GURL& url); | 197 ApplicationLoader* GetLoaderForURL(const GURL& url); |
222 | 198 |
223 void CleanupRunner(NativeRunner* runner); | 199 void CleanupRunner(NativeRunner* runner); |
224 | 200 |
225 ScopedMessagePipeHandle ConnectToServiceByName( | 201 ScopedMessagePipeHandle ConnectToServiceByName( |
226 const GURL& application_url, | 202 const GURL& application_url, |
227 const std::string& interface_name); | 203 const std::string& interface_name); |
228 | 204 |
229 Delegate* const delegate_; | 205 scoped_ptr<ApplicationFetcher> const fetcher_; |
230 // Loader management. | 206 // Loader management. |
231 // Loaders are chosen in the order they are listed here. | 207 // Loaders are chosen in the order they are listed here. |
232 URLToLoaderMap url_to_loader_; | 208 URLToLoaderMap url_to_loader_; |
233 SchemeToLoaderMap scheme_to_loader_; | 209 SchemeToLoaderMap scheme_to_loader_; |
234 scoped_ptr<ApplicationLoader> default_loader_; | 210 scoped_ptr<ApplicationLoader> default_loader_; |
235 scoped_ptr<NativeRunnerFactory> native_runner_factory_; | 211 scoped_ptr<NativeRunnerFactory> native_runner_factory_; |
236 | 212 |
237 ApplicationPackagedAlias application_package_alias_; | 213 ApplicationPackagedAlias application_package_alias_; |
238 IdentityToApplicationInstanceMap identity_to_instance_; | 214 IdentityToApplicationInstanceMap identity_to_instance_; |
239 URLToContentHandlerMap url_to_content_handler_; | 215 URLToContentHandlerMap url_to_content_handler_; |
240 // Note: The keys are URLs after mapping and resolving. | 216 // Note: The keys are URLs after mapping and resolving. |
241 URLToNativeOptionsMap url_to_native_options_; | 217 URLToNativeOptionsMap url_to_native_options_; |
242 | 218 |
243 base::SequencedWorkerPool* blocking_pool_; | 219 base::SequencedWorkerPool* blocking_pool_; |
244 NetworkServicePtr network_service_; | |
245 URLLoaderFactoryPtr url_loader_factory_; | |
246 updater::UpdaterPtr updater_; | 220 updater::UpdaterPtr updater_; |
247 MimeTypeToURLMap mime_type_to_url_; | 221 MimeTypeToURLMap mime_type_to_url_; |
248 ScopedVector<NativeRunner> native_runners_; | 222 ScopedVector<NativeRunner> native_runners_; |
249 bool disable_cache_; | |
250 // Counter used to assign ids to content_handlers. | 223 // Counter used to assign ids to content_handlers. |
251 uint32_t content_handler_id_counter_; | 224 uint32_t content_handler_id_counter_; |
252 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; | 225 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; |
253 | 226 |
254 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); | 227 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); |
255 }; | 228 }; |
256 | 229 |
257 Shell::ConnectToApplicationCallback EmptyConnectCallback(); | 230 Shell::ConnectToApplicationCallback EmptyConnectCallback(); |
258 | 231 |
259 } // namespace shell | 232 } // namespace shell |
260 } // namespace mojo | 233 } // namespace mojo |
261 | 234 |
262 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ | 235 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ |
OLD | NEW |