Bug 1265368 - enable refresh to be used with the -p switch, r?MattN
MozReview-Commit-ID: 7LAkVljrlAS
--- 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;