Bug 995206 - Sync app.update.{channel,url} settings with preferences. r=vingtetun
authorJan Keromnes <janx@linux.com>
Wed, 23 Apr 2014 08:14:00 +0200
changeset 179834 1d7b9a01b8cf2759e071e2b120dc588aafc5f34a
parent 179833 1d0a4cd6ec208089412293f3344252a1be3d3dc1
child 179835 38be37271c25398ee5bf1753d2bb334aaada90e9
push id6466
push usercbook@mozilla.com
push dateThu, 24 Apr 2014 09:09:28 +0000
treeherderb2g-inbound@91946180b1e7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs995206
milestone31.0a1
Bug 995206 - Sync app.update.{channel,url} settings with preferences. r=vingtetun
b2g/chrome/content/settings.js
--- a/b2g/chrome/content/settings.js
+++ b/b2g/chrome/content/settings.js
@@ -141,17 +141,16 @@ Components.utils.import('resource://gre/
   // from configure.in, defaults to 1.0.0 if this value is not exist.
 #filter attemptSubstitution
   let os_version = '@MOZ_B2G_VERSION@';
   let os_name = '@MOZ_B2G_OS_NAME@';
 #unfilter attemptSubstitution
 
   let appInfo = Cc["@mozilla.org/xre/app-info;1"]
                   .getService(Ci.nsIXULAppInfo);
-  let update_channel = Services.prefs.getCharPref('app.update.channel');
 
   // Get the hardware info and firmware revision from device properties.
   let hardware_info = null;
   let firmware_revision = null;
   let product_model = null;
 #ifdef MOZ_WIDGET_GONK
     hardware_info = libcutils.property_get('ro.hardware');
     firmware_revision = libcutils.property_get('ro.firmware_revision');
@@ -159,17 +158,16 @@ Components.utils.import('resource://gre/
 #endif
 
   let software = os_name + ' ' + os_version;
   let setting = {
     'deviceinfo.os': os_version,
     'deviceinfo.software': software,
     'deviceinfo.platform_version': appInfo.platformVersion,
     'deviceinfo.platform_build_id': appInfo.platformBuildID,
-    'deviceinfo.update_channel': update_channel,
     'deviceinfo.hardware': hardware_info,
     'deviceinfo.firmware_revision': firmware_revision,
     'deviceinfo.product_model': product_model
   }
   window.navigator.mozSettings.createLock().set(setting);
 })();
 
 // =================== DevTools ====================
@@ -541,16 +539,17 @@ function setUpdateTrackingId() {
       Services.prefs.setCharPref('app.update.custom', trackingId);
     }
   } catch(e) {
     dump('Error getting tracking ID ' + e + '\n');
   }
 }
 setUpdateTrackingId();
 
+
 // ================ Debug ================
 (function Composer2DSettingToPref() {
   //layers.composer.enabled can be enabled in three ways
   //In order of precedence they are:
   //
   //1. mozSettings "layers.composer.enabled"
   //2. a gecko pref "layers.composer.enabled"
   //3. presence of ro.display.colorfill at the Gonk level
@@ -675,48 +674,74 @@ let settingsToObserve = {
     defaultValue: false
   },
   'debug.paint-flashing.enabled': {
     prefName: 'nglayout.debug.paint_flashing',
     defaultValue: false
   },
   'layers.draw-borders': false,
   'app.update.interval': 86400,
+  'app.update.url': {
+    resetToPref: true
+  },
+  'app.update.channel': {
+    resetToPref: true
+  },
   'debug.log-animations.enabled': {
     prefName: 'layers.offmainthreadcomposition.log-animations',
     defaultValue: false
   }
 };
 
 for (let key in settingsToObserve) {
   let setting = settingsToObserve[key];
 
-  // By default, assume the setting name and the pref name are the same.
-  let prefName = key;
-  let defaultValue = setting;
-
-  // Check if the pref name has been overidden.
-  if (typeof setting == 'object') {
-    prefName = setting.prefName;
-    defaultValue = setting.defaultValue;
+  // Allow setting to contain flags redefining prefName and defaultValue.
+  let prefName = setting.prefName || key;
+  let defaultValue = setting.defaultValue;
+  if (defaultValue === undefined) {
+    defaultValue = setting;
   }
 
+  let prefs = Services.prefs;
+
+  // If requested, reset setting value and defaultValue to the pref value.
+  if (setting.resetToPref) {
+    switch (prefs.getPrefType(prefName)) {
+      case Ci.nsIPrefBranch.PREF_BOOL:
+        defaultValue = prefs.getBoolPref(prefName);
+        break;
+
+      case Ci.nsIPrefBranch.PREF_INT:
+        defaultValue = prefs.getIntPref(prefName);
+        break;
+
+      case Ci.nsIPrefBranch.PREF_STRING:
+        defaultValue = prefs.getCharPref(prefName);
+        break;
+    }
+
+    let setting = {};
+    setting[key] = defaultValue;
+    window.navigator.mozSettings.createLock().set(setting);
+  }
+
+  // Figure out the right setter function for this type of pref.
+  let setPref;
   switch (typeof defaultValue) {
     case 'boolean':
-      SettingsListener.observe(key, defaultValue, function(value) {
-        Services.prefs.setBoolPref(prefName, value);
-      });
+      setPref = prefs.setBoolPref.bind(prefs);
+      break;
+
+    case 'number':
+      setPref = prefs.setIntPref.bind(prefs);
       break;
 
     case 'string':
-      SettingsListener.observe(key, defaultValue, function(value) {
-        Services.prefs.setCharPref(prefName, value);
-      });
-      break;
-
-    case 'number':
-      SettingsListener.observe(key, defaultValue, function(value) {
-        Services.prefs.setIntPref(prefName, value);
-      });
+      setPref = prefs.setCharPref.bind(prefs);
       break;
   }
+
+  SettingsListener.observe(key, defaultValue, function(value) {
+    setPref(prefName, value);
+  });
 };