
To keep ChildProcessLauncher in line with the base::Process API, SetProcessBackgrounded is renamed to SetProcessPriority and its own callers are updated. The change bubbles up to BrowserChildProcessHostImpl R=boliu@chromium.org Bug: 1466479 Change-Id: I241a45cd3a7470577344bbcc1fc3b943ab4a3073 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4752878 Reviewed-by: Bo Liu <boliu@chromium.org> Commit-Queue: Bo Liu <boliu@chromium.org> Auto-Submit: Patrick Monette <pmonette@chromium.org> Cr-Commit-Position: refs/heads/main@{#1180383}
112 lines
4.0 KiB
C++
112 lines
4.0 KiB
C++
// 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;
|
|
info.status = known_dead ? base::GetKnownDeadTerminationStatus(
|
|
process.process.Handle(), &info.exit_code)
|
|
: base::GetTerminationStatus(
|
|
process.process.Handle(), &info.exit_code);
|
|
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::SetProcessPriorityOnLauncherThread(
|
|
base::Process process,
|
|
base::Process::Priority priority) {}
|
|
|
|
// 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
|