Bug 1299445 - Use distribution.ini directly to check if automigration is enabled. r=mkaply, a=lizzard
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 31 Aug 2016 14:58:23 +0100
changeset 347993 7c6b0d878e8233344aa5cd9cc8356341fc8741d5
parent 347992 599fa314173b04654ab8e94ef04d77657ed91d59
child 347994 1636a87ec69424d84aaa3fc00ff1894c658221a1
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkaply, lizzard
bugs1299445
milestone50.0a2
Bug 1299445 - Use distribution.ini directly to check if automigration is enabled. r=mkaply, a=lizzard MozReview-Commit-ID: DINI8rnyMfe
browser/components/migration/AutoMigrate.jsm
--- a/browser/components/migration/AutoMigrate.jsm
+++ b/browser/components/migration/AutoMigrate.jsm
@@ -46,18 +46,38 @@ function getBundle() {
 }
 
 const AutoMigrate = {
   get resourceTypesToUse() {
     let {BOOKMARKS, HISTORY, PASSWORDS} = Ci.nsIBrowserProfileMigrator;
     return BOOKMARKS | HISTORY | PASSWORDS;
   },
 
+  _checkIfEnabled() {
+    let pref = Preferences.get(kAutoMigrateEnabledPref, false);
+    // User-set values should take precedence:
+    if (Services.prefs.prefHasUserValue(kAutoMigrateEnabledPref)) {
+      return pref;
+    }
+    // If we're using the default value, make sure the distribution.ini
+    // value is taken into account even early on startup.
+    try {
+      let distributionFile = Services.dirsvc.get("XREAppDist", Ci.nsIFile);
+      distributionFile.append("distribution.ini");
+      let parser = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].
+                 getService(Ci.nsIINIParserFactory).
+                 createINIParser(distributionFile);
+      return JSON.parse(parser.getString("Preferences", kAutoMigrateEnabledPref));
+    } catch (ex) { /* ignore exceptions (file doesn't exist, invalid value, etc.) */ }
+
+    return pref;
+  },
+
   init() {
-    this.enabled = Preferences.get(kAutoMigrateEnabledPref, false) &&
+    this.enabled = this._checkIfEnabled() &&
                    Cc["@mozilla.org/chrome/chrome-registry;1"].
                      getService(Ci.nsIXULChromeRegistry).
                      getSelectedLocale("browser") == "en-US";
     if (this.enabled) {
       this.maybeInitUndoObserver();
     }
   },