Browse Source

refactor: reduce scope of relauncher's internal constants (#44860)

* refactor: make kRelauncherArgSeparator private to relauncher.cc

* refactor: make kRelauncherTypeArg private to relauncher.cc

* refactor: remove unused type relauncher::CharType

* refactor: move private constants into standalone private namespace

* refactor: move kWaitEventName into the only function that uses it
Charles Kerr 4 months ago
parent
commit
033a0abb59
3 changed files with 24 additions and 24 deletions
  1. 22 7
      shell/browser/relauncher.cc
  2. 0 13
      shell/browser/relauncher.h
  3. 2 4
      shell/browser/relauncher_win.cc

+ 22 - 7
shell/browser/relauncher.cc

@@ -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);

+ 0 - 13
shell/browser/relauncher.h

@@ -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);
 

+ 2 - 4
shell/browser/relauncher_win.cc

@@ -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) {