Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [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 | |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 5 | #include "content/browser/child_process_host_impl.h" |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 6 | |
[email protected] | 4306c379 | 2011-12-02 01:57:53 | [diff] [blame] | 7 | #include <limits> |
Avi Drissman | 5d5d48d6 | 2022-01-07 20:23:58 | [diff] [blame] | 8 | #include <tuple> |
[email protected] | 4306c379 | 2011-12-02 01:57:53 | [diff] [blame] | 9 | |
[email protected] | 3cb7cc953 | 2014-01-08 22:55:51 | [diff] [blame] | 10 | #include "base/atomic_sequence_num.h" |
Sebastien Marchand | bd02bc29e | 2020-03-11 15:53:36 | [diff] [blame] | 11 | #include "base/clang_profiling_buildflags.h" |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 12 | #include "base/command_line.h" |
Sajjad Mirza | 94c68bc | 2019-08-15 01:02:35 | [diff] [blame] | 13 | #include "base/files/file.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
Daniel Cheng | c058199 | 2019-03-29 04:52:56 | [diff] [blame] | 15 | #include "base/hash/hash.h" |
[email protected] | 8c40f32 | 2011-08-24 03:33:36 | [diff] [blame] | 16 | #include "base/logging.h" |
Gabriel Charette | 9f60dd1 | 2020-03-06 20:48:04 | [diff] [blame] | 17 | #include "base/memory/ptr_util.h" |
asvitkine | 8d51e9d | 2016-09-02 23:55:43 | [diff] [blame] | 18 | #include "base/metrics/histogram_macros.h" |
reveman | 22dd929 | 2014-10-13 20:52:05 | [diff] [blame] | 19 | #include "base/numerics/safe_math.h" |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 20 | #include "base/path_service.h" |
[email protected] | 71ed8e02 | 2013-07-25 14:39:57 | [diff] [blame] | 21 | #include "base/process/process_metrics.h" |
[email protected] | 4306c379 | 2011-12-02 01:57:53 | [diff] [blame] | 22 | #include "base/rand_util.h" |
erikchen | 5708aae | 2015-09-14 17:45:12 | [diff] [blame] | 23 | #include "base/synchronization/lock.h" |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 24 | #include "base/task/single_thread_task_runner.h" |
avi | a9aa7a8 | 2015-12-25 03:06:31 | [diff] [blame] | 25 | #include "build/build_config.h" |
Dominic Farolino | 1f77378 | 2020-09-08 20:03:36 | [diff] [blame] | 26 | #include "content/common/content_constants_internal.h" |
Lukasz Anforowicz | 2b8b8623 | 2021-08-18 23:35:50 | [diff] [blame] | 27 | #include "content/common/pseudonymization_salt.h" |
Emily Andrews | 2eab36a | 2024-12-03 20:15:48 | [diff] [blame] | 28 | #include "content/public/browser/browser_thread.h" |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 29 | #include "content/public/browser/child_process_host_delegate.h" |
| 30 | #include "content/public/browser/content_browser_client.h" |
Richard Knoll | db46ceb | 2021-01-14 20:39:37 | [diff] [blame] | 31 | #include "content/public/common/content_client.h" |
[email protected] | 5d921d4c | 2011-10-21 22:26:14 | [diff] [blame] | 32 | #include "content/public/common/content_paths.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 33 | #include "content/public/common/content_switches.h" |
rockot | da988790 | 2016-08-19 20:46:42 | [diff] [blame] | 34 | #include "ipc/ipc.mojom.h" |
[email protected] | 5c41e6e1 | 2012-03-17 02:20:46 | [diff] [blame] | 35 | #include "ipc/ipc_channel.h" |
amistry | d4aa70d | 2016-06-23 07:52:37 | [diff] [blame] | 36 | #include "ipc/ipc_channel_mojo.h" |
Ken Rockot | 95c888a4 | 2018-02-11 05:54:11 | [diff] [blame] | 37 | #include "services/resource_coordinator/public/mojom/memory_instrumentation/constants.mojom.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 38 | #include "services/service_manager/public/cpp/interface_provider.h" |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 39 | |
Xiaohan Wang | b317893 | 2022-01-11 00:08:27 | [diff] [blame] | 40 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 41 | #include "base/linux_util.h" |
Xiaohan Wang | b317893 | 2022-01-11 00:08:27 | [diff] [blame] | 42 | #elif BUILDFLAG(IS_MAC) |
Avi Drissman | eac566b0 | 2023-08-18 02:56:21 | [diff] [blame] | 43 | #include "base/apple/foundation_util.h" |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 44 | #include "content/browser/mac_helpers.h" |
Xiaohan Wang | b317893 | 2022-01-11 00:08:27 | [diff] [blame] | 45 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 46 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 47 | namespace content { |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 48 | |
Lei Zhang | 0e004cb | 2021-12-01 16:43:34 | [diff] [blame] | 49 | ChildProcessHost::~ChildProcessHost() = default; |
| 50 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 51 | // static |
Ayu Ishii | 75cc106 | 2019-01-08 01:27:37 | [diff] [blame] | 52 | std::unique_ptr<ChildProcessHost> ChildProcessHost::Create( |
Tom Sepez | 7bf8900 | 2025-07-17 23:44:04 | [diff] [blame] | 53 | ChildProcessHostDelegate* delegate) { |
| 54 | return base::WrapUnique(new ChildProcessHostImpl(delegate)); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | // static |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 58 | base::FilePath ChildProcessHost::GetChildPath(int flags) { |
| 59 | base::FilePath child_path; |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 60 | |
[email protected] | 47927870 | 2014-08-11 20:32:09 | [diff] [blame] | 61 | child_path = base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 62 | switches::kBrowserSubprocessPath); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 63 | |
Xiaohan Wang | b317893 | 2022-01-11 00:08:27 | [diff] [blame] | 64 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 65 | // Use /proc/self/exe rather than our known binary path so updates |
| 66 | // can't swap out the binary from underneath us. |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 67 | if (child_path.empty() && flags & CHILD_ALLOW_SELF) { |
[email protected] | a732916 | 2013-02-07 19:21:48 | [diff] [blame] | 68 | child_path = base::FilePath(base::kProcSelfExe); |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 69 | } |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | // On most platforms, the child executable is the same as the current |
| 73 | // executable. |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 74 | if (child_path.empty()) { |
Avi Drissman | 1cb5e9f | 2018-05-01 15:53:28 | [diff] [blame] | 75 | base::PathService::Get(CHILD_PROCESS_EXE, &child_path); |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 76 | } |
Robert Sesek | 4be2698 | 2019-06-17 17:41:28 | [diff] [blame] | 77 | |
Xiaohan Wang | b317893 | 2022-01-11 00:08:27 | [diff] [blame] | 78 | #if BUILDFLAG(IS_MAC) |
Robert Sesek | 4be2698 | 2019-06-17 17:41:28 | [diff] [blame] | 79 | std::string child_base_name = child_path.BaseName().value(); |
| 80 | |
Avi Drissman | eac566b0 | 2023-08-18 02:56:21 | [diff] [blame] | 81 | if (flags != CHILD_NORMAL && base::apple::AmIBundled()) { |
Robert Sesek | 4be2698 | 2019-06-17 17:41:28 | [diff] [blame] | 82 | // This is a specialized helper, with the |child_path| at |
| 83 | // ../Framework.framework/Versions/X/Helpers/Chromium Helper.app/Contents/ |
| 84 | // MacOS/Chromium Helper. Go back up to the "Helpers" directory to select |
| 85 | // a different variant. |
| 86 | child_path = child_path.DirName().DirName().DirName().DirName(); |
| 87 | |
| 88 | if (flags == CHILD_RENDERER) { |
| 89 | child_base_name += kMacHelperSuffix_renderer; |
Robert Sesek | 413f603 | 2019-07-19 21:46:50 | [diff] [blame] | 90 | } else if (flags == CHILD_GPU) { |
| 91 | child_base_name += kMacHelperSuffix_gpu; |
Robert Sesek | 4be2698 | 2019-06-17 17:41:28 | [diff] [blame] | 92 | } else if (flags == CHILD_PLUGIN) { |
| 93 | child_base_name += kMacHelperSuffix_plugin; |
Richard Knoll | db46ceb | 2021-01-14 20:39:37 | [diff] [blame] | 94 | } else if (flags > CHILD_EMBEDDER_FIRST) { |
Marshall Greenblatt | 46a4055 | 2023-04-21 20:23:36 | [diff] [blame] | 95 | child_base_name += |
| 96 | GetContentClient()->browser()->GetChildProcessSuffix(flags); |
Robert Sesek | 4be2698 | 2019-06-17 17:41:28 | [diff] [blame] | 97 | } else { |
Peter Boström | fc7ddc18 | 2024-10-31 19:37:21 | [diff] [blame] | 98 | NOTREACHED(); |
Robert Sesek | 4be2698 | 2019-06-17 17:41:28 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | child_path = child_path.Append(child_base_name + ".app") |
| 102 | .Append("Contents") |
| 103 | .Append("MacOS") |
| 104 | .Append(child_base_name); |
| 105 | } |
Xiaohan Wang | 6028ac2 | 2022-01-15 19:18:41 | [diff] [blame] | 106 | #endif // BUILDFLAG(IS_MAC) |
Robert Sesek | 4be2698 | 2019-06-17 17:41:28 | [diff] [blame] | 107 | |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 108 | return child_path; |
| 109 | } |
| 110 | |
Tom Sepez | 7bf8900 | 2025-07-17 23:44:04 | [diff] [blame] | 111 | ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) |
| 112 | : delegate_(delegate), opening_channel_(false) { |
| 113 | child_process_.Bind(mojo::PendingRemote<mojom::ChildProcess>( |
| 114 | mojo_invitation_->AttachMessagePipe(kChildProcessReceiverAttachmentName), |
| 115 | /*version=*/0)); |
| 116 | receiver_.Bind(mojo::PendingReceiver<mojom::ChildProcessHost>( |
| 117 | mojo_invitation_->AttachMessagePipe( |
| 118 | kChildProcessHostRemoteAttachmentName))); |
| 119 | receiver_.set_disconnect_handler( |
| 120 | base::BindOnce(&ChildProcessHostImpl::OnDisconnectedFromChildProcess, |
| 121 | base::Unretained(this))); |
Ken Rockot | 692493f | 2019-11-18 22:36:57 | [diff] [blame] | 122 | } |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 123 | |
Tom Sepez | 893f420f | 2025-07-01 23:02:30 | [diff] [blame] | 124 | ChildProcessHostImpl::~ChildProcessHostImpl() = default; |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 125 | |
Ken Rockot | ced3127 | 2019-08-02 21:12:18 | [diff] [blame] | 126 | void ChildProcessHostImpl::BindReceiver(mojo::GenericPendingReceiver receiver) { |
| 127 | child_process_->BindReceiver(std::move(receiver)); |
| 128 | } |
| 129 | |
Georg Neis | 35ff854b | 2024-12-17 02:02:08 | [diff] [blame] | 130 | #if BUILDFLAG(IS_CHROMEOS) |
Andrea Orru | 966ff88 | 2022-09-08 03:24:24 | [diff] [blame] | 131 | void ChildProcessHostImpl::ReinitializeLogging( |
| 132 | uint32_t logging_dest, |
| 133 | base::ScopedFD log_file_descriptor) { |
| 134 | auto logging_settings = mojom::LoggingSettings::New(); |
| 135 | logging_settings->logging_dest = logging_dest; |
| 136 | logging_settings->log_file_descriptor = |
| 137 | mojo::PlatformHandle(std::move(log_file_descriptor)); |
| 138 | child_process()->ReinitializeLogging(std::move(logging_settings)); |
| 139 | } |
Georg Neis | 35ff854b | 2024-12-17 02:02:08 | [diff] [blame] | 140 | #endif // BUILDFLAG(IS_CHROMEOS) |
Andrea Orru | 966ff88 | 2022-09-08 03:24:24 | [diff] [blame] | 141 | |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 142 | base::Process& ChildProcessHostImpl::GetPeerProcess() { |
| 143 | if (!peer_process_.IsValid()) { |
| 144 | const base::Process& process = delegate_->GetProcess(); |
| 145 | if (process.IsValid()) { |
| 146 | peer_process_ = base::Process::OpenWithExtraPrivileges(process.Pid()); |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 147 | if (!peer_process_.IsValid()) { |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 148 | peer_process_ = process.Duplicate(); |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 149 | } |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 150 | DCHECK(peer_process_.IsValid()); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | return peer_process_; |
| 155 | } |
| 156 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 157 | void ChildProcessHostImpl::ForceShutdown() { |
Ken Rockot | 62fb435 | 2019-07-18 16:03:38 | [diff] [blame] | 158 | child_process_->ProcessShutdown(); |
[email protected] | bdae981 | 2011-10-15 00:33:03 | [diff] [blame] | 159 | } |
[email protected] | 91443fc | 2010-07-14 05:08:46 | [diff] [blame] | 160 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 161 | std::optional<mojo::OutgoingInvitation>& |
Ken Rockot | 692493f | 2019-11-18 22:36:57 | [diff] [blame] | 162 | ChildProcessHostImpl::GetMojoInvitation() { |
| 163 | return mojo_invitation_; |
| 164 | } |
| 165 | |
rockot | da988790 | 2016-08-19 20:46:42 | [diff] [blame] | 166 | void ChildProcessHostImpl::CreateChannelMojo() { |
Tom Sepez | 7bf8900 | 2025-07-17 23:44:04 | [diff] [blame] | 167 | DCHECK(!channel_); |
| 168 | DCHECK(child_process_); |
Ken Rockot | 10bca42 | 2019-12-04 05:47:59 | [diff] [blame] | 169 | |
Tom Sepez | 7bf8900 | 2025-07-17 23:44:04 | [diff] [blame] | 170 | mojo::ScopedMessagePipeHandle bootstrap = |
| 171 | mojo_invitation_->AttachMessagePipe(kLegacyIpcBootstrapAttachmentName); |
| 172 | channel_ = IPC::ChannelMojo::Create( |
| 173 | std::move(bootstrap), IPC::Channel::MODE_SERVER, this, |
| 174 | base::SingleThreadTaskRunner::GetCurrentDefault(), |
| 175 | base::SingleThreadTaskRunner::GetCurrentDefault()); |
| 176 | |
rockot | da988790 | 2016-08-19 20:46:42 | [diff] [blame] | 177 | DCHECK(channel_); |
| 178 | |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 179 | // Since we're initializing a legacy IPC Channel, we will use its connection |
Tom Sepez | 7bf8900 | 2025-07-17 23:44:04 | [diff] [blame] | 180 | // status to monitor child process lifetime instead of using the status of |
| 181 | // the `receiver_` endpoint. |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 182 | if (receiver_.is_bound()) { |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 183 | receiver_.set_disconnect_handler(base::NullCallback()); |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 184 | } |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 185 | |
rockot | da988790 | 2016-08-19 20:46:42 | [diff] [blame] | 186 | bool initialized = InitChannel(); |
| 187 | DCHECK(initialized); |
| 188 | } |
| 189 | |
amistry | ab52b0c | 2016-06-07 04:22:57 | [diff] [blame] | 190 | bool ChildProcessHostImpl::InitChannel() { |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 191 | if (!channel_->Connect()) { |
amistry | ab52b0c | 2016-06-07 04:22:57 | [diff] [blame] | 192 | return false; |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 193 | } |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 194 | |
sadrul | 6c5aed8c | 2017-01-11 23:11:44 | [diff] [blame] | 195 | delegate_->OnChannelInitialized(channel_.get()); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 196 | opening_channel_ = true; |
| 197 | |
amistry | ab52b0c | 2016-06-07 04:22:57 | [diff] [blame] | 198 | return true; |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 199 | } |
| 200 | |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 201 | void ChildProcessHostImpl::OnDisconnectedFromChildProcess() { |
| 202 | if (channel_) { |
| 203 | opening_channel_ = false; |
| 204 | delegate_->OnChannelError(); |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | // This will delete host_, which will also destroy this! |
| 208 | delegate_->OnChildDisconnected(); |
| 209 | } |
| 210 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 211 | bool ChildProcessHostImpl::IsChannelOpening() { |
| 212 | return opening_channel_; |
| 213 | } |
| 214 | |
Marijn Kruisselbrink | 67f4101 | 2024-04-17 00:35:53 | [diff] [blame] | 215 | // static |
Emily Andrews | 2eab36a | 2024-12-03 20:15:48 | [diff] [blame] | 216 | ChildProcessId ChildProcessHost::GenerateChildProcessUniqueId() { |
| 217 | CHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 3cb7cc953 | 2014-01-08 22:55:51 | [diff] [blame] | 218 | // Historically, this function returned ids started with 1, so in several |
| 219 | // places in the code a value of 0 (rather than kInvalidUniqueID) was used as |
| 220 | // an invalid value. So we retain those semantics. |
Emily Andrews | 2eab36a | 2024-12-03 20:15:48 | [diff] [blame] | 221 | static ChildProcessId::Generator child_process_id_generator; |
| 222 | return child_process_id_generator.GenerateNextId(); |
[email protected] | 4306c379 | 2011-12-02 01:57:53 | [diff] [blame] | 223 | } |
| 224 | |
Emily Andrews | 2eab36a | 2024-12-03 20:15:48 | [diff] [blame] | 225 | uint64_t ChildProcessHostImpl::ChildProcessIdToTracingProcessId( |
| 226 | ChildProcessId child_process_id) { |
ssid | 1050d80 | 2015-07-28 20:28:14 | [diff] [blame] | 227 | // In single process mode, all the children are hosted in the same process, |
| 228 | // therefore the generated memory dump guids should not be conditioned by the |
| 229 | // child process id. The clients need not be aware of SPM and the conversion |
| 230 | // takes care of the SPM special case while translating child process ids to |
| 231 | // tracing process ids. |
| 232 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 233 | switches::kSingleProcess)) { |
chiniforooshan | 6e4c507 | 2017-03-17 07:56:56 | [diff] [blame] | 234 | return memory_instrumentation::mojom::kServiceTracingProcessId; |
Will Harris | cd57b83 | 2023-01-05 20:03:10 | [diff] [blame] | 235 | } |
ssid | 1050d80 | 2015-07-28 20:28:14 | [diff] [blame] | 236 | |
| 237 | // The hash value is incremented so that the tracing id is never equal to |
| 238 | // MemoryDumpManager::kInvalidTracingProcessId. |
Tom Sepez | 5972fdf | 2024-08-05 23:20:00 | [diff] [blame] | 239 | return static_cast<uint64_t>( |
| 240 | base::PersistentHash(base::byte_span_from_ref(child_process_id))) + |
ssid | 1050d80 | 2015-07-28 20:28:14 | [diff] [blame] | 241 | 1; |
| 242 | } |
| 243 | |
Emily Andrews | 2eab36a | 2024-12-03 20:15:48 | [diff] [blame] | 244 | uint64_t ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( |
| 245 | int child_process_id) { |
| 246 | return ChildProcessIdToTracingProcessId(ChildProcessId(child_process_id)); |
| 247 | } |
| 248 | |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 249 | void ChildProcessHostImpl::Ping(PingCallback callback) { |
| 250 | std::move(callback).Run(); |
| 251 | } |
| 252 | |
Ken Rockot | 4f8c3c3 | 2019-08-16 16:32:33 | [diff] [blame] | 253 | void ChildProcessHostImpl::BindHostReceiver( |
| 254 | mojo::GenericPendingReceiver receiver) { |
| 255 | delegate_->BindHostReceiver(std::move(receiver)); |
| 256 | } |
| 257 | |
avi | a9aa7a8 | 2015-12-25 03:06:31 | [diff] [blame] | 258 | void ChildProcessHostImpl::OnChannelConnected(int32_t peer_pid) { |
Lukasz Anforowicz | 2b8b8623 | 2021-08-18 23:35:50 | [diff] [blame] | 259 | // Propagate the pseudonymization salt to all the child processes. |
| 260 | // |
Lukasz Anforowicz | de7891f | 2023-11-08 22:42:55 | [diff] [blame] | 261 | // Doing this as the first step in this method helps to minimize scenarios |
| 262 | // where child process runs code that depends on the pseudonymization salt |
| 263 | // before it has been set. See also https://crbug.com/1479308#c5 |
| 264 | // |
Lukasz Anforowicz | 2b8b8623 | 2021-08-18 23:35:50 | [diff] [blame] | 265 | // TODO(dullweber, lukasza): Figure out if it is possible to reset the salt |
| 266 | // at a regular interval (on the order of hours?). The browser would need |
| 267 | // to be responsible for 1) deciding when the refresh happens and 2) pushing |
| 268 | // the updated salt to all the child processes. |
| 269 | child_process_->SetPseudonymizationSalt(GetPseudonymizationSalt()); |
| 270 | |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 271 | // We ignore the `peer_pid` argument, which ultimately comes over IPC from the |
| 272 | // remote process, in favor of the PID already known by the browser after |
| 273 | // launching the process. This is partly because IPC Channel is being phased |
| 274 | // out and some process types no longer use it, but also because there's |
| 275 | // really no need to get this information from the child process when we |
| 276 | // already have it. |
| 277 | // |
Alison Gale | 53c77f6 | 2024-04-22 15:16:27 | [diff] [blame] | 278 | // TODO(crbug.com/41256971): Remove the peer_pid argument altogether from |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 279 | // IPC::Listener::OnChannelConnected. |
| 280 | const base::Process& peer_process = GetPeerProcess(); |
| 281 | base::ProcessId pid = |
| 282 | peer_process.IsValid() ? peer_process.Pid() : base::GetCurrentProcId(); |
[email protected] | 4cb4310 | 2011-12-02 20:24:49 | [diff] [blame] | 283 | opening_channel_ = false; |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 284 | delegate_->OnChannelConnected(pid); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 285 | } |
| 286 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 287 | void ChildProcessHostImpl::OnChannelError() { |
Ken Rockot | 9836cfb7 | 2021-06-16 23:16:02 | [diff] [blame] | 288 | OnDisconnectedFromChildProcess(); |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 289 | } |
| 290 | |
[email protected] | ef2f6ba | 2014-05-15 23:06:07 | [diff] [blame] | 291 | void ChildProcessHostImpl::OnBadMessageReceived(const IPC::Message& message) { |
| 292 | delegate_->OnBadMessageReceived(message); |
| 293 | } |
| 294 | |
Sebastien Marchand | f552e98 | 2020-09-09 20:19:38 | [diff] [blame] | 295 | #if BUILDFLAG(CLANG_PROFILING_INSIDE_SANDBOX) |
| 296 | void ChildProcessHostImpl::DumpProfilingData(base::OnceClosure callback) { |
| 297 | child_process_->WriteClangProfilingProfile(std::move(callback)); |
| 298 | } |
Will Harris | 6f5f50a | 2021-12-03 17:39:45 | [diff] [blame] | 299 | |
| 300 | void ChildProcessHostImpl::SetProfilingFile(base::File file) { |
| 301 | child_process_->SetProfilingFile(std::move(file)); |
| 302 | } |
Sebastien Marchand | f552e98 | 2020-09-09 20:19:38 | [diff] [blame] | 303 | #endif |
| 304 | |
Takashi Sakamoto | 9fe220a8 | 2022-12-12 16:41:13 | [diff] [blame] | 305 | #if BUILDFLAG(IS_ANDROID) |
| 306 | // Notifies the child process of memory pressure level. |
| 307 | void ChildProcessHostImpl::NotifyMemoryPressureToChildProcess( |
| 308 | base::MemoryPressureListener::MemoryPressureLevel level) { |
| 309 | child_process()->OnMemoryPressure(level); |
| 310 | } |
| 311 | #endif |
| 312 | |
Etienne Pierre-doray | e531336 | 2024-07-18 20:07:24 | [diff] [blame] | 313 | void ChildProcessHostImpl::SetBatterySaverMode( |
| 314 | bool battery_saver_mode_enabled) { |
| 315 | child_process()->SetBatterySaverMode(battery_saver_mode_enabled); |
| 316 | } |
| 317 | |
[email protected] | 4734d0b | 2011-12-03 07:10:44 | [diff] [blame] | 318 | } // namespace content |