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 #include "mojo/shell/application_manager.h" | 5 #include "mojo/shell/application_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 return; | 283 return; |
284 } | 284 } |
285 | 285 |
286 const GURL app_url = | 286 const GURL app_url = |
287 requested_url.scheme() == "mojo" ? requested_url : fetcher->GetURL(); | 287 requested_url.scheme() == "mojo" ? requested_url : fetcher->GetURL(); |
288 | 288 |
289 InterfaceRequest<Application> request( | 289 InterfaceRequest<Application> request( |
290 RegisterShell(app_url, qualifier, requestor_url, services.Pass(), | 290 RegisterShell(app_url, qualifier, requestor_url, services.Pass(), |
291 exposed_services.Pass(), on_application_end)); | 291 exposed_services.Pass(), on_application_end)); |
292 | 292 |
293 // For resources that are loaded with content handlers, we group app instances | |
294 // by site. | |
295 | |
293 // If the response begins with a #!mojo <content-handler-url>, use it. | 296 // If the response begins with a #!mojo <content-handler-url>, use it. |
294 GURL content_handler_url; | 297 GURL content_handler_url; |
295 std::string shebang; | 298 std::string shebang; |
296 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { | 299 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { |
297 LoadWithContentHandler( | 300 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
298 content_handler_url, requestor_url, qualifier, request.Pass(), | 301 switches::kEnableMultiprocess)) { |
jam
2015/07/09 22:32:37
why should this behavior change with multiprocess?
| |
299 fetcher->AsURLResponse(blocking_pool_, | 302 if (!network_service_) |
300 static_cast<int>(shebang.size()))); | 303 ConnectToService(GURL("mojo:network_service"), &network_service_); |
304 network_service_->GetSiteForURL( | |
305 fetcher->GetURL().spec(), | |
306 base::Bind(&ApplicationManager::LoadWithContentHandler, | |
307 weak_ptr_factory_.GetWeakPtr(), | |
308 content_handler_url, | |
309 requestor_url, | |
310 base::Passed(request.Pass()), | |
311 base::Passed(fetcher->AsURLResponse(blocking_pool_, 0)))); | |
312 } else { | |
313 LoadWithContentHandler( | |
314 content_handler_url, requestor_url, | |
315 request.Pass(), | |
316 fetcher->AsURLResponse(blocking_pool_, | |
317 static_cast<int>(shebang.size())), | |
318 qualifier); | |
319 } | |
301 return; | 320 return; |
302 } | 321 } |
303 | 322 |
304 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); | 323 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); |
305 if (iter != mime_type_to_url_.end()) { | 324 if (iter != mime_type_to_url_.end()) { |
306 LoadWithContentHandler(iter->second, requestor_url, qualifier, | 325 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
307 request.Pass(), | 326 switches::kEnableMultiprocess)) { |
308 fetcher->AsURLResponse(blocking_pool_, 0)); | 327 if (!network_service_) |
328 ConnectToService(GURL("mojo:network_service"), &network_service_); | |
329 network_service_->GetSiteForURL( | |
330 fetcher->GetURL().spec(), | |
331 base::Bind(&ApplicationManager::LoadWithContentHandler, | |
332 weak_ptr_factory_.GetWeakPtr(), | |
333 iter->second, | |
334 requestor_url, | |
335 base::Passed(request.Pass()), | |
336 base::Passed(fetcher->AsURLResponse(blocking_pool_, 0)))); | |
337 } else { | |
338 LoadWithContentHandler( | |
339 iter->second, requestor_url, | |
340 request.Pass(), | |
341 fetcher->AsURLResponse(blocking_pool_, | |
342 static_cast<int>(shebang.size())), | |
343 qualifier); | |
344 } | |
309 return; | 345 return; |
310 } | 346 } |
311 | 347 |
312 auto alias_iter = application_package_alias_.find(app_url); | 348 auto alias_iter = application_package_alias_.find(app_url); |
313 if (alias_iter != application_package_alias_.end()) { | 349 if (alias_iter != application_package_alias_.end()) { |
314 // We replace the qualifier with the one our package alias requested. | 350 // We replace the qualifier with the one our package alias requested. |
315 URLResponsePtr response(URLResponse::New()); | 351 URLResponsePtr response(URLResponse::New()); |
316 response->url = String::From(app_url.spec()); | 352 response->url = String::From(app_url.spec()); |
317 | 353 |
318 std::string qualifier; | 354 std::string qualifier; |
319 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 355 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
320 switches::kEnableMultiprocess)) { | 356 switches::kEnableMultiprocess)) { |
321 // Why can't we use this in single process mode? Because of | 357 // Why can't we use this in single process mode? Because of |
322 // base::AtExitManager. If you link in ApplicationRunner into | 358 // base::AtExitManager. If you link in ApplicationRunner into |
323 // your code, and then we make initialize multiple copies of the | 359 // your code, and then we make initialize multiple copies of the |
324 // application, we end up with multiple AtExitManagers and will check on | 360 // application, we end up with multiple AtExitManagers and will check on |
325 // the second one being created. | 361 // the second one being created. |
326 // | 362 // |
327 // Why doesn't that happen when running different apps? Because | 363 // Why doesn't that happen when running different apps? Because |
328 // your_thing.mojo!base::AtExitManager and | 364 // your_thing.mojo!base::AtExitManager and |
329 // my_thing.mojo!base::AtExitManager are different symbols. | 365 // my_thing.mojo!base::AtExitManager are different symbols. |
330 qualifier = alias_iter->second.second; | 366 qualifier = alias_iter->second.second; |
331 } | 367 } |
332 | 368 |
333 LoadWithContentHandler(alias_iter->second.first, requestor_url, qualifier, | 369 LoadWithContentHandler(alias_iter->second.first, requestor_url, |
334 request.Pass(), response.Pass()); | 370 request.Pass(), response.Pass(), qualifier); |
335 return; | 371 return; |
336 } | 372 } |
337 | 373 |
338 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo | 374 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo |
339 // application. That could either mean looking for the platform-specific dll | 375 // application. That could either mean looking for the platform-specific dll |
340 // header, or looking for some specific mojo signature prepended to the | 376 // header, or looking for some specific mojo signature prepended to the |
341 // library. | 377 // library. |
342 // TODO(vtl): (Maybe this should be done by the factory/runner?) | 378 // TODO(vtl): (Maybe this should be done by the factory/runner?) |
343 | 379 |
344 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); | 380 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
396 const GURL& alias, | 432 const GURL& alias, |
397 const GURL& content_handler_package, | 433 const GURL& content_handler_package, |
398 const std::string& qualifier) { | 434 const std::string& qualifier) { |
399 application_package_alias_[alias] = | 435 application_package_alias_[alias] = |
400 std::make_pair(content_handler_package, qualifier); | 436 std::make_pair(content_handler_package, qualifier); |
401 } | 437 } |
402 | 438 |
403 void ApplicationManager::LoadWithContentHandler( | 439 void ApplicationManager::LoadWithContentHandler( |
404 const GURL& content_handler_url, | 440 const GURL& content_handler_url, |
405 const GURL& requestor_url, | 441 const GURL& requestor_url, |
406 const std::string& qualifier, | |
407 InterfaceRequest<Application> application_request, | 442 InterfaceRequest<Application> application_request, |
408 URLResponsePtr url_response) { | 443 URLResponsePtr url_response, |
444 const std::string& qualifier) { | |
409 ContentHandlerConnection* connection = nullptr; | 445 ContentHandlerConnection* connection = nullptr; |
410 std::pair<GURL, std::string> key(content_handler_url, qualifier); | 446 std::pair<GURL, std::string> key(content_handler_url, qualifier); |
411 URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key); | 447 URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key); |
412 if (iter != url_to_content_handler_.end()) { | 448 if (iter != url_to_content_handler_.end()) { |
413 connection = iter->second; | 449 connection = iter->second; |
414 } else { | 450 } else { |
415 connection = new ContentHandlerConnection(this, content_handler_url, | 451 connection = new ContentHandlerConnection(this, content_handler_url, |
416 requestor_url, qualifier); | 452 requestor_url, qualifier); |
417 url_to_content_handler_[key] = connection; | 453 url_to_content_handler_[key] = connection; |
418 } | 454 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 return pipe.handle0.Pass(); | 535 return pipe.handle0.Pass(); |
500 } | 536 } |
501 | 537 |
502 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 538 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
503 native_runners_.erase( | 539 native_runners_.erase( |
504 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 540 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
505 } | 541 } |
506 | 542 |
507 } // namespace shell | 543 } // namespace shell |
508 } // namespace mojo | 544 } // namespace mojo |
OLD | NEW |