Bug 1122480 - Part 8 - Update the settings: show upload & extended recording. r=rvitillo
☠☠ backed out by b9faa176ef67 ☠ ☠
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Mon, 11 May 2015 19:40:23 +0200
changeset 243293 6ae5efa4292857ca7840cda483fdc84f5b41bf56
parent 243292 ea2720c41747a39467242a5207f5621b6ebd59f8
child 243294 9fff6229aa8e4de92f20f676aa2462bfc60c66dc
push id28736
push usercbook@mozilla.com
push dateTue, 12 May 2015 10:01:42 +0000
treeherdermozilla-central@0ca37b3cb73d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrvitillo
bugs1122480
milestone40.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 1122480 - Part 8 - Update the settings: show upload & extended recording. r=rvitillo
toolkit/content/aboutTelemetry.css
toolkit/content/aboutTelemetry.js
toolkit/content/aboutTelemetry.xhtml
toolkit/locales/en-US/chrome/global/aboutTelemetry.dtd
toolkit/locales/en-US/chrome/global/aboutTelemetry.properties
--- a/toolkit/content/aboutTelemetry.css
+++ b/toolkit/content/aboutTelemetry.css
@@ -22,21 +22,26 @@ h2 {
 }
 
 #page-description {
   border: 1px solid threedshadow;
   margin: 0px;
   padding: 10px;
 }
 
-#description-enabled > span {
+.description-enabled,
+.description-disabled {
+  margin: 0px;
+}
+
+.description-enabled > span {
   color: green;
 }
 
-#description-disabled > span {
+.description-disabled > span {
   color: red;
 }
 
 .data-section {
   background-color: -moz-Field;
   color: -moz-FieldText;
   border-top: 1px solid threedshadow;
   border-bottom: 1px solid threedshadow;
--- a/toolkit/content/aboutTelemetry.js
+++ b/toolkit/content/aboutTelemetry.js
@@ -24,16 +24,17 @@ const brandBundle = Services.strings.cre
 // Maximum height of a histogram bar (in em for html, in chars for text)
 const MAX_BAR_HEIGHT = 18;
 const MAX_BAR_CHARS = 25;
 const PREF_TELEMETRY_SERVER_OWNER = "toolkit.telemetry.server_owner";
 const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";
 const PREF_DEBUG_SLOW_SQL = "toolkit.telemetry.debugSlowSql";
 const PREF_SYMBOL_SERVER_URI = "profiler.symbolicationUrl";
 const DEFAULT_SYMBOL_SERVER_URI = "http://symbolapi.mozilla.org";
+const PREF_FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
 
 // ms idle before applying the filter (allow uninterrupted typing)
 const FILTER_IDLE_TIMEOUT = 500;
 
 const isWindows = (Services.appinfo.OS == "WINNT");
 const EOL = isWindows ? "\r\n" : "\n";
 
 // This is the ping object currently displayed in the page.
@@ -120,47 +121,62 @@ function filterObject(obj, filterOut) {
 function sectionalizeObject(obj) {
   let map = new Map();
   for (let k of Object.keys(obj)) {
     map.set(k, explodeObject(obj[k]));
   }
   return map;
 }
 
-let observer = {
-
-  enableTelemetry: bundle.GetStringFromName("enableTelemetry"),
-
-  disableTelemetry: bundle.GetStringFromName("disableTelemetry"),
+let Settings = {
+  SETTINGS: [
+    // data upload
+    {
+      pref: PREF_FHR_UPLOAD_ENABLED,
+      defaultPrefValue: false,
+      descriptionEnabledId: "description-upload-enabled",
+      descriptionDisabledId: "description-upload-disabled",
+    },
+    // extended "Telemetry" recording
+    {
+      pref: PREF_TELEMETRY_ENABLED,
+      defaultPrefValue: false,
+      descriptionEnabledId: "description-extended-recording-enabled",
+      descriptionDisabledId: "description-extended-recording-disabled",
+    },
+  ],
 
-  /**
-   * Observer is called whenever Telemetry is enabled or disabled
-   */
-  observe: function observe(aSubject, aTopic, aData) {
-    if (aData == PREF_TELEMETRY_ENABLED) {
-      this.updatePrefStatus();
+  attachObservers: function() {
+    for (let s of this.SETTINGS) {
+      let setting = s;
+      Preferences.observe(setting.pref, this.render, this);
+    }
+  },
+
+  detachObservers: function() {
+    for (let setting of this.SETTINGS) {
+      Preferences.ignore(setting.pref, this.render, this);
     }
   },
 
   /**
    * Updates the button & text at the top of the page to reflect Telemetry state.
    */
-  updatePrefStatus: function updatePrefStatus() {
-    // Notify user whether Telemetry is enabled
-    let enabledElement = document.getElementById("description-enabled");
-    let disabledElement = document.getElementById("description-disabled");
-    let toggleElement = document.getElementById("toggle-telemetry");
-    if (Preferences.get(PREF_TELEMETRY_ENABLED, false)) {
-      enabledElement.classList.remove("hidden");
-      disabledElement.classList.add("hidden");
-      toggleElement.innerHTML = this.disableTelemetry;
-    } else {
-      enabledElement.classList.add("hidden");
-      disabledElement.classList.remove("hidden");
-      toggleElement.innerHTML = this.enableTelemetry;
+  render: function() {
+    for (let setting of this.SETTINGS) {
+      let enabledElement = document.getElementById(setting.descriptionEnabledId);
+      let disabledElement = document.getElementById(setting.descriptionDisabledId);
+
+      if (Preferences.get(setting.pref, setting.defaultPrefValue)) {
+        enabledElement.classList.remove("hidden");
+        disabledElement.classList.add("hidden");
+      } else {
+        enabledElement.classList.add("hidden");
+        disabledElement.classList.remove("hidden");
+      }
     }
   }
 };
 
 let GeneralData = {
   /**
    * Renders the general data
    */
@@ -1045,30 +1061,23 @@ function setupPageHeader()
   let subtitleElement = document.getElementById("page-subtitle");
   subtitleElement.appendChild(document.createTextNode(subtitleText));
 }
 
 /**
  * Initializes load/unload, pref change and mouse-click listeners
  */
 function setupListeners() {
-  Services.prefs.addObserver(PREF_TELEMETRY_ENABLED, observer, false);
-  observer.updatePrefStatus();
+  Settings.attachObservers();
 
   // Clean up observers when page is closed
   window.addEventListener("unload",
     function unloadHandler(aEvent) {
       window.removeEventListener("unload", unloadHandler);
-      Services.prefs.removeObserver(PREF_TELEMETRY_ENABLED, observer);
-  }, false);
-
-  document.getElementById("toggle-telemetry").addEventListener("click",
-    function () {
-      let value = Preferences.get(PREF_TELEMETRY_ENABLED, false);
-      Preferences.set(PREF_TELEMETRY_ENABLED, !value);
+      Settings.detachObservers();
   }, false);
 
   document.getElementById("chrome-hangs-fetch-symbols").addEventListener("click",
     function () {
       if (!gPingData) {
         return;
       }
 
@@ -1128,16 +1137,19 @@ function onLoad() {
   window.removeEventListener("load", onLoad);
 
   // Set the text in the page header
   setupPageHeader();
 
   // Set up event listeners
   setupListeners();
 
+  // Render settings.
+  Settings.render();
+
   // Get the Telemetry Ping payload
   Telemetry.asyncFetchTelemetryData(displayPingData);
 
   // Restore sections states
   let stateboxes = document.getElementsByClassName("statebox");
   for (let box of stateboxes) {
     if (box.checked) { // Was open. Will still display as empty if not has-data
         box.parentElement.classList.add("expanded");
--- a/toolkit/content/aboutTelemetry.xhtml
+++ b/toolkit/content/aboutTelemetry.xhtml
@@ -24,20 +24,30 @@
 
   <body dir="&locale.dir;">
 
     <header id="page-description">
       <h1>&aboutTelemetry.pageTitle;</h1>
 
       <h2 id="page-subtitle"></h2>
 
-      <p id="description-enabled">&aboutTelemetry.telemetryEnabled;</p>
-      <p id="description-disabled">&aboutTelemetry.telemetryDisabled;</p>
-
-      <button id="toggle-telemetry" type="button"/>
+      <table id="settings">
+        <tr>
+          <td>
+            <p id="description-upload-enabled" class="description-enabled">&aboutTelemetry.uploadEnabled;</p>
+            <p id="description-upload-disabled" class="description-disabled">&aboutTelemetry.uploadDisabled;</p>
+          </td>
+        </tr>
+        <tr>
+          <td>
+            <p id="description-extended-recording-enabled" class="description-enabled">&aboutTelemetry.extendedRecordingEnabled;</p>
+            <p id="description-extended-recording-disabled" class="description-disabled">&aboutTelemetry.extendedRecordingDisabled;</p>
+          </td>
+        </tr>
+      </table>
     </header>
 
     <section id="general-data-section" class="data-section">
       <input type="checkbox" class="statebox"/>
       <h1 class="section-name">&aboutTelemetry.generalDataSection;</h1>
       <span class="toggle-caption">&aboutTelemetry.toggle;</span>
       <span class="empty-caption">&aboutTelemetry.emptySection;</span>
       <div id="general-data" class="data">
--- a/toolkit/locales/en-US/chrome/global/aboutTelemetry.dtd
+++ b/toolkit/locales/en-US/chrome/global/aboutTelemetry.dtd
@@ -1,20 +1,28 @@
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - 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/. -->
 
 <!ENTITY aboutTelemetry.pageTitle "Telemetry Data">
 
-<!ENTITY aboutTelemetry.telemetryEnabled "
-  Telemetry is <span>enabled</span>.
+<!ENTITY aboutTelemetry.uploadEnabled "
+  FHR data upload is <span>enabled</span>.
 ">
 
-<!ENTITY aboutTelemetry.telemetryDisabled "
-  Telemetry is <span>disabled</span>.
+<!ENTITY aboutTelemetry.uploadDisabled "
+  FHR data upload is <span>disabled</span>.
+">
+
+<!ENTITY aboutTelemetry.extendedRecordingEnabled "
+  Extended Telemetry recording is <span>enabled</span>.
+">
+
+<!ENTITY aboutTelemetry.extendedRecordingDisabled "
+  Extended Telemetry recording is <span>disabled</span>.
 ">
 
 <!ENTITY aboutTelemetry.generalDataSection "
   General Data
 ">
 
 <!ENTITY aboutTelemetry.environmentDataSection "
   Environment Data
--- a/toolkit/locales/en-US/chrome/global/aboutTelemetry.properties
+++ b/toolkit/locales/en-US/chrome/global/aboutTelemetry.properties
@@ -53,20 +53,16 @@ errorFetchingSymbols = An error occurred
 histogramSamples = samples
 
 histogramAverage = average
 
 histogramSum = sum
 
 histogramCopy = Copy
 
-disableTelemetry = Disable Telemetry
-
-enableTelemetry = Enable Telemetry
-
 keysHeader = Property
 
 valuesHeader = Value
 
 addonTableID = Add-on ID
 
 addonTableDetails = Details