| 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 ApplicationFetcher; | 36 class PackageManager; |
| 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<ApplicationFetcher> fetcher); | 58 explicit ApplicationManager(scoped_ptr<PackageManager> package_manager); |
| 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 | |
| 102 // Sets the default Loader to be used if not overridden by SetLoaderForURL(). | 89 // Sets the default Loader to be used if not overridden by SetLoaderForURL(). |
| 103 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { | 90 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { |
| 104 default_loader_ = loader.Pass(); | 91 default_loader_ = loader.Pass(); |
| 105 } | 92 } |
| 106 void set_native_runner_factory( | 93 void set_native_runner_factory( |
| 107 scoped_ptr<NativeRunnerFactory> runner_factory) { | 94 scoped_ptr<NativeRunnerFactory> runner_factory) { |
| 108 native_runner_factory_ = runner_factory.Pass(); | 95 native_runner_factory_ = runner_factory.Pass(); |
| 109 } | 96 } |
| 110 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { | 97 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { |
| 111 blocking_pool_ = blocking_pool; | 98 blocking_pool_ = blocking_pool; |
| 112 } | 99 } |
| 113 // Sets a Loader to be used for a specific url. | 100 // Sets a Loader to be used for a specific url. |
| 114 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); | 101 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); |
| 115 | 102 |
| 116 // Destroys all Shell-ends of connections established with Applications. | 103 // Destroys all Shell-ends of connections established with Applications. |
| 117 // Applications connected by this ApplicationManager will observe pipe errors | 104 // Applications connected by this ApplicationManager will observe pipe errors |
| 118 // and have a chance to shutdown. | 105 // and have a chance to shutdown. |
| 119 void TerminateShellConnections(); | 106 void TerminateShellConnections(); |
| 120 | 107 |
| 121 // Removes a ApplicationInstance when it encounters an error. | 108 // Removes a ApplicationInstance when it encounters an error. |
| 122 void OnApplicationInstanceError(ApplicationInstance* instance); | 109 void OnApplicationInstanceError(ApplicationInstance* instance); |
| 123 | 110 |
| 124 // Removes a ContentHandler when its connection is closed. | 111 // Removes a ContentHandler when its connection is closed. |
| 125 void OnContentHandlerConnectionClosed( | 112 void OnContentHandlerConnectionClosed( |
| 126 ContentHandlerConnection* content_handler); | 113 ContentHandlerConnection* content_handler); |
| 127 | 114 |
| 128 ApplicationInstance* GetApplicationInstance(const Identity& identity) const; | 115 ApplicationInstance* GetApplicationInstance(const Identity& identity) const; |
| 129 | 116 |
| 130 private: | 117 private: |
| 131 using ApplicationPackagedAlias = std::map<GURL, std::pair<GURL, std::string>>; | |
| 132 using IdentityToApplicationInstanceMap = | 118 using IdentityToApplicationInstanceMap = |
| 133 std::map<Identity, ApplicationInstance*>; | 119 std::map<Identity, ApplicationInstance*>; |
| 134 using MimeTypeToURLMap = std::map<std::string, GURL>; | |
| 135 using URLToContentHandlerMap = | 120 using URLToContentHandlerMap = |
| 136 std::map<std::pair<GURL, std::string>, ContentHandlerConnection*>; | 121 std::map<std::pair<GURL, std::string>, ContentHandlerConnection*>; |
| 137 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; | 122 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; |
| 138 | 123 |
| 139 // Takes the contents of |params| only when it returns true. | 124 // Takes the contents of |params| only when it returns true. |
| 140 bool ConnectToRunningApplication( | 125 bool ConnectToRunningApplication( |
| 141 scoped_ptr<ConnectToApplicationParams>* params); | 126 scoped_ptr<ConnectToApplicationParams>* params); |
| 142 // |resolved_url| is the URL to load by |loader| (if loader is not null). It | 127 // |resolved_url| is the URL to load by |loader| (if loader is not null). It |
| 143 // may be different from |(*params)->app_url()| because of mappings and | 128 // may be different from |(*params)->app_url()| because of mappings and |
| 144 // resolution rules. | 129 // resolution rules. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // Returns the appropriate loader for |url|, or the default loader if there is | 163 // Returns the appropriate loader for |url|, or the default loader if there is |
| 179 // no loader configured for the URL. | 164 // no loader configured for the URL. |
| 180 ApplicationLoader* GetLoaderForURL(const GURL& url); | 165 ApplicationLoader* GetLoaderForURL(const GURL& url); |
| 181 | 166 |
| 182 void CleanupRunner(NativeRunner* runner); | 167 void CleanupRunner(NativeRunner* runner); |
| 183 | 168 |
| 184 ScopedMessagePipeHandle ConnectToServiceByName( | 169 ScopedMessagePipeHandle ConnectToServiceByName( |
| 185 const GURL& application_url, | 170 const GURL& application_url, |
| 186 const std::string& interface_name); | 171 const std::string& interface_name); |
| 187 | 172 |
| 188 scoped_ptr<ApplicationFetcher> const fetcher_; | 173 scoped_ptr<PackageManager> const package_manager_; |
| 189 // Loader management. | 174 // Loader management. |
| 190 // Loaders are chosen in the order they are listed here. | 175 // Loaders are chosen in the order they are listed here. |
| 191 URLToLoaderMap url_to_loader_; | 176 URLToLoaderMap url_to_loader_; |
| 192 scoped_ptr<ApplicationLoader> default_loader_; | 177 scoped_ptr<ApplicationLoader> default_loader_; |
| 193 scoped_ptr<NativeRunnerFactory> native_runner_factory_; | 178 scoped_ptr<NativeRunnerFactory> native_runner_factory_; |
| 194 | 179 |
| 195 ApplicationPackagedAlias application_package_alias_; | |
| 196 IdentityToApplicationInstanceMap identity_to_instance_; | 180 IdentityToApplicationInstanceMap identity_to_instance_; |
| 197 URLToContentHandlerMap url_to_content_handler_; | 181 URLToContentHandlerMap url_to_content_handler_; |
| 198 | 182 |
| 199 base::SequencedWorkerPool* blocking_pool_; | 183 base::SequencedWorkerPool* blocking_pool_; |
| 200 updater::UpdaterPtr updater_; | 184 updater::UpdaterPtr updater_; |
| 201 MimeTypeToURLMap mime_type_to_url_; | |
| 202 ScopedVector<NativeRunner> native_runners_; | 185 ScopedVector<NativeRunner> native_runners_; |
| 203 // Counter used to assign ids to content_handlers. | 186 // Counter used to assign ids to content_handlers. |
| 204 uint32_t content_handler_id_counter_; | 187 uint32_t content_handler_id_counter_; |
| 205 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; | 188 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; |
| 206 | 189 |
| 207 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); | 190 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); |
| 208 }; | 191 }; |
| 209 | 192 |
| 210 Shell::ConnectToApplicationCallback EmptyConnectCallback(); | 193 Shell::ConnectToApplicationCallback EmptyConnectCallback(); |
| 211 | 194 |
| 212 } // namespace shell | 195 } // namespace shell |
| 213 } // namespace mojo | 196 } // namespace mojo |
| 214 | 197 |
| 215 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ | 198 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ |
| OLD | NEW |