chromium/headless/lib/headless_content_main_delegate.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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  // BUILDFLAG(IS_WIN)

#if defined(HEADLESS_USE_EMBEDDED_RESOURCES)
#include "headless/embedded_resource_pack_data.h"     // nogncheck
#include "headless/embedded_resource_pack_strings.h"  // nogncheck
#endif

#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "components/crash/core/app/crashpad.h"
#endif  // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "components/crash/core/app/crash_switches.h"
#endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)

#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 {

// Keep in sync with content/common/content_constants_internal.h.
// TODO(skyostil): Add a tracing test for this.
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() {
  // RegisterClassEx will fail if the session's pool of ATOMs is exhausted. This
  // appears to happen most often when the browser is being driven by automation
  // tools, though the underlying reason for this remains a mystery
  // (https://crbug.com/1470483). There is nothing that Chrome can do to
  // meaningfully run until the user restarts their session by signing out of
  // Windows or restarting their computer.
  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  // BUILDFLAG(IS_WIN)

void InitializeResourceBundle(const base::CommandLine& command_line) {}

void InitApplicationLocale(const base::CommandLine& command_line) {}

void AddSwitchesForVirtualTime() {}

}  // namespace

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  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)

// static
HeadlessContentMainDelegate* HeadlessContentMainDelegate::GetInstance() {}

std::optional<int> HeadlessContentMainDelegate::PreBrowserMain() {}

#if BUILDFLAG(IS_WIN)
bool HeadlessContentMainDelegate::ShouldHandleConsoleControlEvents() {
  // Handle console control events so that orderly shutdown can be performed by
  // HeadlessContentBrowserClient's override of SessionEnding.
  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  // defined(HEADLESS_SUPPORT_FIELD_TRIALS)

}  // namespace headless