#include "content/browser/child_process_launcher.h"
#include <optional>
#include <utility>
#include "base/check_op.h"
#include "base/clang_profiling_buildflags.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/i18n/icu_util.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/process/launch.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "base/tracing/protos/chrome_track_event.pbzero.h"
#include "base/types/expected.h"
#include "base/types/optional_util.h"
#include "build/build_config.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/child_process_binding_types.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "content/browser/child_process_task_port_provider_mac.h"
#endif
namespace content {
namespace {
#if !BUILDFLAG(IS_ANDROID)
std::optional<base::TimeDelta> GetCPUUsage(base::ProcessHandle process_handle) { … }
#endif
}
ChildProcessLauncherHelper;
void RenderProcessPriority::WriteIntoTrace(
perfetto::TracedProto<TraceProto> proto) const { … }
ChildProcessLauncherFileData::ChildProcessLauncherFileData() = default;
ChildProcessLauncherFileData::~ChildProcessLauncherFileData() = default;
#if BUILDFLAG(IS_ANDROID)
bool ChildProcessLauncher::Client::CanUseWarmUpConnection() {
return true;
}
#endif
ChildProcessLauncher::ChildProcessLauncher(
std::unique_ptr<SandboxedProcessLauncherDelegate> delegate,
std::unique_ptr<base::CommandLine> command_line,
int child_process_id,
Client* client,
mojo::OutgoingInvitation mojo_invitation,
const mojo::ProcessErrorCallback& process_error_callback,
std::unique_ptr<ChildProcessLauncherFileData> file_data,
base::UnsafeSharedMemoryRegion histogram_memory_region,
base::ReadOnlySharedMemoryRegion tracing_config_memory_region,
bool terminate_on_shutdown)
: … { … }
ChildProcessLauncher::~ChildProcessLauncher() { … }
#if BUILDFLAG(IS_ANDROID)
void ChildProcessLauncher::SetRenderProcessPriority(
const RenderProcessPriority& priority) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::Process to_pass = process_.process.Duplicate();
GetProcessLauncherTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(
&ChildProcessLauncherHelper::SetRenderProcessPriorityOnLauncherThread,
helper_, std::move(to_pass), priority));
}
#else
void ChildProcessLauncher::SetProcessPriority(
base::Process::Priority priority) { … }
#endif
void ChildProcessLauncher::Notify(ChildProcessLauncherHelper::Process process,
#if BUILDFLAG(IS_WIN)
DWORD last_error,
#endif
int error_code) { … }
bool ChildProcessLauncher::IsStarting() { … }
const base::Process& ChildProcessLauncher::GetProcess() const { … }
ChildProcessTerminationInfo ChildProcessLauncher::GetChildTerminationInfo(
bool known_dead) { … }
bool ChildProcessLauncher::Terminate(int exit_code) { … }
bool ChildProcessLauncher::TerminateProcess(const base::Process& process,
int exit_code) { … }
#if BUILDFLAG(IS_ANDROID)
base::android::ChildBindingState
ChildProcessLauncher::GetEffectiveChildBindingState() {
return helper_->GetEffectiveChildBindingState();
}
void ChildProcessLauncher::DumpProcessStack() {
base::Process to_pass = process_.process.Duplicate();
GetProcessLauncherTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&ChildProcessLauncherHelper::DumpProcessStack,
helper_, std::move(to_pass)));
}
#endif
ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest(
Client* client) { … }
bool RenderProcessPriority::is_background() const { … }
base::Process::Priority RenderProcessPriority::GetProcessPriority() const { … }
bool RenderProcessPriority::operator==(
const RenderProcessPriority& other) const = default;
bool RenderProcessPriority::operator!=(
const RenderProcessPriority& other) const = default;
}