| 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 "mojo/runner/context.h" | 5 #include "mojo/runner/context.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/process/process_info.h" | 16 #include "base/process/process_info.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "components/devtools_service/public/cpp/switches.h" | 23 #include "components/devtools_service/public/cpp/switches.h" |
| 24 #include "components/devtools_service/public/interfaces/devtools_service.mojom.h
" | 24 #include "components/devtools_service/public/interfaces/devtools_service.mojom.h
" |
| 25 #include "mojo/application/public/cpp/application_connection.h" | 25 #include "mojo/application/public/cpp/application_connection.h" |
| 26 #include "mojo/application/public/cpp/application_delegate.h" | 26 #include "mojo/application/public/cpp/application_delegate.h" |
| 27 #include "mojo/application/public/cpp/application_impl.h" | 27 #include "mojo/application/public/cpp/application_impl.h" |
| 28 #include "mojo/common/trace_controller_impl.h" | 28 #include "mojo/common/trace_controller_impl.h" |
| 29 #include "mojo/common/tracing_impl.h" | 29 #include "mojo/common/tracing_impl.h" |
| 30 #include "mojo/edk/embedder/embedder.h" | |
| 31 #include "mojo/edk/embedder/simple_platform_support.h" | |
| 32 #include "mojo/package_manager/package_manager_impl.h" | 30 #include "mojo/package_manager/package_manager_impl.h" |
| 33 #include "mojo/runner/in_process_native_runner.h" | 31 #include "mojo/runner/in_process_native_runner.h" |
| 34 #include "mojo/runner/out_of_process_native_runner.h" | 32 #include "mojo/runner/out_of_process_native_runner.h" |
| 35 #include "mojo/runner/switches.h" | 33 #include "mojo/runner/switches.h" |
| 36 #include "mojo/services/tracing/public/cpp/switches.h" | 34 #include "mojo/services/tracing/public/cpp/switches.h" |
| 37 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" | 35 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" |
| 38 #include "mojo/shell/application_loader.h" | 36 #include "mojo/shell/application_loader.h" |
| 39 #include "mojo/shell/connect_to_application_params.h" | 37 #include "mojo/shell/connect_to_application_params.h" |
| 40 #include "mojo/shell/query_util.h" | 38 #include "mojo/shell/query_util.h" |
| 41 #include "mojo/shell/switches.h" | 39 #include "mojo/shell/switches.h" |
| 42 #include "mojo/util/filename_util.h" | 40 #include "mojo/util/filename_util.h" |
| 43 #include "url/gurl.h" | 41 #include "url/gurl.h" |
| 44 | 42 |
| 43 #if defined(USE_CHROME_EDK) |
| 44 #include "mojo/edk/embedder/embedder.h" |
| 45 #include "mojo/edk/embedder/simple_platform_support.h" |
| 46 #else |
| 47 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
| 48 #include "third_party/mojo/src/mojo/edk/embedder/simple_platform_support.h" |
| 49 #endif |
| 50 |
| 45 namespace mojo { | 51 namespace mojo { |
| 46 namespace runner { | 52 namespace runner { |
| 47 namespace { | 53 namespace { |
| 48 | 54 |
| 49 // Used to ensure we only init once. | 55 // Used to ensure we only init once. |
| 50 class Setup { | 56 class Setup { |
| 51 public: | 57 public: |
| 52 Setup() { | 58 Setup() { |
| 59 #if defined(USE_CHROME_EDK) |
| 60 edk::Init(make_scoped_ptr(new edk::SimplePlatformSupport())); |
| 61 #else |
| 53 embedder::Init(make_scoped_ptr(new embedder::SimplePlatformSupport())); | 62 embedder::Init(make_scoped_ptr(new embedder::SimplePlatformSupport())); |
| 63 #endif |
| 54 } | 64 } |
| 55 | 65 |
| 56 ~Setup() {} | 66 ~Setup() {} |
| 57 | 67 |
| 58 private: | 68 private: |
| 59 DISALLOW_COPY_AND_ASSIGN(Setup); | 69 DISALLOW_COPY_AND_ASSIGN(Setup); |
| 60 }; | 70 }; |
| 61 | 71 |
| 62 void InitContentHandlers(package_manager::PackageManagerImpl* manager, | 72 void InitContentHandlers(package_manager::PackageManagerImpl* manager, |
| 63 const base::CommandLine& command_line) { | 73 const base::CommandLine& command_line) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 188 |
| 179 bool Context::Init() { | 189 bool Context::Init() { |
| 180 TRACE_EVENT0("mojo_shell", "Context::Init"); | 190 TRACE_EVENT0("mojo_shell", "Context::Init"); |
| 181 const base::CommandLine& command_line = | 191 const base::CommandLine& command_line = |
| 182 *base::CommandLine::ForCurrentProcess(); | 192 *base::CommandLine::ForCurrentProcess(); |
| 183 | 193 |
| 184 EnsureEmbedderIsInitialized(); | 194 EnsureEmbedderIsInitialized(); |
| 185 task_runners_.reset( | 195 task_runners_.reset( |
| 186 new TaskRunners(base::MessageLoop::current()->task_runner())); | 196 new TaskRunners(base::MessageLoop::current()->task_runner())); |
| 187 | 197 |
| 198 #if defined(USE_CHROME_EDK) |
| 199 edk::InitIPCSupport( |
| 200 task_runners_->shell_runner(), this, task_runners_->io_runner(), |
| 201 edk::ScopedPlatformHandle()); |
| 202 #else |
| 188 // TODO(vtl): This should be MASTER, not NONE. | 203 // TODO(vtl): This should be MASTER, not NONE. |
| 189 embedder::InitIPCSupport( | 204 embedder::InitIPCSupport( |
| 190 embedder::ProcessType::NONE, task_runners_->shell_runner(), this, | 205 embedder::ProcessType::NONE, task_runners_->shell_runner(), this, |
| 191 task_runners_->io_runner(), embedder::ScopedPlatformHandle()); | 206 task_runners_->io_runner(), embedder::ScopedPlatformHandle()); |
| 207 #endif |
| 192 | 208 |
| 193 package_manager_ = new package_manager::PackageManagerImpl(shell_file_root_); | 209 package_manager_ = new package_manager::PackageManagerImpl(shell_file_root_); |
| 194 InitContentHandlers(package_manager_, command_line); | 210 InitContentHandlers(package_manager_, command_line); |
| 195 | 211 |
| 196 application_manager_.reset( | 212 application_manager_.reset( |
| 197 new shell::ApplicationManager(make_scoped_ptr(package_manager_))); | 213 new shell::ApplicationManager(make_scoped_ptr(package_manager_))); |
| 198 | 214 |
| 199 scoped_ptr<shell::NativeRunnerFactory> runner_factory; | 215 scoped_ptr<shell::NativeRunnerFactory> runner_factory; |
| 200 if (command_line.HasSwitch(switches::kEnableMultiprocess)) | 216 if (command_line.HasSwitch(switches::kEnableMultiprocess)) |
| 201 runner_factory.reset(new OutOfProcessNativeRunnerFactory(this)); | 217 runner_factory.reset(new OutOfProcessNativeRunnerFactory(this)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 253 |
| 238 void Context::Shutdown() { | 254 void Context::Shutdown() { |
| 239 // Actions triggered by ApplicationManager's destructor may require a current | 255 // Actions triggered by ApplicationManager's destructor may require a current |
| 240 // message loop, so we should destruct it explicitly now as ~Context() occurs | 256 // message loop, so we should destruct it explicitly now as ~Context() occurs |
| 241 // post message loop shutdown. | 257 // post message loop shutdown. |
| 242 application_manager_.reset(); | 258 application_manager_.reset(); |
| 243 | 259 |
| 244 TRACE_EVENT0("mojo_shell", "Context::Shutdown"); | 260 TRACE_EVENT0("mojo_shell", "Context::Shutdown"); |
| 245 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 261 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
| 246 task_runners_->shell_runner()); | 262 task_runners_->shell_runner()); |
| 263 #if defined(USE_CHROME_EDK) |
| 264 edk::ShutdownIPCSupport(); |
| 265 #else |
| 247 embedder::ShutdownIPCSupport(); | 266 embedder::ShutdownIPCSupport(); |
| 267 #endif |
| 248 // We'll quit when we get OnShutdownComplete(). | 268 // We'll quit when we get OnShutdownComplete(). |
| 249 base::MessageLoop::current()->Run(); | 269 base::MessageLoop::current()->Run(); |
| 250 } | 270 } |
| 251 | 271 |
| 252 void Context::OnShutdownComplete() { | 272 void Context::OnShutdownComplete() { |
| 253 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 273 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
| 254 task_runners_->shell_runner()); | 274 task_runners_->shell_runner()); |
| 255 base::MessageLoop::current()->Quit(); | 275 base::MessageLoop::current()->Quit(); |
| 256 } | 276 } |
| 257 | 277 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 base::MessageLoop::current()->Quit(); | 315 base::MessageLoop::current()->Quit(); |
| 296 } else { | 316 } else { |
| 297 app_complete_callback_.Run(); | 317 app_complete_callback_.Run(); |
| 298 } | 318 } |
| 299 } | 319 } |
| 300 } | 320 } |
| 301 } | 321 } |
| 302 | 322 |
| 303 } // namespace runner | 323 } // namespace runner |
| 304 } // namespace mojo | 324 } // namespace mojo |
| OLD | NEW |