refactor: reduce scope of relauncher's internal constants (#44892)
* 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
a92b3944a1
commit
dc0c6c6f3f
3 changed files with 24 additions and 24 deletions
|
@ -23,6 +23,24 @@
|
|||
#include "base/posix/eintr_wrapper.h"
|
||||
#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 internal {
|
||||
|
@ -31,9 +49,6 @@ namespace internal {
|
|||
const int kRelauncherSyncFD = STDERR_FILENO + 1;
|
||||
#endif
|
||||
|
||||
const CharType* kRelauncherTypeArg = FILE_PATH_LITERAL("--type=relauncher");
|
||||
const CharType* kRelauncherArgSeparator = FILE_PATH_LITERAL("---");
|
||||
|
||||
} // namespace internal
|
||||
|
||||
bool RelaunchApp(const StringVector& argv) {
|
||||
|
@ -58,7 +73,7 @@ bool RelaunchAppWithHelper(const base::FilePath& helper,
|
|||
const StringVector& argv) {
|
||||
StringVector relaunch_argv;
|
||||
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
|
||||
// is not recognized by the service_manager, explicitly set
|
||||
// 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(),
|
||||
relauncher_args.end());
|
||||
|
||||
relaunch_argv.push_back(internal::kRelauncherArgSeparator);
|
||||
relaunch_argv.push_back(kRelauncherArgSeparator);
|
||||
|
||||
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) {
|
||||
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";
|
||||
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) {
|
||||
const StringType& arg(argv[argv_index]);
|
||||
if (!in_relauncher_args) {
|
||||
if (arg == internal::kRelauncherArgSeparator) {
|
||||
if (arg == kRelauncherArgSeparator) {
|
||||
in_relauncher_args = true;
|
||||
} else {
|
||||
relauncher_args.push_back(arg);
|
||||
|
|
|
@ -41,7 +41,6 @@ struct MainFunctionParams;
|
|||
|
||||
namespace relauncher {
|
||||
|
||||
using CharType = base::CommandLine::CharType;
|
||||
using StringType = base::CommandLine::StringType;
|
||||
using StringVector = base::CommandLine::StringVector;
|
||||
|
||||
|
@ -83,18 +82,6 @@ namespace internal {
|
|||
extern const int kRelauncherSyncFD;
|
||||
#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)
|
||||
StringType GetWaitEventName(base::ProcessId pid);
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@ namespace relauncher::internal {
|
|||
|
||||
namespace {
|
||||
|
||||
const CharType* kWaitEventName = L"ElectronRelauncherWaitEvent";
|
||||
|
||||
struct PROCESS_BASIC_INFORMATION {
|
||||
union {
|
||||
NTSTATUS ExitStatus;
|
||||
|
@ -98,8 +96,8 @@ StringType AddQuoteForArg(const StringType& arg) {
|
|||
} // namespace
|
||||
|
||||
StringType GetWaitEventName(base::ProcessId pid) {
|
||||
return base::StrCat(
|
||||
{kWaitEventName, L"-", base::NumberToWString(static_cast<int>(pid))});
|
||||
return base::StrCat({L"ElectronRelauncherWaitEvent-",
|
||||
base::NumberToWString(static_cast<int>(pid))});
|
||||
}
|
||||
|
||||
StringType ArgvToCommandLineString(const StringVector& argv) {
|
||||
|
|
Loading…
Reference in a new issue