Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: mojo/shell/application_manager.cc

Issue 1706063002: Eliminate ShellClientFactoryConnection & just have the ApplicationManager do it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@factory
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/shell/application_manager.h ('k') | mojo/shell/application_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "mojo/shell/application_manager.h" 5 #include "mojo/shell/application_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/process/process.h" 15 #include "base/process/process.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
19 #include "mojo/common/url_type_converters.h" 19 #include "mojo/common/url_type_converters.h"
20 #include "mojo/public/cpp/bindings/binding.h" 20 #include "mojo/public/cpp/bindings/binding.h"
21 #include "mojo/services/package_manager/loader.h" 21 #include "mojo/services/package_manager/loader.h"
22 #include "mojo/shell/application_instance.h" 22 #include "mojo/shell/application_instance.h"
23 #include "mojo/shell/connect_util.h" 23 #include "mojo/shell/connect_util.h"
24 #include "mojo/shell/public/cpp/connect.h" 24 #include "mojo/shell/public/cpp/connect.h"
25 #include "mojo/shell/shell_application_loader.h" 25 #include "mojo/shell/shell_application_loader.h"
26 #include "mojo/shell/shell_client_factory_connection.h"
27 #include "mojo/shell/switches.h" 26 #include "mojo/shell/switches.h"
28 #include "mojo/util/filename_util.h" 27 #include "mojo/util/filename_util.h"
29 28
30 namespace mojo { 29 namespace mojo {
31 namespace shell { 30 namespace shell {
32 31
33 namespace { 32 namespace {
34 33
35 // Used by TestAPI. 34 // Used by TestAPI.
36 bool has_created_instance = false; 35 bool has_created_instance = false;
37 36
38 void OnEmptyOnConnectCallback(uint32_t remote_id, 37 void OnEmptyOnConnectCallback(uint32_t remote_id) {
39 uint32_t shell_client_factory_id) {
40 } 38 }
41 39
42 } // namespace 40 } // namespace
43 41
44 // static 42 // static
45 ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager) 43 ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager)
46 : manager_(manager) { 44 : manager_(manager) {
47 } 45 }
48 46
49 ApplicationManager::TestAPI::~TestAPI() { 47 ApplicationManager::TestAPI::~TestAPI() {
(...skipping 20 matching lines...) Expand all
70 : task_runner_(task_runner), 68 : task_runner_(task_runner),
71 native_runner_factory_(std::move(native_runner_factory)), 69 native_runner_factory_(std::move(native_runner_factory)),
72 weak_ptr_factory_(this) { 70 weak_ptr_factory_(this) {
73 SetLoaderForURL(make_scoped_ptr(new ShellApplicationLoader(this)), 71 SetLoaderForURL(make_scoped_ptr(new ShellApplicationLoader(this)),
74 GURL("mojo://shell/")); 72 GURL("mojo://shell/"));
75 73
76 GURL package_manager_url("mojo://package_manager/"); 74 GURL package_manager_url("mojo://package_manager/");
77 SetLoaderForURL(make_scoped_ptr(new package_manager::Loader( 75 SetLoaderForURL(make_scoped_ptr(new package_manager::Loader(
78 task_runner_, register_mojo_url_schemes)), package_manager_url); 76 task_runner_, register_mojo_url_schemes)), package_manager_url);
79 77
80 ConnectToInterface(this, package_manager_url, &shell_resolver_); 78 ConnectToInterface(this, CreateShellIdentity(), package_manager_url,
79 &shell_resolver_);
81 } 80 }
82 81
83 ApplicationManager::~ApplicationManager() { 82 ApplicationManager::~ApplicationManager() {
84 TerminateShellConnections(); 83 TerminateShellConnections();
85 STLDeleteValues(&url_to_loader_); 84 STLDeleteValues(&url_to_loader_);
86 for (auto& runner : native_runners_) 85 for (auto& runner : native_runners_)
87 runner.reset(); 86 runner.reset();
88 } 87 }
89 88
90 void ApplicationManager::TerminateShellConnections() { 89 void ApplicationManager::TerminateShellConnections() {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 211
213 ApplicationInstance* ApplicationManager::CreateInstance( 212 ApplicationInstance* ApplicationManager::CreateInstance(
214 const Identity& target_id, 213 const Identity& target_id,
215 const mojom::Shell::ConnectToApplicationCallback& connect_callback, 214 const mojom::Shell::ConnectToApplicationCallback& connect_callback,
216 const base::Closure& on_application_end, 215 const base::Closure& on_application_end,
217 const String& application_name, 216 const String& application_name,
218 mojom::ShellClientRequest* request) { 217 mojom::ShellClientRequest* request) {
219 mojom::ShellClientPtr shell_client; 218 mojom::ShellClientPtr shell_client;
220 *request = GetProxy(&shell_client); 219 *request = GetProxy(&shell_client);
221 ApplicationInstance* instance = new ApplicationInstance( 220 ApplicationInstance* instance = new ApplicationInstance(
222 std::move(shell_client), this, target_id, 221 std::move(shell_client), this, target_id, connect_callback,
223 mojom::Shell::kInvalidApplicationID, connect_callback,on_application_end, 222 on_application_end, application_name);
224 application_name);
225 DCHECK(identity_to_instance_.find(target_id) == 223 DCHECK(identity_to_instance_.find(target_id) ==
226 identity_to_instance_.end()); 224 identity_to_instance_.end());
227 identity_to_instance_[target_id] = instance; 225 identity_to_instance_[target_id] = instance;
228 mojom::ApplicationInfoPtr application_info = 226 mojom::ApplicationInfoPtr application_info =
229 CreateApplicationInfoForInstance(instance); 227 CreateApplicationInfoForInstance(instance);
230 listeners_.ForAllPtrs( 228 listeners_.ForAllPtrs(
231 [this, &application_info](mojom::ApplicationManagerListener* listener) { 229 [this, &application_info](mojom::ApplicationManagerListener* listener) {
232 listener->ApplicationInstanceCreated(application_info.Clone()); 230 listener->ApplicationInstanceCreated(application_info.Clone());
233 }); 231 });
234 instance->InitializeApplication(); 232 instance->InitializeApplication();
235 return instance; 233 return instance;
236 } 234 }
237 235
238 uint32_t ApplicationManager::StartShellClientFactory( 236 void ApplicationManager::CreateShellClient(
239 const Identity& source, 237 const Identity& source,
240 const Identity& shell_client_factory, 238 const Identity& shell_client_factory,
241 const GURL& url, 239 const GURL& url,
242 mojom::ShellClientRequest request) { 240 mojom::ShellClientRequest request) {
243 ShellClientFactoryConnection* connection = 241 mojom::ShellClientFactory* factory =
244 GetShellClientFactory(shell_client_factory, source); 242 GetShellClientFactory(shell_client_factory, source);
245 connection->CreateShellClient(std::move(request), url); 243 factory->CreateShellClient(std::move(request), url.spec());
246 return connection->id();
247 } 244 }
248 245
249 ShellClientFactoryConnection* ApplicationManager::GetShellClientFactory( 246 mojom::ShellClientFactory* ApplicationManager::GetShellClientFactory(
250 const Identity& shell_client_factory_identity, 247 const Identity& shell_client_factory_identity,
251 const Identity& source_identity) { 248 const Identity& source_identity) {
252 auto it = identity_to_shell_client_factory_.find( 249 auto it = shell_client_factories_.find(shell_client_factory_identity);
253 shell_client_factory_identity); 250 if (it != shell_client_factories_.end())
254 if (it != identity_to_shell_client_factory_.end()) 251 return it->second.get();
255 return it->second;
256 252
257 ShellClientFactoryConnection* connection = new ShellClientFactoryConnection( 253 mojom::ShellClientFactoryPtr factory;
258 this, source_identity, 254 // TODO(beng): we should forward the original source identity!
259 shell_client_factory_identity, 255 ConnectToInterface(this, source_identity, shell_client_factory_identity.url(),
260 ++shell_client_factory_id_counter_, 256 &factory);
261 base::Bind(&ApplicationManager::OnShellClientFactoryConnectionClosed, 257 mojom::ShellClientFactory* factory_interface = factory.get();
262 weak_ptr_factory_.GetWeakPtr())); 258 factory.set_connection_error_handler(
263 identity_to_shell_client_factory_[shell_client_factory_identity] = connection; 259 base::Bind(&ApplicationManager::OnShellClientFactoryLost,
264 return connection; 260 weak_ptr_factory_.GetWeakPtr(),
261 shell_client_factory_identity));
262 shell_client_factories_[shell_client_factory_identity] = std::move(factory);
263 return factory_interface;
265 } 264 }
266 265
267 void ApplicationManager::OnShellClientFactoryConnectionClosed( 266 void ApplicationManager::OnShellClientFactoryLost(const Identity& which) {
268 ShellClientFactoryConnection* connection) {
269 // Remove the mapping. 267 // Remove the mapping.
270 auto it = identity_to_shell_client_factory_.find(connection->identity()); 268 auto it = shell_client_factories_.find(which);
271 DCHECK(it != identity_to_shell_client_factory_.end()); 269 DCHECK(it != shell_client_factories_.end());
272 identity_to_shell_client_factory_.erase(it); 270 shell_client_factories_.erase(it);
273 } 271 }
274 272
275 void ApplicationManager::OnGotResolvedURL( 273 void ApplicationManager::OnGotResolvedURL(
276 scoped_ptr<ConnectToApplicationParams> params, 274 scoped_ptr<ConnectToApplicationParams> params,
277 const String& resolved_url, 275 const String& resolved_url,
278 const String& file_url, 276 const String& file_url,
279 const String& application_name, 277 const String& application_name,
280 mojom::CapabilityFilterPtr base_filter) { 278 mojom::CapabilityFilterPtr base_filter) {
281 // It's possible that when this manifest request was issued, another one was 279 // It's possible that when this manifest request was issued, another one was
282 // already in-progress and completed by the time this one did, and so the 280 // already in-progress and completed by the time this one did, and so the
283 // requested application may already be running. 281 // requested application may already be running.
284 if (ConnectToRunningApplication(&params)) 282 if (ConnectToRunningApplication(&params))
285 return; 283 return;
286 284
287 GURL resolved_gurl = resolved_url.To<GURL>(); 285 GURL resolved_gurl = resolved_url.To<GURL>();
288 if (params->target().url().spec() != resolved_url) { 286 if (params->target().url().spec() != resolved_url) {
289 CapabilityFilter capability_filter = GetPermissiveCapabilityFilter(); 287 CapabilityFilter capability_filter = GetPermissiveCapabilityFilter();
290 if (!base_filter.is_null()) 288 if (!base_filter.is_null())
291 capability_filter = base_filter->filter.To<CapabilityFilter>(); 289 capability_filter = base_filter->filter.To<CapabilityFilter>();
292 290
293 // TODO(beng): For now, we just use the legacy PackageManagerImpl to manage 291 // TODO(beng): For now, we just use the legacy PackageManagerImpl to manage
294 // the ShellClientFactory connection. Once we get rid of the 292 // the ShellClientFactory connection. Once we get rid of the
295 // non-remote package manager path we will have to fold this in 293 // non-remote package manager path we will have to fold this in
296 // here. 294 // here.
297 Identity source, target; 295 Identity source, target;
298 mojom::ShellClientRequest request; 296 mojom::ShellClientRequest request;
299 ApplicationInstance* instance = CreateAndConnectToInstance( 297 ApplicationInstance* instance = CreateAndConnectToInstance(
300 std::move(params), &source, &target, application_name, &request); 298 std::move(params), &source, &target, application_name, &request);
301 299 CreateShellClient(source, Identity(resolved_gurl, target.qualifier(),
302 uint32_t shell_client_factory_id = StartShellClientFactory( 300 capability_filter), target.url(), std::move(request));
303 source, Identity(resolved_gurl, target.qualifier(), capability_filter),
304 target.url(), std::move(request));
305 CHECK(shell_client_factory_id != mojom::Shell::kInvalidApplicationID);
306 instance->set_requesting_shell_client_factory_id(shell_client_factory_id);
307 instance->RunConnectCallback(); 301 instance->RunConnectCallback();
308 return; 302 return;
309 } 303 }
310 CreateAndRunLocalApplication(std::move(params), application_name, 304 CreateAndRunLocalApplication(std::move(params), application_name,
311 file_url.To<GURL>()); 305 file_url.To<GURL>());
312 } 306 }
313 307
314 void ApplicationManager::CreateAndRunLocalApplication( 308 void ApplicationManager::CreateAndRunLocalApplication(
315 scoped_ptr<ConnectToApplicationParams> params, 309 scoped_ptr<ConnectToApplicationParams> params,
316 const String& application_name, 310 const String& application_name,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 395 }
402 } 396 }
403 } 397 }
404 398
405 mojom::Shell::ConnectToApplicationCallback EmptyConnectCallback() { 399 mojom::Shell::ConnectToApplicationCallback EmptyConnectCallback() {
406 return base::Bind(&OnEmptyOnConnectCallback); 400 return base::Bind(&OnEmptyOnConnectCallback);
407 } 401 }
408 402
409 } // namespace shell 403 } // namespace shell
410 } // namespace mojo 404 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager.h ('k') | mojo/shell/application_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698