Bug 725987 - Create Telemetry (opt-out) notification for Nightly and Aurora (mobile). r=bnicholson
authorTheo Chevalier <theo.chevalier11@gmail.com>
Mon, 10 Dec 2012 23:25:52 +0100
changeset 115556 ad491d4e39da0197c08a2ffc10f9206ea7bea82d
parent 115555 7b3ffe203ebf4db8308c9e37394d592e03887ae9
child 115557 4c4bdc7fc6c6dd96ce72a768a4acd8dd0df2daf3
push id19412
push usertheo.chevalier11@gmail.com
push dateMon, 10 Dec 2012 22:26:27 +0000
treeherdermozilla-inbound@4c4bdc7fc6c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs725987
milestone20.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 725987 - Create Telemetry (opt-out) notification for Nightly and Aurora (mobile). r=bnicholson
browser/locales/en-US/chrome/browser/browser.properties
mobile/android/chrome/content/browser.js
mobile/android/locales/en-US/chrome/browser.properties
--- a/browser/locales/en-US/chrome/browser/browser.properties
+++ b/browser/locales/en-US/chrome/browser/browser.properties
@@ -381,17 +381,17 @@ keywordPrompt.noButton.accessKey  = N
 webapps.install = Install
 webapps.install.accesskey = I
 #LOCALIZATION NOTE (webapps.requestInstall) %1$S is the web app name, %2$S is the site from which the web app is installed
 webapps.requestInstall = Do you want to install "%1$S" from this site (%2$S)?
 webapps.install.success = Application Installed
 
 # Telemetry opt-out prompt for Aurora and Nightly
 # LOCALIZATION NOTE (telemetryOptOutPrompt): %1$S and %3$S will be replaced by
-# brandFullName, and %2$S by the value of the toolkit.telemetry.server_owner preference.
+# brandShortName, and %2$S by the value of the toolkit.telemetry.server_owner preference.
 telemetryOptOutPrompt = %1$S sends information about performance, hardware, usage and customizations back to %2$S to help improve %3$S.
 
 # LOCALIZATION NOTE (fullscreen.entered): displayed when we enter HTML5 fullscreen mode, %S is the domain name of the focused website (e.g. mozilla.com).
 fullscreen.entered=%S is now fullscreen.
 # LOCALIZATION NOTE (fullscreen.rememberDecision): displayed when we enter HTML5 fullscreen mode, %S is the domain name of the focused website (e.g. mozilla.com).
 fullscreen.rememberDecision=Remember decision for %S
 
 # LOCALIZATION NOTE (social.activated.description): %1$S is the name of the social provider, %2$S is brandShortName (e.g. Firefox)
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -7101,27 +7101,29 @@ var RemoteDebugger = {
 
   _stop: function rd_start() {
     DebuggerServer.closeListener();
     dump("Remote debugger stopped");
   }
 };
 
 var Telemetry = {
-  _PREF_TELEMETRY_PROMPTED: "toolkit.telemetry.prompted",
 #ifdef MOZ_TELEMETRY_ON_BY_DEFAULT
   _PREF_TELEMETRY_ENABLED: "toolkit.telemetry.enabledPreRelease",
+  _PREF_TELEMETRY_DISPLAYED: "toolkit.telemetry.notifiedOptOut",
 #else
   _PREF_TELEMETRY_ENABLED: "toolkit.telemetry.enabled",
+  _PREF_TELEMETRY_DISPLAYED: "toolkit.telemetry.prompted",
 #endif
   _PREF_TELEMETRY_REJECTED: "toolkit.telemetry.rejected",
   _PREF_TELEMETRY_SERVER_OWNER: "toolkit.telemetry.server_owner",
 
-  // This is used to reprompt users when privacy message changes
-  _TELEMETRY_PROMPT_REV: "@MOZ_TELEMETRY_DISPLAY_REV@",
+  // This is used to reprompt Beta/GA users and notify again
+  // Nightly/Aurora users when privacy message changes
+  _TELEMETRY_DISPLAY_REV: @MOZ_TELEMETRY_DISPLAY_REV@,
 
   init: function init() {
     Services.obs.addObserver(this, "Preferences:Set", false);
     Services.obs.addObserver(this, "Telemetry:Add", false);
     Services.obs.addObserver(this, "Telemetry:Prompt", false);
   },
 
   uninit: function uninit() {
@@ -7136,72 +7138,135 @@ var Telemetry = {
     histogram.add(aValue);
   },
 
   observe: function observe(aSubject, aTopic, aData) {
     if (aTopic == "Preferences:Set") {
       // if user changes telemetry pref, treat it like they have been prompted
       let pref = JSON.parse(aData);
       if (pref.name == this._PREF_TELEMETRY_ENABLED)
-        Services.prefs.setIntPref(this._PREF_TELEMETRY_PROMPTED, this._TELEMETRY_PROMPT_REV);
+        Services.prefs.setIntPref(this._PREF_TELEMETRY_DISPLAYED, this._TELEMETRY_DISPLAY_REV);
     } else if (aTopic == "Telemetry:Add") {
       let json = JSON.parse(aData);
       this.addData(json.name, json.value);
     } else if (aTopic == "Telemetry:Prompt") {
 #ifdef MOZ_TELEMETRY_REPORTING
       this.prompt();
 #endif
     }
   },
 
   prompt: function prompt() {
+    let brandShortName = Strings.brand.GetStringFromName("brandShortName");
     let serverOwner = Services.prefs.getCharPref(this._PREF_TELEMETRY_SERVER_OWNER);
-    let telemetryPrompted = null;
+    let telemetryEnabled = Services.prefs.getBoolPref(this._PREF_TELEMETRY_ENABLED);
+    let message;
+    let buttons;
     let self = this;
+
+    /*
+     * Display an opt-out notification when telemetry is enabled by default,
+     * an opt-in prompt otherwise.
+     *
+     * But do not display this prompt/notification if:
+     *
+     * - The last accepted/refused policy (either by accepting the prompt or by
+     *   manually flipping the telemetry preference) is already at version
+     *   TELEMETRY_DISPLAY_REV.
+     */
+    let telemetryDisplayed;
     try {
-      telemetryPrompted = Services.prefs.getIntPref(this._PREF_TELEMETRY_PROMPTED);
-    } catch (e) { /* Optional */ }
-
-    // If the user has seen the latest telemetry prompt, do not prompt again
-    // else clear old prefs and reprompt
-    if (telemetryPrompted === this._TELEMETRY_PROMPT_REV)
+      telemetryDisplayed = Services.prefs.getIntPref(self._PREF_TELEMETRY_DISPLAYED);
+    } catch(e) {}
+    if (telemetryDisplayed === self._TELEMETRY_DISPLAY_REV)
+      return;
+
+#ifdef MOZ_TELEMETRY_ON_BY_DEFAULT
+    /*
+     * Additionally, in opt-out builds, don't display the notification if:
+     *
+     * - Telemetry is disabled
+     * - Telemetry was explicitly refused through the UI
+     * - Opt-in telemetry was already enabled, don't notify the user until next
+     *   policy update. (Do the check only at first run with opt-out builds)
+     */
+
+    let telemetryEnabled = Services.prefs.getBoolPref(self._PREF_TELEMETRY_ENABLED);
+    if (!telemetryEnabled)
+      return;
+
+    // If telemetry was explicitly refused through the UI,
+    // also disable opt-out telemetry and bail out.
+    let telemetryRejected = false;
+    try {
+      telemetryRejected = Services.prefs.getBoolPref(self._PREF_TELEMETRY_REJECTED);
+    } catch(e) {}
+    if (telemetryRejected) {
+      Services.prefs.setBoolPref(self._PREF_TELEMETRY_ENABLED, false);
+      Services.prefs.setIntPref(self._PREF_TELEMETRY_DISPLAYED, self._TELEMETRY_DISPLAY_REV);
       return;
-
-    Services.prefs.clearUserPref(this._PREF_TELEMETRY_PROMPTED);
-    Services.prefs.clearUserPref(this._PREF_TELEMETRY_ENABLED);
-
-    let buttons = [
+    }
+
+    // If opt-in telemetry was already enabled, don't notify the user until next
+    // policy update. (Do the check only at first run with opt-out builds)
+    let optInTelemetryEnabled = false;
+    try {
+      optInTelemetryEnabled = Services.prefs.getBoolPref("toolkit.telemetry.enabled");
+    } catch(e) {}
+    if (optInTelemetryEnabled && telemetryDisplayed === undefined) {
+      Services.prefs.setBoolPref(self._PREF_TELEMETRY_REJECTED, false);
+      Services.prefs.setIntPref(self._PREF_TELEMETRY_DISPLAYED, self._TELEMETRY_DISPLAY_REV);
+      return;
+    }
+
+    message = Strings.browser.formatStringFromName("telemetry.optout.message",
+                                                    [brandShortName, serverOwner, brandShortName], 3);
+    buttons = [
+      {
+        label: Strings.browser.GetStringFromName("telemetry.optout.ok"),
+        callback: function () {
+          Services.prefs.setIntPref(self._PREF_TELEMETRY_DISPLAYED, self._TELEMETRY_DISPLAY_REV);
+        }
+      }
+    ];
+#else
+    // Clear old prefs and reprompt
+    Services.prefs.clearUserPref(self._PREF_TELEMETRY_DISPLAYED);
+    Services.prefs.clearUserPref(self._PREF_TELEMETRY_ENABLED);
+    Services.prefs.clearUserPref(self._PREF_TELEMETRY_REJECTED);
+
+    message = Strings.browser.formatStringFromName("telemetry.optin.message2",
+                                                  [serverOwner, brandShortName], 2);
+    buttons = [
       {
         label: Strings.browser.GetStringFromName("telemetry.optin.yes"),
         callback: function () {
-          Services.prefs.setIntPref(self._PREF_TELEMETRY_PROMPTED, self._TELEMETRY_PROMPT_REV);
+          Services.prefs.setIntPref(self._PREF_TELEMETRY_DISPLAYED, self._TELEMETRY_DISPLAY_REV);
           Services.prefs.setBoolPref(self._PREF_TELEMETRY_ENABLED, true);
         }
       },
       {
         label: Strings.browser.GetStringFromName("telemetry.optin.no"),
         callback: function () {
-          Services.prefs.setIntPref(self._PREF_TELEMETRY_PROMPTED, self._TELEMETRY_PROMPT_REV);
+          Services.prefs.setIntPref(self._PREF_TELEMETRY_DISPLAYED, self._TELEMETRY_DISPLAY_REV);
           Services.prefs.setBoolPref(self._PREF_TELEMETRY_REJECTED, true);
         }
       }
     ];
-
-    let brandShortName = Strings.brand.GetStringFromName("brandShortName");
-    let message = Strings.browser.formatStringFromName("telemetry.optin.message2", [serverOwner, brandShortName], 2);
+#endif
     let learnMoreLabel = Strings.browser.GetStringFromName("telemetry.optin.learnMore");
     let learnMoreUrl = Services.urlFormatter.formatURLPref("app.support.baseURL");
     learnMoreUrl += "how-can-i-help-submitting-performance-data";
     let options = {
       link: {
         label: learnMoreLabel,
         url: learnMoreUrl
       }
     };
-    NativeWindow.doorhanger.show(message, "telemetry-optin", buttons, BrowserApp.selectedTab.id, options);
+    NativeWindow.doorhanger.show(message, "telemetry-prompt", buttons, BrowserApp.selectedTab.id, options);
   },
 };
 
 let Reader = {
   // Version of the cache database schema
   DB_VERSION: 1,
 
   DEBUG: 0,
--- a/mobile/android/locales/en-US/chrome/browser.properties
+++ b/mobile/android/locales/en-US/chrome/browser.properties
@@ -62,16 +62,20 @@ safeBrowsingDoorhanger=This site has bee
 blockPopups.label=Block Popups
 
 # Telemetry
 # %1$S = server owner (Mozilla); %2$S = product name (Firefox)
 telemetry.optin.message2=Send info to %1$S so that we can improve %2$S?
 telemetry.optin.learnMore=Learn more
 telemetry.optin.yes=Yes
 telemetry.optin.no=No
+# LOCALIZATION NOTE (telemetry.optout.message): %1$S and %3$S will be replaced by
+# brandShortName, and %2$S by the value of the toolkit.telemetry.server_owner preference.
+telemetry.optout.message=%1$S sends information about performance, hardware, usage and customizations back to %2$S to help improve %3$S.
+telemetry.optout.ok=OK
 
 # XPInstall
 xpinstallPromptWarning2=%S prevented this site (%S) from asking you to install software on your device.
 xpinstallPromptAllowButton=Allow
 xpinstallDisabledMessageLocked=Software installation has been disabled by your system administrator.
 xpinstallDisabledMessage2=Software installation is currently disabled. Press Enable and try again.
 xpinstallDisabledButton=Enable