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" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 class FilePath; | 29 class FilePath; |
30 class SequencedWorkerPool; | 30 class SequencedWorkerPool; |
31 } | 31 } |
32 | 32 |
33 namespace mojo { | 33 namespace mojo { |
34 namespace shell { | 34 namespace shell { |
35 | 35 |
36 class PackageManager; | 36 class ApplicationFetcher; |
37 class ApplicationInstance; | 37 class ApplicationInstance; |
38 class ContentHandlerConnection; | 38 class ContentHandlerConnection; |
39 | 39 |
40 class ApplicationManager { | 40 class ApplicationManager { |
41 public: | 41 public: |
42 // API for testing. | 42 // API for testing. |
43 class TestAPI { | 43 class TestAPI { |
44 public: | 44 public: |
45 explicit TestAPI(ApplicationManager* manager); | 45 explicit TestAPI(ApplicationManager* manager); |
46 ~TestAPI(); | 46 ~TestAPI(); |
47 | 47 |
48 // Returns true if the shared instance has been created. | 48 // Returns true if the shared instance has been created. |
49 static bool HasCreatedInstance(); | 49 static bool HasCreatedInstance(); |
50 // Returns true if there is a ApplicationInstance for this URL. | 50 // Returns true if there is a ApplicationInstance for this URL. |
51 bool HasRunningInstanceForURL(const GURL& url) const; | 51 bool HasRunningInstanceForURL(const GURL& url) const; |
52 private: | 52 private: |
53 ApplicationManager* manager_; | 53 ApplicationManager* manager_; |
54 | 54 |
55 DISALLOW_COPY_AND_ASSIGN(TestAPI); | 55 DISALLOW_COPY_AND_ASSIGN(TestAPI); |
56 }; | 56 }; |
57 | 57 |
58 explicit ApplicationManager(scoped_ptr<PackageManager> package_manager); | 58 explicit ApplicationManager(scoped_ptr<ApplicationFetcher> fetcher); |
59 ~ApplicationManager(); | 59 ~ApplicationManager(); |
60 | 60 |
61 // Loads a service if necessary and establishes a new client connection. | 61 // Loads a service if necessary and establishes a new client connection. |
62 // |originator| can be NULL (e.g. for the first application or in tests), but | 62 // |originator| can be NULL (e.g. for the first application or in tests), but |
63 // typically is non-NULL and identifies the instance initiating the | 63 // typically is non-NULL and identifies the instance initiating the |
64 // connection. | 64 // connection. |
65 // Please see the comments in connect_to_application_params.h for more details | 65 // Please see the comments in connect_to_application_params.h for more details |
66 // about the parameters. | 66 // about the parameters. |
67 void ConnectToApplication( | 67 void ConnectToApplication( |
68 ApplicationInstance* originator, | 68 ApplicationInstance* originator, |
(...skipping 10 matching lines...) Expand all Loading... |
79 // Must only be used by shell internals and test code as it does not forward | 79 // Must only be used by shell internals and test code as it does not forward |
80 // capability filters. | 80 // capability filters. |
81 template <typename Interface> | 81 template <typename Interface> |
82 inline void ConnectToService(const GURL& application_url, | 82 inline void ConnectToService(const GURL& application_url, |
83 InterfacePtr<Interface>* ptr) { | 83 InterfacePtr<Interface>* ptr) { |
84 ScopedMessagePipeHandle service_handle = | 84 ScopedMessagePipeHandle service_handle = |
85 ConnectToServiceByName(application_url, Interface::Name_); | 85 ConnectToServiceByName(application_url, Interface::Name_); |
86 ptr->Bind(InterfacePtrInfo<Interface>(service_handle.Pass(), 0u)); | 86 ptr->Bind(InterfacePtrInfo<Interface>(service_handle.Pass(), 0u)); |
87 } | 87 } |
88 | 88 |
| 89 void RegisterContentHandler(const std::string& mime_type, |
| 90 const GURL& content_handler_url); |
| 91 |
| 92 // Registers a package alias. When attempting to load |alias|, it will |
| 93 // instead redirect to |content_handler_package|, which is a content handler |
| 94 // which will be passed the |alias| as the URLResponse::url. Different values |
| 95 // of |alias| with the same |qualifier| that are in the same |
| 96 // |content_handler_package| will run in the same process in multi-process |
| 97 // mode. |
| 98 void RegisterApplicationPackageAlias(const GURL& alias, |
| 99 const GURL& content_handler_package, |
| 100 const std::string& qualifier); |
| 101 |
89 // Sets the default Loader to be used if not overridden by SetLoaderForURL(). | 102 // Sets the default Loader to be used if not overridden by SetLoaderForURL(). |
90 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { | 103 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { |
91 default_loader_ = loader.Pass(); | 104 default_loader_ = loader.Pass(); |
92 } | 105 } |
93 void set_native_runner_factory( | 106 void set_native_runner_factory( |
94 scoped_ptr<NativeRunnerFactory> runner_factory) { | 107 scoped_ptr<NativeRunnerFactory> runner_factory) { |
95 native_runner_factory_ = runner_factory.Pass(); | 108 native_runner_factory_ = runner_factory.Pass(); |
96 } | 109 } |
97 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { | 110 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { |
98 blocking_pool_ = blocking_pool; | 111 blocking_pool_ = blocking_pool; |
99 } | 112 } |
100 // Sets a Loader to be used for a specific url. | 113 // Sets a Loader to be used for a specific url. |
101 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); | 114 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); |
102 | 115 |
103 // Destroys all Shell-ends of connections established with Applications. | 116 // Destroys all Shell-ends of connections established with Applications. |
104 // Applications connected by this ApplicationManager will observe pipe errors | 117 // Applications connected by this ApplicationManager will observe pipe errors |
105 // and have a chance to shutdown. | 118 // and have a chance to shutdown. |
106 void TerminateShellConnections(); | 119 void TerminateShellConnections(); |
107 | 120 |
108 // Removes a ApplicationInstance when it encounters an error. | 121 // Removes a ApplicationInstance when it encounters an error. |
109 void OnApplicationInstanceError(ApplicationInstance* instance); | 122 void OnApplicationInstanceError(ApplicationInstance* instance); |
110 | 123 |
111 // Removes a ContentHandler when its connection is closed. | 124 // Removes a ContentHandler when its connection is closed. |
112 void OnContentHandlerConnectionClosed( | 125 void OnContentHandlerConnectionClosed( |
113 ContentHandlerConnection* content_handler); | 126 ContentHandlerConnection* content_handler); |
114 | 127 |
115 ApplicationInstance* GetApplicationInstance(const Identity& identity) const; | 128 ApplicationInstance* GetApplicationInstance(const Identity& identity) const; |
116 | 129 |
117 private: | 130 private: |
| 131 using ApplicationPackagedAlias = std::map<GURL, std::pair<GURL, std::string>>; |
118 using IdentityToApplicationInstanceMap = | 132 using IdentityToApplicationInstanceMap = |
119 std::map<Identity, ApplicationInstance*>; | 133 std::map<Identity, ApplicationInstance*>; |
| 134 using MimeTypeToURLMap = std::map<std::string, GURL>; |
120 using URLToContentHandlerMap = | 135 using URLToContentHandlerMap = |
121 std::map<std::pair<GURL, std::string>, ContentHandlerConnection*>; | 136 std::map<std::pair<GURL, std::string>, ContentHandlerConnection*>; |
122 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; | 137 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; |
123 | 138 |
124 // Takes the contents of |params| only when it returns true. | 139 // Takes the contents of |params| only when it returns true. |
125 bool ConnectToRunningApplication( | 140 bool ConnectToRunningApplication( |
126 scoped_ptr<ConnectToApplicationParams>* params); | 141 scoped_ptr<ConnectToApplicationParams>* params); |
127 // |resolved_url| is the URL to load by |loader| (if loader is not null). It | 142 // |resolved_url| is the URL to load by |loader| (if loader is not null). It |
128 // may be different from |(*params)->app_url()| because of mappings and | 143 // may be different from |(*params)->app_url()| because of mappings and |
129 // resolution rules. | 144 // resolution rules. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // Returns the appropriate loader for |url|, or the default loader if there is | 178 // Returns the appropriate loader for |url|, or the default loader if there is |
164 // no loader configured for the URL. | 179 // no loader configured for the URL. |
165 ApplicationLoader* GetLoaderForURL(const GURL& url); | 180 ApplicationLoader* GetLoaderForURL(const GURL& url); |
166 | 181 |
167 void CleanupRunner(NativeRunner* runner); | 182 void CleanupRunner(NativeRunner* runner); |
168 | 183 |
169 ScopedMessagePipeHandle ConnectToServiceByName( | 184 ScopedMessagePipeHandle ConnectToServiceByName( |
170 const GURL& application_url, | 185 const GURL& application_url, |
171 const std::string& interface_name); | 186 const std::string& interface_name); |
172 | 187 |
173 scoped_ptr<PackageManager> const package_manager_; | 188 scoped_ptr<ApplicationFetcher> const fetcher_; |
174 // Loader management. | 189 // Loader management. |
175 // Loaders are chosen in the order they are listed here. | 190 // Loaders are chosen in the order they are listed here. |
176 URLToLoaderMap url_to_loader_; | 191 URLToLoaderMap url_to_loader_; |
177 scoped_ptr<ApplicationLoader> default_loader_; | 192 scoped_ptr<ApplicationLoader> default_loader_; |
178 scoped_ptr<NativeRunnerFactory> native_runner_factory_; | 193 scoped_ptr<NativeRunnerFactory> native_runner_factory_; |
179 | 194 |
| 195 ApplicationPackagedAlias application_package_alias_; |
180 IdentityToApplicationInstanceMap identity_to_instance_; | 196 IdentityToApplicationInstanceMap identity_to_instance_; |
181 URLToContentHandlerMap url_to_content_handler_; | 197 URLToContentHandlerMap url_to_content_handler_; |
182 | 198 |
183 base::SequencedWorkerPool* blocking_pool_; | 199 base::SequencedWorkerPool* blocking_pool_; |
184 updater::UpdaterPtr updater_; | 200 updater::UpdaterPtr updater_; |
| 201 MimeTypeToURLMap mime_type_to_url_; |
185 ScopedVector<NativeRunner> native_runners_; | 202 ScopedVector<NativeRunner> native_runners_; |
186 // Counter used to assign ids to content_handlers. | 203 // Counter used to assign ids to content_handlers. |
187 uint32_t content_handler_id_counter_; | 204 uint32_t content_handler_id_counter_; |
188 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; | 205 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; |
189 | 206 |
190 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); | 207 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); |
191 }; | 208 }; |
192 | 209 |
193 Shell::ConnectToApplicationCallback EmptyConnectCallback(); | 210 Shell::ConnectToApplicationCallback EmptyConnectCallback(); |
194 | 211 |
195 } // namespace shell | 212 } // namespace shell |
196 } // namespace mojo | 213 } // namespace mojo |
197 | 214 |
198 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ | 215 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ |
OLD | NEW |