Bug 1357517 - Remove or delay Preferences.jsm usage from Marionette. r=ato
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Sun, 30 Jul 2017 20:05:22 +0200
changeset 423066 3362528e5e2524be4fce4bb8cf3496bb01fe2e82
parent 423021 6d1b50a370b4adffbb1ee73b9f51707c90d6a2b1
child 423067 6025b5b43ec638821540a4199be4c10e2160f6e3
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1357517
milestone56.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 1357517 - Remove or delay Preferences.jsm usage from Marionette. r=ato
testing/marionette/components/marionette.js
--- a/testing/marionette/components/marionette.js
+++ b/testing/marionette/components/marionette.js
@@ -2,23 +2,25 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const {Constructor: CC, interfaces: Ci, utils: Cu, classes: Cc} = Components;
 
 Cu.import("resource://gre/modules/Log.jsm");
-Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(
     this, "env", "@mozilla.org/process/environment;1", "nsIEnvironment");
 
+XPCOMUtils.defineLazyModuleGetter(this, "Preferences",
+  "resource://gre/modules/Preferences.jsm");
+
 const MARIONETTE_CONTRACT_ID = "@mozilla.org/remote/marionette;1";
 const MARIONETTE_CID = Components.ID("{786a1369-dca5-4adc-8486-33d23c88010a}");
 
 const PREF_PORT = "marionette.port";
 const PREF_PORT_FALLBACK = "marionette.defaultPrefs.port";
 const PREF_LOG_LEVEL = "marionette.log.level";
 const PREF_LOG_LEVEL_FALLBACK = "marionette.logging";
 
@@ -62,23 +64,53 @@ const ENV_ENABLED = "MOZ_MARIONETTE";
 // something like {"port": 4444} would result in the marionette.port
 // pref being set to 4444.
 const ENV_PRESERVE_PREFS = "MOZ_MARIONETTE_PREF_STATE_ACROSS_RESTARTS";
 
 const ServerSocket = CC("@mozilla.org/network/server-socket;1",
     "nsIServerSocket",
     "initSpecialConnection");
 
+const {PREF_STRING, PREF_BOOL, PREF_INT, PREF_INVALID} = Ci.nsIPrefBranch;
+
+function getPrefVal(pref) {
+  let prefType = Services.prefs.getPrefType(pref);
+  let prefValue;
+  switch (prefType) {
+    case PREF_STRING:
+      prefValue = Services.prefs.getStringPref(pref);
+      break;
+
+    case PREF_BOOL:
+      prefValue = Services.prefs.getBoolPref(pref);
+      break;
+
+    case PREF_INT:
+      prefValue = Services.prefs.getIntPref(pref);
+      break;
+
+    case PREF_INVALID:
+      prefValue = undefined;
+      break;
+
+    default:
+      throw new TypeError(`Unexpected preference type (${prefType}) for ${pref}`);
+  }
+
+  return prefValue;
+}
+
 // Get preference value of |preferred|, falling back to |fallback|
 // if |preferred| is not user-modified and |fallback| exists.
 function getPref(preferred, fallback) {
-  if (!Preferences.isSet(preferred) && Preferences.has(fallback)) {
-    return Preferences.get(fallback, Preferences.get(preferred));
+  if (!Services.prefs.prefHasUserValue(preferred) &&
+      Services.prefs.getPrefType(fallback) != Ci.nsIPrefBranch.PREF_INVALID) {
+    return getPrefVal(fallback, getPrefVal(preferred));
   }
-  return Preferences.get(preferred);
+  return getPrefVal(preferred);
 }
 
 // Marionette preferences recently changed names.  This is an abstraction
 // that first looks for the new name, but falls back to using the old name
 // if the new does not exist.
 //
 // This shim can be removed when Firefox 55 ships.
 const prefs = {