Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/context.h" | 5 #include "shell/context.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/lazy_instance.h" | |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 18 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 19 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 20 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 21 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 22 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
| 23 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 24 #include "mojo/common/trace_provider_impl.h" | 23 #include "mojo/common/trace_provider_impl.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 46 #if !defined(OS_MACOSX) | 45 #if !defined(OS_MACOSX) |
| 47 #include "shell/url_response_disk_cache_loader.h" | 46 #include "shell/url_response_disk_cache_loader.h" |
| 48 #endif | 47 #endif |
| 49 | 48 |
| 50 using mojo::ServiceProvider; | 49 using mojo::ServiceProvider; |
| 51 using mojo::ServiceProviderPtr; | 50 using mojo::ServiceProviderPtr; |
| 52 | 51 |
| 53 namespace shell { | 52 namespace shell { |
| 54 namespace { | 53 namespace { |
| 55 | 54 |
| 56 // Used to ensure we only init once. | |
| 57 class Setup { | |
| 58 public: | |
| 59 Setup() { | |
| 60 mojo::embedder::Init(mojo::embedder::CreateSimplePlatformSupport()); | |
| 61 } | |
| 62 | |
| 63 ~Setup() {} | |
| 64 | |
| 65 private: | |
| 66 DISALLOW_COPY_AND_ASSIGN(Setup); | |
| 67 }; | |
| 68 | |
| 69 ApplicationManager::Options MakeApplicationManagerOptions() { | 55 ApplicationManager::Options MakeApplicationManagerOptions() { |
| 70 ApplicationManager::Options options; | 56 ApplicationManager::Options options; |
| 71 options.disable_cache = base::CommandLine::ForCurrentProcess()->HasSwitch( | 57 options.disable_cache = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 72 switches::kDisableCache); | 58 switches::kDisableCache); |
| 73 options.force_offline_by_default = | 59 options.force_offline_by_default = |
| 74 base::CommandLine::ForCurrentProcess()->HasSwitch( | 60 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 75 switches::kForceOfflineByDefault); | 61 switches::kForceOfflineByDefault); |
| 76 return options; | 62 return options; |
| 77 } | 63 } |
| 78 | 64 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 PathService::Get(base::DIR_CURRENT, &cwd); | 232 PathService::Get(base::DIR_CURRENT, &cwd); |
| 247 SetCommandLineCWD(cwd); | 233 SetCommandLineCWD(cwd); |
| 248 } | 234 } |
| 249 | 235 |
| 250 Context::~Context() { | 236 Context::~Context() { |
| 251 DCHECK(!base::MessageLoop::current()); | 237 DCHECK(!base::MessageLoop::current()); |
| 252 } | 238 } |
| 253 | 239 |
| 254 // static | 240 // static |
| 255 void Context::EnsureEmbedderIsInitialized() { | 241 void Context::EnsureEmbedderIsInitialized() { |
| 256 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; | 242 static bool initialized = ([]() { |
| 257 setup.Get(); | 243 mojo::embedder::Init(mojo::embedder::CreateSimplePlatformSupport()); |
| 244 return true; | |
| 245 })(); | |
| 246 std::ignore = initialized; | |
|
jamesr
2016/02/10 21:28:39
arguably this is too fancy, especially since it co
viettrungluu
2016/02/10 23:55:50
Should probably use MOJO_ALLOW_UNUSED_LOCAL from m
| |
| 258 } | 247 } |
| 259 | 248 |
| 260 void Context::SetShellFileRoot(const base::FilePath& path) { | 249 void Context::SetShellFileRoot(const base::FilePath& path) { |
| 261 shell_file_root_ = AddTrailingSlashIfNeeded(FilePathToFileURL(path)); | 250 shell_file_root_ = AddTrailingSlashIfNeeded(FilePathToFileURL(path)); |
| 262 } | 251 } |
| 263 | 252 |
| 264 GURL Context::ResolveShellFileURL(const std::string& path) { | 253 GURL Context::ResolveShellFileURL(const std::string& path) { |
| 265 return shell_file_root_.Resolve(path); | 254 return shell_file_root_.Resolve(path); |
| 266 } | 255 } |
| 267 | 256 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 if (app_urls_.find(url) != app_urls_.end()) { | 386 if (app_urls_.find(url) != app_urls_.end()) { |
| 398 app_urls_.erase(url); | 387 app_urls_.erase(url); |
| 399 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { | 388 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { |
| 400 DCHECK(task_runners_->shell_runner()->RunsTasksOnCurrentThread()); | 389 DCHECK(task_runners_->shell_runner()->RunsTasksOnCurrentThread()); |
| 401 base::MessageLoop::current()->Quit(); | 390 base::MessageLoop::current()->Quit(); |
| 402 } | 391 } |
| 403 } | 392 } |
| 404 } | 393 } |
| 405 | 394 |
| 406 } // namespace shell | 395 } // namespace shell |
| OLD | NEW |