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 "shell/application_manager/application_manager.h" | 5 #include "shell/application_manager/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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 return; | 345 return; |
346 } | 346 } |
347 | 347 |
348 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo | 348 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo |
349 // application. That could either mean looking for the platform-specific dll | 349 // application. That could either mean looking for the platform-specific dll |
350 // header, or looking for some specific mojo signature prepended to the | 350 // header, or looking for some specific mojo signature prepended to the |
351 // library. | 351 // library. |
352 // TODO(vtl): (Maybe this should be done by the factory/runner?) | 352 // TODO(vtl): (Maybe this should be done by the factory/runner?) |
353 | 353 |
354 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); | 354 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); |
355 NativeRunnerFactory::Options options; | 355 NativeApplicationOptions options; |
356 if (url_to_native_options_.find(base_resolved_url) != | 356 if (url_to_native_options_.find(base_resolved_url) != |
357 url_to_native_options_.end()) { | 357 url_to_native_options_.end()) { |
358 DVLOG(2) << "Applying stored native options to resolved URL " | 358 DVLOG(2) << "Applying stored native options to resolved URL " |
359 << fetcher->GetURL(); | 359 << fetcher->GetURL(); |
360 options = url_to_native_options_[base_resolved_url]; | 360 options = url_to_native_options_[base_resolved_url]; |
361 } | 361 } |
362 | 362 |
363 TRACE_EVENT_ASYNC_BEGIN1("mojo_shell", "ApplicationManager::RetrievePath", | 363 TRACE_EVENT_ASYNC_BEGIN1("mojo_shell", "ApplicationManager::RetrievePath", |
364 fetcher.get(), "url", fetcher->GetURL().spec()); | 364 fetcher.get(), "url", fetcher->GetURL().spec()); |
365 fetcher->AsPath( | 365 fetcher->AsPath( |
366 blocking_pool_, | 366 blocking_pool_, |
367 base::Bind(&ApplicationManager::RunNativeApplication, | 367 base::Bind(&ApplicationManager::RunNativeApplication, |
368 weak_ptr_factory_.GetWeakPtr(), base::Passed(request.Pass()), | 368 weak_ptr_factory_.GetWeakPtr(), base::Passed(request.Pass()), |
369 options, base::Passed(fetcher.Pass()))); | 369 options, base::Passed(fetcher.Pass()))); |
370 } | 370 } |
371 | 371 |
372 void ApplicationManager::RunNativeApplication( | 372 void ApplicationManager::RunNativeApplication( |
373 InterfaceRequest<Application> application_request, | 373 InterfaceRequest<Application> application_request, |
374 const NativeRunnerFactory::Options& options, | 374 const NativeApplicationOptions& options, |
375 scoped_ptr<Fetcher> fetcher, | 375 scoped_ptr<Fetcher> fetcher, |
376 const base::FilePath& path, | 376 const base::FilePath& path, |
377 bool path_exists) { | 377 bool path_exists) { |
378 TRACE_EVENT_ASYNC_END0("mojo_shell", "ApplicationManager::RetrievePath", | 378 TRACE_EVENT_ASYNC_END0("mojo_shell", "ApplicationManager::RetrievePath", |
379 fetcher.get()); | 379 fetcher.get()); |
380 // We only passed fetcher to keep it alive. Done with it now. | 380 // We only passed fetcher to keep it alive. Done with it now. |
381 fetcher.reset(); | 381 fetcher.reset(); |
382 | 382 |
383 DCHECK(application_request.is_pending()); | 383 DCHECK(application_request.is_pending()); |
384 | 384 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 url_to_args_[mapped_url].insert(url_to_args_[mapped_url].end(), | 441 url_to_args_[mapped_url].insert(url_to_args_[mapped_url].end(), |
442 args.begin(), args.end()); | 442 args.begin(), args.end()); |
443 } | 443 } |
444 GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); | 444 GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); |
445 if (resolved_url != mapped_url) { | 445 if (resolved_url != mapped_url) { |
446 url_to_args_[resolved_url].insert(url_to_args_[resolved_url].end(), | 446 url_to_args_[resolved_url].insert(url_to_args_[resolved_url].end(), |
447 args.begin(), args.end()); | 447 args.begin(), args.end()); |
448 } | 448 } |
449 } | 449 } |
450 | 450 |
451 void ApplicationManager::SetNativeOptionsForURL( | 451 NativeApplicationOptions* ApplicationManager::GetNativeApplicationOptionsForURL( |
452 const NativeRunnerFactory::Options& options, | |
453 const GURL& url) { | 452 const GURL& url) { |
454 DCHECK(!url.has_query()); // Precondition. | 453 DCHECK(!url.has_query()); // Precondition. |
455 // Apply mappings and resolution to get the resolved URL. | 454 // Apply mappings and resolution to get the resolved URL. |
456 GURL resolved_url = | 455 GURL resolved_url = |
457 delegate_->ResolveMojoURL(delegate_->ResolveMappings(url)); | 456 delegate_->ResolveMojoURL(delegate_->ResolveMappings(url)); |
458 DCHECK(!resolved_url.has_query()); // Still shouldn't have query. | |
459 // TODO(vtl): We should probably also remove/disregard the query string (and | 457 // TODO(vtl): We should probably also remove/disregard the query string (and |
460 // maybe canonicalize in other ways). | 458 // maybe canonicalize in other ways). |
461 DVLOG(2) << "Storing native options for resolved URL " << resolved_url | 459 DCHECK(!resolved_url.has_query()); // Still shouldn't have query. |
462 << " (original URL " << url << ")"; | 460 return &url_to_native_options_[resolved_url]; |
463 url_to_native_options_[resolved_url] = options; | |
464 } | 461 } |
465 | 462 |
466 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) { | 463 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) { |
467 auto url_it = url_to_loader_.find(GetBaseURLAndQuery(url, nullptr)); | 464 auto url_it = url_to_loader_.find(GetBaseURLAndQuery(url, nullptr)); |
468 if (url_it != url_to_loader_.end()) | 465 if (url_it != url_to_loader_.end()) |
469 return url_it->second.get(); | 466 return url_it->second.get(); |
470 auto scheme_it = scheme_to_loader_.find(url.scheme()); | 467 auto scheme_it = scheme_to_loader_.find(url.scheme()); |
471 if (scheme_it != scheme_to_loader_.end()) | 468 if (scheme_it != scheme_to_loader_.end()) |
472 return scheme_it->second.get(); | 469 return scheme_it->second.get(); |
473 return nullptr; | 470 return nullptr; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 return args_it->second; | 508 return args_it->second; |
512 return std::vector<std::string>(); | 509 return std::vector<std::string>(); |
513 } | 510 } |
514 | 511 |
515 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 512 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
516 native_runners_.erase( | 513 native_runners_.erase( |
517 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 514 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
518 } | 515 } |
519 | 516 |
520 } // namespace shell | 517 } // namespace shell |
OLD | NEW |