Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: mojo/runner/host/child_process.cc

Issue 1488853002: Add multiplexing of message pipes in the new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tsepez review comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/c/system/message_pipe.h ('k') | mojo/runner/host/child_process_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); 117 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0);
118 CHECK(io_thread_.StartWithOptions(io_thread_options)); 118 CHECK(io_thread_.StartWithOptions(io_thread_options));
119 io_runner_ = io_thread_.task_runner().get(); 119 io_runner_ = io_thread_.task_runner().get();
120 CHECK(io_runner_.get()); 120 CHECK(io_runner_.get());
121 121
122 // TODO(vtl): This should be SLAVE, not NONE. 122 // TODO(vtl): This should be SLAVE, not NONE.
123 // This must be created before controller_thread_ since MessagePumpMojo will 123 // This must be created before controller_thread_ since MessagePumpMojo will
124 // create a message pipe which requires this code to be run first. 124 // create a message pipe which requires this code to be run first.
125 embedder::InitIPCSupport(embedder::ProcessType::NONE, this, io_runner_, 125 embedder::InitIPCSupport(embedder::ProcessType::NONE, this, io_runner_,
126 embedder::ScopedPlatformHandle()); 126 embedder::ScopedPlatformHandle());
127 }
127 128
129 void StartControllerThread() {
128 // Create and start our controller thread. 130 // Create and start our controller thread.
129 base::Thread::Options controller_thread_options; 131 base::Thread::Options controller_thread_options;
130 controller_thread_options.message_loop_type = 132 controller_thread_options.message_loop_type =
131 base::MessageLoop::TYPE_CUSTOM; 133 base::MessageLoop::TYPE_CUSTOM;
132 controller_thread_options.message_pump_factory = 134 controller_thread_options.message_pump_factory =
133 base::Bind(&common::MessagePumpMojo::Create); 135 base::Bind(&common::MessagePumpMojo::Create);
134 CHECK(controller_thread_.StartWithOptions(controller_thread_options)); 136 CHECK(controller_thread_.StartWithOptions(controller_thread_options));
135 controller_runner_ = controller_thread_.task_runner().get(); 137 controller_runner_ = controller_thread_.task_runner().get();
136 CHECK(controller_runner_.get()); 138 CHECK(controller_runner_.get());
137 } 139 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return sandbox.Pass(); 300 return sandbox.Pass();
299 } 301 }
300 #endif 302 #endif
301 303
302 ScopedMessagePipeHandle InitializeHostMessagePipe( 304 ScopedMessagePipeHandle InitializeHostMessagePipe(
303 embedder::ScopedPlatformHandle platform_channel, 305 embedder::ScopedPlatformHandle platform_channel,
304 scoped_refptr<base::TaskRunner> io_task_runner) { 306 scoped_refptr<base::TaskRunner> io_task_runner) {
305 ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel( 307 ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel(
306 platform_channel.Pass(), base::Bind(&DidCreateChannel), io_task_runner)); 308 platform_channel.Pass(), base::Bind(&DidCreateChannel), io_task_runner));
307 309
308 #if defined(OS_WIN)
309 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { 310 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) {
310 // When using the new Mojo EDK, each message pipe is backed by a platform 311 // When using the new Mojo EDK, each message pipe is backed by a platform
311 // handle. The one platform handle that comes on the command line is used 312 // handle. The one platform handle that comes on the command line is used
312 // to bind to the ChildController interface. However we also want a 313 // to bind to the ChildController interface. However we also want a
313 // platform handle to setup the communication channel by which we exchange 314 // platform handle to setup the communication channel by which we exchange
314 // handles to/from tokens, which is needed for sandboxed Windows 315 // handles to/from tokens, which is needed for sandboxed Windows
315 // processes. 316 // processes.
316 char broker_handle[10]; 317 char broker_handle[10];
317 MojoHandleSignalsState state; 318 MojoHandleSignalsState state;
318 MojoResult rv = 319 MojoResult rv =
(...skipping 13 matching lines...) Expand all
332 embedder::SetParentPipeHandle( 333 embedder::SetParentPipeHandle(
333 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle( 334 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle(
334 broker_channel.release(). 335 broker_channel.release().
335 #if defined(OS_WIN) 336 #if defined(OS_WIN)
336 handle 337 handle
337 #else 338 #else
338 fd 339 fd
339 #endif 340 #endif
340 ))); 341 )));
341 } 342 }
342 #else
343 // TODO(jam): hook up on POSIX
344 #endif
345 343
346 return host_message_pipe.Pass(); 344 return host_message_pipe.Pass();
347 } 345 }
348 346
349 } // namespace 347 } // namespace
350 348
351 int ChildProcessMain() { 349 int ChildProcessMain() {
352 DVLOG(2) << "ChildProcessMain()"; 350 DVLOG(2) << "ChildProcessMain()";
353 const base::CommandLine& command_line = 351 const base::CommandLine& command_line =
354 *base::CommandLine::ForCurrentProcess(); 352 *base::CommandLine::ForCurrentProcess();
(...skipping 23 matching lines...) Expand all
378 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( 376 embedder::PlatformChannelPair::PassClientHandleFromParentProcess(
379 command_line); 377 command_line);
380 CHECK(platform_channel.is_valid()); 378 CHECK(platform_channel.is_valid());
381 379
382 DCHECK(!base::MessageLoop::current()); 380 DCHECK(!base::MessageLoop::current());
383 381
384 AppContext app_context; 382 AppContext app_context;
385 app_context.Init(); 383 app_context.Init();
386 ScopedMessagePipeHandle host_message_pipe = InitializeHostMessagePipe( 384 ScopedMessagePipeHandle host_message_pipe = InitializeHostMessagePipe(
387 platform_channel.Pass(), app_context.io_runner()); 385 platform_channel.Pass(), app_context.io_runner());
386 app_context.StartControllerThread();
388 Blocker blocker; 387 Blocker blocker;
389 app_context.controller_runner()->PostTask( 388 app_context.controller_runner()->PostTask(
390 FROM_HERE, 389 FROM_HERE,
391 base::Bind(&ChildControllerImpl::Init, base::Unretained(&app_context), 390 base::Bind(&ChildControllerImpl::Init, base::Unretained(&app_context),
392 base::Unretained(app_library), 391 base::Unretained(app_library),
393 base::Passed(&host_message_pipe), blocker.GetUnblocker())); 392 base::Passed(&host_message_pipe), blocker.GetUnblocker()));
394 // This will block, then run whatever the controller wants. 393 // This will block, then run whatever the controller wants.
395 blocker.Block(); 394 blocker.Block();
396 395
397 app_context.Shutdown(); 396 app_context.Shutdown();
398 397
399 return 0; 398 return 0;
400 } 399 }
401 400
402 } // namespace runner 401 } // namespace runner
403 } // namespace mojo 402 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/c/system/message_pipe.h ('k') | mojo/runner/host/child_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698