refactor: use process_util.h
helpers (#38574)
refactor: use process_util.h helpers
This commit is contained in:
parent
8d689c565a
commit
bb2ba35b51
6 changed files with 41 additions and 41 deletions
|
@ -22,6 +22,7 @@
|
||||||
#include "ppapi/buildflags/buildflags.h"
|
#include "ppapi/buildflags/buildflags.h"
|
||||||
#include "shell/common/electron_paths.h"
|
#include "shell/common/electron_paths.h"
|
||||||
#include "shell/common/options_switches.h"
|
#include "shell/common/options_switches.h"
|
||||||
|
#include "shell/common/process_util.h"
|
||||||
#include "third_party/widevine/cdm/buildflags.h"
|
#include "third_party/widevine/cdm/buildflags.h"
|
||||||
#include "ui/base/l10n/l10n_util.h"
|
#include "ui/base/l10n/l10n_util.h"
|
||||||
#include "ui/base/resource/resource_bundle.h"
|
#include "ui/base/resource/resource_bundle.h"
|
||||||
|
@ -148,16 +149,13 @@ base::RefCountedMemory* ElectronContentClient::GetDataResourceBytes(
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronContentClient::AddAdditionalSchemes(Schemes* schemes) {
|
void ElectronContentClient::AddAdditionalSchemes(Schemes* schemes) {
|
||||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
||||||
std::string process_type =
|
|
||||||
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
|
||||||
// Browser Process registration happens in
|
// Browser Process registration happens in
|
||||||
// `api::Protocol::RegisterSchemesAsPrivileged`
|
// `api::Protocol::RegisterSchemesAsPrivileged`
|
||||||
//
|
//
|
||||||
// Renderer Process registration happens in `RendererClientBase`
|
// Renderer Process registration happens in `RendererClientBase`
|
||||||
//
|
//
|
||||||
// We use this for registration to network utility process
|
// We use this for registration to network utility process
|
||||||
if (process_type == ::switches::kUtilityProcess) {
|
if (IsUtilityProcess()) {
|
||||||
AppendDelimitedSwitchToVector(switches::kServiceWorkerSchemes,
|
AppendDelimitedSwitchToVector(switches::kServiceWorkerSchemes,
|
||||||
&schemes->service_worker_schemes);
|
&schemes->service_worker_schemes);
|
||||||
AppendDelimitedSwitchToVector(switches::kStandardSchemes,
|
AppendDelimitedSwitchToVector(switches::kStandardSchemes,
|
||||||
|
|
|
@ -316,9 +316,7 @@ absl::optional<int> ElectronMainDelegate::BasicStartupComplete() {
|
||||||
|
|
||||||
void ElectronMainDelegate::PreSandboxStartup() {
|
void ElectronMainDelegate::PreSandboxStartup() {
|
||||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||||
|
std::string process_type = GetProcessType();
|
||||||
std::string process_type =
|
|
||||||
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
|
||||||
|
|
||||||
base::FilePath user_data_dir =
|
base::FilePath user_data_dir =
|
||||||
command_line->GetSwitchValuePath(::switches::kUserDataDir);
|
command_line->GetSwitchValuePath(::switches::kUserDataDir);
|
||||||
|
@ -335,9 +333,9 @@ void ElectronMainDelegate::PreSandboxStartup() {
|
||||||
// know the correct user-data directory. (And, further, accessing the
|
// know the correct user-data directory. (And, further, accessing the
|
||||||
// application name on Linux can cause glib calls that end up spawning
|
// application name on Linux can cause glib calls that end up spawning
|
||||||
// threads, which if done before the zygote is booted, causes a CHECK().)
|
// threads, which if done before the zygote is booted, causes a CHECK().)
|
||||||
logging::InitElectronLogging(*command_line,
|
logging::InitElectronLogging(
|
||||||
/* is_preinit = */ process_type.empty() ||
|
*command_line,
|
||||||
process_type == ::switches::kZygoteProcess);
|
/* is_preinit = */ IsBrowserProcess() || IsZygoteProcess());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !IS_MAS_BUILD()
|
#if !IS_MAS_BUILD()
|
||||||
|
@ -356,7 +354,7 @@ void ElectronMainDelegate::PreSandboxStartup() {
|
||||||
// In the main process, we wait for JS to call crashReporter.start() before
|
// In the main process, we wait for JS to call crashReporter.start() before
|
||||||
// initializing crashpad. If we're in the renderer, we want to initialize it
|
// initializing crashpad. If we're in the renderer, we want to initialize it
|
||||||
// immediately at boot.
|
// immediately at boot.
|
||||||
if (!process_type.empty()) {
|
if (!IsBrowserProcess()) {
|
||||||
ElectronCrashReporterClient::Create();
|
ElectronCrashReporterClient::Create();
|
||||||
crash_reporter::InitializeCrashpad(false, process_type);
|
crash_reporter::InitializeCrashpad(false, process_type);
|
||||||
}
|
}
|
||||||
|
@ -364,7 +362,7 @@ void ElectronMainDelegate::PreSandboxStartup() {
|
||||||
|
|
||||||
#if BUILDFLAG(IS_LINUX)
|
#if BUILDFLAG(IS_LINUX)
|
||||||
// Zygote needs to call InitCrashReporter() in RunZygote().
|
// Zygote needs to call InitCrashReporter() in RunZygote().
|
||||||
if (process_type != ::switches::kZygoteProcess && !process_type.empty()) {
|
if (!IsZygoteProcess() && !IsBrowserProcess()) {
|
||||||
ElectronCrashReporterClient::Create();
|
ElectronCrashReporterClient::Create();
|
||||||
if (command_line->HasSwitch(
|
if (command_line->HasSwitch(
|
||||||
crash_reporter::switches::kCrashpadHandlerPid)) {
|
crash_reporter::switches::kCrashpadHandlerPid)) {
|
||||||
|
@ -414,12 +412,8 @@ absl::optional<int> ElectronMainDelegate::PreBrowserMain() {
|
||||||
}
|
}
|
||||||
|
|
||||||
base::StringPiece ElectronMainDelegate::GetBrowserV8SnapshotFilename() {
|
base::StringPiece ElectronMainDelegate::GetBrowserV8SnapshotFilename() {
|
||||||
const base::CommandLine* command_line =
|
|
||||||
base::CommandLine::ForCurrentProcess();
|
|
||||||
std::string process_type =
|
|
||||||
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
|
||||||
bool load_browser_process_specific_v8_snapshot =
|
bool load_browser_process_specific_v8_snapshot =
|
||||||
process_type.empty() &&
|
IsBrowserProcess() &&
|
||||||
electron::fuses::IsLoadBrowserProcessSpecificV8SnapshotEnabled();
|
electron::fuses::IsLoadBrowserProcessSpecificV8SnapshotEnabled();
|
||||||
if (load_browser_process_specific_v8_snapshot) {
|
if (load_browser_process_specific_v8_snapshot) {
|
||||||
return "browser_v8_context_snapshot.bin";
|
return "browser_v8_context_snapshot.bin";
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "shell/common/gin_converters/time_converter.h"
|
#include "shell/common/gin_converters/time_converter.h"
|
||||||
#include "shell/common/gin_helper/dictionary.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
#include "shell/common/process_util.h"
|
||||||
#include "shell/common/thread_restrictions.h"
|
#include "shell/common/thread_restrictions.h"
|
||||||
|
|
||||||
#if !IS_MAS_BUILD()
|
#if !IS_MAS_BUILD()
|
||||||
|
@ -142,17 +143,13 @@ void Start(const std::string& submit_url,
|
||||||
ElectronCrashReporterClient::Get()->SetShouldRateLimit(rate_limit);
|
ElectronCrashReporterClient::Get()->SetShouldRateLimit(rate_limit);
|
||||||
ElectronCrashReporterClient::Get()->SetShouldCompressUploads(compress);
|
ElectronCrashReporterClient::Get()->SetShouldCompressUploads(compress);
|
||||||
ElectronCrashReporterClient::Get()->SetGlobalAnnotations(global_extra);
|
ElectronCrashReporterClient::Get()->SetGlobalAnnotations(global_extra);
|
||||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
std::string process_type = is_node_process ? "node" : GetProcessType();
|
||||||
std::string process_type =
|
|
||||||
is_node_process
|
|
||||||
? "node"
|
|
||||||
: command_line->GetSwitchValueASCII(::switches::kProcessType);
|
|
||||||
#if BUILDFLAG(IS_LINUX)
|
#if BUILDFLAG(IS_LINUX)
|
||||||
for (const auto& pair : extra)
|
for (const auto& pair : extra)
|
||||||
electron::crash_keys::SetCrashKey(pair.first, pair.second);
|
electron::crash_keys::SetCrashKey(pair.first, pair.second);
|
||||||
{
|
{
|
||||||
electron::ScopedAllowBlockingForElectron allow_blocking;
|
electron::ScopedAllowBlockingForElectron allow_blocking;
|
||||||
::crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
|
::crash_reporter::InitializeCrashpad(IsBrowserProcess(), process_type);
|
||||||
}
|
}
|
||||||
if (ignore_system_crash_handler) {
|
if (ignore_system_crash_handler) {
|
||||||
crashpad::CrashpadInfo::GetCrashpadInfo()
|
crashpad::CrashpadInfo::GetCrashpadInfo()
|
||||||
|
@ -161,7 +158,7 @@ void Start(const std::string& submit_url,
|
||||||
#elif BUILDFLAG(IS_MAC)
|
#elif BUILDFLAG(IS_MAC)
|
||||||
for (const auto& pair : extra)
|
for (const auto& pair : extra)
|
||||||
electron::crash_keys::SetCrashKey(pair.first, pair.second);
|
electron::crash_keys::SetCrashKey(pair.first, pair.second);
|
||||||
::crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
|
::crash_reporter::InitializeCrashpad(IsBrowserProcess(), process_type);
|
||||||
if (ignore_system_crash_handler) {
|
if (ignore_system_crash_handler) {
|
||||||
crashpad::CrashpadInfo::GetCrashpadInfo()
|
crashpad::CrashpadInfo::GetCrashpadInfo()
|
||||||
->set_system_crash_reporter_forwarding(crashpad::TriState::kDisabled);
|
->set_system_crash_reporter_forwarding(crashpad::TriState::kDisabled);
|
||||||
|
@ -172,8 +169,8 @@ void Start(const std::string& submit_url,
|
||||||
base::FilePath user_data_dir;
|
base::FilePath user_data_dir;
|
||||||
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
|
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
|
||||||
::crash_reporter::InitializeCrashpadWithEmbeddedHandler(
|
::crash_reporter::InitializeCrashpadWithEmbeddedHandler(
|
||||||
process_type.empty(), process_type,
|
IsBrowserProcess(), process_type, base::WideToUTF8(user_data_dir.value()),
|
||||||
base::WideToUTF8(user_data_dir.value()), base::FilePath());
|
base::FilePath());
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "base/trace_event/trace_event.h"
|
#include "base/trace_event/trace_event.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/common/content_paths.h"
|
#include "content/public/common/content_paths.h"
|
||||||
#include "content/public/common/content_switches.h"
|
|
||||||
#include "electron/buildflags/buildflags.h"
|
#include "electron/buildflags/buildflags.h"
|
||||||
#include "electron/fuses.h"
|
#include "electron/fuses.h"
|
||||||
#include "shell/browser/api/electron_api_app.h"
|
#include "shell/browser/api/electron_api_app.h"
|
||||||
|
@ -350,20 +349,17 @@ NodeBindings::~NodeBindings() {
|
||||||
|
|
||||||
void NodeBindings::RegisterBuiltinBindings() {
|
void NodeBindings::RegisterBuiltinBindings() {
|
||||||
#define V(modname) _register_##modname();
|
#define V(modname) _register_##modname();
|
||||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
if (IsBrowserProcess()) {
|
||||||
std::string process_type =
|
|
||||||
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
|
||||||
if (process_type.empty()) {
|
|
||||||
ELECTRON_BROWSER_BINDINGS(V)
|
ELECTRON_BROWSER_BINDINGS(V)
|
||||||
#if BUILDFLAG(ENABLE_VIEWS_API)
|
#if BUILDFLAG(ENABLE_VIEWS_API)
|
||||||
ELECTRON_VIEWS_BINDINGS(V)
|
ELECTRON_VIEWS_BINDINGS(V)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
ELECTRON_COMMON_BINDINGS(V)
|
ELECTRON_COMMON_BINDINGS(V)
|
||||||
if (process_type == ::switches::kRendererProcess) {
|
if (IsRendererProcess()) {
|
||||||
ELECTRON_RENDERER_BINDINGS(V)
|
ELECTRON_RENDERER_BINDINGS(V)
|
||||||
}
|
}
|
||||||
if (process_type == ::switches::kUtilityProcess) {
|
if (IsUtilityProcess()) {
|
||||||
ELECTRON_UTILITY_BINDINGS(V)
|
ELECTRON_UTILITY_BINDINGS(V)
|
||||||
}
|
}
|
||||||
#if DCHECK_IS_ON()
|
#if DCHECK_IS_ON()
|
||||||
|
|
|
@ -26,18 +26,29 @@ void EmitWarning(node::Environment* env,
|
||||||
emit_warning.Run(warning_msg, warning_type, "");
|
emit_warning.Run(warning_msg, warning_type, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsBrowserProcess() {
|
std::string GetProcessType() {
|
||||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||||
std::string process_type =
|
return command_line->GetSwitchValueASCII(switches::kProcessType);
|
||||||
command_line->GetSwitchValueASCII(switches::kProcessType);
|
}
|
||||||
return process_type.empty();
|
|
||||||
|
bool IsBrowserProcess() {
|
||||||
|
static bool result = GetProcessType().empty();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsRendererProcess() {
|
bool IsRendererProcess() {
|
||||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
static bool result = GetProcessType() == switches::kRendererProcess;
|
||||||
std::string process_type =
|
return result;
|
||||||
command_line->GetSwitchValueASCII(switches::kProcessType);
|
}
|
||||||
return process_type == switches::kRendererProcess;
|
|
||||||
|
bool IsUtilityProcess() {
|
||||||
|
static bool result = GetProcessType() == switches::kUtilityProcess;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsZygoteProcess() {
|
||||||
|
static bool result = GetProcessType() == switches::kZygoteProcess;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
|
@ -17,8 +17,12 @@ void EmitWarning(node::Environment* env,
|
||||||
const std::string& warning_msg,
|
const std::string& warning_msg,
|
||||||
const std::string& warning_type);
|
const std::string& warning_type);
|
||||||
|
|
||||||
|
std::string GetProcessType();
|
||||||
|
|
||||||
bool IsBrowserProcess();
|
bool IsBrowserProcess();
|
||||||
bool IsRendererProcess();
|
bool IsRendererProcess();
|
||||||
|
bool IsUtilityProcess();
|
||||||
|
bool IsZygoteProcess();
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue