Bug 1518591: Make the profile service responsible for protecting against downgrading to builds before dev-edition had a separate profile. r=froydnj
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 10 Jan 2019 21:15:53 +0000
changeset 513744 8844751cb1698c69c2fead027fb31e791bc0ab00
parent 513743 394b490d3e2deb8c31c71214320ebfc16a8db008
child 513745 944a2fbd7454ba098144293f95f5fe6011339073
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1518591
milestone66.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 1518591: Make the profile service responsible for protecting against downgrading to builds before dev-edition had a separate profile. r=froydnj Because older versions of Firefox auto-select a profile if there is only one in the database when running dev-edition which uses its own profile we create a default for normal channels to use. Currently the browser code is responsible for doing this but it uses a bad heuristic for deciding when to do that. It's much easier to do it from the profile manager when the dev-edition profile is created. Differential Revision: https://phabricator.services.mozilla.com/D16117
browser/components/nsBrowserGlue.js
toolkit/profile/nsToolkitProfileService.cpp
toolkit/profile/xpcshell/test_create_default.js
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -1626,22 +1626,16 @@ BrowserGlue.prototype = {
             Cc[WINTASKBAR_CONTRACTID].getService(Ci.nsIWinTaskbar).available) {
           let temp = {};
           ChromeUtils.import("resource:///modules/WindowsJumpLists.jsm", temp);
           temp.WinTaskbarJumpList.startup();
         }
       });
     }
 
-    if (AppConstants.MOZ_DEV_EDITION) {
-      Services.tm.idleDispatchToMainThread(() => {
-        this._createExtraDefaultProfile();
-      });
-    }
-
     Services.tm.idleDispatchToMainThread(() => {
       this._checkForDefaultBrowser();
     });
 
     Services.tm.idleDispatchToMainThread(() => {
       let {setTimeout} = ChromeUtils.import("resource://gre/modules/Timer.jsm", {});
       setTimeout(function() {
         Services.tm.idleDispatchToMainThread(Services.startup.trackStartupCrashEnd);
@@ -1712,50 +1706,16 @@ BrowserGlue.prototype = {
       this._gmpInstallManager.simpleCheckAndInstall().catch(() => {});
     });
 
     Services.tm.idleDispatchToMainThread(() => {
       RemoteSettings.init();
     });
   },
 
-  _createExtraDefaultProfile() {
-    if (!AppConstants.MOZ_DEV_EDITION) {
-      return;
-    }
-    // If Developer Edition is the only installed Firefox version and no other
-    // profiles are present, create a second one for use by other versions.
-    // This helps Firefox versions earlier than 35 avoid accidentally using the
-    // unsuitable Developer Edition profile.
-    let profileService = Cc["@mozilla.org/toolkit/profile-service;1"]
-                         .getService(Ci.nsIToolkitProfileService);
-    let profileCount = profileService.profileCount;
-    if (profileCount == 1 && profileService.selectedProfile.name != "default") {
-      let newProfile;
-      try {
-        newProfile = profileService.createProfile(null, "default");
-        profileService.defaultProfile = newProfile;
-        profileService.flush();
-      } catch (e) {
-        Cu.reportError("Could not create profile 'default': " + e);
-      }
-      if (newProfile) {
-        // We don't want a default profile with Developer Edition settings, an
-        // empty profile directory will do. The profile service of the other
-        // Firefox will populate it with its own stuff.
-        let newProfilePath = newProfile.rootDir.path;
-        OS.File.removeDir(newProfilePath).then(() => {
-          return OS.File.makeDir(newProfilePath);
-        }).catch(e => {
-          Cu.reportError("Could not empty profile 'default': " + e);
-        });
-      }
-    }
-  },
-
   _onQuitRequest: function BG__onQuitRequest(aCancelQuit, aQuitType) {
     // If user has already dismissed quit request, then do nothing
     if ((aCancelQuit instanceof Ci.nsISupportsPRBool) && aCancelQuit.data)
       return;
 
     // There are several cases where we won't show a dialog here:
     // 1. There is only 1 tab open in 1 window
     // 2. browser.warnOnQuit == false
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -41,16 +41,17 @@
 #include "nsReadableUtils.h"
 #include "nsNativeCharsetUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Sprintf.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)
     : mPrev(aPrev),
       mName(aName),
       mRootDir(aRootDir),
       mLocalDir(aLocalDir),
       mLock(nullptr) {
@@ -712,21 +713,29 @@ nsresult nsToolkitProfileService::Select
       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"),
+                                NS_LITERAL_CSTRING(DEFAULT_NAME),
 #endif
                                 getter_AddRefs(mChosen));
     if (NS_SUCCEEDED(rv)) {
-#ifndef MOZ_DEV_EDITION
+#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));
+      }
+#else
       SetDefaultProfile(mChosen);
 #endif
       Flush();
 
       mChosen->GetRootDir(aRootDir);
       mChosen->GetLocalDir(aLocalDir);
       NS_ADDREF(*aProfile = mChosen);
 
--- a/toolkit/profile/xpcshell/test_create_default.js
+++ b/toolkit/profile/xpcshell/test_create_default.js
@@ -4,12 +4,16 @@
 
 add_task(async () => {
   let service = getProfileService();
 
   let { profile, didCreate } = selectStartupProfile();
   checkProfileService();
 
   Assert.ok(didCreate, "Should have created a new profile.");
-  Assert.equal(service.profileCount, 1, "Should be only one profile.");
-  Assert.equal(profile, service.selectedProfile, "Should now be the selected 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.name, PROFILE_DEFAULT, "Should have created a new profile with the right name.");
 });