| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); | 116 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); |
| 117 CHECK(io_thread_.StartWithOptions(io_thread_options)); | 117 CHECK(io_thread_.StartWithOptions(io_thread_options)); |
| 118 io_runner_ = io_thread_.task_runner().get(); | 118 io_runner_ = io_thread_.task_runner().get(); |
| 119 CHECK(io_runner_.get()); | 119 CHECK(io_runner_.get()); |
| 120 | 120 |
| 121 // TODO(vtl): This should be SLAVE, not NONE. | 121 // TODO(vtl): This should be SLAVE, not NONE. |
| 122 // This must be created before controller_thread_ since MessagePumpMojo will | 122 // This must be created before controller_thread_ since MessagePumpMojo will |
| 123 // create a message pipe which requires this code to be run first. | 123 // create a message pipe which requires this code to be run first. |
| 124 embedder::InitIPCSupport(embedder::ProcessType::NONE, this, io_runner_, | 124 embedder::InitIPCSupport(embedder::ProcessType::NONE, this, io_runner_, |
| 125 embedder::ScopedPlatformHandle()); | 125 embedder::ScopedPlatformHandle()); |
| 126 } |
| 126 | 127 |
| 128 void StartControllerThread() { |
| 127 // Create and start our controller thread. | 129 // Create and start our controller thread. |
| 128 base::Thread::Options controller_thread_options; | 130 base::Thread::Options controller_thread_options; |
| 129 controller_thread_options.message_loop_type = | 131 controller_thread_options.message_loop_type = |
| 130 base::MessageLoop::TYPE_CUSTOM; | 132 base::MessageLoop::TYPE_CUSTOM; |
| 131 controller_thread_options.message_pump_factory = | 133 controller_thread_options.message_pump_factory = |
| 132 base::Bind(&common::MessagePumpMojo::Create); | 134 base::Bind(&common::MessagePumpMojo::Create); |
| 133 CHECK(controller_thread_.StartWithOptions(controller_thread_options)); | 135 CHECK(controller_thread_.StartWithOptions(controller_thread_options)); |
| 134 controller_runner_ = controller_thread_.task_runner().get(); | 136 controller_runner_ = controller_thread_.task_runner().get(); |
| 135 CHECK(controller_runner_.get()); | 137 CHECK(controller_runner_.get()); |
| 136 } | 138 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 return sandbox.Pass(); | 299 return sandbox.Pass(); |
| 298 } | 300 } |
| 299 #endif | 301 #endif |
| 300 | 302 |
| 301 ScopedMessagePipeHandle InitializeHostMessagePipe( | 303 ScopedMessagePipeHandle InitializeHostMessagePipe( |
| 302 embedder::ScopedPlatformHandle platform_channel, | 304 embedder::ScopedPlatformHandle platform_channel, |
| 303 scoped_refptr<base::TaskRunner> io_task_runner) { | 305 scoped_refptr<base::TaskRunner> io_task_runner) { |
| 304 ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel( | 306 ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel( |
| 305 platform_channel.Pass(), base::Bind(&DidCreateChannel), io_task_runner)); | 307 platform_channel.Pass(), base::Bind(&DidCreateChannel), io_task_runner)); |
| 306 | 308 |
| 307 #if defined(OS_WIN) | |
| 308 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { | 309 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { |
| 309 // When using the new Mojo EDK, each message pipe is backed by a platform | 310 // When using the new Mojo EDK, each message pipe is backed by a platform |
| 310 // handle. The one platform handle that comes on the command line is used | 311 // handle. The one platform handle that comes on the command line is used |
| 311 // to bind to the ChildController interface. However we also want a | 312 // to bind to the ChildController interface. However we also want a |
| 312 // platform handle to setup the communication channel by which we exchange | 313 // platform handle to setup the communication channel by which we exchange |
| 313 // handles to/from tokens, which is needed for sandboxed Windows | 314 // handles to/from tokens, which is needed for sandboxed Windows |
| 314 // processes. | 315 // processes. |
| 315 char broker_handle[10]; | 316 char broker_handle[10]; |
| 316 MojoHandleSignalsState state; | 317 MojoHandleSignalsState state; |
| 317 MojoResult rv = | 318 MojoResult rv = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 331 embedder::SetParentPipeHandle( | 332 embedder::SetParentPipeHandle( |
| 332 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle( | 333 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle( |
| 333 broker_channel.release(). | 334 broker_channel.release(). |
| 334 #if defined(OS_WIN) | 335 #if defined(OS_WIN) |
| 335 handle | 336 handle |
| 336 #else | 337 #else |
| 337 fd | 338 fd |
| 338 #endif | 339 #endif |
| 339 ))); | 340 ))); |
| 340 } | 341 } |
| 341 #else | |
| 342 // TODO(jam): hook up on POSIX | |
| 343 #endif | |
| 344 | 342 |
| 345 return host_message_pipe.Pass(); | 343 return host_message_pipe.Pass(); |
| 346 } | 344 } |
| 347 | 345 |
| 348 } // namespace | 346 } // namespace |
| 349 | 347 |
| 350 int ChildProcessMain() { | 348 int ChildProcessMain() { |
| 351 DVLOG(2) << "ChildProcessMain()"; | 349 DVLOG(2) << "ChildProcessMain()"; |
| 352 const base::CommandLine& command_line = | 350 const base::CommandLine& command_line = |
| 353 *base::CommandLine::ForCurrentProcess(); | 351 *base::CommandLine::ForCurrentProcess(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 372 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( | 370 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( |
| 373 command_line); | 371 command_line); |
| 374 CHECK(platform_channel.is_valid()); | 372 CHECK(platform_channel.is_valid()); |
| 375 | 373 |
| 376 DCHECK(!base::MessageLoop::current()); | 374 DCHECK(!base::MessageLoop::current()); |
| 377 | 375 |
| 378 AppContext app_context; | 376 AppContext app_context; |
| 379 app_context.Init(); | 377 app_context.Init(); |
| 380 ScopedMessagePipeHandle host_message_pipe = InitializeHostMessagePipe( | 378 ScopedMessagePipeHandle host_message_pipe = InitializeHostMessagePipe( |
| 381 platform_channel.Pass(), app_context.io_runner()); | 379 platform_channel.Pass(), app_context.io_runner()); |
| 380 app_context.StartControllerThread(); |
| 382 Blocker blocker; | 381 Blocker blocker; |
| 383 app_context.controller_runner()->PostTask( | 382 app_context.controller_runner()->PostTask( |
| 384 FROM_HERE, | 383 FROM_HERE, |
| 385 base::Bind(&ChildControllerImpl::Init, base::Unretained(&app_context), | 384 base::Bind(&ChildControllerImpl::Init, base::Unretained(&app_context), |
| 386 base::Unretained(app_library), | 385 base::Unretained(app_library), |
| 387 base::Passed(&host_message_pipe), blocker.GetUnblocker())); | 386 base::Passed(&host_message_pipe), blocker.GetUnblocker())); |
| 388 // This will block, then run whatever the controller wants. | 387 // This will block, then run whatever the controller wants. |
| 389 blocker.Block(); | 388 blocker.Block(); |
| 390 | 389 |
| 391 app_context.Shutdown(); | 390 app_context.Shutdown(); |
| 392 | 391 |
| 393 return 0; | 392 return 0; |
| 394 } | 393 } |
| 395 | 394 |
| 396 } // namespace runner | 395 } // namespace runner |
| 397 } // namespace mojo | 396 } // namespace mojo |
| OLD | NEW |