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 #include <utility> | |
10 #include <vector> | 9 #include <vector> |
11 | 10 |
12 #include "base/macros.h" | 11 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
15 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | |
16 #include "mojo/public/cpp/bindings/interface_request.h" | |
17 #include "mojo/public/cpp/bindings/weak_interface_ptr_set.h" | 14 #include "mojo/public/cpp/bindings/weak_interface_ptr_set.h" |
18 #include "mojo/services/package_manager/public/interfaces/shell_resolver.mojom.h
" | 15 #include "mojo/services/package_manager/public/interfaces/shell_resolver.mojom.h
" |
19 #include "mojo/shell/application_loader.h" | 16 #include "mojo/shell/application_loader.h" |
20 #include "mojo/shell/capability_filter.h" | 17 #include "mojo/shell/capability_filter.h" |
21 #include "mojo/shell/connect_to_application_params.h" | 18 #include "mojo/shell/connect_to_application_params.h" |
22 #include "mojo/shell/fetcher.h" | |
23 #include "mojo/shell/identity.h" | 19 #include "mojo/shell/identity.h" |
24 #include "mojo/shell/native_runner.h" | 20 #include "mojo/shell/native_runner.h" |
25 #include "mojo/shell/public/interfaces/application_manager.mojom.h" | 21 #include "mojo/shell/public/interfaces/application_manager.mojom.h" |
26 #include "mojo/shell/public/interfaces/interface_provider.mojom.h" | 22 #include "mojo/shell/public/interfaces/interface_provider.mojom.h" |
27 #include "mojo/shell/public/interfaces/shell.mojom.h" | 23 #include "mojo/shell/public/interfaces/shell.mojom.h" |
28 #include "mojo/shell/public/interfaces/shell_client.mojom.h" | 24 #include "mojo/shell/public/interfaces/shell_client.mojom.h" |
29 #include "url/gurl.h" | 25 #include "url/gurl.h" |
30 | 26 |
31 namespace base { | 27 namespace base { |
32 class FilePath; | 28 class FilePath; |
33 class SequencedWorkerPool; | 29 class SequencedWorkerPool; |
34 } | 30 } |
35 | 31 |
36 namespace mojo { | 32 namespace mojo { |
37 namespace shell { | 33 namespace shell { |
38 | 34 |
39 class PackageManager; | |
40 class ApplicationInstance; | 35 class ApplicationInstance; |
41 class ContentHandlerConnection; | 36 class ContentHandlerConnection; |
42 | 37 |
43 class ApplicationManager { | 38 class ApplicationManager { |
44 public: | 39 public: |
45 // API for testing. | 40 // API for testing. |
46 class TestAPI { | 41 class TestAPI { |
47 public: | 42 public: |
48 explicit TestAPI(ApplicationManager* manager); | 43 explicit TestAPI(ApplicationManager* manager); |
49 ~TestAPI(); | 44 ~TestAPI(); |
50 | 45 |
51 // Returns true if the shared instance has been created. | 46 // Returns true if the shared instance has been created. |
52 static bool HasCreatedInstance(); | 47 static bool HasCreatedInstance(); |
53 // Returns true if there is a ApplicationInstance for this URL. | 48 // Returns true if there is a ApplicationInstance for this URL. |
54 bool HasRunningInstanceForURL(const GURL& url) const; | 49 bool HasRunningInstanceForURL(const GURL& url) const; |
55 private: | 50 private: |
56 ApplicationManager* manager_; | 51 ApplicationManager* manager_; |
57 | 52 |
58 DISALLOW_COPY_AND_ASSIGN(TestAPI); | 53 DISALLOW_COPY_AND_ASSIGN(TestAPI); |
59 }; | 54 }; |
60 | 55 |
61 // Creates an ApplicationManager. | 56 // Creates an ApplicationManager. |
62 // |package_manager| is an instance of an object that handles URL resolution, | 57 explicit ApplicationManager(bool register_mojo_url_schemes); |
63 // fetching and updating of applications. See package_manager.h. | |
64 ApplicationManager(scoped_ptr<PackageManager> package_manager, | |
65 bool register_mojo_url_schemes); | |
66 // |native_runner_factory| is an instance of an object capable of vending | 58 // |native_runner_factory| is an instance of an object capable of vending |
67 // implementations of NativeRunner, e.g. for in or out-of-process execution. | 59 // implementations of NativeRunner, e.g. for in or out-of-process execution. |
68 // See native_runner.h and RunNativeApplication(). | 60 // See native_runner.h and RunNativeApplication(). |
69 // |task_runner| provides access to a thread to perform file copy operations | 61 // |task_runner| provides access to a thread to perform file copy operations |
70 // on. This may be null only in testing environments where applications are | 62 // on. This may be null only in testing environments where applications are |
71 // loaded via ApplicationLoader implementations. | 63 // loaded via ApplicationLoader implementations. |
72 // When |register_mojo_url_schemes| is true, mojo: and exe: URL schems are | 64 // When |register_mojo_url_schemes| is true, mojo: and exe: URL schems are |
73 // registered as "standard" which faciliates resolving. | 65 // registered as "standard" which faciliates resolving. |
74 ApplicationManager(scoped_ptr<PackageManager> package_manager, | 66 ApplicationManager(scoped_ptr<NativeRunnerFactory> native_runner_factory, |
75 scoped_ptr<NativeRunnerFactory> native_runner_factory, | |
76 base::TaskRunner* task_runner, | 67 base::TaskRunner* task_runner, |
77 bool register_mojo_url_schemes); | 68 bool register_mojo_url_schemes); |
78 ~ApplicationManager(); | 69 ~ApplicationManager(); |
79 | 70 |
80 // Loads a service if necessary and establishes a new client connection. | 71 // Loads a service if necessary and establishes a new client connection. |
81 // Please see the comments in connect_to_application_params.h for more details | 72 // Please see the comments in connect_to_application_params.h for more details |
82 // about the parameters. | 73 // about the parameters. |
83 void ConnectToApplication(scoped_ptr<ConnectToApplicationParams> params); | 74 void ConnectToApplication(scoped_ptr<ConnectToApplicationParams> params); |
84 | 75 |
85 // Sets the default Loader to be used if not overridden by SetLoaderForURL(). | 76 // Sets the default Loader to be used if not overridden by SetLoaderForURL(). |
(...skipping 19 matching lines...) Expand all Loading... |
105 const GURL& url, | 96 const GURL& url, |
106 mojom::CapabilityFilterPtr filter, | 97 mojom::CapabilityFilterPtr filter, |
107 InterfaceRequest<mojom::PIDReceiver> pid_receiver); | 98 InterfaceRequest<mojom::PIDReceiver> pid_receiver); |
108 void AddListener(mojom::ApplicationManagerListenerPtr listener); | 99 void AddListener(mojom::ApplicationManagerListenerPtr listener); |
109 | 100 |
110 void ApplicationPIDAvailable(uint32_t id, base::ProcessId pid); | 101 void ApplicationPIDAvailable(uint32_t id, base::ProcessId pid); |
111 | 102 |
112 private: | 103 private: |
113 using IdentityToInstanceMap = std::map<Identity, ApplicationInstance*>; | 104 using IdentityToInstanceMap = std::map<Identity, ApplicationInstance*>; |
114 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; | 105 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; |
115 | 106 using IdentityToContentHandlerMap = |
116 void UseRemotePackageManager(bool register_mojo_url_schemes); | 107 std::map<Identity, ContentHandlerConnection*>; |
117 | 108 |
118 // Takes the contents of |params| only when it returns true. | 109 // Takes the contents of |params| only when it returns true. |
119 bool ConnectToRunningApplication( | 110 bool ConnectToRunningApplication( |
120 scoped_ptr<ConnectToApplicationParams>* params); | 111 scoped_ptr<ConnectToApplicationParams>* params); |
121 | 112 |
122 ApplicationInstance* CreateAndConnectToInstance( | 113 ApplicationInstance* CreateAndConnectToInstance( |
123 scoped_ptr<ConnectToApplicationParams> params, | 114 scoped_ptr<ConnectToApplicationParams> params, |
124 Identity* source, | 115 Identity* source, |
125 Identity* target, | 116 Identity* target, |
126 const std::string& application_name, | 117 const std::string& application_name, |
127 mojom::ShellClientRequest* request); | 118 mojom::ShellClientRequest* request); |
128 ApplicationInstance* CreateInstance( | 119 ApplicationInstance* CreateInstance( |
129 const Identity& target_id, | 120 const Identity& target_id, |
130 const mojom::Shell::ConnectToApplicationCallback& connect_callback, | 121 const mojom::Shell::ConnectToApplicationCallback& connect_callback, |
131 const base::Closure& on_application_end, | 122 const base::Closure& on_application_end, |
132 const String& application_name, | 123 const String& application_name, |
133 mojom::ShellClientRequest* request); | 124 mojom::ShellClientRequest* request); |
134 | 125 |
| 126 uint32_t StartContentHandler(const Identity& source, |
| 127 const Identity& content_handler, |
| 128 const GURL& url, |
| 129 mojom::ShellClientRequest request); |
| 130 // Returns a running ContentHandler for |content_handler_identity|, if there |
| 131 // is not one running one is started for |source_identity|. |
| 132 ContentHandlerConnection* GetContentHandler( |
| 133 const Identity& content_handler_identity, |
| 134 const Identity& source_identity); |
| 135 void OnContentHandlerConnectionClosed( |
| 136 ContentHandlerConnection* content_handler); |
| 137 |
135 // Callback when remote PackageManager resolves mojo:foo to mojo:bar. | 138 // Callback when remote PackageManager resolves mojo:foo to mojo:bar. |
136 // |params| are the params passed to Connect(). | 139 // |params| are the params passed to Connect(). |
137 // |resolved_url| is the mojo: url identifying the physical package | 140 // |resolved_url| is the mojo: url identifying the physical package |
138 // application. | 141 // application. |
139 // |file_url| is the resolved file:// URL of the physical package. | 142 // |file_url| is the resolved file:// URL of the physical package. |
140 // |application_name| is the requested application's pretty name, from its | 143 // |application_name| is the requested application's pretty name, from its |
141 // manifest. | 144 // manifest. |
142 // |base_filter| is the CapabilityFilter the requested application should be | 145 // |base_filter| is the CapabilityFilter the requested application should be |
143 // run with, from its manifest. | 146 // run with, from its manifest. |
144 void OnGotResolvedURL(scoped_ptr<ConnectToApplicationParams> params, | 147 void OnGotResolvedURL(scoped_ptr<ConnectToApplicationParams> params, |
145 const String& resolved_url, | 148 const String& resolved_url, |
146 const String& file_url, | 149 const String& file_url, |
147 const String& application_name, | 150 const String& application_name, |
148 mojom::CapabilityFilterPtr base_filter); | 151 mojom::CapabilityFilterPtr base_filter); |
149 | 152 |
150 // In response to a request via Connect() with |params|, creates an | 153 // In response to a request via Connect() with |params|, creates an |
151 // ApplicationInstance and runs the application at |file_url|. | 154 // ApplicationInstance and runs the application at |file_url|. |
152 void CreateAndRunLocalApplication( | 155 void CreateAndRunLocalApplication( |
153 scoped_ptr<ConnectToApplicationParams> params, | 156 scoped_ptr<ConnectToApplicationParams> params, |
154 const String& application_name, | 157 const String& application_name, |
155 const GURL& file_url); | 158 const GURL& file_url); |
156 | 159 |
157 void AddListenerManifestsReady(mojom::ApplicationManagerListenerPtr listener); | |
158 | |
159 // Called once |fetcher| has found app. |params->app_url()| is the url of | |
160 // the requested application before any mappings/resolution have been applied. | |
161 // The corresponding URLRequest struct in |params| has been taken. | |
162 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params, | |
163 scoped_ptr<Fetcher> fetcher); | |
164 | |
165 void RunNativeApplication(InterfaceRequest<mojom::ShellClient> request, | 160 void RunNativeApplication(InterfaceRequest<mojom::ShellClient> request, |
166 bool start_sandboxed, | 161 bool start_sandboxed, |
167 scoped_ptr<Fetcher> fetcher, | |
168 ApplicationInstance* instance, | 162 ApplicationInstance* instance, |
169 const base::FilePath& file_path, | 163 const base::FilePath& file_path); |
170 bool path_exists); | |
171 | 164 |
172 // Returns the appropriate loader for |url|, or the default loader if there is | 165 // Returns the appropriate loader for |url|, or the default loader if there is |
173 // no loader configured for the URL. | 166 // no loader configured for the URL. |
174 ApplicationLoader* GetLoaderForURL(const GURL& url); | 167 ApplicationLoader* GetLoaderForURL(const GURL& url); |
175 | 168 |
176 void CleanupRunner(NativeRunner* runner); | 169 void CleanupRunner(NativeRunner* runner); |
177 | 170 |
178 mojom::ApplicationInfoPtr CreateApplicationInfoForInstance( | 171 mojom::ApplicationInfoPtr CreateApplicationInfoForInstance( |
179 ApplicationInstance* instance) const; | 172 ApplicationInstance* instance) const; |
180 | 173 |
181 bool use_remote_package_manager_; | |
182 package_manager::mojom::ShellResolverPtr shell_resolver_; | 174 package_manager::mojom::ShellResolverPtr shell_resolver_; |
183 | 175 |
184 scoped_ptr<PackageManager> const package_manager_; | |
185 // Loader management. | 176 // Loader management. |
186 // Loaders are chosen in the order they are listed here. | 177 // Loaders are chosen in the order they are listed here. |
187 URLToLoaderMap url_to_loader_; | 178 URLToLoaderMap url_to_loader_; |
188 scoped_ptr<ApplicationLoader> default_loader_; | 179 scoped_ptr<ApplicationLoader> default_loader_; |
189 | 180 |
190 IdentityToInstanceMap identity_to_instance_; | 181 IdentityToInstanceMap identity_to_instance_; |
191 | 182 |
| 183 IdentityToContentHandlerMap identity_to_content_handler_; |
| 184 // Counter used to assign ids to content handlers. |
| 185 uint32_t content_handler_id_counter_; |
| 186 |
192 WeakInterfacePtrSet<mojom::ApplicationManagerListener> listeners_; | 187 WeakInterfacePtrSet<mojom::ApplicationManagerListener> listeners_; |
193 | 188 |
194 base::TaskRunner* task_runner_; | 189 base::TaskRunner* task_runner_; |
195 scoped_ptr<NativeRunnerFactory> native_runner_factory_; | 190 scoped_ptr<NativeRunnerFactory> native_runner_factory_; |
196 std::vector<scoped_ptr<NativeRunner>> native_runners_; | 191 std::vector<scoped_ptr<NativeRunner>> native_runners_; |
197 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; | 192 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; |
198 | 193 |
199 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); | 194 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); |
200 }; | 195 }; |
201 | 196 |
202 mojom::Shell::ConnectToApplicationCallback EmptyConnectCallback(); | 197 mojom::Shell::ConnectToApplicationCallback EmptyConnectCallback(); |
203 | 198 |
204 } // namespace shell | 199 } // namespace shell |
205 } // namespace mojo | 200 } // namespace mojo |
206 | 201 |
207 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ | 202 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ |
OLD | NEW |