| // Copyright 2023 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "base/mac/mach_port_rendezvous.h" |
| #include "content/browser/child_process_launcher.h" |
| #include "content/browser/child_process_launcher_helper.h" |
| #include "content/browser/child_process_launcher_helper_posix.h" |
| #include "content/public/browser/child_process_launcher_utils.h" |
| |
| namespace content { |
| namespace internal { |
| |
| // TODO(crbug.com/1412835): Fill this class out. |
| |
| absl::optional<mojo::NamedPlatformChannel> |
| ChildProcessLauncherHelper::CreateNamedPlatformChannelOnLauncherThread() { |
| DCHECK(CurrentlyOnProcessLauncherTaskRunner()); |
| return absl::nullopt; |
| } |
| |
| void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() { |
| DCHECK(client_task_runner_->RunsTasksInCurrentSequence()); |
| } |
| |
| std::unique_ptr<PosixFileDescriptorInfo> |
| ChildProcessLauncherHelper::GetFilesToMap() { |
| DCHECK(CurrentlyOnProcessLauncherTaskRunner()); |
| return CreateDefaultPosixFilesToMap( |
| child_process_id(), mojo_channel_->remote_endpoint(), |
| /*files_to_preload=*/{}, GetProcessType(), command_line()); |
| } |
| |
| bool ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread( |
| FileMappedForLaunch& files_to_register, |
| base::LaunchOptions* options) { |
| mojo::PlatformHandle endpoint = |
| mojo_channel_->TakeRemoteEndpoint().TakePlatformHandle(); |
| DCHECK(endpoint.is_valid_mach_receive()); |
| options->mach_ports_for_rendezvous.insert(std::make_pair( |
| 'mojo', base::MachRendezvousPort(endpoint.TakeMachReceiveRight()))); |
| return true; |
| } |
| |
| ChildProcessLauncherHelper::Process |
| ChildProcessLauncherHelper::LaunchProcessOnLauncherThread( |
| const base::LaunchOptions* options, |
| std::unique_ptr<PosixFileDescriptorInfo> files_to_register, |
| bool* is_synchronous_launch, |
| int* launch_result) { |
| DCHECK(options); |
| *is_synchronous_launch = true; |
| ChildProcessLauncherHelper::Process process; |
| process.process = base::LaunchProcess(*command_line(), *options); |
| *launch_result = |
| process.process.IsValid() ? LAUNCH_RESULT_SUCCESS : LAUNCH_RESULT_FAILURE; |
| return process; |
| } |
| |
| bool ChildProcessLauncherHelper::IsUsingLaunchOptions() { |
| return true; |
| } |
| |
| void ChildProcessLauncherHelper::AfterLaunchOnLauncherThread( |
| const ChildProcessLauncherHelper::Process& process, |
| const base::LaunchOptions* options) {} |
| |
| ChildProcessTerminationInfo ChildProcessLauncherHelper::GetTerminationInfo( |
| const ChildProcessLauncherHelper::Process& process, |
| bool known_dead) { |
| ChildProcessTerminationInfo info; |
| return info; |
| } |
| |
| // static |
| bool ChildProcessLauncherHelper::TerminateProcess(const base::Process& process, |
| int exit_code) { |
| // TODO(https://crbug.com/818244): Determine whether we should also call |
| // EnsureProcessTerminated() to make sure of process-exit, and reap it. |
| return process.Terminate(exit_code, false); |
| } |
| |
| // static |
| void ChildProcessLauncherHelper::ForceNormalProcessTerminationSync( |
| ChildProcessLauncherHelper::Process process) { |
| DCHECK(CurrentlyOnProcessLauncherTaskRunner()); |
| // Client has gone away, so just kill the process. Using exit code 0 means |
| // that UMA won't treat this as a crash. |
| process.process.Terminate(RESULT_CODE_NORMAL_EXIT, false); |
| base::EnsureProcessTerminated(std::move(process.process)); |
| } |
| |
| void ChildProcessLauncherHelper::SetProcessBackgroundedOnLauncherThread( |
| base::Process process, |
| bool is_background) {} |
| |
| // static |
| base::File OpenFileToShare(const base::FilePath& path, |
| base::MemoryMappedFile::Region* region) { |
| // Not used yet (until required files are described in the service manifest on |
| // iOS). |
| NOTREACHED(); |
| return base::File(); |
| } |
| |
| } // namespace internal |
| } // namespace content |