#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "content/browser/gpu/gpu_process_host.h"
#include <stddef.h>
#include <algorithm>
#include <list>
#include <memory>
#include <utility>
#include "base/base64.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_pump_type.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/discardable_memory/service/discardable_shared_memory_manager.h"
#include "components/tracing/common/tracing_switches.h"
#include "components/viz/common/features.h"
#include "components/viz/common/switches.h"
#include "content/browser/browser_child_process_host_impl.h"
#include "content/browser/child_process_host_impl.h"
#include "content/browser/child_process_launcher.h"
#include "content/browser/compositor/image_transport_factory.h"
#include "content/browser/gpu/compositor_util.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/browser/gpu/gpu_disk_cache_factory.h"
#include "content/browser/gpu/gpu_main_thread_factory.h"
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/service_worker/service_worker_host.h"
#include "content/browser/storage_partition_impl.h"
#include "content/browser/worker_host/dedicated_worker_host.h"
#include "content/browser/worker_host/dedicated_worker_service_impl.h"
#include "content/browser/worker_host/shared_worker_host.h"
#include "content/browser/worker_host/shared_worker_service_impl.h"
#include "content/common/child_process.mojom.h"
#include "content/common/features.h"
#include "content/common/in_process_child_thread_params.h"
#include "content/public/browser/browser_child_process_host.h"
#include "content/public/browser/browser_main_runner.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/gpu_utils.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h"
#include "content/public/common/zygote/zygote_buildflags.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/config/gpu_driver_bug_list.h"
#include "gpu/config/gpu_driver_bug_workaround_type.h"
#include "gpu/config/gpu_finch_features.h"
#include "gpu/config/gpu_preferences.h"
#include "gpu/config/gpu_switches.h"
#include "gpu/ipc/common/gpu_client_ids.h"
#include "gpu/ipc/common/result_codes.h"
#include "gpu/ipc/host/gpu_disk_cache.h"
#include "media/base/media_switches.h"
#include "media/media_buildflags.h"
#include "mojo/public/cpp/bindings/generic_pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/base/network_isolation_key.h"
#include "sandbox/policy/mojom/sandbox.mojom.h"
#include "sandbox/policy/sandbox_type.h"
#include "sandbox/policy/switches.h"
#include "services/webnn/webnn_switches.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "ui/display/display_switches.h"
#include "ui/gfx/font_render_params.h"
#include "ui/gfx/switches.h"
#include "ui/gl/gl_switches.h"
#include "ui/latency/janky_duration_tracker.h"
#include "ui/latency/latency_info.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/application_status_listener.h"
#else
#include "components/metrics/stability_metrics_helper.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/win/access_token.h"
#include "base/win/security_descriptor.h"
#include "base/win/win_util.h"
#include "components/app_launch_prefetch/app_launch_prefetch.h"
#include "sandbox/policy/win/sandbox_win.h"
#include "sandbox/win/src/sandbox_policy.h"
#include "sandbox/win/src/window.h"
#include "ui/gfx/win/rendering_window_manager.h"
#endif
#if BUILDFLAG(IS_OZONE)
#include "ui/ozone/public/gpu_platform_support_host.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/ozone_switches.h"
#endif
#if BUILDFLAG(USE_ZYGOTE)
#include "content/common/zygote/zygote_handle_impl_linux.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "content/browser/gpu/browser_child_process_backgrounded_bridge.h"
#include "content/browser/gpu/ca_transaction_gpu_coordinator.h"
#endif
namespace content {
base::subtle::Atomic32 GpuProcessHost::gpu_crash_count_ = …;
bool GpuProcessHost::crashed_before_ = …;
int GpuProcessHost::recent_crash_count_ = …;
gpu::GpuMode GpuProcessHost::last_crash_mode_ = …;
static_assert …;
namespace {
constexpr char kFallbackEventCause[] = …;
constexpr char kProcessLifetimeEventsHardwareAccelerated[] = …;
constexpr char kProcessLifetimeEventsSwiftShader[] = …;
const char* GetProcessLifetimeUmaName(gpu::GpuMode gpu_mode) { … }
constexpr int kForgiveGpuCrashMinutes = …;
constexpr int kForgiveDisplayCompositorCrashMinutes = …;
int GetForgiveMinutes(gpu::GpuMode gpu_mode) { … }
enum class GpuTerminationStatus { … };
GpuTerminationStatus ConvertToGpuTerminationStatus(
base::TerminationStatus status) { … }
static const char* const kSwitchNames[] = …;
enum class GPUFallbackEventCauseType { … };
enum GPUProcessLifetimeEvent { … };
GpuProcessHost* g_gpu_process_hosts[GPU_PROCESS_KIND_COUNT];
static void RunCallbackOnUI(
GpuProcessKind kind,
bool force_create,
base::OnceCallback<void(GpuProcessHost*)> callback) { … }
void OnGpuProcessHostDestroyedOnUI(int host_id, const std::string& message) { … }
class GpuSandboxedProcessLauncherDelegate
: public SandboxedProcessLauncherDelegate { … };
void BindDiscardableMemoryReceiverOnIO(
mojo::PendingReceiver<
discardable_memory::mojom::DiscardableSharedMemoryManager> receiver,
discardable_memory::DiscardableSharedMemoryManager* manager) { … }
void BindDiscardableMemoryReceiverOnUI(
mojo::PendingReceiver<
discardable_memory::mojom::DiscardableSharedMemoryManager> receiver) { … }
}
bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { … }
GpuProcessHost* GpuProcessHost::Get(GpuProcessKind kind, bool force_create) { … }
void GpuProcessHost::GetHasGpuProcess(base::OnceCallback<void(bool)> callback) { … }
void GpuProcessHost::CallOnUI(
const base::Location& location,
GpuProcessKind kind,
bool force_create,
base::OnceCallback<void(GpuProcessHost*)> callback) { … }
void GpuProcessHost::BindInterface(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) { … }
#if BUILDFLAG(IS_OZONE)
void GpuProcessHost::TerminateGpuProcess(const std::string& message) { … }
#endif
GpuProcessHost* GpuProcessHost::FromID(int host_id) { … }
int GpuProcessHost::GetGpuCrashCount() { … }
void GpuProcessHost::IncrementCrashCount(gpu::GpuMode gpu_mode) { … }
GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind)
: … { … }
GpuProcessHost::~GpuProcessHost() { … }
bool GpuProcessHost::Init() { … }
void GpuProcessHost::OnProcessLaunched() { … }
void GpuProcessHost::OnProcessLaunchFailed(int error_code) { … }
void GpuProcessHost::OnProcessCrashed(int exit_code) { … }
gpu::GPUInfo GpuProcessHost::GetGPUInfo() const { … }
gpu::GpuFeatureInfo GpuProcessHost::GetGpuFeatureInfo() const { … }
void GpuProcessHost::DidInitialize(
const gpu::GPUInfo& gpu_info,
const gpu::GpuFeatureInfo& gpu_feature_info,
const std::optional<gpu::GPUInfo>& gpu_info_for_hardware_gpu,
const std::optional<gpu::GpuFeatureInfo>& gpu_feature_info_for_hardware_gpu,
const gfx::GpuExtraInfo& gpu_extra_info) { … }
void GpuProcessHost::DidFailInitialize() { … }
void GpuProcessHost::DidCreateContextSuccessfully() { … }
void GpuProcessHost::MaybeShutdownGpuProcess() { … }
void GpuProcessHost::DidUpdateGPUInfo(const gpu::GPUInfo& gpu_info) { … }
#if BUILDFLAG(IS_WIN)
void GpuProcessHost::DidUpdateOverlayInfo(
const gpu::OverlayInfo& overlay_info) {
GpuDataManagerImpl::GetInstance()->UpdateOverlayInfo(overlay_info);
}
void GpuProcessHost::DidUpdateDXGIInfo(gfx::mojom::DXGIInfoPtr dxgi_info) {
GpuDataManagerImpl::GetInstance()->UpdateDXGIInfo(std::move(dxgi_info));
}
#endif
std::string GpuProcessHost::GetIsolationKey(
int32_t process_id,
const blink::WebGPUExecutionContextToken& token) { … }
void GpuProcessHost::BlockDomainsFrom3DAPIs(const std::set<GURL>& urls,
gpu::DomainGuilt guilt) { … }
bool GpuProcessHost::GpuAccessAllowed() const { … }
void GpuProcessHost::DisableGpuCompositing() { … }
gpu::GpuDiskCacheFactory* GpuProcessHost::GetGpuDiskCacheFactory() { … }
void GpuProcessHost::RecordLogMessage(int32_t severity,
const std::string& header,
const std::string& message) { … }
void GpuProcessHost::BindDiscardableMemoryReceiver(
mojo::PendingReceiver<
discardable_memory::mojom::DiscardableSharedMemoryManager> receiver) { … }
GpuProcessKind GpuProcessHost::kind() { … }
void GpuProcessHost::ForceShutdown() { … }
void GpuProcessHost::DumpProcessStack() { … }
void GpuProcessHost::RunServiceImpl(mojo::GenericPendingReceiver receiver) { … }
bool GpuProcessHost::LaunchGpuProcess() { … }
void GpuProcessHost::SendOutstandingReplies() { … }
int GpuProcessHost::GetFallbackCrashLimit() const { … }
void GpuProcessHost::RecordProcessCrash() { … }
viz::mojom::GpuService* GpuProcessHost::gpu_service() { … }
#if BUILDFLAG(IS_WIN)
viz::mojom::InfoCollectionGpuService*
GpuProcessHost::info_collection_gpu_service() {
DCHECK(gpu_host_);
return gpu_host_->info_collection_gpu_service();
}
#endif
int GpuProcessHost::GetIDForTesting() const { … }
#if !BUILDFLAG(IS_ANDROID)
void GpuProcessHost::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel level) { … }
#endif
}