Bug 1548324: Improve implementation of force-launcher in the launcher process; r=mhowell
authorAaron Klotz <aklotz@mozilla.com>
Wed, 01 May 2019 20:56:43 +0000
changeset 531139 b94f9b2fbe2c695e26fa9473464b39439f2307c1
parent 531138 26c271a86fddbef6275e2c62140db382266ba392
child 531140 4e111da826529376e126b44cbdeabb5202da88d7
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell
bugs1548324
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1548324: Improve implementation of force-launcher in the launcher process; r=mhowell This patch replaces the quick-n-dirty implementation of -force-launcher with one that makes LauncherRegistryInfo aware of that state, thus correctly setting the affected registry values. Differential Revision: https://phabricator.services.mozilla.com/D29545
browser/app/winlauncher/LauncherProcessWin.cpp
toolkit/xre/LauncherRegistryInfo.cpp
toolkit/xre/LauncherRegistryInfo.h
--- a/browser/app/winlauncher/LauncherProcessWin.cpp
+++ b/browser/app/winlauncher/LauncherProcessWin.cpp
@@ -158,38 +158,43 @@ static mozilla::Maybe<bool> RunAsLaunche
                         static_cast<const wchar_t**>(nullptr),
                         mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND) {
     return mozilla::Some(false);
   }
 
   bool runAsLauncher = DoLauncherProcessChecks(argc, argv);
 
 #if defined(MOZ_LAUNCHER_PROCESS)
+  bool forceLauncher = runAsLauncher &&
+                       mozilla::CheckArg(argc, argv, L"force-launcher",
+                                         static_cast<const wchar_t**>(nullptr),
+                                         mozilla::CheckArgFlag::RemoveArg) ==
+                       mozilla::ARG_FOUND;
+
   mozilla::LauncherRegistryInfo::ProcessType desiredType =
       runAsLauncher ? mozilla::LauncherRegistryInfo::ProcessType::Launcher
                     : mozilla::LauncherRegistryInfo::ProcessType::Browser;
+
+  mozilla::LauncherRegistryInfo::CheckOption checkOption =
+      forceLauncher ? mozilla::LauncherRegistryInfo::CheckOption::Force
+                    : mozilla::LauncherRegistryInfo::CheckOption::Default;
+
   mozilla::LauncherRegistryInfo regInfo;
   mozilla::LauncherResult<mozilla::LauncherRegistryInfo::ProcessType>
-      runAsType = regInfo.Check(desiredType);
+      runAsType = regInfo.Check(desiredType, checkOption);
 
   if (runAsType.isErr()) {
     mozilla::HandleLauncherError(runAsType);
     return mozilla::Nothing();
   }
 
   runAsLauncher = runAsType.unwrap() ==
                   mozilla::LauncherRegistryInfo::ProcessType::Launcher;
 #endif  // defined(MOZ_LAUNCHER_PROCESS)
 
-  // We must check for force-launcher *after* we do LauncherRegistryInfo checks
-  runAsLauncher |=
-      mozilla::CheckArg(argc, argv, L"force-launcher",
-                        static_cast<const wchar_t**>(nullptr),
-                        mozilla::CheckArgFlag::RemoveArg) == mozilla::ARG_FOUND;
-
   if (!runAsLauncher) {
     // In this case, we will be proceeding to run as the browser.
     // We should check MOZ_DEBUG_BROWSER_* env vars.
     MaybeBreakForBrowserDebugging();
   }
 
   return mozilla::Some(runAsLauncher);
 }
--- a/toolkit/xre/LauncherRegistryInfo.cpp
+++ b/toolkit/xre/LauncherRegistryInfo.cpp
@@ -111,17 +111,17 @@ LauncherVoidResult LauncherRegistryInfo:
   if (result != ERROR_SUCCESS) {
     return LAUNCHER_ERROR_FROM_WIN32(result);
   }
 
   return Ok();
 }
 
 LauncherResult<LauncherRegistryInfo::ProcessType> LauncherRegistryInfo::Check(
-    const ProcessType aDesiredType) {
+    const ProcessType aDesiredType, const CheckOption aOption) {
   LauncherResult<Disposition> disposition = Open();
   if (disposition.isErr()) {
     return LAUNCHER_ERROR_FROM_RESULT(disposition);
   }
 
   LauncherResult<DWORD> ourImageTimestamp = GetCurrentImageTimestamp();
   if (ourImageTimestamp.isErr()) {
     return LAUNCHER_ERROR_FROM_RESULT(ourImageTimestamp);
@@ -191,16 +191,22 @@ LauncherResult<LauncherRegistryInfo::Pro
     // If we have neither timestamp, then we should try running as suggested
     // by |aDesiredType|.
     // We shouldn't really have this scenario unless we're going to be running
     // as the launcher process.
     MOZ_ASSERT(typeToRunAs == ProcessType::Launcher);
     // No change to typeToRunAs
   }
 
+  // Debugging setting that forces the desired type regardless of the various
+  // tests that have been performed.
+  if (aOption == CheckOption::Force) {
+    typeToRunAs = aDesiredType;
+  }
+
   LauncherVoidResult wroteTimestamp = Ok();
 
   if (typeToRunAs == ProcessType::Browser && aDesiredType != typeToRunAs) {
     // We were hoping to run as the launcher, but some failure has caused us
     // to run as the browser. Set the browser timestamp to zero as an indicator.
     wroteTimestamp = WriteStartTimestamp(typeToRunAs, Some(0ULL));
   } else {
     wroteTimestamp = WriteStartTimestamp(typeToRunAs);
--- a/toolkit/xre/LauncherRegistryInfo.h
+++ b/toolkit/xre/LauncherRegistryInfo.h
@@ -27,23 +27,30 @@ class LauncherRegistryInfo final {
   enum class ProcessType { Launcher, Browser };
 
   enum class EnabledState : uint32_t {
     Enabled = 0,
     FailDisabled = 1,
     ForceDisabled = 2,
   };
 
+  enum class CheckOption {
+    Default,
+    Force,
+  };
+
   LauncherRegistryInfo() : mBinPath(GetFullBinaryPath().get()) {}
 
   LauncherVoidResult ReflectPrefToRegistry(const bool aEnable);
   LauncherResult<EnabledState> IsEnabled();
   LauncherResult<bool> IsTelemetryEnabled();
   LauncherVoidResult ReflectTelemetryPrefToRegistry(const bool aEnable);
-  LauncherResult<ProcessType> Check(const ProcessType aDesiredType);
+  LauncherResult<ProcessType> Check(const ProcessType aDesiredType,
+                                    const CheckOption aOption =
+                                      CheckOption::Default);
   LauncherVoidResult DisableDueToFailure();
 
  private:
   enum class Disposition { CreatedNew, OpenedExisting };
 
  private:
   LauncherResult<Disposition> Open();
   LauncherVoidResult WriteStartTimestamp(