Bug 1167733 - Consolidate prefs access and usage in the new performance tool, r=jsantell, a=sledru
authorVictor Porof <vporof@mozilla.com>
Fri, 22 May 2015 17:46:59 -0400
changeset 274876 2a600507cad0330bdc0103008e023509e55b1997
parent 274875 9febab7820650d8eff4d9f85b8fc8b44a18f39c2
child 274877 d6d39fe9ec036203b6aa7d33efc62d87ceb90fbb
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsantell, sledru
bugs1167733
milestone40.0a2
Bug 1167733 - Consolidate prefs access and usage in the new performance tool, r=jsantell, a=sledru
browser/devtools/performance/modules/global.js
browser/devtools/performance/performance-controller.js
--- a/browser/devtools/performance/modules/global.js
+++ b/browser/devtools/performance/modules/global.js
@@ -17,18 +17,23 @@ const L10N = new ViewHelpers.MultiL10N([
   "chrome://browser/locale/devtools/timeline.properties",
   "chrome://browser/locale/devtools/profiler.properties"
 ]);
 
 /**
  * A list of preferences for this tool. The values automatically update
  * if somebody edits edits about:config or the prefs change somewhere else.
  */
-const Prefs = new ViewHelpers.Prefs("devtools.performance.ui", {
-  showPlatformData: ["Bool", "show-platform-data"]
+const PREFS = new ViewHelpers.Prefs("devtools.performance", {
+  "show-platform-data": ["Bool", "ui.show-platform-data"],
+  "hidden-markers": ["Json", "timeline.hidden-markers"],
+  "memory-sample-probability": ["Float", "memory.sample-probability"],
+  "memory-max-log-length": ["Int", "memory.max-log-length"],
+  "profiler-buffer-size": ["Int", "profiler.buffer-size"],
+  "profiler-sample-frequency": ["Int", "profiler.sample-frequency-khz"],
 }, {
   monitorChanges: true
 });
 
 /**
  * Details about each profile entry cateogry.
  * @see CATEGORY_MAPPINGS.
  */
@@ -234,17 +239,17 @@ function getJSLabel (marker={}) {
 /**
  * Returns a hash for computing a fields object for a JS marker. If the cause
  * is considered content (so an entry exists in the JS_MARKER_MAP), do not display it
  * since it's redundant with the label. Otherwise for Gecko code, either display
  * the cause, or "(Gecko)", depending on if "show-platform-data" is set.
  */
 function getJSFields (marker) {
   if ("causeName" in marker && !JS_MARKER_MAP[marker.causeName]) {
-    return { Reason: Prefs.showPlatformData ? marker.causeName : GECKO_SYMBOL };
+    return { Reason: PREFS["show-platform-data"] ? marker.causeName : GECKO_SYMBOL };
   }
 }
 
 function getDOMEventFields (marker) {
   let fields = Object.create(null);
   if ("type" in marker) {
     fields[L10N.getStr("timeline.markerDetail.DOMEventType")] = marker.type;
   }
@@ -333,15 +338,16 @@ const [CATEGORY_MASK, CATEGORY_MASK_LIST
 const CATEGORY_OTHER = CATEGORY_MASK('other');
 
 // Human-readable JIT category bitmask. Certain pseudo-frames in a sample,
 // like "EnterJIT", don't have any associated `cateogry` information.
 const CATEGORY_JIT = CATEGORY_MASK('js');
 
 // Exported symbols.
 exports.L10N = L10N;
+exports.PREFS = PREFS;
 exports.TIMELINE_BLUEPRINT = TIMELINE_BLUEPRINT;
 exports.CATEGORIES = CATEGORIES;
 exports.CATEGORY_MAPPINGS = CATEGORY_MAPPINGS;
 exports.CATEGORY_MASK = CATEGORY_MASK;
 exports.CATEGORY_MASK_LIST = CATEGORY_MASK_LIST;
 exports.CATEGORY_OTHER = CATEGORY_OTHER;
 exports.CATEGORY_JIT = CATEGORY_JIT;
--- a/browser/devtools/performance/performance-controller.js
+++ b/browser/devtools/performance/performance-controller.js
@@ -195,32 +195,20 @@ let PerformanceController = {
     this._onRecordingSelectFromView = this._onRecordingSelectFromView.bind(this);
     this._onPrefChanged = this._onPrefChanged.bind(this);
     this._onThemeChanged = this._onThemeChanged.bind(this);
     this._onRecordingStateChange = this._onRecordingStateChange.bind(this);
     this._onProfilerStatusUpdated = this._onProfilerStatusUpdated.bind(this);
 
     // Store data regarding if e10s is enabled.
     this._e10s = Services.appinfo.browserTabsRemoteAutostart;
-
     this._setMultiprocessAttributes();
 
-    // All boolean prefs should be handled via the OptionsView in the
-    // ToolbarView, so that they may be accessible via the "gear" menu.
-    // Every other pref should be registered here.
-    this._nonBooleanPrefs = new ViewHelpers.Prefs("devtools.performance", {
-      "hidden-markers": ["Json", "timeline.hidden-markers"],
-      "memory-sample-probability": ["Float", "memory.sample-probability"],
-      "memory-max-log-length": ["Int", "memory.max-log-length"],
-      "profiler-buffer-size": ["Int", "profiler.buffer-size"],
-      "profiler-sample-frequency": ["Int", "profiler.sample-frequency-khz"],
-    });
-
-    this._nonBooleanPrefs.registerObserver();
-    this._nonBooleanPrefs.on("pref-changed", this._onPrefChanged);
+    this._prefs = require("devtools/performance/global").PREFS;
+    this._prefs.on("pref-changed", this._onPrefChanged);
 
     gFront.on("recording-starting", this._onRecordingStateChange);
     gFront.on("recording-started", this._onRecordingStateChange);
     gFront.on("recording-stopping", this._onRecordingStateChange);
     gFront.on("recording-stopped", this._onRecordingStateChange);
     gFront.on("profiler-status", this._onProfilerStatusUpdated);
     ToolbarView.on(EVENTS.PREF_CHANGED, this._onPrefChanged);
     PerformanceView.on(EVENTS.UI_START_RECORDING, this.startRecording);
@@ -232,18 +220,17 @@ let PerformanceController = {
 
     gDevTools.on("pref-changed", this._onThemeChanged);
   }),
 
   /**
    * Remove events handled by the PerformanceController
    */
   destroy: function() {
-    this._nonBooleanPrefs.unregisterObserver();
-    this._nonBooleanPrefs.off("pref-changed", this._onPrefChanged);
+    this._prefs.off("pref-changed", this._onPrefChanged);
 
     gFront.off("recording-starting", this._onRecordingStateChange);
     gFront.off("recording-started", this._onRecordingStateChange);
     gFront.off("recording-stopping", this._onRecordingStateChange);
     gFront.off("recording-stopped", this._onRecordingStateChange);
     gFront.off("profiler-status", this._onProfilerStatusUpdated);
     ToolbarView.off(EVENTS.PREF_CHANGED, this._onPrefChanged);
     PerformanceView.off(EVENTS.UI_START_RECORDING, this.startRecording);
@@ -260,41 +247,46 @@ let PerformanceController = {
    * Returns the current devtools theme.
    */
   getTheme: function () {
     return Services.prefs.getCharPref("devtools.theme");
   },
 
   /**
    * Get a boolean preference setting from `prefName` via the underlying
-   * OptionsView in the ToolbarView.
+   * OptionsView in the ToolbarView. This preference is guaranteed to be
+   * displayed in the UI.
    *
    * @param string prefName
    * @return boolean
    */
   getOption: function (prefName) {
     return ToolbarView.optionsView.getPref(prefName);
   },
 
   /**
-   * Get a preference setting from `prefName`.
+   * Get a preference setting from `prefName`. This preference can be of
+   * any type and might not be displayed in the UI.
+   *
    * @param string prefName
-   * @return object
+   * @return any
    */
   getPref: function (prefName) {
-    return this._nonBooleanPrefs[prefName];
+    return this._prefs[prefName];
   },
 
   /**
-   * Set a preference setting from `prefName`.
+   * Set a preference setting from `prefName`. This preference can be of
+   * any type and might not be displayed in the UI.
+   *
    * @param string prefName
-   * @param object prefValue
+   * @param any prefValue
    */
   setPref: function (prefName, prefValue) {
-    this._nonBooleanPrefs[prefName] = prefValue;
+    this._prefs[prefName] = prefValue;
   },
 
   /**
    * Starts recording with the PerformanceFront. Emits `EVENTS.RECORDING_STARTED`
    * when the front has started to record.
    */
   startRecording: Task.async(function *() {
     let options = {