refactor: reduce scope of relauncher's internal constants (#44894)
* refactor: make kRelauncherArgSeparator private to relauncher.cc Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: make kRelauncherTypeArg private to relauncher.cc Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: remove unused type relauncher::CharType Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: move private constants into standalone private namespace Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: move kWaitEventName into the only function that uses it Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
8f790e4e3f
commit
1f4d5cd564
3 changed files with 24 additions and 24 deletions
|
@ -23,6 +23,24 @@
|
||||||
#include "base/posix/eintr_wrapper.h"
|
#include "base/posix/eintr_wrapper.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// The argument separating arguments intended for the relauncher process from
|
||||||
|
// those intended for the relaunched process. "---" is chosen instead of "--"
|
||||||
|
// because CommandLine interprets "--" as meaning "end of switches", but
|
||||||
|
// for many purposes, the relauncher process' CommandLine ought to interpret
|
||||||
|
// arguments intended for the relaunched process, to get the correct settings
|
||||||
|
// for such things as logging and the user-data-dir in case it affects crash
|
||||||
|
// reporting.
|
||||||
|
constexpr base::CommandLine::CharType kRelauncherArgSeparator[] =
|
||||||
|
FILE_PATH_LITERAL("---");
|
||||||
|
|
||||||
|
// The "type" argument identifying a relauncher process ("--type=relauncher").
|
||||||
|
constexpr base::CommandLine::CharType kRelauncherTypeArg[] =
|
||||||
|
FILE_PATH_LITERAL("--type=relauncher");
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
namespace relauncher {
|
namespace relauncher {
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
@ -31,9 +49,6 @@ namespace internal {
|
||||||
const int kRelauncherSyncFD = STDERR_FILENO + 1;
|
const int kRelauncherSyncFD = STDERR_FILENO + 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const CharType* kRelauncherTypeArg = FILE_PATH_LITERAL("--type=relauncher");
|
|
||||||
const CharType* kRelauncherArgSeparator = FILE_PATH_LITERAL("---");
|
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
bool RelaunchApp(const StringVector& argv) {
|
bool RelaunchApp(const StringVector& argv) {
|
||||||
|
@ -58,7 +73,7 @@ bool RelaunchAppWithHelper(const base::FilePath& helper,
|
||||||
const StringVector& argv) {
|
const StringVector& argv) {
|
||||||
StringVector relaunch_argv;
|
StringVector relaunch_argv;
|
||||||
relaunch_argv.push_back(helper.value());
|
relaunch_argv.push_back(helper.value());
|
||||||
relaunch_argv.push_back(internal::kRelauncherTypeArg);
|
relaunch_argv.push_back(kRelauncherTypeArg);
|
||||||
// Relauncher process has its own --type=relauncher which
|
// Relauncher process has its own --type=relauncher which
|
||||||
// is not recognized by the service_manager, explicitly set
|
// is not recognized by the service_manager, explicitly set
|
||||||
// the sandbox type to avoid CHECK failure in
|
// the sandbox type to avoid CHECK failure in
|
||||||
|
@ -68,7 +83,7 @@ bool RelaunchAppWithHelper(const base::FilePath& helper,
|
||||||
relaunch_argv.insert(relaunch_argv.end(), relauncher_args.begin(),
|
relaunch_argv.insert(relaunch_argv.end(), relauncher_args.begin(),
|
||||||
relauncher_args.end());
|
relauncher_args.end());
|
||||||
|
|
||||||
relaunch_argv.push_back(internal::kRelauncherArgSeparator);
|
relaunch_argv.push_back(kRelauncherArgSeparator);
|
||||||
|
|
||||||
relaunch_argv.insert(relaunch_argv.end(), argv.begin(), argv.end());
|
relaunch_argv.insert(relaunch_argv.end(), argv.begin(), argv.end());
|
||||||
|
|
||||||
|
@ -147,7 +162,7 @@ bool RelaunchAppWithHelper(const base::FilePath& helper,
|
||||||
int RelauncherMain(const content::MainFunctionParams& main_parameters) {
|
int RelauncherMain(const content::MainFunctionParams& main_parameters) {
|
||||||
const StringVector& argv = electron::ElectronCommandLine::argv();
|
const StringVector& argv = electron::ElectronCommandLine::argv();
|
||||||
|
|
||||||
if (argv.size() < 4 || argv[1] != internal::kRelauncherTypeArg) {
|
if (argv.size() < 4 || argv[1] != kRelauncherTypeArg) {
|
||||||
LOG(ERROR) << "relauncher process invoked with unexpected arguments";
|
LOG(ERROR) << "relauncher process invoked with unexpected arguments";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +177,7 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) {
|
||||||
for (size_t argv_index = 2; argv_index < argv.size(); ++argv_index) {
|
for (size_t argv_index = 2; argv_index < argv.size(); ++argv_index) {
|
||||||
const StringType& arg(argv[argv_index]);
|
const StringType& arg(argv[argv_index]);
|
||||||
if (!in_relauncher_args) {
|
if (!in_relauncher_args) {
|
||||||
if (arg == internal::kRelauncherArgSeparator) {
|
if (arg == kRelauncherArgSeparator) {
|
||||||
in_relauncher_args = true;
|
in_relauncher_args = true;
|
||||||
} else {
|
} else {
|
||||||
relauncher_args.push_back(arg);
|
relauncher_args.push_back(arg);
|
||||||
|
|
|
@ -41,7 +41,6 @@ struct MainFunctionParams;
|
||||||
|
|
||||||
namespace relauncher {
|
namespace relauncher {
|
||||||
|
|
||||||
using CharType = base::CommandLine::CharType;
|
|
||||||
using StringType = base::CommandLine::StringType;
|
using StringType = base::CommandLine::StringType;
|
||||||
using StringVector = base::CommandLine::StringVector;
|
using StringVector = base::CommandLine::StringVector;
|
||||||
|
|
||||||
|
@ -83,18 +82,6 @@ namespace internal {
|
||||||
extern const int kRelauncherSyncFD;
|
extern const int kRelauncherSyncFD;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// The "type" argument identifying a relauncher process ("--type=relauncher").
|
|
||||||
extern const CharType* kRelauncherTypeArg;
|
|
||||||
|
|
||||||
// The argument separating arguments intended for the relauncher process from
|
|
||||||
// those intended for the relaunched process. "---" is chosen instead of "--"
|
|
||||||
// because CommandLine interprets "--" as meaning "end of switches", but
|
|
||||||
// for many purposes, the relauncher process' CommandLine ought to interpret
|
|
||||||
// arguments intended for the relaunched process, to get the correct settings
|
|
||||||
// for such things as logging and the user-data-dir in case it affects crash
|
|
||||||
// reporting.
|
|
||||||
extern const CharType* kRelauncherArgSeparator;
|
|
||||||
|
|
||||||
#if BUILDFLAG(IS_WIN)
|
#if BUILDFLAG(IS_WIN)
|
||||||
StringType GetWaitEventName(base::ProcessId pid);
|
StringType GetWaitEventName(base::ProcessId pid);
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,6 @@ namespace relauncher::internal {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const CharType* kWaitEventName = L"ElectronRelauncherWaitEvent";
|
|
||||||
|
|
||||||
struct PROCESS_BASIC_INFORMATION {
|
struct PROCESS_BASIC_INFORMATION {
|
||||||
union {
|
union {
|
||||||
NTSTATUS ExitStatus;
|
NTSTATUS ExitStatus;
|
||||||
|
@ -100,8 +98,8 @@ StringType AddQuoteForArg(const StringType& arg) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
StringType GetWaitEventName(base::ProcessId pid) {
|
StringType GetWaitEventName(base::ProcessId pid) {
|
||||||
return base::StrCat(
|
return base::StrCat({L"ElectronRelauncherWaitEvent-",
|
||||||
{kWaitEventName, L"-", base::NumberToWString(static_cast<int>(pid))});
|
base::NumberToWString(static_cast<int>(pid))});
|
||||||
}
|
}
|
||||||
|
|
||||||
StringType ArgvToCommandLineString(const StringVector& argv) {
|
StringType ArgvToCommandLineString(const StringVector& argv) {
|
||||||
|
|
Loading…
Reference in a new issue