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/updater/updater.mojom.h" |
19 #include "mojo/shell/application_loader.h" | 20 #include "mojo/shell/application_loader.h" |
20 #include "mojo/shell/capability_filter.h" | 21 #include "mojo/shell/capability_filter.h" |
21 #include "mojo/shell/connect_to_application_params.h" | 22 #include "mojo/shell/connect_to_application_params.h" |
22 #include "mojo/shell/fetcher.h" | 23 #include "mojo/shell/fetcher.h" |
23 #include "mojo/shell/identity.h" | 24 #include "mojo/shell/identity.h" |
24 #include "mojo/shell/native_runner.h" | 25 #include "mojo/shell/native_runner.h" |
25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
26 | 27 |
27 namespace base { | 28 namespace base { |
28 class FilePath; | 29 class FilePath; |
(...skipping 22 matching lines...) Expand all Loading... |
51 private: | 52 private: |
52 ApplicationManager* manager_; | 53 ApplicationManager* manager_; |
53 | 54 |
54 DISALLOW_COPY_AND_ASSIGN(TestAPI); | 55 DISALLOW_COPY_AND_ASSIGN(TestAPI); |
55 }; | 56 }; |
56 | 57 |
57 explicit ApplicationManager(scoped_ptr<PackageManager> package_manager); | 58 explicit ApplicationManager(scoped_ptr<PackageManager> package_manager); |
58 ~ApplicationManager(); | 59 ~ApplicationManager(); |
59 | 60 |
60 // 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 |
| 63 // typically is non-NULL and identifies the instance initiating the |
| 64 // connection. |
61 // 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 |
62 // about the parameters. | 66 // about the parameters. |
| 67 void ConnectToApplication( |
| 68 ApplicationInstance* originator, |
| 69 URLRequestPtr app_url_request, |
| 70 const std::string& qualifier, |
| 71 InterfaceRequest<ServiceProvider> services, |
| 72 ServiceProviderPtr exposed_services, |
| 73 const CapabilityFilter& filter, |
| 74 const base::Closure& on_application_end, |
| 75 const Shell::ConnectToApplicationCallback& connect_callback); |
| 76 |
63 void ConnectToApplication(scoped_ptr<ConnectToApplicationParams> params); | 77 void ConnectToApplication(scoped_ptr<ConnectToApplicationParams> params); |
64 | 78 |
| 79 // Must only be used by shell internals and test code as it does not forward |
| 80 // capability filters. |
| 81 template <typename Interface> |
| 82 inline void ConnectToService(const GURL& application_url, |
| 83 InterfacePtr<Interface>* ptr) { |
| 84 ScopedMessagePipeHandle service_handle = |
| 85 ConnectToServiceByName(application_url, Interface::Name_); |
| 86 ptr->Bind(InterfacePtrInfo<Interface>(service_handle.Pass(), 0u)); |
| 87 } |
| 88 |
65 // 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(). |
66 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { | 90 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { |
67 default_loader_ = loader.Pass(); | 91 default_loader_ = loader.Pass(); |
68 } | 92 } |
69 void set_native_runner_factory( | 93 void set_native_runner_factory( |
70 scoped_ptr<NativeRunnerFactory> runner_factory) { | 94 scoped_ptr<NativeRunnerFactory> runner_factory) { |
71 native_runner_factory_ = runner_factory.Pass(); | 95 native_runner_factory_ = runner_factory.Pass(); |
72 } | 96 } |
73 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { | 97 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { |
74 blocking_pool_ = blocking_pool; | 98 blocking_pool_ = blocking_pool; |
75 } | 99 } |
76 // Sets a Loader to be used for a specific url. | 100 // Sets a Loader to be used for a specific url. |
77 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); | 101 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); |
78 | 102 |
79 // Destroys all Shell-ends of connections established with Applications. | 103 // Destroys all Shell-ends of connections established with Applications. |
80 // Applications connected by this ApplicationManager will observe pipe errors | 104 // Applications connected by this ApplicationManager will observe pipe errors |
81 // and have a chance to shutdown. | 105 // and have a chance to shutdown. |
82 void TerminateShellConnections(); | 106 void TerminateShellConnections(); |
83 | 107 |
84 // Removes a ApplicationInstance when it encounters an error. | 108 // Removes a ApplicationInstance when it encounters an error. |
85 void OnApplicationInstanceError(ApplicationInstance* instance); | 109 void OnApplicationInstanceError(ApplicationInstance* instance); |
86 | 110 |
87 // Removes a ContentHandler when its connection is closed. | 111 // Removes a ContentHandler when its connection is closed. |
88 void OnContentHandlerConnectionClosed( | 112 void OnContentHandlerConnectionClosed( |
89 ContentHandlerConnection* content_handler); | 113 ContentHandlerConnection* content_handler); |
90 | 114 |
91 ApplicationInstance* GetApplicationInstance(const Identity& identity) const; | 115 ApplicationInstance* GetApplicationInstance(const Identity& identity) const; |
92 | 116 |
93 private: | 117 private: |
94 using IdentityToInstanceMap = std::map<Identity, ApplicationInstance*>; | 118 using IdentityToApplicationInstanceMap = |
95 using IdentityToContentHandlerMap = | 119 std::map<Identity, ApplicationInstance*>; |
96 std::map<Identity, ContentHandlerConnection*>; | 120 using URLToContentHandlerMap = |
| 121 std::map<std::pair<GURL, std::string>, ContentHandlerConnection*>; |
97 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; | 122 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; |
98 | 123 |
99 // Takes the contents of |params| only when it returns true. | 124 // Takes the contents of |params| only when it returns true. |
100 bool ConnectToRunningApplication( | 125 bool ConnectToRunningApplication( |
101 scoped_ptr<ConnectToApplicationParams>* params); | 126 scoped_ptr<ConnectToApplicationParams>* params); |
102 // |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 |
103 // may be different from |(*params)->app_url()| because of mappings and | 128 // may be different from |(*params)->app_url()| because of mappings and |
104 // resolution rules. | 129 // resolution rules. |
105 // Takes the contents of |params| only when it returns true. | 130 // Takes the contents of |params| only when it returns true. |
106 void ConnectToApplicationWithLoader( | 131 void ConnectToApplicationWithLoader( |
107 scoped_ptr<ConnectToApplicationParams>* params, | 132 scoped_ptr<ConnectToApplicationParams>* params, |
108 const GURL& resolved_url, | 133 const GURL& resolved_url, |
109 ApplicationLoader* loader); | 134 ApplicationLoader* loader); |
110 | 135 |
111 InterfaceRequest<Application> CreateInstance( | 136 InterfaceRequest<Application> RegisterInstance( |
112 scoped_ptr<ConnectToApplicationParams> params, | 137 scoped_ptr<ConnectToApplicationParams> params, |
113 ApplicationInstance** instance); | 138 ApplicationInstance** resulting_instance); |
114 | 139 |
115 // Called once |fetcher| has found app. |params->app_url()| is the url of | 140 // Called once |fetcher| has found app. |params->app_url()| is the url of |
116 // the requested application before any mappings/resolution have been applied. | 141 // the requested application before any mappings/resolution have been applied. |
117 // The corresponding URLRequest struct in |params| has been taken. | 142 // The corresponding URLRequest struct in |params| has been taken. |
118 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params, | 143 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params, |
119 scoped_ptr<Fetcher> fetcher); | 144 scoped_ptr<Fetcher> fetcher); |
120 | 145 |
121 void RunNativeApplication(InterfaceRequest<Application> application_request, | 146 void RunNativeApplication(InterfaceRequest<Application> application_request, |
122 bool start_sandboxed, | 147 bool start_sandboxed, |
123 scoped_ptr<Fetcher> fetcher, | 148 scoped_ptr<Fetcher> fetcher, |
(...skipping 10 matching lines...) Expand all Loading... |
134 ApplicationInstance* app, | 159 ApplicationInstance* app, |
135 InterfaceRequest<Application> application_request, | 160 InterfaceRequest<Application> application_request, |
136 URLResponsePtr url_response); | 161 URLResponsePtr url_response); |
137 | 162 |
138 // 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 |
139 // no loader configured for the URL. | 164 // no loader configured for the URL. |
140 ApplicationLoader* GetLoaderForURL(const GURL& url); | 165 ApplicationLoader* GetLoaderForURL(const GURL& url); |
141 | 166 |
142 void CleanupRunner(NativeRunner* runner); | 167 void CleanupRunner(NativeRunner* runner); |
143 | 168 |
| 169 ScopedMessagePipeHandle ConnectToServiceByName( |
| 170 const GURL& application_url, |
| 171 const std::string& interface_name); |
| 172 |
144 scoped_ptr<PackageManager> const package_manager_; | 173 scoped_ptr<PackageManager> const package_manager_; |
145 // Loader management. | 174 // Loader management. |
146 // Loaders are chosen in the order they are listed here. | 175 // Loaders are chosen in the order they are listed here. |
147 URLToLoaderMap url_to_loader_; | 176 URLToLoaderMap url_to_loader_; |
148 scoped_ptr<ApplicationLoader> default_loader_; | 177 scoped_ptr<ApplicationLoader> default_loader_; |
149 scoped_ptr<NativeRunnerFactory> native_runner_factory_; | 178 scoped_ptr<NativeRunnerFactory> native_runner_factory_; |
150 | 179 |
151 IdentityToInstanceMap identity_to_instance_; | 180 IdentityToApplicationInstanceMap identity_to_instance_; |
152 IdentityToContentHandlerMap identity_to_content_handler_; | 181 URLToContentHandlerMap url_to_content_handler_; |
153 | 182 |
154 base::SequencedWorkerPool* blocking_pool_; | 183 base::SequencedWorkerPool* blocking_pool_; |
| 184 updater::UpdaterPtr updater_; |
155 ScopedVector<NativeRunner> native_runners_; | 185 ScopedVector<NativeRunner> native_runners_; |
156 // Counter used to assign ids to content_handlers. | 186 // Counter used to assign ids to content_handlers. |
157 uint32_t content_handler_id_counter_; | 187 uint32_t content_handler_id_counter_; |
158 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; | 188 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; |
159 | 189 |
160 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); | 190 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); |
161 }; | 191 }; |
162 | 192 |
163 Shell::ConnectToApplicationCallback EmptyConnectCallback(); | 193 Shell::ConnectToApplicationCallback EmptyConnectCallback(); |
164 | 194 |
165 } // namespace shell | 195 } // namespace shell |
166 } // namespace mojo | 196 } // namespace mojo |
167 | 197 |
168 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ | 198 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ |
OLD | NEW |