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
|
@ -23,7 +23,6 @@
|
|||
#include "base/trace_event/trace_event.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/common/content_paths.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "electron/fuses.h"
|
||||
#include "shell/browser/api/electron_api_app.h"
|
||||
|
@ -350,20 +349,17 @@ NodeBindings::~NodeBindings() {
|
|||
|
||||
void NodeBindings::RegisterBuiltinBindings() {
|
||||
#define V(modname) _register_##modname();
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
std::string process_type =
|
||||
command_line->GetSwitchValueASCII(::switches::kProcessType);
|
||||
if (process_type.empty()) {
|
||||
if (IsBrowserProcess()) {
|
||||
ELECTRON_BROWSER_BINDINGS(V)
|
||||
#if BUILDFLAG(ENABLE_VIEWS_API)
|
||||
ELECTRON_VIEWS_BINDINGS(V)
|
||||
#endif
|
||||
}
|
||||
ELECTRON_COMMON_BINDINGS(V)
|
||||
if (process_type == ::switches::kRendererProcess) {
|
||||
if (IsRendererProcess()) {
|
||||
ELECTRON_RENDERER_BINDINGS(V)
|
||||
}
|
||||
if (process_type == ::switches::kUtilityProcess) {
|
||||
if (IsUtilityProcess()) {
|
||||
ELECTRON_UTILITY_BINDINGS(V)
|
||||
}
|
||||
#if DCHECK_IS_ON()
|
||||
|
|
|
@ -26,18 +26,29 @@ void EmitWarning(node::Environment* env,
|
|||
emit_warning.Run(warning_msg, warning_type, "");
|
||||
}
|
||||
|
||||
bool IsBrowserProcess() {
|
||||
std::string GetProcessType() {
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
std::string process_type =
|
||||
command_line->GetSwitchValueASCII(switches::kProcessType);
|
||||
return process_type.empty();
|
||||
return command_line->GetSwitchValueASCII(switches::kProcessType);
|
||||
}
|
||||
|
||||
bool IsBrowserProcess() {
|
||||
static bool result = GetProcessType().empty();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IsRendererProcess() {
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
std::string process_type =
|
||||
command_line->GetSwitchValueASCII(switches::kProcessType);
|
||||
return process_type == switches::kRendererProcess;
|
||||
static bool result = GetProcessType() == switches::kRendererProcess;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IsUtilityProcess() {
|
||||
static bool result = GetProcessType() == switches::kUtilityProcess;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IsZygoteProcess() {
|
||||
static bool result = GetProcessType() == switches::kZygoteProcess;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
|
|
@ -17,8 +17,12 @@ void EmitWarning(node::Environment* env,
|
|||
const std::string& warning_msg,
|
||||
const std::string& warning_type);
|
||||
|
||||
std::string GetProcessType();
|
||||
|
||||
bool IsBrowserProcess();
|
||||
bool IsRendererProcess();
|
||||
bool IsUtilityProcess();
|
||||
bool IsZygoteProcess();
|
||||
|
||||
} // namespace electron
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue