Chromium Code Reviews| 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 "mojo/runner/host/child_process.h" | 5 #include "mojo/runner/host/child_process.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.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" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 // Should be created and initialized on the main thread. | 101 // Should be created and initialized on the main thread. |
| 102 // TODO(use_chrome_edk) | 102 // TODO(use_chrome_edk) |
| 103 // class AppContext : public edk::ProcessDelegate { | 103 // class AppContext : public edk::ProcessDelegate { |
| 104 class AppContext : public embedder::ProcessDelegate { | 104 class AppContext : public embedder::ProcessDelegate { |
| 105 public: | 105 public: |
| 106 AppContext() | 106 AppContext() |
| 107 : io_thread_("io_thread"), controller_thread_("controller_thread") {} | 107 : io_thread_("io_thread"), controller_thread_("controller_thread") {} |
| 108 ~AppContext() override {} | 108 ~AppContext() override {} |
| 109 | 109 |
| 110 void Init() { | 110 void Init() { |
| 111 #if defined(OS_WIN) | |
| 112 embedder::PreInitializeChildProcess(); | 111 embedder::PreInitializeChildProcess(); |
| 113 #endif | |
| 114 | |
| 115 // Initialize Mojo before starting any threads. | 112 // Initialize Mojo before starting any threads. |
| 116 embedder::Init(); | 113 embedder::Init(); |
| 117 | 114 |
| 118 // Create and start our I/O thread. | 115 // Create and start our I/O thread. |
| 119 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); | 116 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); |
| 120 CHECK(io_thread_.StartWithOptions(io_thread_options)); | 117 CHECK(io_thread_.StartWithOptions(io_thread_options)); |
| 121 io_runner_ = io_thread_.task_runner().get(); | 118 io_runner_ = io_thread_.task_runner().get(); |
| 122 CHECK(io_runner_.get()); | 119 CHECK(io_runner_.get()); |
| 123 | 120 |
| 124 // TODO(vtl): This should be SLAVE, not NONE. | 121 // TODO(vtl): This should be SLAVE, not NONE. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 platform_channel.Pass(), base::Bind(&DidCreateChannel), io_task_runner)); | 305 platform_channel.Pass(), base::Bind(&DidCreateChannel), io_task_runner)); |
| 309 | 306 |
| 310 #if defined(OS_WIN) | 307 #if defined(OS_WIN) |
| 311 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { | 308 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { |
| 312 // When using the new Mojo EDK, each message pipe is backed by a platform | 309 // When using the new Mojo EDK, each message pipe is backed by a platform |
| 313 // handle. The one platform handle that comes on the command line is used | 310 // handle. The one platform handle that comes on the command line is used |
| 314 // to bind to the ChildController interface. However we also want a | 311 // to bind to the ChildController interface. However we also want a |
| 315 // platform handle to setup the communication channel by which we exchange | 312 // platform handle to setup the communication channel by which we exchange |
| 316 // handles to/from tokens, which is needed for sandboxed Windows | 313 // handles to/from tokens, which is needed for sandboxed Windows |
| 317 // processes. | 314 // processes. |
| 318 char token_serializer_handle[10]; | 315 char broker_handle[10]; |
| 319 MojoHandleSignalsState state; | 316 MojoHandleSignalsState state; |
| 320 MojoResult rv = | 317 MojoResult rv = |
| 321 MojoWait(host_message_pipe.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 318 MojoWait(host_message_pipe.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| 322 MOJO_DEADLINE_INDEFINITE, &state); | 319 MOJO_DEADLINE_INDEFINITE, &state); |
| 323 CHECK_EQ(MOJO_RESULT_OK, rv); | 320 CHECK_EQ(MOJO_RESULT_OK, rv); |
| 324 uint32_t num_bytes = arraysize(token_serializer_handle); | 321 uint32_t num_bytes = arraysize(broker_handle); |
| 325 rv = MojoReadMessage(host_message_pipe.get().value(), | 322 rv = MojoReadMessage(host_message_pipe.get().value(), |
| 326 token_serializer_handle, &num_bytes, nullptr, 0, | 323 broker_handle, &num_bytes, nullptr, 0, |
| 327 MOJO_READ_MESSAGE_FLAG_NONE); | 324 MOJO_READ_MESSAGE_FLAG_NONE); |
| 328 CHECK_EQ(MOJO_RESULT_OK, rv); | 325 CHECK_EQ(MOJO_RESULT_OK, rv); |
| 329 | 326 |
| 330 edk::ScopedPlatformHandle token_serializer_channel = | 327 edk::ScopedPlatformHandle broker_channel = |
| 331 edk::PlatformChannelPair::PassClientHandleFromParentProcessFromString( | 328 edk::PlatformChannelPair::PassClientHandleFromParentProcessFromString( |
| 332 std::string(token_serializer_handle, num_bytes)); | 329 std::string(broker_handle, num_bytes)); |
| 333 CHECK(token_serializer_channel.is_valid()); | 330 CHECK(broker_channel.is_valid()); |
| 334 embedder::SetParentPipeHandle(token_serializer_channel.release().handle); | 331 embedder::SetParentPipeHandle( |
| 332 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle( | |
| 333 broker_channel.release(). | |
| 334 #if defined(OS_WIN) | |
|
yzshen1
2015/11/25 16:47:09
Does it make sense to have helper methods (in eith
jam
2015/11/25 16:56:09
I thought of that; but the goal should be to delet
| |
| 335 handle | |
| 336 #else | |
| 337 fd | |
| 338 #endif | |
| 339 ))); | |
| 335 } | 340 } |
| 341 #else | |
| 342 // TODO(jam): hook up on POSIX | |
| 336 #endif | 343 #endif |
| 337 | 344 |
| 338 return host_message_pipe.Pass(); | 345 return host_message_pipe.Pass(); |
| 339 } | 346 } |
| 340 | 347 |
| 341 } // namespace | 348 } // namespace |
| 342 | 349 |
| 343 int ChildProcessMain() { | 350 int ChildProcessMain() { |
| 344 DVLOG(2) << "ChildProcessMain()"; | 351 DVLOG(2) << "ChildProcessMain()"; |
| 345 const base::CommandLine& command_line = | 352 const base::CommandLine& command_line = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 // This will block, then run whatever the controller wants. | 387 // This will block, then run whatever the controller wants. |
| 381 blocker.Block(); | 388 blocker.Block(); |
| 382 | 389 |
| 383 app_context.Shutdown(); | 390 app_context.Shutdown(); |
| 384 | 391 |
| 385 return 0; | 392 return 0; |
| 386 } | 393 } |
| 387 | 394 |
| 388 } // namespace runner | 395 } // namespace runner |
| 389 } // namespace mojo | 396 } // namespace mojo |
| OLD | NEW |