Bug 1518639: Always use the same locking code when locking the profile. r=froydnj
authorDave Townsend <dtownsend@oxymoronical.com>
Tue, 12 Feb 2019 20:14:52 +0000
changeset 458797 63fbf50615f9
parent 458796 71102b67960b
child 458798 1acf0670a510
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: Always use the same locking code when locking the profile. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D19419
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -1934,32 +1934,16 @@ static ReturnAbortOnError ProfileLockedD
       NS_ENSURE_SUCCESS_LOG(rv, rv);
 #endif
     }
 
     return NS_ERROR_ABORT;
   }
 }
 
-static nsresult ProfileLockedDialog(nsIToolkitProfile* aProfile,
-                                    nsIProfileUnlocker* aUnlocker,
-                                    nsINativeAppSupport* aNative,
-                                    nsIProfileLock** aResult) {
-  nsCOMPtr<nsIFile> profileDir;
-  nsresult rv = aProfile->GetRootDir(getter_AddRefs(profileDir));
-  if (NS_FAILED(rv)) return rv;
-
-  nsCOMPtr<nsIFile> profileLocalDir;
-  rv = aProfile->GetLocalDir(getter_AddRefs(profileLocalDir));
-  if (NS_FAILED(rv)) return rv;
-
-  return ProfileLockedDialog(profileDir, profileLocalDir, aUnlocker, aNative,
-                             aResult);
-}
-
 static const char kProfileManagerURL[] =
     "chrome://mozapps/content/profile/profileSelection.xul";
 
 static ReturnAbortOnError ShowProfileManager(
     nsIToolkitProfileService* aProfileSvc, nsINativeAppSupport* aNative) {
   nsresult rv;
 
   nsCOMPtr<nsIFile> profD, profLD;
@@ -2165,60 +2149,60 @@ static nsresult SelectProfile(nsIProfile
 
   if (didCreate) {
     // For a fresh install, we would like to let users decide
     // to do profile migration on their own later after using.
     gDoProfileReset = false;
     gDoMigration = false;
   }
 
+  if (gDoProfileReset && !profile) {
+    NS_WARNING("Profile reset is only supported for named profiles.");
+    return NS_ERROR_ABORT;
+  }
+
+  // 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_FAILURE;
+  }
+
+  // We always want to lock the profile even if we're actually going to reset
+  // it later.
+  nsCOMPtr<nsIProfileLock> tempLock;
+  rv = LockProfile(aNative, rootDir, localDir, profile, getter_AddRefs(tempLock));
+  NS_ENSURE_SUCCESS(rv, rv);
+
   if (gDoProfileReset) {
-    if (!profile) {
-      NS_WARNING("Profile reset is only supported for named profiles.");
-      return NS_ERROR_ABORT;
-    }
-
-    {
-      // Check that the source profile is not in use by temporarily
-      // acquiring its lock.
-      nsIProfileLock* tempProfileLock;
-      nsCOMPtr<nsIProfileUnlocker> unlocker;
-      rv = profile->Lock(getter_AddRefs(unlocker), &tempProfileLock);
-      if (NS_FAILED(rv)) {
-        return ProfileLockedDialog(profile, unlocker, aNative,
-                                   &tempProfileLock);
-      }
-    }
+    // Unlock the old profile
+    tempLock->Unlock();
 
     // If we're resetting a profile, create a new one and use it to startup.
     gResetOldProfile = profile;
     rv = aProfileSvc->CreateResetProfile(getter_AddRefs(profile));
     if (NS_SUCCEEDED(rv)) {
       rv = profile->GetRootDir(getter_AddRefs(rootDir));
       NS_ENSURE_SUCCESS(rv, rv);
       SaveFileToEnv("XRE_PROFILE_PATH", rootDir);
 
       rv = profile->GetLocalDir(getter_AddRefs(localDir));
       NS_ENSURE_SUCCESS(rv, rv);
       SaveFileToEnv("XRE_PROFILE_LOCAL_PATH", localDir);
+
+      // Lock the new profile
+      rv = LockProfile(aNative, rootDir, localDir, profile, aResult);
+      NS_ENSURE_SUCCESS(rv, rv);
     } else {
       NS_WARNING("Profile reset failed.");
       return NS_ERROR_ABORT;
     }
-  }
-
-  // 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;
-  }
-
-  rv = LockProfile(aNative, rootDir, localDir, profile, aResult);
-  NS_ENSURE_SUCCESS(rv, rv);
+  } else {
+    tempLock.forget(aResult);
+  }
 
   if (aProfileName && profile) {
     rv = profile->GetName(*aProfileName);
     if (NS_FAILED(rv)) {
       aProfileName->Truncate(0);
     }
   }