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

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

Issue 974403002: Add --force-in-process flag to shell. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: amend comment Created 5 years, 9 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 | « shell/application_manager/application_manager.h ('k') | shell/context.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 "shell/application_manager/application_manager.h" 5 #include "shell/application_manager/application_manager.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "mojo/public/cpp/bindings/binding.h" 15 #include "mojo/public/cpp/bindings/binding.h"
16 #include "mojo/public/cpp/bindings/error_handler.h" 16 #include "mojo/public/cpp/bindings/error_handler.h"
17 #include "mojo/public/interfaces/application/shell.mojom.h" 17 #include "mojo/public/interfaces/application/shell.mojom.h"
18 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom. h" 18 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom. h"
19 #include "shell/application_manager/fetcher.h" 19 #include "shell/application_manager/fetcher.h"
20 #include "shell/application_manager/local_fetcher.h" 20 #include "shell/application_manager/local_fetcher.h"
21 #include "shell/application_manager/network_fetcher.h" 21 #include "shell/application_manager/network_fetcher.h"
22 22
23 namespace mojo { 23 namespace mojo {
24 24
25 namespace { 25 namespace {
26
26 // Used by TestAPI. 27 // Used by TestAPI.
27 bool has_created_instance = false; 28 bool has_created_instance = false;
28 29
29 GURL StripQueryFromURL(const GURL& url) { 30 GURL StripQueryFromURL(const GURL& url) {
30 GURL::Replacements repl; 31 GURL::Replacements repl;
31 repl.SetQueryStr(""); 32 repl.SetQueryStr("");
32 std::string result = url.ReplaceComponents(repl).spec(); 33 std::string result = url.ReplaceComponents(repl).spec();
33 34
34 // Remove the dangling '?' because it's ugly. 35 // Remove the dangling '?' because it's ugly.
35 base::ReplaceChars(result, "?", "", &result); 36 base::ReplaceChars(result, "?", "", &result);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 if (iter != mime_type_to_url_.end()) { 290 if (iter != mime_type_to_url_.end()) {
290 LoadWithContentHandler(iter->second, request.Pass(), 291 LoadWithContentHandler(iter->second, request.Pass(),
291 fetcher->AsURLResponse(blocking_pool_, 0)); 292 fetcher->AsURLResponse(blocking_pool_, 0));
292 return; 293 return;
293 } 294 }
294 295
295 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo 296 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo
296 // application. That could either mean looking for the platform-specific dll 297 // application. That could either mean looking for the platform-specific dll
297 // header, or looking for some specific mojo signature prepended to the 298 // header, or looking for some specific mojo signature prepended to the
298 // library. 299 // library.
300 // TODO(vtl): (Maybe this should be done by the factory/runner?)
301
302 NativeRunnerFactory::Options options;
303 if (url_to_native_options_.find(fetcher->GetURL()) !=
qsr 2015/03/05 14:47:52 As you put it in the comment in SetNativeOptionsFo
viettrungluu 2015/03/05 18:30:10 That's easier now that you've landed your change.
304 url_to_native_options_.end()) {
305 DVLOG(2) << "Applying stored native options to resolved URL "
306 << fetcher->GetURL() << " (requested URL " << requested_url << ")";
307 options = url_to_native_options_[fetcher->GetURL()];
308 }
299 309
300 fetcher->AsPath( 310 fetcher->AsPath(
301 blocking_pool_, 311 blocking_pool_,
302 base::Bind(&ApplicationManager::RunNativeApplication, 312 base::Bind(&ApplicationManager::RunNativeApplication,
303 weak_ptr_factory_.GetWeakPtr(), base::Passed(request.Pass()), 313 weak_ptr_factory_.GetWeakPtr(), base::Passed(request.Pass()),
304 cleanup_behavior, base::Passed(fetcher.Pass()))); 314 options, cleanup_behavior, base::Passed(fetcher.Pass())));
305 } 315 }
306 316
307 void ApplicationManager::RunNativeApplication( 317 void ApplicationManager::RunNativeApplication(
308 InterfaceRequest<Application> application_request, 318 InterfaceRequest<Application> application_request,
319 const NativeRunnerFactory::Options& options,
309 NativeRunner::CleanupBehavior cleanup_behavior, 320 NativeRunner::CleanupBehavior cleanup_behavior,
310 scoped_ptr<Fetcher> fetcher, 321 scoped_ptr<Fetcher> fetcher,
311 const base::FilePath& path, 322 const base::FilePath& path,
312 bool path_exists) { 323 bool path_exists) {
313 // We only passed fetcher to keep it alive. Done with it now. 324 // We only passed fetcher to keep it alive. Done with it now.
314 fetcher.reset(); 325 fetcher.reset();
315 326
316 DCHECK(application_request.is_pending()); 327 DCHECK(application_request.is_pending());
317 328
318 if (!path_exists) { 329 if (!path_exists) {
319 LOG(ERROR) << "Library not started because library path '" << path.value() 330 LOG(ERROR) << "Library not started because library path '" << path.value()
320 << "' does not exist."; 331 << "' does not exist.";
321 return; 332 return;
322 } 333 }
323 334
324 NativeRunner* runner = native_runner_factory_->Create().release(); 335 NativeRunner* runner = native_runner_factory_->Create(options).release();
325 native_runners_.push_back(runner); 336 native_runners_.push_back(runner);
326 runner->Start(path, cleanup_behavior, application_request.Pass(), 337 runner->Start(path, cleanup_behavior, application_request.Pass(),
327 base::Bind(&ApplicationManager::CleanupRunner, 338 base::Bind(&ApplicationManager::CleanupRunner,
328 weak_ptr_factory_.GetWeakPtr(), runner)); 339 weak_ptr_factory_.GetWeakPtr(), runner));
329 } 340 }
330 341
331 void ApplicationManager::RegisterExternalApplication( 342 void ApplicationManager::RegisterExternalApplication(
332 const GURL& url, 343 const GURL& url,
333 const std::vector<std::string>& args, 344 const std::vector<std::string>& args,
334 ApplicationPtr application) { 345 ApplicationPtr application) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 if (it != scheme_to_loader_.end()) 394 if (it != scheme_to_loader_.end())
384 delete it->second; 395 delete it->second;
385 scheme_to_loader_[scheme] = loader.release(); 396 scheme_to_loader_[scheme] = loader.release();
386 } 397 }
387 398
388 void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args, 399 void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args,
389 const GURL& url) { 400 const GURL& url) {
390 url_to_args_[url] = args; 401 url_to_args_[url] = args;
391 } 402 }
392 403
404 void ApplicationManager::SetNativeOptionsForURL(
405 const NativeRunnerFactory::Options& options,
406 const GURL& url) {
407 // Apply mappings and resolution to get the resolved URL.
408 GURL resolved_url = delegate_->ResolveURL(delegate_->ResolveMappings(url));
409 // TODO(vtl): We should probably also remove/disregard the query string (and
410 // maybe canonicalize in other ways).
411 DVLOG(2) << "Storing native options for resolved URL " << resolved_url
412 << " (original URL " << url << ")";
413 url_to_native_options_[resolved_url] = options;
414 }
415
393 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) { 416 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) {
394 auto url_it = url_to_loader_.find(StripQueryFromURL(url)); 417 auto url_it = url_to_loader_.find(StripQueryFromURL(url));
395 if (url_it != url_to_loader_.end()) 418 if (url_it != url_to_loader_.end())
396 return url_it->second; 419 return url_it->second;
397 auto scheme_it = scheme_to_loader_.find(url.scheme()); 420 auto scheme_it = scheme_to_loader_.find(url.scheme());
398 if (scheme_it != scheme_to_loader_.end()) 421 if (scheme_it != scheme_to_loader_.end())
399 return scheme_it->second; 422 return scheme_it->second;
400 return NULL; 423 return NULL;
401 } 424 }
402 425
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 return Array<String>::From(args_it->second); 461 return Array<String>::From(args_it->second);
439 return Array<String>(); 462 return Array<String>();
440 } 463 }
441 464
442 void ApplicationManager::CleanupRunner(NativeRunner* runner) { 465 void ApplicationManager::CleanupRunner(NativeRunner* runner) {
443 native_runners_.erase( 466 native_runners_.erase(
444 std::find(native_runners_.begin(), native_runners_.end(), runner)); 467 std::find(native_runners_.begin(), native_runners_.end(), runner));
445 } 468 }
446 469
447 } // namespace mojo 470 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/application_manager/application_manager.h ('k') | shell/context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698