Bug 1188966 - Telemetry on the slow add-on watcher;r?blassey draft
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Fri, 31 Jul 2015 14:00:10 +0200
changeset 283166 0a231dd340a3449eb8cfca41f22f988ac24b6a3d
parent 282066 6a16c1845238d0bf7963dd18c42ec27ba8348047
child 508057 aac2a255abf743c2c15fd94be8e351fdff6938a9
push id4093
push userdteller@mozilla.com
push dateWed, 05 Aug 2015 15:12:34 +0000
reviewersblassey
bugs1188966
milestone42.0a1
Bug 1188966 - Telemetry on the slow add-on watcher;r?blassey
browser/components/nsBrowserGlue.js
toolkit/components/telemetry/Histograms.json
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -667,62 +667,94 @@ BrowserGlue.prototype = {
       }
 
       let brandBundle = win.document.getElementById("bundle_brand");
       let brandShortName = brandBundle.getString("brandShortName");
       let message = win.gNavigatorBundle.getFormattedString("addonwatch.slow", [addon.name, brandShortName]);
       let notificationBox = win.document.getElementById("global-notificationbox");
       let notificationId = 'addon-slow:' + addonId;
       let notification = notificationBox.getNotificationWithValue(notificationId);
-      if(notification) {
+
+      // Monitor the response of users
+      const RESPONSE_DISABLE_ADDON = 0;
+      const RESPONSE_IGNORE_ADDON_TEMPORARILY = 1;
+      const RESPONSE_IGNORE_ADDON_PERMANENTLY = 2;
+      const RESPONSE_CLOSE_DIALOG = 3;
+
+      Services.telemetry.getHistogramById("SLOW_ADDON_WARNING_SHOWN").add();
+
+      let complete = false;
+      let start = Date.now();
+      let done = function(response) {
+        // Only report the first reason for closing.
+        if (complete) {
+          return;
+        }
+        complete = true;
+        Services.telemetry.getHistogramById("SLOW_ADDON_WARNING_USER_RESPONSE").add(response);
+        Services.telemetry.getHistogramById("SLOW_ADDON_WARNING_RESPONSE_TIME").add(Date.now() - start);
+      };
+
+      if (notification) {
         notification.label = message;
       } else {
         let buttons = [
           {
             label: win.gNavigatorBundle.getFormattedString("addonwatch.disable.label", [addon.name]),
             callback: function() {
               addon.userDisabled = true;
-              if (addon.pendingOperations != addon.PENDING_NONE) {
-                let restartMessage = win.gNavigatorBundle.getFormattedString("addonwatch.restart.message", [addon.name, brandShortName]);
-                let restartButton = [
-                  {
-                    label: win.gNavigatorBundle.getFormattedString("addonwatch.restart.label", [brandShortName]),
-                    accessKey: win.gNavigatorBundle.getString("addonwatch.restart.accesskey"),
-                    callback: function() {
-                      let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"]
-                        .getService(Ci.nsIAppStartup);
-                      appStartup.quit(appStartup.eForceQuit | appStartup.eRestart);
-                    }
+              if (addon.pendingOperations == addon.PENDING_NONE) {
+                done(RESPONSE_DISABLE_ADDON);
+                return;
+              }
+              let restartMessage = win.gNavigatorBundle.getFormattedString("addonwatch.restart.message", [addon.name, brandShortName]);
+              let restartButton = [
+                {
+                  label: win.gNavigatorBundle.getFormattedString("addonwatch.restart.label", [brandShortName]),
+                  accessKey: win.gNavigatorBundle.getString("addonwatch.restart.accesskey"),
+                  callback: function() {
+                    done(RESPONSE_DISABLE_ADDON);
+                    let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"]
+                      .getService(Ci.nsIAppStartup);
+                    appStartup.quit(appStartup.eForceQuit | appStartup.eRestart);
                   }
-                ];
-                const priority = notificationBox.PRIORITY_WARNING_MEDIUM;
-                notificationBox.appendNotification(restartMessage, "restart-" + addonId, "",
-                                                   priority, restartButton);
-              }
+                }
+              ];
+              const priority = notificationBox.PRIORITY_WARNING_MEDIUM;
+              notificationBox.appendNotification(restartMessage, "restart-" + addonId, "",
+                                                 priority, restartButton);
             }
           },
           {
             label: win.gNavigatorBundle.getString("addonwatch.ignoreSession.label"),
             accessKey: win.gNavigatorBundle.getString("addonwatch.ignoreSession.accesskey"),
             callback: function() {
+              done(RESPONSE_IGNORE_ADDON_TEMPORARILY);
               AddonWatcher.ignoreAddonForSession(addonId);
             }
           },
           {
             label: win.gNavigatorBundle.getString("addonwatch.ignorePerm.label"),
             accessKey: win.gNavigatorBundle.getString("addonwatch.ignorePerm.accesskey"),
             callback: function() {
+              done(RESPONSE_IGNORE_ADDON_PERMANENTLY);
               AddonWatcher.ignoreAddonPermanently(addonId);
             }
           },
         ];
 
         const priority = notificationBox.PRIORITY_WARNING_MEDIUM;
-        notificationBox.appendNotification(message, notificationId, "",
-                                             priority, buttons);
+        notification = notificationBox.appendNotification(
+          message, notificationId, "",
+          priority, buttons,
+          function(topic) {
+            if (topic == "removed") {
+              done(RESPONSE_CLOSE_NOTIFICATION);
+            }
+          });
       }
     };
     AddonManager.getAddonByID(addonId, addonCallback);
   },
 
   // runs on startup, before the first command line handler is invoked
   // (i.e. before the first window is opened)
   _finalUIStartup: function BG__finalUIStartup() {
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -5024,16 +5024,34 @@
   },
   "MISBEHAVING_ADDONS_JANK_LEVEL": {
     "expires_in_version": "never",
     "kind": "enumerated",
     "n_values": 10,
     "keyed": true,
     "description": "Longest blocking operation performed by the add-on (log2(duration in ms), keyed by add-on, updated every 15s by default)"
   },
+  "SLOW_ADDON_WARNING_SHOWN": {
+    "expires_in_version": "never",
+    "kind": "count",
+    "description": "Number of times an the Slow Add-on Warning was shown during a session."
+  },
+  "SLOW_ADDON_WARNING_USER_RESPONSE": {
+    "expires_in_version": "never",
+    "kind": "enumerated",
+    "n_values": 20,
+    "description": "User response to Slow Add-on Warning. 0: Disable add-on, 1: Ignore add-on for now, 2: Ignore add-on permanently, 3: Close notification. Other values are reserved for future uses."
+  },
+  "SLOW_ADDON_WARNING_RESPONSE_TIME": {
+    "expires_in_version": "never",
+    "kind": "exponential",
+    "high": "60000",
+    "n_buckets": 20,
+    "description": "Time before responding to Slow Add-on Warning UI (ms). Not updated if the user doesn't respond at all."
+  },
   "SEARCH_COUNTS": {
     "expires_in_version": "never",
     "kind": "count",
     "keyed": true,
     "releaseChannelCollection": "opt-out",
     "description": "Record the search counts for search engines"
   },
   "SEARCH_SERVICE_INIT_MS": {