| 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/shell/standalone/context.h" | 5 #include "mojo/shell/standalone/context.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 20 #include "base/process/process_info.h" | 20 #include "base/process/process_info.h" |
| 21 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
| 22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/string_split.h" | 23 #include "base/strings/string_split.h" |
| 24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 25 #include "base/trace_event/trace_event.h" | 25 #include "base/trace_event/trace_event.h" |
| 26 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 27 #include "components/tracing/tracing_switches.h" | 27 #include "components/tracing/tracing_switches.h" |
| 28 #include "mojo/edk/embedder/embedder.h" |
| 28 #include "mojo/public/cpp/bindings/strong_binding.h" | 29 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 29 #include "mojo/services/tracing/public/cpp/switches.h" | 30 #include "mojo/services/tracing/public/cpp/switches.h" |
| 30 #include "mojo/services/tracing/public/cpp/trace_provider_impl.h" | 31 #include "mojo/services/tracing/public/cpp/trace_provider_impl.h" |
| 31 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | 32 #include "mojo/services/tracing/public/cpp/tracing_impl.h" |
| 32 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" | 33 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" |
| 33 #include "mojo/shell/application_loader.h" | 34 #include "mojo/shell/application_loader.h" |
| 34 #include "mojo/shell/connect_to_application_params.h" | 35 #include "mojo/shell/connect_to_application_params.h" |
| 35 #include "mojo/shell/package_manager/package_manager_impl.h" | 36 #include "mojo/shell/package_manager/package_manager_impl.h" |
| 36 #include "mojo/shell/query_util.h" | 37 #include "mojo/shell/query_util.h" |
| 37 #include "mojo/shell/runner/host/in_process_native_runner.h" | 38 #include "mojo/shell/runner/host/in_process_native_runner.h" |
| 38 #include "mojo/shell/runner/host/out_of_process_native_runner.h" | 39 #include "mojo/shell/runner/host/out_of_process_native_runner.h" |
| 39 #include "mojo/shell/standalone/register_local_aliases.h" | 40 #include "mojo/shell/standalone/register_local_aliases.h" |
| 40 #include "mojo/shell/standalone/switches.h" | 41 #include "mojo/shell/standalone/switches.h" |
| 41 #include "mojo/shell/standalone/tracer.h" | 42 #include "mojo/shell/standalone/tracer.h" |
| 42 #include "mojo/shell/switches.h" | 43 #include "mojo/shell/switches.h" |
| 43 #include "mojo/util/filename_util.h" | 44 #include "mojo/util/filename_util.h" |
| 44 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | |
| 45 #include "url/gurl.h" | 45 #include "url/gurl.h" |
| 46 | 46 |
| 47 namespace mojo { | 47 namespace mojo { |
| 48 namespace shell { | 48 namespace shell { |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 // Used to ensure we only init once. | 51 // Used to ensure we only init once. |
| 52 class Setup { | 52 class Setup { |
| 53 public: | 53 public: |
| 54 Setup() { | 54 Setup() { edk::Init(); } |
| 55 embedder::PreInitializeParentProcess(); | |
| 56 embedder::Init(); | |
| 57 } | |
| 58 | 55 |
| 59 ~Setup() {} | 56 ~Setup() {} |
| 60 | 57 |
| 61 private: | 58 private: |
| 62 DISALLOW_COPY_AND_ASSIGN(Setup); | 59 DISALLOW_COPY_AND_ASSIGN(Setup); |
| 63 }; | 60 }; |
| 64 | 61 |
| 65 void InitContentHandlers(PackageManagerImpl* manager, | 62 void InitContentHandlers(PackageManagerImpl* manager, |
| 66 const base::CommandLine& command_line) { | 63 const base::CommandLine& command_line) { |
| 67 // Default content handlers. | 64 // Default content handlers. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 command_line.GetSwitchValueASCII(switches::kTraceStartup), | 160 command_line.GetSwitchValueASCII(switches::kTraceStartup), |
| 164 command_line.GetSwitchValueASCII(switches::kTraceStartupDuration), | 161 command_line.GetSwitchValueASCII(switches::kTraceStartupDuration), |
| 165 "mojo_runner.trace"); | 162 "mojo_runner.trace"); |
| 166 } | 163 } |
| 167 | 164 |
| 168 EnsureEmbedderIsInitialized(); | 165 EnsureEmbedderIsInitialized(); |
| 169 task_runners_.reset( | 166 task_runners_.reset( |
| 170 new TaskRunners(base::MessageLoop::current()->task_runner())); | 167 new TaskRunners(base::MessageLoop::current()->task_runner())); |
| 171 | 168 |
| 172 // TODO(vtl): This should be MASTER, not NONE. | 169 // TODO(vtl): This should be MASTER, not NONE. |
| 173 embedder::InitIPCSupport(embedder::ProcessType::NONE, this, | 170 edk::InitIPCSupport(this, task_runners_->io_runner()); |
| 174 task_runners_->io_runner(), | |
| 175 embedder::ScopedPlatformHandle()); | |
| 176 | 171 |
| 177 package_manager_ = new PackageManagerImpl( | 172 package_manager_ = new PackageManagerImpl( |
| 178 shell_file_root, task_runners_->blocking_pool(), nullptr); | 173 shell_file_root, task_runners_->blocking_pool(), nullptr); |
| 179 InitContentHandlers(package_manager_, command_line); | 174 InitContentHandlers(package_manager_, command_line); |
| 180 | 175 |
| 181 RegisterLocalAliases(package_manager_); | 176 RegisterLocalAliases(package_manager_); |
| 182 | 177 |
| 183 scoped_ptr<NativeRunnerFactory> runner_factory; | 178 scoped_ptr<NativeRunnerFactory> runner_factory; |
| 184 if (command_line.HasSwitch(switches::kMojoSingleProcess)) { | 179 if (command_line.HasSwitch(switches::kMojoSingleProcess)) { |
| 185 #if defined(COMPONENT_BUILD) | 180 #if defined(COMPONENT_BUILD) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 void Context::Shutdown() { | 232 void Context::Shutdown() { |
| 238 // Actions triggered by ApplicationManager's destructor may require a current | 233 // Actions triggered by ApplicationManager's destructor may require a current |
| 239 // message loop, so we should destruct it explicitly now as ~Context() occurs | 234 // message loop, so we should destruct it explicitly now as ~Context() occurs |
| 240 // post message loop shutdown. | 235 // post message loop shutdown. |
| 241 application_manager_.reset(); | 236 application_manager_.reset(); |
| 242 | 237 |
| 243 TRACE_EVENT0("mojo_shell", "Context::Shutdown"); | 238 TRACE_EVENT0("mojo_shell", "Context::Shutdown"); |
| 244 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 239 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
| 245 task_runners_->shell_runner()); | 240 task_runners_->shell_runner()); |
| 246 // Post a task in case OnShutdownComplete is called synchronously. | 241 // Post a task in case OnShutdownComplete is called synchronously. |
| 247 base::MessageLoop::current()->PostTask( | 242 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 248 FROM_HERE, base::Bind(embedder::ShutdownIPCSupport)); | 243 base::Bind(edk::ShutdownIPCSupport)); |
| 249 // We'll quit when we get OnShutdownComplete(). | 244 // We'll quit when we get OnShutdownComplete(). |
| 250 base::MessageLoop::current()->Run(); | 245 base::MessageLoop::current()->Run(); |
| 251 } | 246 } |
| 252 | 247 |
| 253 void Context::OnShutdownComplete() { | 248 void Context::OnShutdownComplete() { |
| 254 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 249 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
| 255 task_runners_->shell_runner()); | 250 task_runners_->shell_runner()); |
| 256 base::MessageLoop::current()->QuitWhenIdle(); | 251 base::MessageLoop::current()->QuitWhenIdle(); |
| 257 } | 252 } |
| 258 | 253 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 base::MessageLoop::current()->QuitWhenIdle(); | 293 base::MessageLoop::current()->QuitWhenIdle(); |
| 299 } else { | 294 } else { |
| 300 app_complete_callback_.Run(); | 295 app_complete_callback_.Run(); |
| 301 } | 296 } |
| 302 } | 297 } |
| 303 } | 298 } |
| 304 } | 299 } |
| 305 | 300 |
| 306 } // namespace shell | 301 } // namespace shell |
| 307 } // namespace mojo | 302 } // namespace mojo |
| OLD | NEW |