Chromium Code Reviews| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/process/launch.h" | 12 #include "base/process/launch.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "content/public/common/result_codes.h" | 14 #include "content/public/common/result_codes.h" |
| 15 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 15 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 using internal::ChildProcessLauncherHelper; | 19 using internal::ChildProcessLauncherHelper; |
| 20 | 20 |
| 21 ChildProcessLauncher::ChildProcessLauncher( | 21 ChildProcessLauncher::ChildProcessLauncher( |
| 22 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate, | 22 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate, |
| 23 std::unique_ptr<base::CommandLine> command_line, | 23 std::unique_ptr<base::CommandLine> command_line, |
| 24 int child_process_id, | 24 int child_process_id, |
| 25 Client* client, | 25 Client* client, |
| 26 const std::string& mojo_child_token, | 26 std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection, |
| 27 const mojo::edk::ProcessErrorCallback& process_error_callback, | 27 const mojo::edk::ProcessErrorCallback& process_error_callback, |
| 28 bool terminate_on_shutdown) | 28 bool terminate_on_shutdown) |
| 29 : client_(client), | 29 : client_(client), |
| 30 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), | 30 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), |
| 31 exit_code_(RESULT_CODE_NORMAL_EXIT), | 31 exit_code_(RESULT_CODE_NORMAL_EXIT), |
| 32 starting_(true), | 32 starting_(true), |
| 33 pending_connection_(std::move(pending_connection)), | |
| 33 process_error_callback_(process_error_callback), | 34 process_error_callback_(process_error_callback), |
| 34 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ | 35 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ |
| 35 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ | 36 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ |
| 36 defined(UNDEFINED_SANITIZER) | 37 defined(UNDEFINED_SANITIZER) |
| 37 terminate_child_on_shutdown_(false), | 38 terminate_child_on_shutdown_(false), |
| 38 #else | 39 #else |
| 39 terminate_child_on_shutdown_(terminate_on_shutdown), | 40 terminate_child_on_shutdown_(terminate_on_shutdown), |
| 40 #endif | 41 #endif |
| 41 mojo_child_token_(mojo_child_token), | |
| 42 weak_factory_(this) { | 42 weak_factory_(this) { |
| 43 DCHECK(CalledOnValidThread()); | 43 DCHECK(CalledOnValidThread()); |
| 44 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 44 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
| 45 | 45 |
| 46 helper_ = new ChildProcessLauncherHelper( | 46 helper_ = new ChildProcessLauncherHelper( |
| 47 child_process_id, client_thread_id_, | 47 child_process_id, client_thread_id_, |
| 48 std::move(command_line), std::move(delegate), | 48 std::move(command_line), std::move(delegate), |
| 49 weak_factory_.GetWeakPtr(), terminate_on_shutdown); | 49 weak_factory_.GetWeakPtr(), terminate_on_shutdown); |
| 50 helper_->StartLaunchOnClientThread(); | 50 helper_->StartLaunchOnClientThread(); |
| 51 } | 51 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 73 void ChildProcessLauncher::Notify( | 73 void ChildProcessLauncher::Notify( |
| 74 ChildProcessLauncherHelper::Process process, | 74 ChildProcessLauncherHelper::Process process, |
| 75 mojo::edk::ScopedPlatformHandle server_handle, | 75 mojo::edk::ScopedPlatformHandle server_handle, |
| 76 int error_code) { | 76 int error_code) { |
| 77 DCHECK(CalledOnValidThread()); | 77 DCHECK(CalledOnValidThread()); |
| 78 starting_ = false; | 78 starting_ = false; |
| 79 process_ = std::move(process); | 79 process_ = std::move(process); |
| 80 | 80 |
| 81 if (process_.process.IsValid()) { | 81 if (process_.process.IsValid()) { |
| 82 // Set up Mojo IPC to the new process. | 82 // Set up Mojo IPC to the new process. |
| 83 mojo::edk::ChildProcessLaunched(process_.process.Handle(), | 83 DCHECK(pending_connection_); |
| 84 std::move(server_handle), | 84 pending_connection_->Connect(process_.process.Handle(), |
| 85 mojo_child_token_, | 85 std::move(server_handle), |
| 86 process_error_callback_); | 86 process_error_callback_); |
| 87 client_->OnProcessLaunched(); | 87 client_->OnProcessLaunched(); |
| 88 } else { | 88 } else { |
| 89 mojo::edk::ChildProcessLaunchFailed(mojo_child_token_); | 89 pending_connection_.reset(); |
|
Sam McNally
2017/02/09 05:38:47
Can we clear this unconditionally?
Ken Rockot(use gerrit already)
2017/02/09 06:01:58
Sure, done
| |
| 90 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; | 90 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; |
| 91 client_->OnProcessLaunchFailed(error_code); | 91 client_->OnProcessLaunchFailed(error_code); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool ChildProcessLauncher::IsStarting() { | 95 bool ChildProcessLauncher::IsStarting() { |
| 96 // TODO(crbug.com/469248): This fails in some tests. | 96 // TODO(crbug.com/469248): This fails in some tests. |
| 97 // DCHECK(CalledOnValidThread()); | 97 // DCHECK(CalledOnValidThread()); |
| 98 return starting_; | 98 return starting_; |
| 99 } | 99 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 } | 146 } |
| 147 | 147 |
| 148 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 148 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
| 149 Client* client) { | 149 Client* client) { |
| 150 Client* ret = client_; | 150 Client* ret = client_; |
| 151 client_ = client; | 151 client_ = client; |
| 152 return ret; | 152 return ret; |
| 153 } | 153 } |
| 154 | 154 |
| 155 } // namespace content | 155 } // namespace content |
| OLD | NEW |