Bug 1265368 - enable refresh to be used with the -p switch, r?MattN draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 18 Apr 2016 13:46:47 +0100
changeset 363946 d2c8e237de0809d571d83cf6658fda150863b0b3
parent 363945 bfdd391e0254bd3b2b7a2da1ae87f7a439016392
child 520166 faee82f93a11a59404336a2da05e841ad8d99b98
push id17339
push usergijskruitbosch@gmail.com
push dateThu, 05 May 2016 20:43:07 +0000
reviewersMattN
bugs1265368
milestone49.0a1
Bug 1265368 - enable refresh to be used with the -p switch, r?MattN MozReview-Commit-ID: 7LAkVljrlAS
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -2455,18 +2455,39 @@ SelectProfile(nsIProfileLock* *aResult, 
       PR_fprintf(PR_STDERR, "Error: argument -p is invalid when argument --osint is specified\n");
       return NS_ERROR_FAILURE;
     }
     nsCOMPtr<nsIToolkitProfile> profile;
     rv = aProfileSvc->GetProfileByName(nsDependentCString(arg),
                                       getter_AddRefs(profile));
     if (NS_SUCCEEDED(rv)) {
       if (gDoProfileReset) {
-        NS_WARNING("Profile reset is not supported in conjunction with -p .");
-        gDoProfileReset = false;
+        {
+          // 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);
+        }
+
+        nsCOMPtr<nsIToolkitProfile> newProfile;
+        rv = CreateResetProfile(aProfileSvc, getter_AddRefs(newProfile));
+        if (NS_FAILED(rv)) {
+          NS_WARNING("Failed to create a profile to reset to.");
+          gDoProfileReset = false;
+        } else {
+          nsresult gotName = profile->GetName(gResetOldProfileName);
+          if (NS_SUCCEEDED(gotName)) {
+            profile = newProfile;
+          } else {
+            gResetOldProfileName.Truncate(0);
+            gDoProfileReset = false;
+          }
+        }
       }
 
       nsCOMPtr<nsIProfileUnlocker> unlocker;
       rv = profile->Lock(getter_AddRefs(unlocker), aResult);
       if (NS_SUCCEEDED(rv)) {
         if (aProfileName)
           aProfileName->Assign(nsDependentCString(arg));
         return NS_OK;