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

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

Issue 1675603002: [mojo-edk] Simplify multiprocess pipe bootstrap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix some callers to work with sync APIs Created 4 years, 10 months 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
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/shell/runner/host/child_process.h" 5 #include "mojo/shell/runner/host/child_process.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "base/rand_util.h" 44 #include "base/rand_util.h"
45 #include "base/sys_info.h" 45 #include "base/sys_info.h"
46 #include "mojo/shell/runner/host/linux_sandbox.h" 46 #include "mojo/shell/runner/host/linux_sandbox.h"
47 #endif 47 #endif
48 48
49 namespace mojo { 49 namespace mojo {
50 namespace shell { 50 namespace shell {
51 51
52 namespace { 52 namespace {
53 53
54 void DidCreateChannel(embedder::ChannelInfo* channel_info) {
55 DVLOG(2) << "ChildControllerImpl::DidCreateChannel()";
56 }
57
58 // Blocker --------------------------------------------------------------------- 54 // Blocker ---------------------------------------------------------------------
59 55
60 // Blocks a thread until another thread unblocks it, at which point it unblocks 56 // Blocks a thread until another thread unblocks it, at which point it unblocks
61 // and runs a closure provided by that thread. 57 // and runs a closure provided by that thread.
62 class Blocker { 58 class Blocker {
63 public: 59 public:
64 class Unblocker { 60 class Unblocker {
65 public: 61 public:
66 explicit Unblocker(Blocker* blocker = nullptr) : blocker_(blocker) {} 62 explicit Unblocker(Blocker* blocker = nullptr) : blocker_(blocker) {}
67 ~Unblocker() {} 63 ~Unblocker() {}
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 scoped_ptr<mojo::shell::LinuxSandbox> sandbox( 289 scoped_ptr<mojo::shell::LinuxSandbox> sandbox(
294 new mojo::shell::LinuxSandbox(permissions)); 290 new mojo::shell::LinuxSandbox(permissions));
295 sandbox->Warmup(); 291 sandbox->Warmup();
296 sandbox->EngageNamespaceSandbox(); 292 sandbox->EngageNamespaceSandbox();
297 sandbox->EngageSeccompSandbox(); 293 sandbox->EngageSeccompSandbox();
298 sandbox->Seal(); 294 sandbox->Seal();
299 return sandbox; 295 return sandbox;
300 } 296 }
301 #endif 297 #endif
302 298
303 void InitializeHostMessagePipe( 299 ScopedMessagePipeHandle InitializeHostMessagePipe(
304 embedder::ScopedPlatformHandle platform_channel, 300 edk::ScopedPlatformHandle platform_channel,
305 scoped_refptr<base::TaskRunner> io_task_runner, 301 scoped_refptr<base::TaskRunner> io_task_runner) {
306 const base::Callback<void(ScopedMessagePipeHandle)>& callback) { 302 edk::SetParentPipeHandle(std::move(platform_channel));
307 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { 303 std::string primordial_pipe_token =
308 embedder::SetParentPipeHandle(std::move(platform_channel)); 304 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
309 std::string primordial_pipe_token = 305 switches::kPrimordialPipeToken);
310 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 306 return edk::CreateChildMessagePipe(primordial_pipe_token);
311 switches::kPrimordialPipeToken);
312 edk::CreateChildMessagePipe(primordial_pipe_token, callback);
313 } else {
314 ScopedMessagePipeHandle host_message_pipe;
315 host_message_pipe =
316 embedder::CreateChannel(std::move(platform_channel),
317 base::Bind(&DidCreateChannel), io_task_runner);
318 callback.Run(std::move(host_message_pipe));
319 }
320 }
321
322 void OnHostMessagePipeCreated(AppContext* app_context,
323 base::NativeLibrary app_library,
324 const Blocker::Unblocker& unblocker,
325 ScopedMessagePipeHandle pipe) {
326 app_context->controller_runner()->PostTask(
327 FROM_HERE,
328 base::Bind(&ChildControllerImpl::Init, base::Unretained(app_context),
329 base::Unretained(app_library), base::Passed(&pipe),
330 unblocker));
331 } 307 }
332 308
333 } // namespace 309 } // namespace
334 310
335 int ChildProcessMain() { 311 int ChildProcessMain() {
336 DVLOG(2) << "ChildProcessMain()"; 312 DVLOG(2) << "ChildProcessMain()";
337 const base::CommandLine& command_line = 313 const base::CommandLine& command_line =
338 *base::CommandLine::ForCurrentProcess(); 314 *base::CommandLine::ForCurrentProcess();
339 315
340 #if defined(OS_LINUX) && !defined(OS_ANDROID) 316 #if defined(OS_LINUX) && !defined(OS_ANDROID)
(...skipping 12 matching lines...) Expand all
353 #if !defined(OFFICIAL_BUILD) 329 #if !defined(OFFICIAL_BUILD)
354 // Initialize stack dumping just before initializing sandbox to make 330 // Initialize stack dumping just before initializing sandbox to make
355 // sure symbol names in all loaded libraries will be cached. 331 // sure symbol names in all loaded libraries will be cached.
356 base::debug::EnableInProcessStackDumping(); 332 base::debug::EnableInProcessStackDumping();
357 #endif 333 #endif
358 #if defined(OS_LINUX) && !defined(OS_ANDROID) 334 #if defined(OS_LINUX) && !defined(OS_ANDROID)
359 if (command_line.HasSwitch(switches::kEnableSandbox)) 335 if (command_line.HasSwitch(switches::kEnableSandbox))
360 sandbox = InitializeSandbox(); 336 sandbox = InitializeSandbox();
361 #endif 337 #endif
362 338
363 embedder::ScopedPlatformHandle platform_channel = 339 edk::ScopedPlatformHandle platform_channel =
364 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( 340 edk::PlatformChannelPair::PassClientHandleFromParentProcess(
365 command_line); 341 command_line);
366 CHECK(platform_channel.is_valid()); 342 CHECK(platform_channel.is_valid());
367 343
368 DCHECK(!base::MessageLoop::current()); 344 DCHECK(!base::MessageLoop::current());
369 345
370 Blocker blocker; 346 Blocker blocker;
371 AppContext app_context; 347 AppContext app_context;
372 app_context.Init(); 348 app_context.Init();
373 app_context.StartControllerThread(); 349 app_context.StartControllerThread();
374 350
351 ScopedMessagePipeHandle host_pipe = InitializeHostMessagePipe(
352 std::move(platform_channel), app_context.io_runner());
375 app_context.controller_runner()->PostTask( 353 app_context.controller_runner()->PostTask(
376 FROM_HERE, 354 FROM_HERE,
377 base::Bind( 355 base::Bind(&ChildControllerImpl::Init, &app_context, app_library,
378 &InitializeHostMessagePipe, base::Passed(&platform_channel), 356 base::Passed(&host_pipe), blocker.GetUnblocker()));
379 make_scoped_refptr(app_context.io_runner()),
380 base::Bind(&OnHostMessagePipeCreated, base::Unretained(&app_context),
381 base::Unretained(app_library), blocker.GetUnblocker())));
382 357
383 // This will block, then run whatever the controller wants. 358 // This will block, then run whatever the controller wants.
384 blocker.Block(); 359 blocker.Block();
385 360
386 app_context.Shutdown(); 361 app_context.Shutdown();
387 362
388 return 0; 363 return 0;
389 } 364 }
390 365
391 } // namespace shell 366 } // namespace shell
392 } // namespace mojo 367 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/runner/child/runner_connection.cc ('k') | mojo/shell/runner/host/child_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698