Bug 1322797: Replace selectedProfile with currentProfile and fix defaultProfile. r=froydnj, r=flod
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 28 Dec 2018 09:44:47 -0800
changeset 456192 d3b849c06ebc602a15d086f3778f92880ca4f0fd
parent 456191 5d43adb2b26ee297c8585412c0f22521ea5d7ecb
child 456193 58babf220962945b5ed8b4af5309d81eb8376571
push id35474
push useropoprus@mozilla.com
push dateThu, 31 Jan 2019 09:37:52 +0000
treeherdermozilla-central@9ee54a21a22a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, flod
bugs1322797
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 1322797: Replace selectedProfile with currentProfile and fix defaultProfile. r=froydnj, r=flod The current properties selectedProfile and defaultProfile are somewhat confusing selectedProfile actually returns the default profile for the build and defaultProfile returns the default profile for non-dev-edition builds. This confusion leads to callers doing the wrong thing in some places. What most code actually cares about is being able to set/get the default profile for this build and getting the current profile in use. So this patch replaces the previous properties with currentProfile and defaultProfile which do what makes more sense. This patch also switches from using the preprocessor to change behaviour for dev-edition builds to using a boolean flag since some code was incorrectly ignoring the setting to make dev-edition use the same profile as normal builds. In order to make currentProfile correct when resetting a profile I had to move CreateResetProfile into nsToolkitProfileService. Differential Revision: https://phabricator.services.mozilla.com/D16118
browser/components/migration/FirefoxProfileMigrator.js
devtools/shared/system.js
toolkit/content/aboutProfiles.js
toolkit/content/aboutProfiles.xhtml
toolkit/locales/en-US/toolkit/about/aboutProfiles.ftl
toolkit/profile/content/profileSelection.js
toolkit/profile/nsIToolkitProfileService.idl
toolkit/profile/nsToolkitProfileService.cpp
toolkit/profile/nsToolkitProfileService.h
toolkit/profile/xpcshell/head.js
toolkit/profile/xpcshell/test_create_default.js
toolkit/profile/xpcshell/test_select_default.js
toolkit/xre/ProfileReset.cpp
toolkit/xre/ProfileReset.h
toolkit/xre/nsAppRunner.cpp
--- a/browser/components/migration/FirefoxProfileMigrator.js
+++ b/browser/components/migration/FirefoxProfileMigrator.js
@@ -67,17 +67,17 @@ FirefoxProfileMigrator.prototype._getFil
   // copy non-existing files.
   return file.exists() ? file : null;
 };
 
 FirefoxProfileMigrator.prototype.getResources = function(aProfile) {
   let sourceProfileDir = aProfile ? this._getAllProfiles().get(aProfile.id) :
     Cc["@mozilla.org/toolkit/profile-service;1"]
       .getService(Ci.nsIToolkitProfileService)
-      .selectedProfile.rootDir;
+      .currentProfile.rootDir;
   if (!sourceProfileDir || !sourceProfileDir.exists() ||
       !sourceProfileDir.isReadable())
     return null;
 
   // Being a startup-only migrator, we can rely on
   // MigrationUtils.profileStartup being set.
   let currentProfileDir = MigrationUtils.profileStartup.directory;
 
--- a/devtools/shared/system.js
+++ b/devtools/shared/system.js
@@ -175,23 +175,24 @@ function getDeviceName() {
   } catch (e) {
     return null;
   }
 }
 
 function getProfileLocation() {
   // In child processes, we cannot access the profile location.
   try {
+    // For some reason this line must come first or in xpcshell tests
+    // nsXREDirProvider never gets initialised and so the profile service
+    // crashes on initialisation.
     const profd = Services.dirsvc.get("ProfD", Ci.nsIFile);
     const profservice = Cc["@mozilla.org/toolkit/profile-service;1"]
                         .getService(Ci.nsIToolkitProfileService);
-    for (const profile of profservice.profiles) {
-      if (profile.rootDir.path == profd.path) {
-        return profile.name;
-      }
+    if (profservice.currentProfile) {
+      return profservice.currentProfile.name;
     }
 
     return profd.leafName;
   } catch (e) {
     return "";
   }
 }
 
--- a/toolkit/content/aboutProfiles.js
+++ b/toolkit/content/aboutProfiles.js
@@ -9,55 +9,28 @@ const {XPCOMUtils} = ChromeUtils.import(
 
 XPCOMUtils.defineLazyServiceGetter(
   this,
   "ProfileService",
   "@mozilla.org/toolkit/profile-service;1",
   "nsIToolkitProfileService"
 );
 
-// nsIToolkitProfileService.selectProfile can be used only during the selection
-// of the profile in the ProfileManager. If we are showing about:profiles in a
-// tab, the selectedProfile returns the default profile.
-// In this function we use the ProfD to find the current profile.
-function findCurrentProfile() {
-  let cpd;
-  try {
-    cpd = Services.dirsvc.get("ProfD", Ci.nsIFile);
-  } catch (e) {}
-
-  if (cpd) {
-    for (let profile of ProfileService.profiles) {
-      if (profile.rootDir.path == cpd.path) {
-        return profile;
-      }
-    }
-  }
-
-  // selectedProfile can throw if nothing is selected or if the selected profile
-  // has been deleted.
-  try {
-    return ProfileService.selectedProfile;
-  } catch (e) {
-    return null;
-  }
-}
-
 function refreshUI() {
   let parent = document.getElementById("profiles");
   while (parent.firstChild) {
     parent.firstChild.remove();
   }
 
   let defaultProfile;
   try {
     defaultProfile = ProfileService.defaultProfile;
   } catch (e) {}
 
-  let currentProfile = findCurrentProfile();
+  let currentProfile = ProfileService.currentProfile;
 
   for (let profile of ProfileService.profiles) {
     let isCurrentProfile = profile == currentProfile;
     let isInUse = isCurrentProfile;
     if (!isInUse) {
       try {
         let lock = profile.lock({});
         lock.unlock();
@@ -192,20 +165,20 @@ function display(profileData) {
     };
     div.appendChild(runButton);
   }
 
   let sep = document.createElement("hr");
   div.appendChild(sep);
 }
 
+// This is called from the createProfileWizard.xul dialog.
 function CreateProfile(profile) {
-  ProfileService.selectedProfile = profile;
-  ProfileService.flush();
-  refreshUI();
+  // The wizard created a profile, just make it the default.
+  defaultProfile(profile);
 }
 
 function createProfileWizard() {
   // This should be rewritten in HTML eventually.
   window.openDialog("chrome://mozapps/content/profile/createProfileWizard.xul",
                     "", "centerscreen,chrome,modal,titlebar",
                     ProfileService);
 }
@@ -264,40 +237,36 @@ async function removeProfile(profile) {
       return;
     }
 
     if (buttonPressed == 2) {
       deleteFiles = true;
     }
   }
 
-  // If we are deleting the selected or the default profile we must choose a
-  // different one.
-  let isSelected = false;
-  try {
-    isSelected = ProfileService.selectedProfile == profile;
-  } catch (e) {}
-
+  // If we are deleting the default profile we must choose a different one.
   let isDefault = false;
   try {
     isDefault = ProfileService.defaultProfile == profile;
   } catch (e) {}
 
-  if (isSelected || isDefault) {
+  if (isDefault) {
     for (let p of ProfileService.profiles) {
       if (profile == p) {
         continue;
       }
 
-      if (isSelected) {
-        ProfileService.selectedProfile = p;
-      }
-
       if (isDefault) {
-        ProfileService.defaultProfile = p;
+        try {
+          ProfileService.defaultProfile = p;
+        } catch (e) {
+          // This can happen on dev-edition if a non-default profile is in use.
+          // In such a case the next time that dev-edition is started it will
+          // find no default profile and just create a new one.
+        }
       }
 
       break;
     }
   }
 
   try {
     profile.removeInBackground(deleteFiles);
@@ -310,20 +279,29 @@ async function removeProfile(profile) {
     Services.prompt.alert(window, title, msg);
     return;
   }
 
   ProfileService.flush();
   refreshUI();
 }
 
-function defaultProfile(profile) {
-  ProfileService.defaultProfile = profile;
-  ProfileService.selectedProfile = profile;
-  ProfileService.flush();
+async function defaultProfile(profile) {
+  try {
+    ProfileService.defaultProfile = profile;
+    ProfileService.flush();
+  } catch (e) {
+    // This can happen on dev-edition.
+    let [title, msg] = await document.l10n.formatValues([
+        { id: "profiles-cannot-set-as-default-title" },
+        { id: "profiles-cannot-set-as-default-message" },
+    ]);
+
+    Services.prompt.alert(window, title, msg);
+  }
   refreshUI();
 }
 
 function openProfile(profile) {
   let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"]
                      .createInstance(Ci.nsISupportsPRBool);
   Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
--- a/toolkit/content/aboutProfiles.xhtml
+++ b/toolkit/content/aboutProfiles.xhtml
@@ -7,16 +7,17 @@
 <!DOCTYPE html>
 
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
     <title data-l10n-id="profiles-title"></title>
     <link rel="icon" type="image/png" id="favicon" href="chrome://branding/content/icon32.png" />
     <link rel="stylesheet" href="chrome://mozapps/skin/aboutProfiles.css" type="text/css" />
     <script type="application/javascript" src="chrome://global/content/aboutProfiles.js" />
+    <link rel="localization" href="branding/brand.ftl" />
     <link rel="localization" href="toolkit/about/aboutProfiles.ftl" />
 </head>
   <body id="body" class="wide-container">
     <div id="action-box" class="notice-box">
       <h3 data-l10n-id="profiles-restart-title"></h3>
       <button id="restart-in-safe-mode-button" data-l10n-id="profiles-restart-in-safe-mode"></button>
       <button id="restart-button" data-l10n-id="profiles-restart-normal"></button>
     </div>
--- a/toolkit/locales/en-US/toolkit/about/aboutProfiles.ftl
+++ b/toolkit/locales/en-US/toolkit/about/aboutProfiles.ftl
@@ -26,16 +26,19 @@ profiles-localdir = Local Directory
 profiles-current-profile = This is the profile in use and it cannot be deleted.
 profiles-in-use-profile = This profile is in use in another application and it cannot be deleted.
 
 profiles-rename = Rename
 profiles-remove = Remove
 profiles-set-as-default = Set as default profile
 profiles-launch-profile = Launch profile in new browser
 
+profiles-cannot-set-as-default-title = Unable to set default
+profiles-cannot-set-as-default-message = The default profile cannot be changed for { -brand-short-name }.
+
 profiles-yes = yes
 profiles-no = no
 
 profiles-rename-profile-title = Rename Profile
 # Variables:
 #   $name (String) - Name of the profile
 profiles-rename-profile = Rename profile { $name }
 
--- a/toolkit/profile/content/profileSelection.js
+++ b/toolkit/profile/content/profileSelection.js
@@ -34,17 +34,17 @@ function startup() {
     for (let profile of gProfileService.profiles.entries(I.nsIToolkitProfile)) {
       var listitem = profilesElement.appendItem(profile.name, "");
 
       var tooltiptext =
         gProfileManagerBundle.getFormattedString("profileTooltip", [profile.name, profile.rootDir.path]);
       listitem.setAttribute("tooltiptext", tooltiptext);
       listitem.profile = profile;
       try {
-        if (profile === gProfileService.selectedProfile) {
+        if (profile === gProfileService.defaultProfile) {
           setTimeout(function(a) {
             profilesElement.ensureElementIsVisible(a);
             profilesElement.selectItem(a);
           }, 0, listitem);
         }
       } catch (e) { }
     }
 
@@ -88,26 +88,28 @@ function acceptDialog() {
     var locked =
       gProfileManagerBundle.getFormattedString("profileLocked2", [appName, selectedProfile.profile.name, appName]);
     Services.prompt.alert(window, lockedTitle, locked);
 
     return false;
   }
   gDialogParams.objects.insertElementAt(profileLock.nsIProfileLock, 0);
 
-  gProfileService.selectedProfile = selectedProfile.profile;
-  gProfileService.defaultProfile = selectedProfile.profile;
+  try {
+    gProfileService.defaultProfile = selectedProfile.profile;
+  } catch (e) {
+    // This can happen on dev-edition. We'll still restart with the selected
+    // profile based on the lock's directories.
+  }
   updateStartupPrefs();
 
   gDialogParams.SetInt(0, 1);
   /* Bug 257777 */
   gDialogParams.SetInt(1, document.getElementById("offlineState").checked ? 1 : 0);
 
-  gDialogParams.SetString(0, selectedProfile.profile.name);
-
   return true;
 }
 
 function exitDialog() {
   updateStartupPrefs();
 
   return true;
 }
--- a/toolkit/profile/nsIToolkitProfileService.idl
+++ b/toolkit/profile/nsIToolkitProfileService.idl
@@ -13,32 +13,28 @@ interface nsIProfileLock;
 [scriptable, builtinclass, uuid(1947899b-f369-48fa-89da-f7c37bb1e6bc)]
 interface nsIToolkitProfileService : nsISupports
 {
     attribute boolean startWithLastProfile;
 
     readonly attribute nsISimpleEnumerator /*nsIToolkitProfile*/ profiles;
 
     /**
-     * The currently selected profile (the one used or about to be used by the
-     * browser).
+     * The profile currently in use if it is a named profile. This will return
+     * null if the current profile path doesn't match a profile in the database.
      */
-    attribute nsIToolkitProfile selectedProfile;
+    readonly attribute nsIToolkitProfile currentProfile;
 
     /**
-     * The default profile (the one used or about to be used by the
-     * browser if no other profile is specified at runtime). This is the profile
-     * marked with Default=1 in profiles.ini and is usually the same as
-     * selectedProfile, except on Developer Edition.
-     *
-     * Developer Edition uses a profile named "dev-edition-default" as the
-     * default profile (which it creates if it doesn't exist), unless a special
-     * empty file named "ignore-dev-edition-profile" is present next to
-     * profiles.ini. In that case Developer Edition behaves the same as any
-     * other build of Firefox.
+     * The default profile for this build.
+     * On startup this is the profile selected unless overridden by command line
+     * arguments or environment variables. Setting this will change the profile
+     * used by default the next time the application is started.
+     * Attempting to change the default may throw an exception on builds that do
+     * not support changing the default profile, such as developer edition.
      */
     attribute nsIToolkitProfile defaultProfile;
 
     /**
      * Selects or creates a profile to use based on the profiles database, any
      * environment variables and any command line arguments. Will not create
      * a profile if aIsResetting is true. The profile is selected based on this
      * order of preference:
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -37,16 +37,17 @@
 #include "nsINIParser.h"
 #include "nsXREDirProvider.h"
 #include "nsAppRunner.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsNativeCharsetUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Sprintf.h"
+#include "nsPrintfCString.h"
 
 using namespace mozilla;
 
 #define DEV_EDITION_NAME "dev-edition-default"
 #define DEFAULT_NAME "default"
 
 nsToolkitProfile::nsToolkitProfile(const nsACString& aName, nsIFile* aRootDir,
                                    nsIFile* aLocalDir, nsToolkitProfile* aPrev)
@@ -83,18 +84,36 @@ nsToolkitProfile::GetName(nsACString& aR
   aResult = mName;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsToolkitProfile::SetName(const nsACString& aName) {
   NS_ASSERTION(nsToolkitProfileService::gService, "Where did my service go?");
 
+  if (mName.Equals(aName)) {
+    return NS_OK;
+  }
+
+  // Changing the name from the dev-edition default profile name makes this
+  // profile no longer the dev-edition default.
+  if (mName.EqualsLiteral(DEV_EDITION_NAME) &&
+      nsToolkitProfileService::gService->mDevEditionDefault == this) {
+    nsToolkitProfileService::gService->mDevEditionDefault = nullptr;
+  }
+
   mName = aName;
 
+  // Setting the name to the dev-edition default profile name will cause this
+  // profile to become the dev-edition default.
+  if (aName.EqualsLiteral(DEV_EDITION_NAME) &&
+      !nsToolkitProfileService::gService->mDevEditionDefault) {
+    nsToolkitProfileService::gService->mDevEditionDefault = this;
+  }
+
   return NS_OK;
 }
 
 nsresult nsToolkitProfile::RemoveInternal(bool aRemoveFiles,
                                           bool aInBackground) {
   NS_ASSERTION(nsToolkitProfileService::gService, "Whoa, my service is gone.");
 
   if (mLock) return NS_ERROR_FILE_IS_LOCKED;
@@ -142,18 +161,22 @@ nsresult nsToolkitProfile::RemoveInterna
   else
     nsToolkitProfileService::gService->mFirst = mNext;
 
   if (mNext) mNext->mPrev = mPrev;
 
   mPrev = nullptr;
   mNext = nullptr;
 
-  if (nsToolkitProfileService::gService->mChosen == this)
-    nsToolkitProfileService::gService->mChosen = nullptr;
+  if (nsToolkitProfileService::gService->mNormalDefault == this) {
+    nsToolkitProfileService::gService->mNormalDefault = nullptr;
+  }
+  if (nsToolkitProfileService::gService->mDevEditionDefault == this) {
+    nsToolkitProfileService::gService->mDevEditionDefault = nullptr;
+  }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsToolkitProfile::Remove(bool removeFiles) {
   return RemoveInternal(removeFiles, false /* in background */);
 }
@@ -260,17 +283,23 @@ nsToolkitProfileLock::~nsToolkitProfileL
   }
 }
 
 nsToolkitProfileService* nsToolkitProfileService::gService = nullptr;
 
 NS_IMPL_ISUPPORTS(nsToolkitProfileService, nsIToolkitProfileService)
 
 nsToolkitProfileService::nsToolkitProfileService()
-    : mStartupProfileSelected(false), mStartWithLast(true), mIsFirstRun(true) {
+    : mStartupProfileSelected(false),
+      mStartWithLast(true),
+      mIsFirstRun(true),
+      mUseDevEditionProfile(false) {
+#ifdef MOZ_DEV_EDITION
+  mUseDevEditionProfile = true;
+#endif
   gService = this;
 }
 
 nsToolkitProfileService::~nsToolkitProfileService() { gService = nullptr; }
 
 nsresult nsToolkitProfileService::Init() {
   NS_ASSERTION(gDirServiceProvider, "No dirserviceprovider!");
   nsresult rv;
@@ -318,16 +347,18 @@ nsresult nsToolkitProfileService::Init()
 
   rv = ignoreSeparateProfile->AppendNative(
       NS_LITERAL_CSTRING("ignore-dev-edition-profile"));
   if (NS_FAILED(rv)) return rv;
 
   bool shouldIgnoreSeparateProfile;
   rv = ignoreSeparateProfile->Exists(&shouldIgnoreSeparateProfile);
   if (NS_FAILED(rv)) return rv;
+
+  mUseDevEditionProfile = !shouldIgnoreSeparateProfile;
 #endif
 
   nsCOMPtr<nsIToolkitProfile> autoSelectProfile;
 
   unsigned int nonDevEditionProfiles = 0;
   unsigned int c = 0;
   for (c = 0; true; ++c) {
     nsAutoCString profileID("Profile");
@@ -377,52 +408,40 @@ nsresult nsToolkitProfileService::Init()
     }
 
     currentProfile =
         new nsToolkitProfile(name, rootDir, localDir, currentProfile);
     NS_ENSURE_TRUE(currentProfile, NS_ERROR_OUT_OF_MEMORY);
 
     rv = parser.GetString(profileID.get(), "Default", buffer);
     if (NS_SUCCEEDED(rv) && buffer.EqualsLiteral("1")) {
-      mDefault = currentProfile;
+      mNormalDefault = currentProfile;
     }
 
     if (name.EqualsLiteral(DEV_EDITION_NAME)) {
-#ifdef MOZ_DEV_EDITION
-      // Use the dev-edition-default profile if this is an Aurora build and
-      // ignore-dev-edition-profile is not present.
-      if (!shouldIgnoreSeparateProfile) {
-        mChosen = currentProfile;
-      }
-#endif
+      mDevEditionDefault = currentProfile;
     } else {
       nonDevEditionProfiles++;
       autoSelectProfile = currentProfile;
     }
   }
 
   // If there is only one non-dev-edition profile then mark it as the default.
-  if (!mDefault && nonDevEditionProfiles == 1) {
-    mDefault = autoSelectProfile;
+  if (!mNormalDefault && nonDevEditionProfiles == 1) {
+    mNormalDefault = autoSelectProfile;
   }
 
-  // Normally having no non-dev-edition builds suggests this is the first run.
-  mIsFirstRun = nonDevEditionProfiles == 0;
-
-#ifdef MOZ_DEV_EDITION
-  if (!shouldIgnoreSeparateProfile) {
-    // Except when using the separate dev-edition profile, in which case not
-    // finding it means this is a first run.
-    mIsFirstRun = !mChosen;
+  if (mUseDevEditionProfile) {
+    // When using the separate dev-edition profile not finding it means this is
+    // a first run.
+    mIsFirstRun = !mDevEditionDefault;
   } else {
-    mChosen = mDefault;
+    // If there are no normal profiles then this is a first run.
+    mIsFirstRun = nonDevEditionProfiles == 0;
   }
-#else
-  mChosen = mDefault;
-#endif
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsToolkitProfileService::SetStartWithLastProfile(bool aValue) {
   if (mStartWithLast != aValue) {
     mStartWithLast = aValue;
@@ -457,47 +476,40 @@ nsToolkitProfileService::ProfileEnumerat
 
   NS_ADDREF(*aResult = mCurrent);
 
   mCurrent = mCurrent->mNext;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsToolkitProfileService::GetSelectedProfile(nsIToolkitProfile** aResult) {
-  if (!mChosen && mFirst && !mFirst->mNext)  // only one profile
-    mChosen = mFirst;
-
-  if (!mChosen) return NS_ERROR_FAILURE;
-
-  NS_ADDREF(*aResult = mChosen);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsToolkitProfileService::SetSelectedProfile(nsIToolkitProfile* aProfile) {
-  if (mChosen != aProfile) {
-    mChosen = aProfile;
-  }
+nsToolkitProfileService::GetCurrentProfile(nsIToolkitProfile** aResult) {
+  NS_IF_ADDREF(*aResult = mCurrent);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsToolkitProfileService::GetDefaultProfile(nsIToolkitProfile** aResult) {
-  if (!mDefault) return NS_ERROR_FAILURE;
+  if (mUseDevEditionProfile) {
+    NS_IF_ADDREF(*aResult = mDevEditionDefault);
+    return NS_OK;
+  }
 
-  NS_ADDREF(*aResult = mDefault);
+  NS_IF_ADDREF(*aResult = mNormalDefault);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsToolkitProfileService::SetDefaultProfile(nsIToolkitProfile* aProfile) {
-  if (mDefault != aProfile) {
-    mDefault = aProfile;
+  if (mUseDevEditionProfile && aProfile != mDevEditionDefault) {
+    // The separate profile is hardcoded.
+    return NS_ERROR_FAILURE;
   }
+
+  mNormalDefault = aProfile;
   return NS_OK;
 }
 
 /**
  * An implementation of SelectStartupProfile callable from JavaScript via XPCOM.
  * See nsIToolkitProfileService.idl.
  */
 NS_IMETHODIMP
@@ -550,36 +562,36 @@ nsresult nsToolkitProfileService::Select
     return NS_ERROR_ALREADY_INITIALIZED;
   }
 
   mStartupProfileSelected = true;
   *aDidCreate = false;
 
   nsresult rv;
   const char* arg;
-  nsCOMPtr<nsIToolkitProfile> profile;
 
   // Use the profile specified in the environment variables (generally from an
   // app initiated restart).
   nsCOMPtr<nsIFile> lf = GetFileFromEnv("XRE_PROFILE_PATH");
   if (lf) {
     nsCOMPtr<nsIFile> localDir = GetFileFromEnv("XRE_PROFILE_LOCAL_PATH");
     if (!localDir) {
       localDir = lf;
     }
 
     // Clear out flags that we handled (or should have handled!) last startup.
     const char* dummy;
     CheckArg(*aArgc, aArgv, "p", &dummy);
     CheckArg(*aArgc, aArgv, "profile", &dummy);
     CheckArg(*aArgc, aArgv, "profilemanager");
 
-    GetProfileByDir(lf, localDir, aProfile);
+    GetProfileByDir(lf, localDir, getter_AddRefs(mCurrent));
     lf.forget(aRootDir);
     localDir.forget(aLocalDir);
+    NS_IF_ADDREF(*aProfile = mCurrent);
     return NS_OK;
   }
 
   // Check the -profile command line argument. It accepts a single argument that
   // gives the path to use for the profile.
   ArgResult ar = CheckArg(*aArgc, aArgv, "profile", &arg,
                           CheckArgFlag::CheckOSInt | CheckArgFlag::RemoveArg);
   if (ar == ARG_BAD) {
@@ -607,34 +619,36 @@ nsresult nsToolkitProfileService::Select
             PR_STDERR,
             "Error: argument --profile requires a path to a directory\n");
         return NS_ERROR_FAILURE;
       }
     }
 
     // If a profile path is specified directly on the command line, then
     // assume that the temp directory is the same as the given directory.
-    GetProfileByDir(lf, lf, aProfile);
+    GetProfileByDir(lf, lf, getter_AddRefs(mCurrent));
     NS_ADDREF(*aRootDir = lf);
     lf.forget(aLocalDir);
+    NS_IF_ADDREF(*aProfile = mCurrent);
     return NS_OK;
   }
 
   // Check the -createprofile command line argument. It accepts a single
   // argument that is either the name for the new profile or the name followed
   // by the path to use.
   ar = CheckArg(*aArgc, aArgv, "createprofile", &arg,
                 CheckArgFlag::CheckOSInt | CheckArgFlag::RemoveArg);
   if (ar == ARG_BAD) {
     PR_fprintf(PR_STDERR,
                "Error: argument --createprofile requires a profile name\n");
     return NS_ERROR_FAILURE;
   }
   if (ar) {
     const char* delim = strchr(arg, ' ');
+    nsCOMPtr<nsIToolkitProfile> profile;
     if (delim) {
       nsCOMPtr<nsIFile> lf;
       rv = NS_NewNativeLocalFile(nsDependentCString(delim + 1), true,
                                  getter_AddRefs(lf));
       if (NS_FAILED(rv)) {
         PR_fprintf(PR_STDERR, "Error: profile path not valid.\n");
         return rv;
       }
@@ -676,21 +690,22 @@ nsresult nsToolkitProfileService::Select
     ar = CheckArg(*aArgc, aArgv, "osint");
     if (ar == ARG_FOUND) {
       PR_fprintf(
           PR_STDERR,
           "Error: argument -p is invalid when argument --osint is specified\n");
       return NS_ERROR_FAILURE;
     }
 
-    rv = GetProfileByName(nsDependentCString(arg), getter_AddRefs(profile));
+    rv = GetProfileByName(nsDependentCString(arg), getter_AddRefs(mCurrent));
     if (NS_SUCCEEDED(rv)) {
-      profile->GetRootDir(aRootDir);
-      profile->GetLocalDir(aLocalDir);
-      profile.forget(aProfile);
+      mCurrent->GetRootDir(aRootDir);
+      mCurrent->GetLocalDir(aLocalDir);
+
+      NS_ADDREF(*aProfile = mCurrent);
       return NS_OK;
     }
 
     return NS_ERROR_SHOW_PROFILE_MANAGER;
   }
 
   ar = CheckArg(*aArgc, aArgv, "profilemanager", (const char**)nullptr,
                 CheckArgFlag::CheckOSInt | CheckArgFlag::RemoveArg);
@@ -709,64 +724,98 @@ nsresult nsToolkitProfileService::Select
     if (aIsResetting) {
       // We don't want to create a fresh profile when we're attempting a
       // profile reset so just bail out here, the calling code will handle it.
       *aProfile = nullptr;
       return NS_OK;
     }
 
     // create a default profile
-    nsresult rv = CreateProfile(nullptr,  // choose a default dir for us
-#ifdef MOZ_DEV_EDITION
-                                NS_LITERAL_CSTRING(DEV_EDITION_NAME),
-#else
-                                NS_LITERAL_CSTRING(DEFAULT_NAME),
-#endif
-                                getter_AddRefs(mChosen));
+    nsAutoCString name;
+    if (mUseDevEditionProfile) {
+      name.AssignLiteral(DEV_EDITION_NAME);
+    } else {
+      name.AssignLiteral(DEFAULT_NAME);
+    }
+
+    nsresult rv = CreateProfile(nullptr, name, getter_AddRefs(mCurrent));
     if (NS_SUCCEEDED(rv)) {
-#ifdef MOZ_DEV_EDITION
-      // If the only profile is the new dev-edition-profile then older versions
-      // may try to auto-select it. Create a default profile for them to use
-      // instead.
-      if (mFirst && !mFirst->mNext) {
-        CreateProfile(nullptr, NS_LITERAL_CSTRING(DEFAULT_NAME),
-                      getter_AddRefs(mDefault));
+      if (mUseDevEditionProfile) {
+        mDevEditionDefault = mCurrent;
+
+        // If the only profile is the new dev-edition-profile then older
+        // versions may try to auto-select it. Create a default profile for them
+        // to use instead.
+        if (mFirst && !mFirst->mNext) {
+          CreateProfile(nullptr, NS_LITERAL_CSTRING(DEFAULT_NAME),
+                        getter_AddRefs(mNormalDefault));
+        }
+      } else {
+        mNormalDefault = mCurrent;
       }
-#else
-      SetDefaultProfile(mChosen);
-#endif
       Flush();
 
-      mChosen->GetRootDir(aRootDir);
-      mChosen->GetLocalDir(aLocalDir);
-      NS_ADDREF(*aProfile = mChosen);
+      mCurrent->GetRootDir(aRootDir);
+      mCurrent->GetLocalDir(aLocalDir);
+      NS_ADDREF(*aProfile = mCurrent);
 
       *aDidCreate = true;
       return NS_OK;
     }
   }
 
   // There are multiple profiles available.
   if (!mStartWithLast) {
     return NS_ERROR_SHOW_PROFILE_MANAGER;
   }
 
-  // GetSelectedProfile will auto-select the only profile if there's just one
-  GetSelectedProfile(getter_AddRefs(profile));
+  GetDefaultProfile(getter_AddRefs(mCurrent));
 
   // None of the profiles was marked as default (generally only happens if the
   // user modifies profiles.ini manually). Let the user choose.
-  if (!profile) {
+  if (!mCurrent) {
     return NS_ERROR_SHOW_PROFILE_MANAGER;
   }
 
   // Use the selected profile.
-  profile->GetRootDir(aRootDir);
-  profile->GetLocalDir(aLocalDir);
-  profile.forget(aProfile);
+  mCurrent->GetRootDir(aRootDir);
+  mCurrent->GetLocalDir(aLocalDir);
+  NS_ADDREF(*aProfile = mCurrent);
+
+  return NS_OK;
+}
+
+/**
+ * Creates a new profile for reset and mark it as the current profile.
+ */
+nsresult nsToolkitProfileService::CreateResetProfile(
+    nsIToolkitProfile** aNewProfile) {
+  nsAutoCString oldProfileName;
+  mCurrent->GetName(oldProfileName);
+
+  nsCOMPtr<nsIToolkitProfile> newProfile;
+  // Make the new profile name the old profile (or "default-") + the time in
+  // seconds since epoch for uniqueness.
+  nsAutoCString newProfileName;
+  if (!oldProfileName.IsEmpty()) {
+    newProfileName.Assign(oldProfileName);
+    newProfileName.Append("-");
+  } else {
+    newProfileName.AssignLiteral("default-");
+  }
+  newProfileName.AppendPrintf("%" PRId64, PR_Now() / 1000);
+  nsresult rv = CreateProfile(nullptr,  // choose a default dir for us
+                              newProfileName, getter_AddRefs(newProfile));
+  if (NS_FAILED(rv)) return rv;
+
+  rv = Flush();
+  if (NS_FAILED(rv)) return rv;
+
+  mCurrent = newProfile;
+  newProfile.forget(aNewProfile);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsToolkitProfileService::GetProfileByName(const nsACString& aName,
                                           nsIToolkitProfile** aResult) {
   nsToolkitProfile* curP = mFirst;
@@ -907,23 +956,29 @@ nsToolkitProfileService::CreateProfile(n
   // We created a new profile dir. Let's store a creation timestamp.
   // Note that this code path does not apply if the profile dir was
   // created prior to launching.
   rv = CreateTimesInternal(rootDir);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsToolkitProfile* last = mFirst.get();
   if (last) {
-    while (last->mNext) last = last->mNext;
+    while (last->mNext) {
+      last = last->mNext;
+    }
   }
 
   nsCOMPtr<nsIToolkitProfile> profile =
       new nsToolkitProfile(aName, rootDir, localDir, last);
   if (!profile) return NS_ERROR_OUT_OF_MEMORY;
 
+  if (aName.Equals(DEV_EDITION_NAME)) {
+    mDevEditionDefault = profile;
+  }
+
   profile.forget(aResult);
   return NS_OK;
 }
 
 nsresult nsToolkitProfileService::CreateTimesInternal(nsIFile* aProfileDir) {
   nsresult rv = NS_ERROR_FAILURE;
   nsCOMPtr<nsIFile> creationLog;
   rv = aProfileDir->Clone(getter_AddRefs(creationLog));
@@ -1010,19 +1065,17 @@ nsToolkitProfileService::Flush() {
     pos +=
         snprintf(pos, end - pos,
                  "[Profile%u]\n"
                  "Name=%s\n"
                  "IsRelative=%s\n"
                  "Path=%s\n",
                  pCount, cur->mName.get(), isRelative ? "1" : "0", path.get());
 
-    nsCOMPtr<nsIToolkitProfile> profile;
-    rv = this->GetDefaultProfile(getter_AddRefs(profile));
-    if (NS_SUCCEEDED(rv) && profile == cur) {
+    if (cur == mNormalDefault) {
       pos += snprintf(pos, end - pos, "Default=1\n");
     }
 
     pos += snprintf(pos, end - pos, "\n");
 
     cur = cur->mNext;
     ++pCount;
   }
--- a/toolkit/profile/nsToolkitProfileService.h
+++ b/toolkit/profile/nsToolkitProfileService.h
@@ -71,40 +71,55 @@ class nsToolkitProfileFactory final : pu
 class nsToolkitProfileService final : public nsIToolkitProfileService {
  public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSITOOLKITPROFILESERVICE
 
   nsresult SelectStartupProfile(int* aArgc, char* aArgv[], bool aIsResetting,
                                 nsIFile** aRootDir, nsIFile** aLocalDir,
                                 nsIToolkitProfile** aProfile, bool* aDidCreate);
+  nsresult CreateResetProfile(nsIToolkitProfile** aNewProfile);
 
  private:
   friend class nsToolkitProfile;
   friend class nsToolkitProfileFactory;
   friend nsresult NS_NewToolkitProfileService(nsIToolkitProfileService**);
 
   nsToolkitProfileService();
   ~nsToolkitProfileService();
 
   nsresult Init();
 
   nsresult CreateTimesInternal(nsIFile* profileDir);
   void GetProfileByDir(nsIFile* aRootDir, nsIFile* aLocalDir,
                        nsIToolkitProfile** aResult);
 
+  // Tracks whether SelectStartupProfile has been called.
   bool mStartupProfileSelected;
+  // The first profile in a linked list of profiles loaded from profiles.ini.
   RefPtr<nsToolkitProfile> mFirst;
-  nsCOMPtr<nsIToolkitProfile> mChosen;
-  nsCOMPtr<nsIToolkitProfile> mDefault;
+  // The profile selected for use at startup, if it exists in profiles.ini.
+  nsCOMPtr<nsIToolkitProfile> mCurrent;
+  // The default profile used by non-dev-edition builds.
+  nsCOMPtr<nsIToolkitProfile> mNormalDefault;
+  // The profile used if mUseDevEditionProfile is true (the default on
+  // dev-edition builds).
+  nsCOMPtr<nsIToolkitProfile> mDevEditionDefault;
+  // The directory that holds profiles.ini and profile directories.
   nsCOMPtr<nsIFile> mAppData;
+  // The directory that holds the cache files for profiles.
   nsCOMPtr<nsIFile> mTempData;
+  // The location of profiles.ini.
   nsCOMPtr<nsIFile> mListFile;
+  // Whether to start with the selected profile by default.
   bool mStartWithLast;
+  // True if during startup it appeared that this is the first run.
   bool mIsFirstRun;
+  // True if the default profile is the separate dev-edition-profile.
+  bool mUseDevEditionProfile;
 
   static nsToolkitProfileService* gService;
 
   class ProfileEnumerator final : public nsSimpleEnumerator {
    public:
     NS_DECL_NSISIMPLEENUMERATOR
 
     const nsID& DefaultInterface() override {
--- a/toolkit/profile/xpcshell/head.js
+++ b/toolkit/profile/xpcshell/head.js
@@ -43,25 +43,29 @@ function makeRandomProfileDir(name) {
   return file;
 }
 
 /**
  * A wrapper around nsIToolkitProfileService.selectStartupProfile to make it
  * a bit nicer to use from JS.
  */
 function selectStartupProfile(args = [], isResetting = false) {
+  let service = getProfileService();
   let rootDir = {};
   let localDir = {};
   let profile = {};
-  let didCreate = getProfileService().selectStartupProfile(["xpcshell", ...args], isResetting,
-                                                           rootDir, localDir, profile);
+  let didCreate = service.selectStartupProfile(["xpcshell", ...args], isResetting,
+                                               rootDir, localDir, profile);
 
   if (profile.value) {
     Assert.ok(rootDir.value.equals(profile.value.rootDir), "Should have matched the root dir.");
     Assert.ok(localDir.value.equals(profile.value.localDir), "Should have matched the local dir.");
+    Assert.equal(service.currentProfile, profile.value, "Should have marked the profile as the current profile.");
+  } else {
+    Assert.ok(!service.currentProfile, "Should be no current profile.");
   }
 
   return {
     rootDir: rootDir.value,
     localDir: localDir.value,
     profile: profile.value,
     didCreate,
   };
@@ -205,17 +209,10 @@ function checkProfileService(profileData
       if (expectedProfile.name == PROFILE_DEFAULT) {
         defaultProfile = serviceProfile;
       }
     } else if (expectedProfile.default) {
       defaultProfile = serviceProfile;
     }
   }
 
-  let selectedProfile = null;
-  try {
-    selectedProfile = service.selectedProfile;
-  } catch (e) {
-    // GetSelectedProfile throws when there are no profiles.
-  }
-
-  Assert.equal(selectedProfile, defaultProfile, "Should have seen the right profile selected.");
+  Assert.equal(service.defaultProfile, defaultProfile, "Should have seen the right profile as default.");
 }
--- a/toolkit/profile/xpcshell/test_create_default.js
+++ b/toolkit/profile/xpcshell/test_create_default.js
@@ -1,19 +1,18 @@
 /*
  * Tests that from an empty database a default profile is created.
  */
 
 add_task(async () => {
   let service = getProfileService();
-
   let { profile, didCreate } = selectStartupProfile();
   checkProfileService();
 
   Assert.ok(didCreate, "Should have created a new profile.");
   if (AppConstants.MOZ_DEV_EDITION) {
     Assert.equal(service.profileCount, 2, "Should be two profiles.");
   } else {
     Assert.equal(service.profileCount, 1, "Should be only one profile.");
-    Assert.equal(profile, service.selectedProfile, "Should now be the selected profile.");
+    Assert.equal(profile, service.defaultProfile, "Should now be the default profile.");
   }
   Assert.equal(profile.name, PROFILE_DEFAULT, "Should have created a new profile with the right name.");
 });
--- a/toolkit/profile/xpcshell/test_select_default.js
+++ b/toolkit/profile/xpcshell/test_select_default.js
@@ -36,11 +36,11 @@ add_task(async () => {
   writeProfilesIni(profileData);
 
   let service = getProfileService();
   checkProfileService(profileData);
 
   let { profile, didCreate } = selectStartupProfile();
 
   Assert.ok(!didCreate, "Should not have created a new profile.");
-  Assert.equal(profile, service.selectedProfile, "Should have returned the selected profile.");
+  Assert.equal(profile, service.defaultProfile, "Should have returned the default profile.");
   Assert.equal(profile.name, PROFILE_DEFAULT, "Should have selected the right profile");
 });
--- a/toolkit/xre/ProfileReset.cpp
+++ b/toolkit/xre/ProfileReset.cpp
@@ -9,17 +9,16 @@
 #include "nsIToolkitProfile.h"
 #include "nsIWindowWatcher.h"
 
 #include "ProfileReset.h"
 
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsPIDOMWindow.h"
-#include "nsPrintfCString.h"
 #include "nsString.h"
 #include "nsXPCOMCIDInternal.h"
 #include "mozilla/Components.h"
 #include "mozilla/XREAppData.h"
 
 #include "mozilla/Services.h"
 #include "mozilla/Unused.h"
 #include "prtime.h"
@@ -27,51 +26,16 @@
 using namespace mozilla;
 
 extern const XREAppData* gAppData;
 
 static const char kProfileProperties[] =
     "chrome://mozapps/locale/profile/profileSelection.properties";
 
 /**
- * Creates a new profile with a timestamp in the name to use for profile reset.
- */
-nsresult CreateResetProfile(nsIToolkitProfileService* aProfileSvc,
-                            nsIToolkitProfile* aOldProfile,
-                            nsIToolkitProfile** aNewProfile) {
-  MOZ_ASSERT(aProfileSvc, "NULL profile service");
-
-  nsAutoCString oldProfileName;
-  aOldProfile->GetName(oldProfileName);
-
-  nsCOMPtr<nsIToolkitProfile> newProfile;
-  // Make the new profile the old profile (or "default-") + the time in seconds
-  // since epoch for uniqueness.
-  nsAutoCString newProfileName;
-  if (!oldProfileName.IsEmpty()) {
-    newProfileName.Assign(oldProfileName);
-    newProfileName.Append("-");
-  } else {
-    newProfileName.AssignLiteral("default-");
-  }
-  newProfileName.Append(nsPrintfCString("%" PRId64, PR_Now() / 1000));
-  nsresult rv =
-      aProfileSvc->CreateProfile(nullptr,  // choose a default dir for us
-                                 newProfileName, getter_AddRefs(newProfile));
-  if (NS_FAILED(rv)) return rv;
-
-  rv = aProfileSvc->Flush();
-  if (NS_FAILED(rv)) return rv;
-
-  newProfile.swap(*aNewProfile);
-
-  return NS_OK;
-}
-
-/**
  * Delete the profile directory being reset after a backup and delete the local
  * profile directory.
  */
 nsresult ProfileResetCleanup(nsIToolkitProfile* aOldProfile) {
   nsresult rv;
   nsCOMPtr<nsIFile> profileDir;
   rv = aOldProfile->GetRootDir(getter_AddRefs(profileDir));
   if (NS_FAILED(rv)) return rv;
--- a/toolkit/xre/ProfileReset.h
+++ b/toolkit/xre/ProfileReset.h
@@ -6,20 +6,16 @@
 #include "nsIToolkitProfileService.h"
 #include "nsIFile.h"
 #include "nsThreadUtils.h"
 
 static bool gProfileResetCleanupCompleted = false;
 static const char kResetProgressURL[] =
     "chrome://global/content/resetProfileProgress.xul";
 
-nsresult CreateResetProfile(nsIToolkitProfileService* aProfileSvc,
-                            nsIToolkitProfile* aOldProfile,
-                            nsIToolkitProfile** aNewProfile);
-
 nsresult ProfileResetCleanup(nsIToolkitProfile* aOldProfile);
 
 class ProfileResetCleanupResultTask : public mozilla::Runnable {
  public:
   ProfileResetCleanupResultTask()
       : mozilla::Runnable("ProfileResetCleanupResultTask"),
         mWorkerThread(do_GetCurrentThread()) {
     MOZ_ASSERT(!NS_IsMainThread());
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -1953,18 +1953,16 @@ static nsresult ProfileLockedDialog(nsIT
 static const char kProfileManagerURL[] =
     "chrome://mozapps/content/profile/profileSelection.xul";
 
 static ReturnAbortOnError ShowProfileManager(
     nsIToolkitProfileService* aProfileSvc, nsINativeAppSupport* aNative) {
   nsresult rv;
 
   nsCOMPtr<nsIFile> profD, profLD;
-  char16_t* profileNamePtr;
-  nsAutoCString profileName;
   bool offline = false;
 
   {
     ScopedXPCOMStartup xpcom;
     rv = xpcom.Initialize();
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Initialize the graphics prefs, some of the paths need them before
@@ -2024,22 +2022,16 @@ static ReturnAbortOnError ShowProfileMan
       NS_ENSURE_SUCCESS_LOG(rv, rv);
 
       rv = lock->GetDirectory(getter_AddRefs(profD));
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = lock->GetLocalDirectory(getter_AddRefs(profLD));
       NS_ENSURE_SUCCESS(rv, rv);
 
-      rv = ioParamBlock->GetString(0, &profileNamePtr);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      CopyUTF16toUTF8(MakeStringSpan(profileNamePtr), profileName);
-      free(profileNamePtr);
-
       lock->Unlock();
     }
   }
 
   SaveFileToEnv("XRE_PROFILE_PATH", profD);
   SaveFileToEnv("XRE_PROFILE_LOCAL_PATH", profLD);
 
   if (offline) {
@@ -2205,18 +2197,17 @@ static nsresult SelectProfile(nsIProfile
       if (NS_FAILED(rv)) {
         return ProfileLockedDialog(profile, unlocker, aNative,
                                    &tempProfileLock);
       }
     }
 
     // If we're resetting a profile, create a new one and use it to startup.
     gResetOldProfile = profile;
-    rv = CreateResetProfile(aProfileSvc, gResetOldProfile,
-                            getter_AddRefs(profile));
+    rv = service->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);
@@ -4134,25 +4125,25 @@ nsresult XREMain::XRE_mainRun() {
         if (buf[0] == '0' || buf[0] == 'f' || buf[0] == 'F') {
           gDoMigration = false;
         }
       }
     }
   }
 
   {
-    bool profileWasSelected = false;
+    bool profileWasDefault = false;
     if (gDoProfileReset) {
       nsCOMPtr<nsIToolkitProfile> defaultProfile;
       // This can fail if there is no default profile.
       // That shouldn't stop reset from proceeding.
-      nsresult gotSelected =
-          mProfileSvc->GetSelectedProfile(getter_AddRefs(defaultProfile));
-      if (NS_SUCCEEDED(gotSelected)) {
-        profileWasSelected = defaultProfile == gResetOldProfile;
+      nsresult gotDefault =
+          mProfileSvc->GetDefaultProfile(getter_AddRefs(defaultProfile));
+      if (NS_SUCCEEDED(gotDefault)) {
+        profileWasDefault = defaultProfile == gResetOldProfile;
       }
     }
 
     // Profile Migration
     if (mAppData->flags & NS_XRE_ENABLE_PROFILE_MIGRATOR && gDoMigration) {
       gDoMigration = false;
       nsCOMPtr<nsIProfileMigrator> pm(
           do_CreateInstance(NS_PROFILEMIGRATOR_CONTRACTID));
@@ -4178,17 +4169,17 @@ nsresult XREMain::XRE_mainRun() {
       rv = GetCurrentProfile(mProfileSvc, mProfD, getter_AddRefs(newProfile));
       if (NS_SUCCEEDED(rv)) {
         nsAutoCString name;
         gResetOldProfile->GetName(name);
         newProfile->SetName(name);
         mProfileName.Assign(name);
         // Set the new profile as the default after we're done cleaning up the
         // old profile, iff that profile was already the default
-        if (profileWasSelected) {
+        if (profileWasDefault) {
           rv = mProfileSvc->SetDefaultProfile(newProfile);
           if (NS_FAILED(rv))
             NS_WARNING("Could not set current profile as the default");
         }
       } else {
         NS_WARNING(
             "Could not find current profile to set as default / change name.");
       }