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/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 Loading... |
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 |
54 // Blocker --------------------------------------------------------------------- | 58 // Blocker --------------------------------------------------------------------- |
55 | 59 |
56 // Blocks a thread until another thread unblocks it, at which point it unblocks | 60 // Blocks a thread until another thread unblocks it, at which point it unblocks |
57 // and runs a closure provided by that thread. | 61 // and runs a closure provided by that thread. |
58 class Blocker { | 62 class Blocker { |
59 public: | 63 public: |
60 class Unblocker { | 64 class Unblocker { |
61 public: | 65 public: |
62 explicit Unblocker(Blocker* blocker = nullptr) : blocker_(blocker) {} | 66 explicit Unblocker(Blocker* blocker = nullptr) : blocker_(blocker) {} |
63 ~Unblocker() {} | 67 ~Unblocker() {} |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 scoped_ptr<mojo::shell::LinuxSandbox> sandbox( | 293 scoped_ptr<mojo::shell::LinuxSandbox> sandbox( |
290 new mojo::shell::LinuxSandbox(permissions)); | 294 new mojo::shell::LinuxSandbox(permissions)); |
291 sandbox->Warmup(); | 295 sandbox->Warmup(); |
292 sandbox->EngageNamespaceSandbox(); | 296 sandbox->EngageNamespaceSandbox(); |
293 sandbox->EngageSeccompSandbox(); | 297 sandbox->EngageSeccompSandbox(); |
294 sandbox->Seal(); | 298 sandbox->Seal(); |
295 return sandbox; | 299 return sandbox; |
296 } | 300 } |
297 #endif | 301 #endif |
298 | 302 |
299 ScopedMessagePipeHandle InitializeHostMessagePipe( | 303 void InitializeHostMessagePipe( |
300 edk::ScopedPlatformHandle platform_channel, | 304 embedder::ScopedPlatformHandle platform_channel, |
301 scoped_refptr<base::TaskRunner> io_task_runner) { | 305 scoped_refptr<base::TaskRunner> io_task_runner, |
302 edk::SetParentPipeHandle(std::move(platform_channel)); | 306 const base::Callback<void(ScopedMessagePipeHandle)>& callback) { |
303 std::string primordial_pipe_token = | 307 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { |
304 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 308 embedder::SetParentPipeHandle(std::move(platform_channel)); |
305 switches::kPrimordialPipeToken); | 309 std::string primordial_pipe_token = |
306 return edk::CreateChildMessagePipe(primordial_pipe_token); | 310 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 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)); |
307 } | 331 } |
308 | 332 |
309 } // namespace | 333 } // namespace |
310 | 334 |
311 int ChildProcessMain() { | 335 int ChildProcessMain() { |
312 DVLOG(2) << "ChildProcessMain()"; | 336 DVLOG(2) << "ChildProcessMain()"; |
313 const base::CommandLine& command_line = | 337 const base::CommandLine& command_line = |
314 *base::CommandLine::ForCurrentProcess(); | 338 *base::CommandLine::ForCurrentProcess(); |
315 | 339 |
316 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 340 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
(...skipping 12 matching lines...) Expand all Loading... |
329 #if !defined(OFFICIAL_BUILD) | 353 #if !defined(OFFICIAL_BUILD) |
330 // Initialize stack dumping just before initializing sandbox to make | 354 // Initialize stack dumping just before initializing sandbox to make |
331 // sure symbol names in all loaded libraries will be cached. | 355 // sure symbol names in all loaded libraries will be cached. |
332 base::debug::EnableInProcessStackDumping(); | 356 base::debug::EnableInProcessStackDumping(); |
333 #endif | 357 #endif |
334 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 358 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
335 if (command_line.HasSwitch(switches::kEnableSandbox)) | 359 if (command_line.HasSwitch(switches::kEnableSandbox)) |
336 sandbox = InitializeSandbox(); | 360 sandbox = InitializeSandbox(); |
337 #endif | 361 #endif |
338 | 362 |
339 edk::ScopedPlatformHandle platform_channel = | 363 embedder::ScopedPlatformHandle platform_channel = |
340 edk::PlatformChannelPair::PassClientHandleFromParentProcess( | 364 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( |
341 command_line); | 365 command_line); |
342 CHECK(platform_channel.is_valid()); | 366 CHECK(platform_channel.is_valid()); |
343 | 367 |
344 DCHECK(!base::MessageLoop::current()); | 368 DCHECK(!base::MessageLoop::current()); |
345 | 369 |
346 Blocker blocker; | 370 Blocker blocker; |
347 AppContext app_context; | 371 AppContext app_context; |
348 app_context.Init(); | 372 app_context.Init(); |
349 app_context.StartControllerThread(); | 373 app_context.StartControllerThread(); |
350 | 374 |
351 ScopedMessagePipeHandle host_pipe = InitializeHostMessagePipe( | |
352 std::move(platform_channel), app_context.io_runner()); | |
353 app_context.controller_runner()->PostTask( | 375 app_context.controller_runner()->PostTask( |
354 FROM_HERE, | 376 FROM_HERE, |
355 base::Bind(&ChildControllerImpl::Init, &app_context, app_library, | 377 base::Bind( |
356 base::Passed(&host_pipe), blocker.GetUnblocker())); | 378 &InitializeHostMessagePipe, base::Passed(&platform_channel), |
| 379 make_scoped_refptr(app_context.io_runner()), |
| 380 base::Bind(&OnHostMessagePipeCreated, base::Unretained(&app_context), |
| 381 base::Unretained(app_library), blocker.GetUnblocker()))); |
357 | 382 |
358 // This will block, then run whatever the controller wants. | 383 // This will block, then run whatever the controller wants. |
359 blocker.Block(); | 384 blocker.Block(); |
360 | 385 |
361 app_context.Shutdown(); | 386 app_context.Shutdown(); |
362 | 387 |
363 return 0; | 388 return 0; |
364 } | 389 } |
365 | 390 |
366 } // namespace shell | 391 } // namespace shell |
367 } // namespace mojo | 392 } // namespace mojo |
OLD | NEW |