| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "content/browser/child_process_launcher.h" | 5 #include "content/browser/child_process_launcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/i18n/icu_util.h" | 10 #include "base/i18n/icu_util.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "content/browser/zygote_host/zygote_host_impl_linux.h" | 41 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
| 42 #include "content/common/child_process_sandbox_support_impl_linux.h" | 42 #include "content/common/child_process_sandbox_support_impl_linux.h" |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 #if defined(OS_POSIX) | 45 #if defined(OS_POSIX) |
| 46 #include "base/posix/global_descriptors.h" | 46 #include "base/posix/global_descriptors.h" |
| 47 #include "content/browser/file_descriptor_info_impl.h" | 47 #include "content/browser/file_descriptor_info_impl.h" |
| 48 #include "gin/v8_initializer.h" | 48 #include "gin/v8_initializer.h" |
| 49 #endif | 49 #endif |
| 50 | 50 |
| 51 #if defined(MOJO_SHELL_CLIENT) | |
| 52 #include "base/thread_task_runner_handle.h" | |
| 53 #include "content/public/common/mojo_shell_connection.h" | |
| 54 #include "mojo/application/public/cpp/application_impl.h" | |
| 55 #include "mojo/converters/network/network_type_converters.h" | |
| 56 #include "mojo/shell/application_manager.mojom.h" | |
| 57 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | |
| 58 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" | |
| 59 #include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h" | |
| 60 #endif | |
| 61 | |
| 62 namespace content { | 51 namespace content { |
| 63 | 52 |
| 64 namespace { | 53 namespace { |
| 65 | 54 |
| 66 typedef base::Callback<void(bool, | 55 typedef base::Callback<void(bool, |
| 67 #if defined(OS_ANDROID) | 56 #if defined(OS_ANDROID) |
| 68 base::ScopedFD, | 57 base::ScopedFD, |
| 69 #endif | 58 #endif |
| 70 base::Process)> NotifyCallback; | 59 base::Process)> NotifyCallback; |
| 71 | 60 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 bool background) { | 315 bool background) { |
| 327 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | 316 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 328 if (process.CanBackgroundProcesses()) { | 317 if (process.CanBackgroundProcesses()) { |
| 329 process.SetProcessBackgrounded(background); | 318 process.SetProcessBackgrounded(background); |
| 330 } | 319 } |
| 331 #if defined(OS_ANDROID) | 320 #if defined(OS_ANDROID) |
| 332 SetChildProcessInForeground(process.Handle(), !background); | 321 SetChildProcessInForeground(process.Handle(), !background); |
| 333 #endif | 322 #endif |
| 334 } | 323 } |
| 335 | 324 |
| 336 #if defined(MOJO_SHELL_CLIENT) | |
| 337 void DidCreateChannel(mojo::embedder::ChannelInfo* info) {} | |
| 338 #endif | |
| 339 | |
| 340 } // namespace | 325 } // namespace |
| 341 | 326 |
| 342 ChildProcessLauncher::ChildProcessLauncher( | 327 ChildProcessLauncher::ChildProcessLauncher( |
| 343 SandboxedProcessLauncherDelegate* delegate, | 328 SandboxedProcessLauncherDelegate* delegate, |
| 344 base::CommandLine* cmd_line, | 329 base::CommandLine* cmd_line, |
| 345 int child_process_id, | 330 int child_process_id, |
| 346 Client* client, | 331 Client* client, |
| 347 bool terminate_on_shutdown) | 332 bool terminate_on_shutdown) |
| 348 : client_(client), | 333 : client_(client), |
| 349 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), | 334 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 373 base::Passed(&process_))); | 358 base::Passed(&process_))); |
| 374 } | 359 } |
| 375 } | 360 } |
| 376 | 361 |
| 377 void ChildProcessLauncher::Launch( | 362 void ChildProcessLauncher::Launch( |
| 378 SandboxedProcessLauncherDelegate* delegate, | 363 SandboxedProcessLauncherDelegate* delegate, |
| 379 base::CommandLine* cmd_line, | 364 base::CommandLine* cmd_line, |
| 380 int child_process_id) { | 365 int child_process_id) { |
| 381 DCHECK(CalledOnValidThread()); | 366 DCHECK(CalledOnValidThread()); |
| 382 | 367 |
| 383 #if defined(MOJO_SHELL_CLIENT) | |
| 384 CreateMojoShellChannel(cmd_line, child_process_id); | |
| 385 #endif | |
| 386 | |
| 387 #if defined(OS_ANDROID) | 368 #if defined(OS_ANDROID) |
| 388 // Android only supports renderer, sandboxed utility and gpu. | 369 // Android only supports renderer, sandboxed utility and gpu. |
| 389 std::string process_type = | 370 std::string process_type = |
| 390 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 371 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
| 391 CHECK(process_type == switches::kGpuProcess || | 372 CHECK(process_type == switches::kGpuProcess || |
| 392 process_type == switches::kRendererProcess || | 373 process_type == switches::kRendererProcess || |
| 393 #if defined(ENABLE_PLUGINS) | 374 #if defined(ENABLE_PLUGINS) |
| 394 process_type == switches::kPpapiPluginProcess || | 375 process_type == switches::kPpapiPluginProcess || |
| 395 #endif | 376 #endif |
| 396 process_type == switches::kUtilityProcess) | 377 process_type == switches::kUtilityProcess) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/465841 | 497 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/465841 |
| 517 // is fixed. | 498 // is fixed. |
| 518 tracked_objects::ScopedTracker tracking_profile3( | 499 tracked_objects::ScopedTracker tracking_profile3( |
| 519 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 500 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 520 "465841 ChildProcessLauncher::Context::Notify::ProcessFailed")); | 501 "465841 ChildProcessLauncher::Context::Notify::ProcessFailed")); |
| 521 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; | 502 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; |
| 522 client_->OnProcessLaunchFailed(); | 503 client_->OnProcessLaunchFailed(); |
| 523 } | 504 } |
| 524 } | 505 } |
| 525 | 506 |
| 526 #if defined(MOJO_SHELL_CLIENT) | |
| 527 void ChildProcessLauncher::CreateMojoShellChannel( | |
| 528 base::CommandLine* command_line, | |
| 529 int child_process_id) { | |
| 530 // Some process types get created before the main message loop. | |
| 531 if (!MojoShellConnection::Get()) | |
| 532 return; | |
| 533 | |
| 534 // Create the channel to be shared with the target process. | |
| 535 mojo::embedder::HandlePassingInformation handle_passing_info; | |
| 536 mojo::embedder::PlatformChannelPair platform_channel_pair; | |
| 537 | |
| 538 // Give one end to the shell so that it can create an instance. | |
| 539 mojo::embedder::ScopedPlatformHandle platform_channel = | |
| 540 platform_channel_pair.PassServerHandle(); | |
| 541 mojo::ScopedMessagePipeHandle handle(mojo::embedder::CreateChannel( | |
| 542 platform_channel.Pass(), base::Bind(&DidCreateChannel), | |
| 543 base::ThreadTaskRunnerHandle::Get())); | |
| 544 mojo::shell::mojom::ApplicationManagerPtr application_manager; | |
| 545 MojoShellConnection::Get()->GetApplication()->ConnectToService( | |
| 546 mojo::URLRequest::From(std::string("mojo:shell")), | |
| 547 &application_manager); | |
| 548 // The content of the URL/qualifier we pass is actually meaningless, it's only | |
| 549 // important that they're unique per process. | |
| 550 // TODO(beng): We need to specify a restrictive CapabilityFilter here that | |
| 551 // matches the needs of the target process. Figure out where that | |
| 552 // specification is best determined (not here, this is a common | |
| 553 // chokepoint for all process types) and how to wire it through. | |
| 554 // http://crbug.com/555393 | |
| 555 application_manager->CreateInstanceForHandle( | |
| 556 mojo::ScopedHandle(mojo::Handle(handle.release().value())), | |
| 557 "exe:chrome_renderer", // See above about how this string is meaningless. | |
| 558 base::IntToString(child_process_id)); | |
| 559 | |
| 560 // Put the other end on the command line used to launch the target. | |
| 561 platform_channel_pair.PrepareToPassClientHandleToChildProcess( | |
| 562 command_line, &handle_passing_info); | |
| 563 } | |
| 564 #endif // defined(MOJO_SHELL_CLIENT) | |
| 565 | |
| 566 bool ChildProcessLauncher::IsStarting() { | 507 bool ChildProcessLauncher::IsStarting() { |
| 567 // TODO(crbug.com/469248): This fails in some tests. | 508 // TODO(crbug.com/469248): This fails in some tests. |
| 568 // DCHECK(CalledOnValidThread()); | 509 // DCHECK(CalledOnValidThread()); |
| 569 return starting_; | 510 return starting_; |
| 570 } | 511 } |
| 571 | 512 |
| 572 const base::Process& ChildProcessLauncher::GetProcess() const { | 513 const base::Process& ChildProcessLauncher::GetProcess() const { |
| 573 // TODO(crbug.com/469248): This fails in some tests. | 514 // TODO(crbug.com/469248): This fails in some tests. |
| 574 // DCHECK(CalledOnValidThread()); | 515 // DCHECK(CalledOnValidThread()); |
| 575 return process_; | 516 return process_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 603 } | 544 } |
| 604 | 545 |
| 605 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 546 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
| 606 Client* client) { | 547 Client* client) { |
| 607 Client* ret = client_; | 548 Client* ret = client_; |
| 608 client_ = client; | 549 client_ = client; |
| 609 return ret; | 550 return ret; |
| 610 } | 551 } |
| 611 | 552 |
| 612 } // namespace content | 553 } // namespace content |
| OLD | NEW |