| 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 std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection, | 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 int param_id) |
| 29 : client_(client), | 30 : client_(client), |
| 30 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), | 31 termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), |
| 31 exit_code_(RESULT_CODE_NORMAL_EXIT), | 32 exit_code_(RESULT_CODE_NORMAL_EXIT), |
| 32 starting_(true), | 33 starting_(true), |
| 33 pending_connection_(std::move(pending_connection)), | 34 pending_connection_(std::move(pending_connection)), |
| 34 process_error_callback_(process_error_callback), | 35 process_error_callback_(process_error_callback), |
| 35 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ | 36 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ |
| 36 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ | 37 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ |
| 37 defined(UNDEFINED_SANITIZER) | 38 defined(UNDEFINED_SANITIZER) |
| 38 terminate_child_on_shutdown_(false), | 39 terminate_child_on_shutdown_(false), |
| 39 #else | 40 #else |
| 40 terminate_child_on_shutdown_(terminate_on_shutdown), | 41 terminate_child_on_shutdown_(terminate_on_shutdown), |
| 41 #endif | 42 #endif |
| 42 weak_factory_(this) { | 43 weak_factory_(this) { |
| 43 DCHECK(CalledOnValidThread()); | 44 DCHECK(CalledOnValidThread()); |
| 44 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 45 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
| 45 | 46 |
| 46 helper_ = new ChildProcessLauncherHelper( | 47 helper_ = new ChildProcessLauncherHelper( |
| 47 child_process_id, client_thread_id_, | 48 child_process_id, client_thread_id_, std::move(command_line), |
| 48 std::move(command_line), std::move(delegate), | 49 std::move(delegate), weak_factory_.GetWeakPtr(), terminate_on_shutdown, |
| 49 weak_factory_.GetWeakPtr(), terminate_on_shutdown); | 50 param_id); |
| 50 helper_->StartLaunchOnClientThread(); | 51 helper_->StartLaunchOnClientThread(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 ChildProcessLauncher::~ChildProcessLauncher() { | 54 ChildProcessLauncher::~ChildProcessLauncher() { |
| 54 DCHECK(CalledOnValidThread()); | 55 DCHECK(CalledOnValidThread()); |
| 55 if (process_.process.IsValid() && terminate_child_on_shutdown_) { | 56 if (process_.process.IsValid() && terminate_child_on_shutdown_) { |
| 56 // Client has gone away, so just kill the process. | 57 // Client has gone away, so just kill the process. |
| 57 ChildProcessLauncherHelper::ForceNormalProcessTerminationAsync( | 58 ChildProcessLauncherHelper::ForceNormalProcessTerminationAsync( |
| 58 std::move(process_)); | 59 std::move(process_)); |
| 59 } | 60 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 160 } |
| 160 | 161 |
| 161 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 162 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
| 162 Client* client) { | 163 Client* client) { |
| 163 Client* ret = client_; | 164 Client* ret = client_; |
| 164 client_ = client; | 165 client_ = client; |
| 165 return ret; | 166 return ret; |
| 166 } | 167 } |
| 167 | 168 |
| 168 } // namespace content | 169 } // namespace content |
| OLD | NEW |