Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
jam@chromium.org | 9610ef24 | 2009-11-18 02:41:26 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
jam@chromium.org | df8e899b | 2011-02-22 22:58:22 | [diff] [blame] | 5 | #include "content/browser/child_process_launcher.h" |
jam@chromium.org | 9610ef24 | 2009-11-18 02:41:26 | [diff] [blame] | 6 | |
Joe Mason | ba14528 | 2024-03-12 20:18:19 | [diff] [blame] | 7 | #include <optional> |
Lukasz Anforowicz | b1088809 | 2018-05-04 00:50:08 | [diff] [blame] | 8 | #include <utility> |
| 9 | |
Hans Wennborg | 0917de89 | 2020-04-28 20:21:15 | [diff] [blame] | 10 | #include "base/check_op.h" |
Sebastien Marchand | bd02bc29e | 2020-03-11 15:53:36 | [diff] [blame] | 11 | #include "base/clang_profiling_buildflags.h" |
jam@chromium.org | 9610ef24 | 2009-11-18 02:41:26 | [diff] [blame] | 12 | #include "base/command_line.h" |
thestig | b7aad54f | 2014-09-05 18:25:39 | [diff] [blame] | 13 | #include "base/files/file_util.h" |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 14 | #include "base/functional/bind.h" |
agrieve | fd2d44ab | 2015-06-19 04:33:03 | [diff] [blame] | 15 | #include "base/i18n/icu_util.h" |
Roger McFarlane | cba0e90 | 2024-01-24 17:51:37 | [diff] [blame] | 16 | #include "base/memory/unsafe_shared_memory_region.h" |
rockot | b3b0dfa0 | 2016-02-26 22:43:28 | [diff] [blame] | 17 | #include "base/process/launch.h" |
Olivier Li | 344b0d23 | 2021-05-10 19:30:15 | [diff] [blame] | 18 | #include "base/time/time.h" |
ssid | 6bedaa9 | 2021-06-16 10:25:24 | [diff] [blame] | 19 | #include "base/tracing/protos/chrome_track_event.pbzero.h" |
Joe Mason | 550eed6 | 2024-03-25 18:07:31 | [diff] [blame] | 20 | #include "base/types/expected.h" |
| 21 | #include "base/types/optional_util.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 22 | #include "build/build_config.h" |
Lei Zhang | 8f395da6 | 2022-10-05 15:06:20 | [diff] [blame] | 23 | #include "content/public/browser/browser_thread.h" |
Xi Han | 89d93df | 2018-03-09 20:55:07 | [diff] [blame] | 24 | #include "content/public/browser/child_process_launcher_utils.h" |
Ben Kelly | f4fc4ce0 | 2019-02-12 16:10:01 | [diff] [blame] | 25 | #include "content/public/common/content_features.h" |
Sebastien Marchand | 6a582a0 | 2021-06-29 01:52:23 | [diff] [blame] | 26 | #include "content/public/common/content_switches.h" |
aberent@chromium.org | 121e6138 | 2014-03-13 11:35:15 | [diff] [blame] | 27 | #include "content/public/common/sandboxed_process_launcher_delegate.h" |
jam@chromium.org | fb1277e8 | 2009-11-21 20:32:30 | [diff] [blame] | 28 | |
Calder Kitagawa | bf528665 | 2022-09-14 15:38:19 | [diff] [blame] | 29 | #if BUILDFLAG(IS_ANDROID) |
| 30 | #include "base/android/child_process_binding_types.h" |
| 31 | #endif |
| 32 | |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 33 | #if BUILDFLAG(IS_MAC) |
Olivier Li | 344b0d23 | 2021-05-10 19:30:15 | [diff] [blame] | 34 | #include "content/browser/child_process_task_port_provider_mac.h" |
| 35 | #endif |
| 36 | |
jam@chromium.org | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 37 | namespace content { |
joi@chromium.org | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 38 | |
Patrick Monette | 87b033b6 | 2022-08-24 20:06:12 | [diff] [blame] | 39 | namespace { |
| 40 | |
| 41 | #if !BUILDFLAG(IS_ANDROID) |
| 42 | // Returns the cumulative CPU usage for the specified process. |
Joe Mason | ba14528 | 2024-03-12 20:18:19 | [diff] [blame] | 43 | std::optional<base::TimeDelta> GetCPUUsage(base::ProcessHandle process_handle) { |
Patrick Monette | 87b033b6 | 2022-08-24 20:06:12 | [diff] [blame] | 44 | #if BUILDFLAG(IS_MAC) |
| 45 | std::unique_ptr<base::ProcessMetrics> process_metrics = |
| 46 | base::ProcessMetrics::CreateProcessMetrics( |
| 47 | process_handle, ChildProcessTaskPortProvider::GetInstance()); |
| 48 | #else |
| 49 | std::unique_ptr<base::ProcessMetrics> process_metrics = |
| 50 | base::ProcessMetrics::CreateProcessMetrics(process_handle); |
| 51 | #endif |
Joe Mason | 550eed6 | 2024-03-25 18:07:31 | [diff] [blame] | 52 | return base::OptionalFromExpected(process_metrics->GetCumulativeCPUUsage()); |
Patrick Monette | 87b033b6 | 2022-08-24 20:06:12 | [diff] [blame] | 53 | } |
| 54 | #endif // !BUILDFLAG(IS_ANDROID) |
| 55 | |
| 56 | } // namespace |
| 57 | |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 58 | using internal::ChildProcessLauncherHelper; |
jam@chromium.org | 9610ef24 | 2009-11-18 02:41:26 | [diff] [blame] | 59 | |
Patrick Monette | d54f90e | 2022-12-13 19:03:55 | [diff] [blame] | 60 | void RenderProcessPriority::WriteIntoTrace( |
Alexander Timin | 074cd18 | 2022-03-23 18:11:22 | [diff] [blame] | 61 | perfetto::TracedProto<TraceProto> proto) const { |
Patrick Monette | 5d200fc | 2024-07-23 20:19:38 | [diff] [blame^] | 62 | // TODO(pmonette): Migrate is_background() to GetProcessPriority(). |
ssid | 6bedaa9 | 2021-06-16 10:25:24 | [diff] [blame] | 63 | proto->set_is_backgrounded(is_background()); |
| 64 | proto->set_has_pending_views(boost_for_pending_views); |
| 65 | |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 66 | #if BUILDFLAG(IS_ANDROID) |
ssid | 6bedaa9 | 2021-06-16 10:25:24 | [diff] [blame] | 67 | using PriorityProto = perfetto::protos::pbzero::ChildProcessLauncherPriority; |
| 68 | switch (importance) { |
| 69 | case ChildProcessImportance::IMPORTANT: |
| 70 | proto->set_importance(PriorityProto::IMPORTANCE_IMPORTANT); |
| 71 | break; |
| 72 | case ChildProcessImportance::NORMAL: |
| 73 | proto->set_importance(PriorityProto::IMPORTANCE_NORMAL); |
| 74 | break; |
| 75 | case ChildProcessImportance::MODERATE: |
| 76 | proto->set_importance(PriorityProto::IMPORTANCE_MODERATE); |
| 77 | break; |
| 78 | } |
| 79 | #endif |
| 80 | } |
| 81 | |
Eriko Kurimoto | 9c83b40 | 2022-05-11 02:36:32 | [diff] [blame] | 82 | ChildProcessLauncherFileData::ChildProcessLauncherFileData() = default; |
| 83 | |
| 84 | ChildProcessLauncherFileData::~ChildProcessLauncherFileData() = default; |
| 85 | |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 86 | #if BUILDFLAG(IS_ANDROID) |
Min Qin | eb96190 | 2019-03-16 08:08:22 | [diff] [blame] | 87 | bool ChildProcessLauncher::Client::CanUseWarmUpConnection() { |
| 88 | return true; |
| 89 | } |
| 90 | #endif |
| 91 | |
jam@chromium.org | fb1277e8 | 2009-11-21 20:32:30 | [diff] [blame] | 92 | ChildProcessLauncher::ChildProcessLauncher( |
jcivelli | d20cc0b | 2016-12-22 03:51:41 | [diff] [blame] | 93 | std::unique_ptr<SandboxedProcessLauncherDelegate> delegate, |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 94 | std::unique_ptr<base::CommandLine> command_line, |
jcivelli@chromium.org | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 95 | int child_process_id, |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 96 | Client* client, |
Ken Rockot | 026afc3 | 2018-06-04 19:19:18 | [diff] [blame] | 97 | mojo::OutgoingInvitation mojo_invitation, |
| 98 | const mojo::ProcessErrorCallback& process_error_callback, |
Eriko Kurimoto | 9c83b40 | 2022-05-11 02:36:32 | [diff] [blame] | 99 | std::unique_ptr<ChildProcessLauncherFileData> file_data, |
Roger McFarlane | cba0e90 | 2024-01-24 17:51:37 | [diff] [blame] | 100 | base::UnsafeSharedMemoryRegion histogram_memory_region, |
Etienne Pierre-doray | 25723fa | 2024-06-28 14:05:57 | [diff] [blame] | 101 | base::ReadOnlySharedMemoryRegion tracing_config_memory_region, |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 102 | bool terminate_on_shutdown) |
| 103 | : client_(client), |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 104 | starting_(true), |
| 105 | #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ |
| 106 | defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ |
Sebastien Marchand | bd02bc29e | 2020-03-11 15:53:36 | [diff] [blame] | 107 | defined(UNDEFINED_SANITIZER) || BUILDFLAG(CLANG_PROFILING) |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 108 | terminate_child_on_shutdown_(false) |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 109 | #else |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 110 | terminate_child_on_shutdown_(terminate_on_shutdown) |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 111 | #endif |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 112 | { |
Lei Zhang | 8f395da6 | 2022-10-05 15:06:20 | [diff] [blame] | 113 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 114 | |
Patrick Monette | 1c4c417 | 2022-09-14 22:04:31 | [diff] [blame] | 115 | #if BUILDFLAG(IS_WIN) |
| 116 | should_launch_elevated_ = delegate->ShouldLaunchElevated(); |
| 117 | #endif |
| 118 | |
Ken Rockot | 8e23c3ab | 2019-08-01 23:39:10 | [diff] [blame] | 119 | helper_ = base::MakeRefCounted<ChildProcessLauncherHelper>( |
| 120 | child_process_id, std::move(command_line), std::move(delegate), |
| 121 | weak_factory_.GetWeakPtr(), terminate_on_shutdown, |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 122 | #if BUILDFLAG(IS_ANDROID) |
Min Qin | eb96190 | 2019-03-16 08:08:22 | [diff] [blame] | 123 | client_->CanUseWarmUpConnection(), |
| 124 | #endif |
Roger McFarlane | cba0e90 | 2024-01-24 17:51:37 | [diff] [blame] | 125 | std::move(mojo_invitation), process_error_callback, std::move(file_data), |
Etienne Pierre-doray | 25723fa | 2024-06-28 14:05:57 | [diff] [blame] | 126 | std::move(histogram_memory_region), |
| 127 | std::move(tracing_config_memory_region)); |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 128 | helper_->StartLaunchOnClientThread(); |
jam@chromium.org | 9610ef24 | 2009-11-18 02:41:26 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | ChildProcessLauncher::~ChildProcessLauncher() { |
Lei Zhang | 8f395da6 | 2022-10-05 15:06:20 | [diff] [blame] | 132 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 133 | if (process_.process.IsValid() && terminate_child_on_shutdown_) { |
| 134 | // Client has gone away, so just kill the process. |
| 135 | ChildProcessLauncherHelper::ForceNormalProcessTerminationAsync( |
| 136 | std::move(process_)); |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
Patrick Monette | d54f90e | 2022-12-13 19:03:55 | [diff] [blame] | 140 | #if BUILDFLAG(IS_ANDROID) |
| 141 | void ChildProcessLauncher::SetRenderProcessPriority( |
| 142 | const RenderProcessPriority& priority) { |
Lei Zhang | 8f395da6 | 2022-10-05 15:06:20 | [diff] [blame] | 143 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 144 | base::Process to_pass = process_.process.Duplicate(); |
Xi Han | 89d93df | 2018-03-09 20:55:07 | [diff] [blame] | 145 | GetProcessLauncherTaskRunner()->PostTask( |
| 146 | FROM_HERE, |
tzik | 4fea24af | 2017-08-23 11:41:47 | [diff] [blame] | 147 | base::BindOnce( |
Patrick Monette | d54f90e | 2022-12-13 19:03:55 | [diff] [blame] | 148 | &ChildProcessLauncherHelper::SetRenderProcessPriorityOnLauncherThread, |
tzik | ccf160c | 2018-02-20 12:43:13 | [diff] [blame] | 149 | helper_, std::move(to_pass), priority)); |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 150 | } |
Patrick Monette | d54f90e | 2022-12-13 19:03:55 | [diff] [blame] | 151 | #else // !BUILDFLAG(IS_ANDROID) |
Patrick Monette | 20997a2 | 2023-08-07 17:30:17 | [diff] [blame] | 152 | void ChildProcessLauncher::SetProcessPriority( |
| 153 | base::Process::Priority priority) { |
Patrick Monette | d54f90e | 2022-12-13 19:03:55 | [diff] [blame] | 154 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 155 | base::Process to_pass = process_.process.Duplicate(); |
| 156 | GetProcessLauncherTaskRunner()->PostTask( |
| 157 | FROM_HERE, |
| 158 | base::BindOnce( |
Patrick Monette | 20997a2 | 2023-08-07 17:30:17 | [diff] [blame] | 159 | &ChildProcessLauncherHelper::SetProcessPriorityOnLauncherThread, |
| 160 | helper_, std::move(to_pass), priority)); |
Patrick Monette | d54f90e | 2022-12-13 19:03:55 | [diff] [blame] | 161 | } |
| 162 | #endif // !BUILDFLAG(IS_ANDROID) |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 163 | |
Will Harris | df8fcb4 | 2021-12-18 09:21:31 | [diff] [blame] | 164 | void ChildProcessLauncher::Notify(ChildProcessLauncherHelper::Process process, |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 165 | #if BUILDFLAG(IS_WIN) |
Will Harris | df8fcb4 | 2021-12-18 09:21:31 | [diff] [blame] | 166 | DWORD last_error, |
| 167 | #endif |
| 168 | int error_code) { |
Lei Zhang | 8f395da6 | 2022-10-05 15:06:20 | [diff] [blame] | 169 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 170 | starting_ = false; |
danakj | e3de838f | 2015-12-03 01:49:40 | [diff] [blame] | 171 | process_ = std::move(process); |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 172 | |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 173 | if (process_.process.IsValid()) { |
Olivier Li | 344b0d23 | 2021-05-10 19:30:15 | [diff] [blame] | 174 | process_start_time_ = base::TimeTicks::Now(); |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 175 | client_->OnProcessLaunched(); |
| 176 | } else { |
Bo Liu | 0d2a232 | 2018-04-19 00:18:09 | [diff] [blame] | 177 | termination_info_.status = base::TERMINATION_STATUS_LAUNCH_FAILED; |
Will Harris | df8fcb4 | 2021-12-18 09:21:31 | [diff] [blame] | 178 | termination_info_.exit_code = error_code; |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 179 | #if BUILDFLAG(IS_WIN) |
Will Harris | df8fcb4 | 2021-12-18 09:21:31 | [diff] [blame] | 180 | termination_info_.last_error = last_error; |
| 181 | #endif |
rockot | 1039b82 | 2017-02-09 23:19:41 | [diff] [blame] | 182 | |
| 183 | // NOTE: May delete |this|. |
wfh | 3adf87d | 2016-05-03 23:26:06 | [diff] [blame] | 184 | client_->OnProcessLaunchFailed(error_code); |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 185 | } |
jam@chromium.org | 9610ef24 | 2009-11-18 02:41:26 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | bool ChildProcessLauncher::IsStarting() { |
Lei Zhang | 8f395da6 | 2022-10-05 15:06:20 | [diff] [blame] | 189 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 190 | return starting_; |
jam@chromium.org | 9610ef24 | 2009-11-18 02:41:26 | [diff] [blame] | 191 | } |
| 192 | |
rvargas | 079d184 | 2014-10-17 22:32:16 | [diff] [blame] | 193 | const base::Process& ChildProcessLauncher::GetProcess() const { |
Lei Zhang | 8f395da6 | 2022-10-05 15:06:20 | [diff] [blame] | 194 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Will Harris | 56d162c | 2022-04-12 01:57:51 | [diff] [blame] | 195 | DCHECK(!starting_); |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 196 | return process_.process; |
jam@chromium.org | 9610ef24 | 2009-11-18 02:41:26 | [diff] [blame] | 197 | } |
| 198 | |
Bo Liu | 0d2a232 | 2018-04-19 00:18:09 | [diff] [blame] | 199 | ChildProcessTerminationInfo ChildProcessLauncher::GetChildTerminationInfo( |
| 200 | bool known_dead) { |
Lei Zhang | 8f395da6 | 2022-10-05 15:06:20 | [diff] [blame] | 201 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Lukasz Anforowicz | 2e7a0ea | 2018-04-09 21:21:06 | [diff] [blame] | 202 | |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 203 | if (!process_.process.IsValid()) { |
Lukasz Anforowicz | 2e7a0ea | 2018-04-09 21:21:06 | [diff] [blame] | 204 | // Make sure to avoid using the default termination status if the process |
| 205 | // hasn't even started yet. |
Lukasz Anforowicz | b4b17a4 | 2020-04-09 20:57:42 | [diff] [blame] | 206 | if (IsStarting()) |
Bo Liu | 0d2a232 | 2018-04-19 00:18:09 | [diff] [blame] | 207 | termination_info_.status = base::TERMINATION_STATUS_STILL_RUNNING; |
Lukasz Anforowicz | 2e7a0ea | 2018-04-09 21:21:06 | [diff] [blame] | 208 | |
Bo Liu | 0d2a232 | 2018-04-19 00:18:09 | [diff] [blame] | 209 | // Process doesn't exist, so return the cached termination info. |
| 210 | return termination_info_; |
kkania@chromium.org | cd69619b | 2010-05-05 02:41:38 | [diff] [blame] | 211 | } |
| 212 | |
Patrick Monette | 87b033b6 | 2022-08-24 20:06:12 | [diff] [blame] | 213 | #if !BUILDFLAG(IS_ANDROID) |
Joe Mason | ba14528 | 2024-03-12 20:18:19 | [diff] [blame] | 214 | std::optional<base::TimeDelta> cpu_usage; |
Patrick Monette | 1c4c417 | 2022-09-14 22:04:31 | [diff] [blame] | 215 | if (!should_launch_elevated_) |
| 216 | cpu_usage = GetCPUUsage(process_.process.Handle()); |
Patrick Monette | 87b033b6 | 2022-08-24 20:06:12 | [diff] [blame] | 217 | #endif |
| 218 | |
Bo Liu | 0d2a232 | 2018-04-19 00:18:09 | [diff] [blame] | 219 | termination_info_ = helper_->GetTerminationInfo(process_, known_dead); |
jbates@chromium.org | f3c1d3c | 2011-07-25 18:50:48 | [diff] [blame] | 220 | |
Patrick Monette | 87b033b6 | 2022-08-24 20:06:12 | [diff] [blame] | 221 | #if !BUILDFLAG(IS_ANDROID) |
| 222 | // Get the cumulative CPU usage. This needs to be done before closing the |
| 223 | // process handle (on Windows) or reaping the zombie process (on MacOS, Linux, |
| 224 | // ChromeOS). |
| 225 | termination_info_.cpu_usage = cpu_usage; |
| 226 | #endif |
| 227 | |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 228 | // POSIX: If the process crashed, then the kernel closed the socket for it and |
| 229 | // so the child has already died by the time we get here. Since |
Bo Liu | 0d2a232 | 2018-04-19 00:18:09 | [diff] [blame] | 230 | // GetTerminationInfo called waitpid with WNOHANG, it'll reap the process. |
| 231 | // However, if GetTerminationInfo didn't reap the child (because it was |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 232 | // still running), we'll need to Terminate via ProcessWatcher. So we can't |
| 233 | // close the handle here. |
Bo Liu | 0d2a232 | 2018-04-19 00:18:09 | [diff] [blame] | 234 | if (termination_info_.status != base::TERMINATION_STATUS_STILL_RUNNING) { |
| 235 | process_.process.Exited(termination_info_.exit_code); |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 236 | process_.process.Close(); |
Brian White | ae2a8b9a | 2017-11-02 19:10:36 | [diff] [blame] | 237 | } |
kkania@chromium.org | cd69619b | 2010-05-05 02:41:38 | [diff] [blame] | 238 | |
Bo Liu | 0d2a232 | 2018-04-19 00:18:09 | [diff] [blame] | 239 | return termination_info_; |
ananta@chromium.org | 358cb8e | 2011-05-25 02:12:45 | [diff] [blame] | 240 | } |
jam@chromium.org | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 241 | |
Wez | 0abfbf51 | 2018-03-03 01:54:45 | [diff] [blame] | 242 | bool ChildProcessLauncher::Terminate(int exit_code) { |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 243 | return IsStarting() ? false |
| 244 | : ChildProcessLauncherHelper::TerminateProcess( |
Wez | 0abfbf51 | 2018-03-03 01:54:45 | [diff] [blame] | 245 | GetProcess(), exit_code); |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | // static |
| 249 | bool ChildProcessLauncher::TerminateProcess(const base::Process& process, |
Wez | 0abfbf51 | 2018-03-03 01:54:45 | [diff] [blame] | 250 | int exit_code) { |
| 251 | return ChildProcessLauncherHelper::TerminateProcess(process, exit_code); |
jcivelli | 828cd7f | 2017-01-18 19:50:46 | [diff] [blame] | 252 | } |
| 253 | |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 254 | #if BUILDFLAG(IS_ANDROID) |
Calder Kitagawa | bf528665 | 2022-09-14 15:38:19 | [diff] [blame] | 255 | base::android::ChildBindingState |
| 256 | ChildProcessLauncher::GetEffectiveChildBindingState() { |
| 257 | return helper_->GetEffectiveChildBindingState(); |
| 258 | } |
| 259 | |
Min Qin | f9dd030 | 2019-03-07 18:54:00 | [diff] [blame] | 260 | void ChildProcessLauncher::DumpProcessStack() { |
| 261 | base::Process to_pass = process_.process.Duplicate(); |
| 262 | GetProcessLauncherTaskRunner()->PostTask( |
| 263 | FROM_HERE, base::BindOnce(&ChildProcessLauncherHelper::DumpProcessStack, |
| 264 | helper_, std::move(to_pass))); |
| 265 | } |
| 266 | #endif |
| 267 | |
lfg | 06aac85 | 2015-03-23 22:36:10 | [diff] [blame] | 268 | ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
| 269 | Client* client) { |
sievers | 954e37a | 2015-03-28 01:50:24 | [diff] [blame] | 270 | Client* ret = client_; |
| 271 | client_ = client; |
| 272 | return ret; |
lfg | 06aac85 | 2015-03-23 22:36:10 | [diff] [blame] | 273 | } |
| 274 | |
Patrick Monette | d54f90e | 2022-12-13 19:03:55 | [diff] [blame] | 275 | bool RenderProcessPriority::is_background() const { |
Patrick Monette | 350d1e5 | 2024-07-22 02:25:23 | [diff] [blame] | 276 | #if !BUILDFLAG(IS_ANDROID) |
Patrick Monette | 5d200fc | 2024-07-23 20:19:38 | [diff] [blame^] | 277 | if (priority_override) { |
| 278 | return *priority_override == base::Process::Priority::kBestEffort; |
Patrick Monette | 350d1e5 | 2024-07-22 02:25:23 | [diff] [blame] | 279 | } |
| 280 | #endif |
Andrew Paseltiner | eb3045e | 2021-01-26 16:25:39 | [diff] [blame] | 281 | return !visible && !has_media_stream && !boost_for_pending_views && |
Minoru Chikamune | 56e6a24 | 2024-07-17 06:55:35 | [diff] [blame] | 282 | !has_foreground_service_worker && !boost_for_loading; |
Ben Kelly | f4fc4ce0 | 2019-02-12 16:10:01 | [diff] [blame] | 283 | } |
| 284 | |
Patrick Monette | 7d8aca11 | 2024-06-13 12:11:10 | [diff] [blame] | 285 | base::Process::Priority RenderProcessPriority::GetProcessPriority() const { |
Patrick Monette | 5d200fc | 2024-07-23 20:19:38 | [diff] [blame^] | 286 | #if !BUILDFLAG(IS_ANDROID) |
| 287 | if (priority_override) { |
| 288 | return *priority_override; |
| 289 | } |
| 290 | #endif |
Patrick Monette | 7d8aca11 | 2024-06-13 12:11:10 | [diff] [blame] | 291 | return is_background() ? base::Process::Priority::kBestEffort |
| 292 | : base::Process::Priority::kUserBlocking; |
| 293 | } |
| 294 | |
Patrick Monette | d54f90e | 2022-12-13 19:03:55 | [diff] [blame] | 295 | bool RenderProcessPriority::operator==( |
Patrick Monette | be0144b | 2024-07-18 21:31:29 | [diff] [blame] | 296 | const RenderProcessPriority& other) const = default; |
| 297 | |
| 298 | bool RenderProcessPriority::operator!=( |
| 299 | const RenderProcessPriority& other) const = default; |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 300 | |
jam@chromium.org | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 301 | } // namespace content |