OLD | NEW |
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 <unistd.h> | 5 #include <unistd.h> |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.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/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
22 #include "base/threading/thread_checker.h" | 22 #include "base/threading/thread_checker.h" |
23 #include "mojo/edk/base_edk/platform_task_runner_impl.h" | 23 #include "mojo/edk/base_edk/platform_task_runner_impl.h" |
24 #include "mojo/edk/embedder/embedder.h" | 24 #include "mojo/edk/embedder/embedder.h" |
25 #include "mojo/edk/embedder/platform_channel_pair.h" | 25 #include "mojo/edk/embedder/platform_channel_pair.h" |
26 #include "mojo/edk/embedder/scoped_platform_handle.h" | |
27 #include "mojo/edk/embedder/simple_platform_support.h" | 26 #include "mojo/edk/embedder/simple_platform_support.h" |
28 #include "mojo/edk/embedder/slave_process_delegate.h" | 27 #include "mojo/edk/embedder/slave_process_delegate.h" |
| 28 #include "mojo/edk/platform/scoped_platform_handle.h" |
29 #include "mojo/edk/platform/task_runner.h" | 29 #include "mojo/edk/platform/task_runner.h" |
30 #include "mojo/edk/util/ref_ptr.h" | 30 #include "mojo/edk/util/ref_ptr.h" |
31 #include "mojo/message_pump/message_pump_mojo.h" | 31 #include "mojo/message_pump/message_pump_mojo.h" |
32 #include "mojo/public/cpp/bindings/binding.h" | 32 #include "mojo/public/cpp/bindings/binding.h" |
33 #include "mojo/public/cpp/system/core.h" | 33 #include "mojo/public/cpp/system/core.h" |
34 #include "shell/child_controller.mojom.h" | 34 #include "shell/child_controller.mojom.h" |
35 #include "shell/child_switches.h" | 35 #include "shell/child_switches.h" |
36 #include "shell/init.h" | 36 #include "shell/init.h" |
37 #include "shell/native_application_support.h" | 37 #include "shell/native_application_support.h" |
38 | 38 |
| 39 using mojo::platform::ScopedPlatformHandle; |
39 using mojo::util::MakeRefCounted; | 40 using mojo::util::MakeRefCounted; |
40 using mojo::util::RefPtr; | 41 using mojo::util::RefPtr; |
41 | 42 |
42 namespace shell { | 43 namespace shell { |
43 namespace { | 44 namespace { |
44 | 45 |
45 // Blocker --------------------------------------------------------------------- | 46 // Blocker --------------------------------------------------------------------- |
46 | 47 |
47 // Blocks a thread until another thread unblocks it, at which point it unblocks | 48 // Blocks a thread until another thread unblocks it, at which point it unblocks |
48 // and runs a closure provided by that thread. | 49 // and runs a closure provided by that thread. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 91 |
91 class ChildControllerImpl; | 92 class ChildControllerImpl; |
92 | 93 |
93 // Should be created and initialized on the main thread. | 94 // Should be created and initialized on the main thread. |
94 class AppContext : public mojo::embedder::SlaveProcessDelegate { | 95 class AppContext : public mojo::embedder::SlaveProcessDelegate { |
95 public: | 96 public: |
96 AppContext() | 97 AppContext() |
97 : io_thread_("io_thread"), controller_thread_("controller_thread") {} | 98 : io_thread_("io_thread"), controller_thread_("controller_thread") {} |
98 ~AppContext() override {} | 99 ~AppContext() override {} |
99 | 100 |
100 void Init(mojo::embedder::ScopedPlatformHandle platform_handle) { | 101 void Init(ScopedPlatformHandle platform_handle) { |
101 // Initialize Mojo before starting any threads. | 102 // Initialize Mojo before starting any threads. |
102 // TODO(vtl): Use make_unique when C++14 is available. | 103 // TODO(vtl): Use make_unique when C++14 is available. |
103 mojo::embedder::Init(std::unique_ptr<mojo::embedder::PlatformSupport>( | 104 mojo::embedder::Init(std::unique_ptr<mojo::embedder::PlatformSupport>( |
104 new mojo::embedder::SimplePlatformSupport())); | 105 new mojo::embedder::SimplePlatformSupport())); |
105 | 106 |
106 // Create and start our I/O thread. | 107 // Create and start our I/O thread. |
107 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); | 108 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); |
108 CHECK(io_thread_.StartWithOptions(io_thread_options)); | 109 CHECK(io_thread_.StartWithOptions(io_thread_options)); |
109 io_runner_ = MakeRefCounted<base_edk::PlatformTaskRunnerImpl>( | 110 io_runner_ = MakeRefCounted<base_edk::PlatformTaskRunnerImpl>( |
110 io_thread_.task_runner()); | 111 io_thread_.task_runner()); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 298 |
298 // Make sure that we're really meant to be invoked as the child process. | 299 // Make sure that we're really meant to be invoked as the child process. |
299 | 300 |
300 CHECK(command_line.HasSwitch(switches::kChildConnectionId)); | 301 CHECK(command_line.HasSwitch(switches::kChildConnectionId)); |
301 std::string child_connection_id = | 302 std::string child_connection_id = |
302 command_line.GetSwitchValueASCII(switches::kChildConnectionId); | 303 command_line.GetSwitchValueASCII(switches::kChildConnectionId); |
303 CHECK(!child_connection_id.empty()); | 304 CHECK(!child_connection_id.empty()); |
304 | 305 |
305 std::string platform_channel_info = | 306 std::string platform_channel_info = |
306 command_line.GetSwitchValueASCII(switches::kPlatformChannelHandleInfo); | 307 command_line.GetSwitchValueASCII(switches::kPlatformChannelHandleInfo); |
307 mojo::embedder::ScopedPlatformHandle platform_handle = | 308 ScopedPlatformHandle platform_handle = |
308 mojo::embedder::PlatformChannelPair::PassClientHandleFromParentProcess( | 309 mojo::embedder::PlatformChannelPair::PassClientHandleFromParentProcess( |
309 platform_channel_info); | 310 platform_channel_info); |
310 CHECK(platform_handle.is_valid()); | 311 CHECK(platform_handle.is_valid()); |
311 | 312 |
312 shell::AppContext app_context; | 313 shell::AppContext app_context; |
313 app_context.Init(platform_handle.Pass()); | 314 app_context.Init(platform_handle.Pass()); |
314 | 315 |
315 shell::Blocker blocker; | 316 shell::Blocker blocker; |
316 app_context.controller_runner()->PostTask(base::Bind( | 317 app_context.controller_runner()->PostTask(base::Bind( |
317 &shell::ChildControllerImpl::Init, base::Unretained(&app_context), | 318 &shell::ChildControllerImpl::Init, base::Unretained(&app_context), |
318 child_connection_id, blocker.GetUnblocker())); | 319 child_connection_id, blocker.GetUnblocker())); |
319 // This will block, then run whatever the controller wants. | 320 // This will block, then run whatever the controller wants. |
320 blocker.Block(); | 321 blocker.Block(); |
321 | 322 |
322 app_context.Shutdown(); | 323 app_context.Shutdown(); |
323 | 324 |
324 return 0; | 325 return 0; |
325 } | 326 } |
OLD | NEW |