Bug 1518639: Split out the profile locking attempt into its own function. r=froydnj
☠☠ backed out by fc8431c4497f ☠ ☠
authorDave Townsend <dtownsend@oxymoronical.com>
Tue, 12 Feb 2019 17:36:32 +0000
changeset 458770 e2a0ca34bab9
parent 458769 0780bd0ba2e1
child 458771 9f51da716b8a
push id35548
push useropoprus@mozilla.com
push dateWed, 13 Feb 2019 09:48:26 +0000
treeherdermozilla-central@93e37c529818 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1518639
milestone67.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 1518639: Split out the profile locking attempt into its own function. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D19418
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -2055,16 +2055,48 @@ static ReturnAbortOnError ShowProfileMan
 
   return LaunchChild(aNative);
 }
 
 static bool gDoMigration = false;
 static bool gDoProfileReset = false;
 static nsCOMPtr<nsIToolkitProfile> gResetOldProfile;
 
+static nsresult LockProfile(nsINativeAppSupport* aNative, nsIFile* aRootDir,
+                            nsIFile* aLocalDir, nsIToolkitProfile* aProfile,
+                            nsIProfileLock** aResult) {
+  // If you close Firefox and very quickly reopen it, the old Firefox may
+  // still be closing down. Rather than immediately showing the
+  // "Firefox is running but is not responding" message, we spend a few
+  // seconds retrying first.
+
+  static const int kLockRetrySeconds = 5;
+  static const int kLockRetrySleepMS = 100;
+
+  nsresult rv;
+  nsCOMPtr<nsIProfileUnlocker> unlocker;
+  const TimeStamp start = TimeStamp::Now();
+  do {
+    if (aProfile) {
+      rv = aProfile->Lock(getter_AddRefs(unlocker), aResult);
+    } else {
+      rv = NS_LockProfilePath(aRootDir, aLocalDir, getter_AddRefs(unlocker),
+                              aResult);
+    }
+    if (NS_SUCCEEDED(rv)) {
+      StartupTimeline::Record(StartupTimeline::AFTER_PROFILE_LOCKED);
+      return NS_OK;
+    }
+    PR_Sleep(kLockRetrySleepMS);
+  } while (TimeStamp::Now() - start <
+           TimeDuration::FromSeconds(kLockRetrySeconds));
+
+  return ProfileLockedDialog(aRootDir, aLocalDir, unlocker, aNative, aResult);
+}
+
 // Pick a profile. We need to end up with a profile lock.
 //
 // 1) check for --profile <path>
 // 2) check for -P <name>
 // 3) check for --ProfileManager
 // 4) use the default profile, if there is one
 // 5) if there are *no* profiles, set up profile-migration
 // 6) display the profile-manager UI
@@ -2174,42 +2206,17 @@ static nsresult SelectProfile(nsIProfile
 
   // No profile could be found. This generally shouldn't happen, a new profile
   // should be created in all cases except for profile reset which is covered
   // above, but just in case...
   if (!rootDir) {
     return NS_ERROR_ABORT;
   }
 
-  // If you close Firefox and very quickly reopen it, the old Firefox may
-  // still be closing down. Rather than immediately showing the
-  // "Firefox is running but is not responding" message, we spend a few
-  // seconds retrying first.
-
-  static const int kLockRetrySeconds = 5;
-  static const int kLockRetrySleepMS = 100;
-
-  nsCOMPtr<nsIProfileUnlocker> unlocker;
-  const TimeStamp start = TimeStamp::Now();
-  do {
-    if (profile) {
-      rv = profile->Lock(getter_AddRefs(unlocker), aResult);
-    } else {
-      rv = NS_LockProfilePath(rootDir, localDir, getter_AddRefs(unlocker),
-                              aResult);
-    }
-    if (NS_SUCCEEDED(rv)) {
-      StartupTimeline::Record(StartupTimeline::AFTER_PROFILE_LOCKED);
-      return NS_OK;
-    }
-    PR_Sleep(kLockRetrySleepMS);
-  } while (TimeStamp::Now() - start <
-           TimeDuration::FromSeconds(kLockRetrySeconds));
-
-  return ProfileLockedDialog(rootDir, localDir, unlocker, aNative, aResult);
+  return LockProfile(aNative, rootDir, localDir, profile, aResult);
 }
 
 #ifdef MOZ_BLOCK_PROFILE_DOWNGRADE
 struct FileWriteFunc : public JSONWriteFunc {
   FILE* mFile;
   explicit FileWriteFunc(FILE* aFile) : mFile(aFile) {}
 
   void Write(const char* aStr) override { fprintf(mFile, "%s", aStr); }