#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "content/browser/child_process_host_impl.h"
#include <limits>
#include <tuple>
#include "base/atomic_sequence_num.h"
#include "base/clang_profiling_buildflags.h"
#include "base/command_line.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/hash/hash.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_math.h"
#include "base/path_service.h"
#include "base/process/process_metrics.h"
#include "base/rand_util.h"
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "content/common/content_constants_internal.h"
#include "content/common/pseudonymization_salt.h"
#include "content/public/browser/child_process_host_delegate.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h"
#include "ipc/ipc.mojom.h"
#include "ipc/ipc_channel.h"
#include "ipc/ipc_channel_mojo.h"
#include "ipc/ipc_logging.h"
#include "ipc/message_filter.h"
#include "services/resource_coordinator/public/mojom/memory_instrumentation/constants.mojom.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "base/linux_util.h"
#elif BUILDFLAG(IS_MAC)
#include "base/apple/foundation_util.h"
#include "content/browser/mac_helpers.h"
#endif
namespace {
base::AtomicSequenceNumber g_unique_id;
}
namespace content {
ChildProcessHost::~ChildProcessHost() = default;
std::unique_ptr<ChildProcessHost> ChildProcessHost::Create(
ChildProcessHostDelegate* delegate,
IpcMode ipc_mode) { … }
base::FilePath ChildProcessHost::GetChildPath(int flags) { … }
ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate,
IpcMode ipc_mode)
: … { … }
ChildProcessHostImpl::~ChildProcessHostImpl() { … }
#if BUILDFLAG(CONTENT_ENABLE_LEGACY_IPC)
void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) {
filters_.push_back(filter);
if (channel_) {
filter->OnFilterAdded(channel_.get());
}
}
#endif
void ChildProcessHostImpl::BindReceiver(mojo::GenericPendingReceiver receiver) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
void ChildProcessHostImpl::ReinitializeLogging(
uint32_t logging_dest,
base::ScopedFD log_file_descriptor) {
auto logging_settings = mojom::LoggingSettings::New();
logging_settings->logging_dest = logging_dest;
logging_settings->log_file_descriptor =
mojo::PlatformHandle(std::move(log_file_descriptor));
child_process()->ReinitializeLogging(std::move(logging_settings));
}
#endif
base::Process& ChildProcessHostImpl::GetPeerProcess() { … }
void ChildProcessHostImpl::ForceShutdown() { … }
std::optional<mojo::OutgoingInvitation>&
ChildProcessHostImpl::GetMojoInvitation() { … }
void ChildProcessHostImpl::CreateChannelMojo() { … }
bool ChildProcessHostImpl::InitChannel() { … }
void ChildProcessHostImpl::OnDisconnectedFromChildProcess() { … }
bool ChildProcessHostImpl::IsChannelOpening() { … }
bool ChildProcessHostImpl::Send(IPC::Message* message) { … }
int ChildProcessHost::GenerateChildProcessUniqueId() { … }
uint64_t ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId(
int child_process_id) { … }
void ChildProcessHostImpl::Ping(PingCallback callback) { … }
void ChildProcessHostImpl::BindHostReceiver(
mojo::GenericPendingReceiver receiver) { … }
bool ChildProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { … }
void ChildProcessHostImpl::OnChannelConnected(int32_t peer_pid) { … }
void ChildProcessHostImpl::OnChannelError() { … }
void ChildProcessHostImpl::OnBadMessageReceived(const IPC::Message& message) { … }
#if BUILDFLAG(CLANG_PROFILING_INSIDE_SANDBOX)
void ChildProcessHostImpl::DumpProfilingData(base::OnceClosure callback) {
child_process_->WriteClangProfilingProfile(std::move(callback));
}
void ChildProcessHostImpl::SetProfilingFile(base::File file) {
child_process_->SetProfilingFile(std::move(file));
}
#endif
#if BUILDFLAG(IS_ANDROID)
void ChildProcessHostImpl::NotifyMemoryPressureToChildProcess(
base::MemoryPressureListener::MemoryPressureLevel level) {
child_process()->OnMemoryPressure(level);
}
#endif
void ChildProcessHostImpl::SetBatterySaverMode(
bool battery_saver_mode_enabled) { … }
}