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

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

Issue 1082513002: Revert of Simplify mojo_shell since it's now only used for Mandoline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase. Created 5 years, 8 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
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/application_manager.h" 5 #include "mojo/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 11 matching lines...) Expand all
22 #include "third_party/mojo_services/src/content_handler/public/interfaces/conten t_handler.mojom.h" 22 #include "third_party/mojo_services/src/content_handler/public/interfaces/conten t_handler.mojom.h"
23 23
24 namespace mojo { 24 namespace mojo {
25 namespace shell { 25 namespace shell {
26 26
27 namespace { 27 namespace {
28 28
29 // Used by TestAPI. 29 // Used by TestAPI.
30 bool has_created_instance = false; 30 bool has_created_instance = false;
31 31
32 std::vector<std::string> Concatenate(const std::vector<std::string>& v1,
33 const std::vector<std::string>& v2) {
34 if (!v1.size())
35 return v2;
36 if (!v2.size())
37 return v1;
38 std::vector<std::string> result(v1);
39 result.insert(result.end(), v1.begin(), v1.end());
40 return result;
41 }
42
32 } // namespace 43 } // namespace
33 44
34 ApplicationManager::Delegate::~Delegate() { 45 ApplicationManager::Delegate::~Delegate() {
35 } 46 }
36 47
37 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) { 48 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) {
38 return url; 49 return url;
39 } 50 }
40 51
41 GURL ApplicationManager::Delegate::ResolveMappings(const GURL& url) { 52 GURL ApplicationManager::Delegate::ResolveMappings(const GURL& url) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return; 147 return;
137 } 148 }
138 149
139 GURL resolved_url = delegate_->ResolveURL(mapped_url); 150 GURL resolved_url = delegate_->ResolveURL(mapped_url);
140 if (ConnectToRunningApplication(resolved_url, requestor_url, &services, 151 if (ConnectToRunningApplication(resolved_url, requestor_url, &services,
141 &exposed_services)) { 152 &exposed_services)) {
142 return; 153 return;
143 } 154 }
144 155
145 // The application is not running, let's compute the parameters. 156 // The application is not running, let's compute the parameters.
157 std::vector<std::string> parameters =
158 Concatenate(pre_redirect_parameters, GetArgsForURL(resolved_url));
159
146 if (ConnectToApplicationWithLoader(mapped_url, requestor_url, &services, 160 if (ConnectToApplicationWithLoader(mapped_url, requestor_url, &services,
147 &exposed_services, on_application_end, 161 &exposed_services, on_application_end,
148 pre_redirect_parameters, 162 parameters, GetLoaderForURL(mapped_url))) {
149 GetLoaderForURL(mapped_url))) { 163 return;
164 }
165
166 if (ConnectToApplicationWithLoader(
167 resolved_url, requestor_url, &services, &exposed_services,
168 on_application_end, parameters, GetLoaderForURL(resolved_url))) {
150 return; 169 return;
151 } 170 }
152 171
153 if (ConnectToApplicationWithLoader(resolved_url, requestor_url, &services, 172 if (ConnectToApplicationWithLoader(resolved_url, requestor_url, &services,
154 &exposed_services, on_application_end, 173 &exposed_services, on_application_end,
155 pre_redirect_parameters, 174 parameters, default_loader_.get())) {
156 GetLoaderForURL(resolved_url))) {
157 return; 175 return;
158 } 176 }
159 177
160 if (ConnectToApplicationWithLoader( 178 auto callback = base::Bind(
161 resolved_url, requestor_url, &services, &exposed_services, 179 &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(),
162 on_application_end, pre_redirect_parameters, default_loader_.get())) { 180 requestor_url, base::Passed(services.Pass()),
163 return; 181 base::Passed(exposed_services.Pass()), on_application_end,
164 } 182 parameters);
165
166 auto callback = base::Bind(&ApplicationManager::HandleFetchCallback,
167 weak_ptr_factory_.GetWeakPtr(), requestor_url,
168 base::Passed(services.Pass()),
169 base::Passed(exposed_services.Pass()),
170 on_application_end, pre_redirect_parameters);
171 183
172 if (resolved_url.SchemeIsFile()) { 184 if (resolved_url.SchemeIsFile()) {
173 new LocalFetcher( 185 new LocalFetcher(
174 resolved_url, GetBaseURLAndQuery(resolved_url, nullptr), 186 resolved_url, GetBaseURLAndQuery(resolved_url, nullptr),
175 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); 187 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE));
176 return; 188 return;
177 } 189 }
178 190
179 if (!network_service_) 191 if (!network_service_)
180 ConnectToService(GURL("mojo:network_service"), &network_service_); 192 ConnectToService(GURL("mojo:network_service"), &network_service_);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 368
357 TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path", 369 TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path",
358 path.AsUTF8Unsafe()); 370 path.AsUTF8Unsafe());
359 NativeRunner* runner = native_runner_factory_->Create(options).release(); 371 NativeRunner* runner = native_runner_factory_->Create(options).release();
360 native_runners_.push_back(runner); 372 native_runners_.push_back(runner);
361 runner->Start(path, cleanup, application_request.Pass(), 373 runner->Start(path, cleanup, application_request.Pass(),
362 base::Bind(&ApplicationManager::CleanupRunner, 374 base::Bind(&ApplicationManager::CleanupRunner,
363 weak_ptr_factory_.GetWeakPtr(), runner)); 375 weak_ptr_factory_.GetWeakPtr(), runner));
364 } 376 }
365 377
378 void ApplicationManager::RegisterExternalApplication(
379 const GURL& url,
380 const std::vector<std::string>& args,
381 ApplicationPtr application) {
382 const auto& args_it = url_to_args_.find(url);
383 if (args_it != url_to_args_.end()) {
384 LOG(WARNING) << "--args-for provided for external application " << url
385 << " <ignored>";
386 }
387 Identity identity(url);
388 ShellImpl* shell_impl =
389 new ShellImpl(application.Pass(), this, identity, base::Closure());
390 identity_to_shell_impl_[identity] = shell_impl;
391 shell_impl->InitializeApplication(Array<String>::From(args));
392 }
393
366 void ApplicationManager::RegisterContentHandler( 394 void ApplicationManager::RegisterContentHandler(
367 const std::string& mime_type, 395 const std::string& mime_type,
368 const GURL& content_handler_url) { 396 const GURL& content_handler_url) {
369 DCHECK(content_handler_url.is_valid()) 397 DCHECK(content_handler_url.is_valid())
370 << "Content handler URL is invalid for mime type " << mime_type; 398 << "Content handler URL is invalid for mime type " << mime_type;
371 mime_type_to_url_[mime_type] = content_handler_url; 399 mime_type_to_url_[mime_type] = content_handler_url;
372 } 400 }
373 401
374 void ApplicationManager::LoadWithContentHandler( 402 void ApplicationManager::LoadWithContentHandler(
375 const GURL& content_handler_url, 403 const GURL& content_handler_url,
(...skipping 23 matching lines...) Expand all
399 427
400 void ApplicationManager::SetLoaderForScheme( 428 void ApplicationManager::SetLoaderForScheme(
401 scoped_ptr<ApplicationLoader> loader, 429 scoped_ptr<ApplicationLoader> loader,
402 const std::string& scheme) { 430 const std::string& scheme) {
403 SchemeToLoaderMap::iterator it = scheme_to_loader_.find(scheme); 431 SchemeToLoaderMap::iterator it = scheme_to_loader_.find(scheme);
404 if (it != scheme_to_loader_.end()) 432 if (it != scheme_to_loader_.end())
405 delete it->second; 433 delete it->second;
406 scheme_to_loader_[scheme] = loader.release(); 434 scheme_to_loader_[scheme] = loader.release();
407 } 435 }
408 436
437 void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args,
438 const GURL& url) {
439 url_to_args_[url].insert(url_to_args_[url].end(), args.begin(), args.end());
440 GURL mapped_url = delegate_->ResolveMappings(url);
441 if (mapped_url != url) {
442 url_to_args_[mapped_url].insert(url_to_args_[mapped_url].end(),
443 args.begin(), args.end());
444 }
445 GURL resolved_url = delegate_->ResolveURL(mapped_url);
446 if (resolved_url != mapped_url) {
447 url_to_args_[resolved_url].insert(url_to_args_[resolved_url].end(),
448 args.begin(), args.end());
449 }
450 }
451
409 void ApplicationManager::SetNativeOptionsForURL( 452 void ApplicationManager::SetNativeOptionsForURL(
410 const NativeRunnerFactory::Options& options, 453 const NativeRunnerFactory::Options& options,
411 const GURL& url) { 454 const GURL& url) {
412 DCHECK(!url.has_query()); // Precondition. 455 DCHECK(!url.has_query()); // Precondition.
413 // Apply mappings and resolution to get the resolved URL. 456 // Apply mappings and resolution to get the resolved URL.
414 GURL resolved_url = delegate_->ResolveURL(delegate_->ResolveMappings(url)); 457 GURL resolved_url = delegate_->ResolveURL(delegate_->ResolveMappings(url));
415 DCHECK(!resolved_url.has_query()); // Still shouldn't have query. 458 DCHECK(!resolved_url.has_query()); // Still shouldn't have query.
416 // TODO(vtl): We should probably also remove/disregard the query string (and 459 // TODO(vtl): We should probably also remove/disregard the query string (and
417 // maybe canonicalize in other ways). 460 // maybe canonicalize in other ways).
418 DVLOG(2) << "Storing native options for resolved URL " << resolved_url 461 DVLOG(2) << "Storing native options for resolved URL " << resolved_url
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 const GURL& application_url, 500 const GURL& application_url,
458 const std::string& interface_name) { 501 const std::string& interface_name) {
459 ServiceProviderPtr services; 502 ServiceProviderPtr services;
460 ConnectToApplication(application_url, GURL(), GetProxy(&services), nullptr, 503 ConnectToApplication(application_url, GURL(), GetProxy(&services), nullptr,
461 base::Closure()); 504 base::Closure());
462 MessagePipe pipe; 505 MessagePipe pipe;
463 services->ConnectToService(interface_name, pipe.handle1.Pass()); 506 services->ConnectToService(interface_name, pipe.handle1.Pass());
464 return pipe.handle0.Pass(); 507 return pipe.handle0.Pass();
465 } 508 }
466 509
510 std::vector<std::string> ApplicationManager::GetArgsForURL(const GURL& url) {
511 const auto& args_it = url_to_args_.find(url);
512 if (args_it != url_to_args_.end())
513 return args_it->second;
514 return std::vector<std::string>();
515 }
516
467 void ApplicationManager::CleanupRunner(NativeRunner* runner) { 517 void ApplicationManager::CleanupRunner(NativeRunner* runner) {
468 native_runners_.erase( 518 native_runners_.erase(
469 std::find(native_runners_.begin(), native_runners_.end(), runner)); 519 std::find(native_runners_.begin(), native_runners_.end(), runner));
470 } 520 }
471 521
472 } // namespace shell 522 } // namespace shell
473 } // namespace mojo 523 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager/application_manager.h ('k') | mojo/shell/application_manager/application_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698