#include "headless/lib/headless_content_main_delegate.h"
#include <cstdint>
#include <memory>
#include <utility>
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/path_service.h"
#include "base/process/current_process.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "cc/base/switches.h"
#include "components/crash/core/common/crash_key.h"
#include "components/crash/core/common/crash_keys.h"
#include "components/devtools/devtools_pipe/devtools_pipe.h"
#include "components/viz/common/switches.h"
#include "content/public/browser/browser_main_runner.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
#include "content/public/common/profiling.h"
#include "gpu/config/gpu_switches.h"
#include "headless/lib/browser/command_line_handler.h"
#include "headless/lib/browser/headless_browser_impl.h"
#include "headless/lib/browser/headless_content_browser_client.h"
#include "headless/lib/headless_crash_reporter_client.h"
#include "headless/lib/renderer/headless_content_renderer_client.h"
#include "headless/lib/utility/headless_content_utility_client.h"
#include "headless/public/switches.h"
#include "sandbox/policy/switches.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/common/switches.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/switches.h"
#include "ui/gl/gl_switches.h"
#include "ui/ozone/public/ozone_switches.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/resource_exhaustion.h"
#endif
#if defined(HEADLESS_USE_EMBEDDED_RESOURCES)
#include "headless/embedded_resource_pack_data.h"
#include "headless/embedded_resource_pack_strings.h"
#endif
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "components/crash/core/app/crashpad.h"
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "components/crash/core/app/crash_switches.h"
#endif
#if BUILDFLAG(IS_POSIX)
#include <signal.h>
#endif
#if defined(HEADLESS_USE_PREFS)
#include "components/prefs/pref_service.h"
#endif
#if defined(HEADLESS_SUPPORT_FIELD_TRIALS)
#include "content/public/app/initialize_mojo_core.h"
#include "headless/lib/browser/headless_field_trials.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#endif
namespace headless {
namespace features {
BASE_FEATURE(…);
}
const base::FilePath::CharType kDefaultProfileName[] = …);
namespace {
const int kTraceEventBrowserProcessSortIndex = …;
HeadlessContentMainDelegate* g_current_headless_content_main_delegate = …;
#if !BUILDFLAG(IS_FUCHSIA)
base::LazyInstance<HeadlessCrashReporterClient>::Leaky g_headless_crash_client = …;
#endif
const char kLogFileName[] = …;
const char kHeadlessCrashKey[] = …;
#if BUILDFLAG(IS_WIN)
void OnResourceExhausted() {
LOG(ERROR) << "Your computer has run out of resources. "
"Sign out of Windows or restart your computer and try again.";
base::Process::TerminateCurrentProcessImmediately(EXIT_FAILURE);
}
#endif
void InitializeResourceBundle(const base::CommandLine& command_line) { … }
void InitApplicationLocale(const base::CommandLine& command_line) { … }
void AddSwitchesForVirtualTime() { … }
}
HeadlessContentMainDelegate::HeadlessContentMainDelegate(
std::unique_ptr<HeadlessBrowserImpl> browser)
: … { … }
HeadlessContentMainDelegate::~HeadlessContentMainDelegate() { … }
std::optional<int> HeadlessContentMainDelegate::BasicStartupComplete() { … }
void HeadlessContentMainDelegate::InitLogging(
const base::CommandLine& command_line) { … }
void HeadlessContentMainDelegate::InitCrashReporter(
const base::CommandLine& command_line) { … }
void HeadlessContentMainDelegate::PreSandboxStartup() { … }
absl::variant<int, content::MainFunctionParams>
HeadlessContentMainDelegate::RunProcess(
const std::string& process_type,
content::MainFunctionParams main_function_params) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
void SIGTERMProfilingShutdown(int signal) { … }
void SetUpProfilingShutdownHandler() { … }
void HeadlessContentMainDelegate::ZygoteForked() { … }
#endif
HeadlessContentMainDelegate* HeadlessContentMainDelegate::GetInstance() { … }
std::optional<int> HeadlessContentMainDelegate::PreBrowserMain() { … }
#if BUILDFLAG(IS_WIN)
bool HeadlessContentMainDelegate::ShouldHandleConsoleControlEvents() {
return true;
}
#endif
content::ContentClient* HeadlessContentMainDelegate::CreateContentClient() { … }
content::ContentBrowserClient*
HeadlessContentMainDelegate::CreateContentBrowserClient() { … }
content::ContentRendererClient*
HeadlessContentMainDelegate::CreateContentRendererClient() { … }
content::ContentUtilityClient*
HeadlessContentMainDelegate::CreateContentUtilityClient() { … }
std::optional<int> HeadlessContentMainDelegate::PostEarlyInitialization(
InvokedIn invoked_in) { … }
#if defined(HEADLESS_SUPPORT_FIELD_TRIALS)
bool HeadlessContentMainDelegate::ShouldCreateFeatureList(
InvokedIn invoked_in) { … }
bool HeadlessContentMainDelegate::ShouldInitializeMojo(InvokedIn invoked_in) { … }
#endif
}