| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 114 } |
| 115 #endif | 115 #endif |
| 116 | 116 |
| 117 void LaunchOnLauncherThread(const NotifyCallback& callback, | 117 void LaunchOnLauncherThread(const NotifyCallback& callback, |
| 118 BrowserThread::ID client_thread_id, | 118 BrowserThread::ID client_thread_id, |
| 119 int child_process_id, | 119 int child_process_id, |
| 120 SandboxedProcessLauncherDelegate* delegate, | 120 SandboxedProcessLauncherDelegate* delegate, |
| 121 #if defined(OS_ANDROID) | 121 #if defined(OS_ANDROID) |
| 122 base::ScopedFD ipcfd, | 122 base::ScopedFD ipcfd, |
| 123 #endif | 123 #endif |
| 124 const base::SharedMemory* field_trial_state, |
| 124 mojo::edk::ScopedPlatformHandle client_handle, | 125 mojo::edk::ScopedPlatformHandle client_handle, |
| 125 base::CommandLine* cmd_line) { | 126 base::CommandLine* cmd_line) { |
| 126 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | 127 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 127 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); | 128 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); |
| 128 #if !defined(OS_ANDROID) | 129 #if !defined(OS_ANDROID) |
| 129 ZygoteHandle zygote = nullptr; | 130 ZygoteHandle zygote = nullptr; |
| 130 int launch_result = LAUNCH_RESULT_FAILURE; | 131 int launch_result = LAUNCH_RESULT_FAILURE; |
| 131 #endif | 132 #endif |
| 132 #if defined(OS_WIN) | 133 #if defined(OS_WIN) |
| 133 bool launch_elevated = delegate->ShouldLaunchElevated(); | 134 bool launch_elevated = delegate->ShouldLaunchElevated(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 145 #if defined(OS_WIN) | 146 #if defined(OS_WIN) |
| 146 if (launch_elevated) { | 147 if (launch_elevated) { |
| 147 // When establishing a Mojo connection, the pipe path has already been added | 148 // When establishing a Mojo connection, the pipe path has already been added |
| 148 // to the command line. | 149 // to the command line. |
| 149 base::LaunchOptions options; | 150 base::LaunchOptions options; |
| 150 options.start_hidden = true; | 151 options.start_hidden = true; |
| 151 process = base::LaunchElevatedProcess(*cmd_line, options); | 152 process = base::LaunchElevatedProcess(*cmd_line, options); |
| 152 } else { | 153 } else { |
| 153 base::HandlesToInheritVector handles; | 154 base::HandlesToInheritVector handles; |
| 154 handles.push_back(client_handle.get().handle); | 155 handles.push_back(client_handle.get().handle); |
| 156 if (field_trial_state) |
| 157 handles.push_back(field_trial_state->handle().GetHandle()); |
| 155 cmd_line->AppendSwitchASCII( | 158 cmd_line->AppendSwitchASCII( |
| 156 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch, | 159 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch, |
| 157 base::UintToString(base::win::HandleToUint32(handles[0]))); | 160 base::UintToString(base::win::HandleToUint32(handles[0]))); |
| 158 launch_result = | 161 launch_result = |
| 159 StartSandboxedProcess(delegate, cmd_line, handles, &process); | 162 StartSandboxedProcess(delegate, cmd_line, handles, &process); |
| 160 } | 163 } |
| 161 #elif defined(OS_POSIX) | 164 #elif defined(OS_POSIX) |
| 162 std::string process_type = | 165 std::string process_type = |
| 163 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 166 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
| 164 std::unique_ptr<FileDescriptorInfo> files_to_register( | 167 std::unique_ptr<FileDescriptorInfo> files_to_register( |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 #endif | 390 #endif |
| 388 } | 391 } |
| 389 | 392 |
| 390 } // namespace | 393 } // namespace |
| 391 | 394 |
| 392 ChildProcessLauncher::ChildProcessLauncher( | 395 ChildProcessLauncher::ChildProcessLauncher( |
| 393 SandboxedProcessLauncherDelegate* delegate, | 396 SandboxedProcessLauncherDelegate* delegate, |
| 394 base::CommandLine* cmd_line, | 397 base::CommandLine* cmd_line, |
| 395 int child_process_id, | 398 int child_process_id, |
| 396 Client* client, | 399 Client* client, |
| 400 const base::SharedMemory* field_trial_state, |
| 397 const std::string& mojo_child_token, | 401 const std::string& mojo_child_token, |
| 398 const mojo::edk::ProcessErrorCallback& process_error_callback, | 402 const mojo::edk::ProcessErrorCallback& process_error_callback, |
| 399 bool terminate_on_shutdown) | 403 bool terminate_on_shutdown) |
| 400 : client_(client), | 404 : client_(client), |
| 401 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), | 405 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), |
| 402 exit_code_(RESULT_CODE_NORMAL_EXIT), | 406 exit_code_(RESULT_CODE_NORMAL_EXIT), |
| 403 zygote_(nullptr), | 407 zygote_(nullptr), |
| 404 starting_(true), | 408 starting_(true), |
| 405 process_error_callback_(process_error_callback), | 409 process_error_callback_(process_error_callback), |
| 406 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ | 410 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ |
| 407 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ | 411 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ |
| 408 defined(UNDEFINED_SANITIZER) | 412 defined(UNDEFINED_SANITIZER) |
| 409 terminate_child_on_shutdown_(false), | 413 terminate_child_on_shutdown_(false), |
| 410 #else | 414 #else |
| 411 terminate_child_on_shutdown_(terminate_on_shutdown), | 415 terminate_child_on_shutdown_(terminate_on_shutdown), |
| 412 #endif | 416 #endif |
| 413 mojo_child_token_(mojo_child_token), | 417 mojo_child_token_(mojo_child_token), |
| 414 weak_factory_(this) { | 418 weak_factory_(this) { |
| 415 DCHECK(CalledOnValidThread()); | 419 DCHECK(CalledOnValidThread()); |
| 416 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 420 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
| 417 Launch(delegate, cmd_line, child_process_id); | 421 Launch(delegate, cmd_line, child_process_id, field_trial_state); |
| 418 } | 422 } |
| 419 | 423 |
| 420 ChildProcessLauncher::~ChildProcessLauncher() { | 424 ChildProcessLauncher::~ChildProcessLauncher() { |
| 421 DCHECK(CalledOnValidThread()); | 425 DCHECK(CalledOnValidThread()); |
| 422 if (process_.IsValid() && terminate_child_on_shutdown_) { | 426 if (process_.IsValid() && terminate_child_on_shutdown_) { |
| 423 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So | 427 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So |
| 424 // don't this on the UI/IO threads. | 428 // don't this on the UI/IO threads. |
| 425 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 429 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| 426 base::Bind(&TerminateOnLauncherThread, zygote_, | 430 base::Bind(&TerminateOnLauncherThread, zygote_, |
| 427 base::Passed(&process_))); | 431 base::Passed(&process_))); |
| 428 } | 432 } |
| 429 } | 433 } |
| 430 | 434 |
| 431 void ChildProcessLauncher::Launch( | 435 void ChildProcessLauncher::Launch(SandboxedProcessLauncherDelegate* delegate, |
| 432 SandboxedProcessLauncherDelegate* delegate, | 436 base::CommandLine* cmd_line, |
| 433 base::CommandLine* cmd_line, | 437 int child_process_id, |
| 434 int child_process_id) { | 438 const base::SharedMemory* field_trial_state) { |
| 435 DCHECK(CalledOnValidThread()); | 439 DCHECK(CalledOnValidThread()); |
| 436 | 440 |
| 437 #if defined(OS_ANDROID) | 441 #if defined(OS_ANDROID) |
| 438 // Android only supports renderer, sandboxed utility and gpu. | 442 // Android only supports renderer, sandboxed utility and gpu. |
| 439 std::string process_type = | 443 std::string process_type = |
| 440 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 444 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
| 441 CHECK(process_type == switches::kGpuProcess || | 445 CHECK(process_type == switches::kGpuProcess || |
| 442 process_type == switches::kRendererProcess || | 446 process_type == switches::kRendererProcess || |
| 443 #if defined(ENABLE_PLUGINS) | 447 #if defined(ENABLE_PLUGINS) |
| 444 process_type == switches::kPpapiPluginProcess || | 448 process_type == switches::kPpapiPluginProcess || |
| (...skipping 28 matching lines...) Expand all Loading... |
| 473 weak_factory_.GetWeakPtr(), | 477 weak_factory_.GetWeakPtr(), |
| 474 terminate_child_on_shutdown_, | 478 terminate_child_on_shutdown_, |
| 475 base::Passed(&server_handle))); | 479 base::Passed(&server_handle))); |
| 476 BrowserThread::PostTask( | 480 BrowserThread::PostTask( |
| 477 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 481 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| 478 base::Bind(&LaunchOnLauncherThread, reply_callback, client_thread_id_, | 482 base::Bind(&LaunchOnLauncherThread, reply_callback, client_thread_id_, |
| 479 child_process_id, delegate, | 483 child_process_id, delegate, |
| 480 #if defined(OS_ANDROID) | 484 #if defined(OS_ANDROID) |
| 481 base::Passed(&ipcfd), | 485 base::Passed(&ipcfd), |
| 482 #endif | 486 #endif |
| 483 base::Passed(&client_handle), cmd_line)); | 487 field_trial_state, base::Passed(&client_handle), cmd_line)); |
| 484 } | 488 } |
| 485 | 489 |
| 486 void ChildProcessLauncher::UpdateTerminationStatus(bool known_dead) { | 490 void ChildProcessLauncher::UpdateTerminationStatus(bool known_dead) { |
| 487 DCHECK(CalledOnValidThread()); | 491 DCHECK(CalledOnValidThread()); |
| 488 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 492 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 489 if (zygote_) { | 493 if (zygote_) { |
| 490 termination_status_ = zygote_->GetTerminationStatus( | 494 termination_status_ = zygote_->GetTerminationStatus( |
| 491 process_.Handle(), known_dead, &exit_code_); | 495 process_.Handle(), known_dead, &exit_code_); |
| 492 } else if (known_dead) { | 496 } else if (known_dead) { |
| 493 termination_status_ = | 497 termination_status_ = |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 } | 622 } |
| 619 | 623 |
| 620 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 624 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
| 621 Client* client) { | 625 Client* client) { |
| 622 Client* ret = client_; | 626 Client* ret = client_; |
| 623 client_ = client; | 627 client_ = client; |
| 624 return ret; | 628 return ret; |
| 625 } | 629 } |
| 626 | 630 |
| 627 } // namespace content | 631 } // namespace content |
| OLD | NEW |