Bug 1561012 - Don't register fxmonitor events if telemetry is disabled. r=johannh,robwu a=RyanVM
authorNihanth Subramanya <nhnt11@gmail.com>
Tue, 30 Jul 2019 19:58:40 +0000
changeset 544855 6984cce40f4eaa8611d8eb73fe98889062c8644d
parent 544854 7b2d5bd73d933c9d91fc6d87b05b975e31acc9f4
child 544856 7d4124f1200d0144af30361654d0436e02a9d1d0
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh, robwu, RyanVM
bugs1561012
milestone69.0
Bug 1561012 - Don't register fxmonitor events if telemetry is disabled. r=johannh,robwu a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D36812
browser/extensions/fxmonitor/privileged/api.js
--- a/browser/extensions/fxmonitor/privileged/api.js
+++ b/browser/extensions/fxmonitor/privileged/api.js
@@ -68,18 +68,21 @@ this.FirefoxMonitor = {
   strings: null,
 
   // This is here for documentation, will be redefined to a pref getter
   // using XPCOMUtils.defineLazyPreferenceGetter in init().
   enabled: null,
 
   kEnabledPref: "extensions.fxmonitor.enabled",
 
+  // This is here for documentation, will be redefined to a pref getter
+  // using XPCOMUtils.defineLazyPreferenceGetter in delayedInit().
   // Telemetry event recording is enabled by default.
   // If this pref exists and is true-y, it's disabled.
+  telemetryDisabled: null,
   kTelemetryDisabledPref: "extensions.fxmonitor.telemetryDisabled",
 
   kNotificationID: "fxmonitor",
 
   // This is here for documentation, will be redefined to a pref getter
   // using XPCOMUtils.defineLazyPreferenceGetter in delayedInit().
   // The value of this property is used as the URL to which the user
   // is directed when they click "Check Firefox Monitor".
@@ -192,33 +195,37 @@ this.FirefoxMonitor = {
           "dismiss_btn",
           "never_show_btn",
         ],
         record_on_release: true,
         expired,
       },
     });
 
-    let telemetryEnabled = !Preferences.get(this.kTelemetryDisabledPref);
-    Services.telemetry.setEventRecordingEnabled("fxmonitor", telemetryEnabled);
-
     XPCOMUtils.defineLazyPreferenceGetter(
       this,
       "FirefoxMonitorURL",
       this.kFirefoxMonitorURLPref,
       this.kDefaultFirefoxMonitorURL
     );
 
     XPCOMUtils.defineLazyPreferenceGetter(
       this,
       "firstAlertShown",
       this.kFirstAlertShownPref,
       false
     );
 
+    XPCOMUtils.defineLazyPreferenceGetter(
+      this,
+      "telemetryDisabled",
+      this.kTelemetryDisabledPref,
+      false
+    );
+
     await this.loadStrings();
     await this.loadBreaches();
   },
 
   loadStrings() {
     let l10nManifest;
     if (this.extension.rootURI instanceof Ci.nsIJARURI) {
       l10nManifest = this.extension.rootURI.JARFile.QueryInterface(
@@ -523,21 +530,17 @@ this.FirefoxMonitor = {
           this.notificationsByWindow
             .get(win)
             .delete(
               win.PopupNotifications.getNotification(
                 this.kNotificationID,
                 browser
               )
             );
-          Services.telemetry.recordEvent(
-            "fxmonitor",
-            "interaction",
-            "doorhanger_removed"
-          );
+          this.recordEvent("doorhanger_removed");
           break;
       }
     };
 
     let n = win.PopupNotifications.show(
       browser,
       this.kNotificationID,
       "",
@@ -547,24 +550,28 @@ this.FirefoxMonitor = {
       {
         persistent: true,
         hideClose: true,
         eventCallback: populatePanel,
         popupIconURL: this.getURL("assets/monitor32.svg"),
       }
     );
 
-    Services.telemetry.recordEvent(
-      "fxmonitor",
-      "interaction",
-      "doorhanger_shown"
-    );
+    this.recordEvent("doorhanger_shown");
 
     this.notificationsByWindow.get(win).add(n);
   },
+
+  recordEvent(aEventName) {
+    if (this.telemetryDisabled) {
+      return;
+    }
+
+    Services.telemetry.recordEvent("fxmonitor", "interaction", aEventName);
+  },
 };
 
 function PanelUI(doc) {
   this.site = null;
   this.doc = doc;
 
   let box = doc.createElementNS(XUL_NS, "vbox");
 
@@ -614,49 +621,41 @@ PanelUI.prototype = {
       callback: () => {
         let win = this.doc.defaultView;
         win.openTrustedLinkIn(
           this.getFirefoxMonitorURL(this.site.Name),
           "tab",
           {}
         );
 
-        Services.telemetry.recordEvent("fxmonitor", "interaction", "check_btn");
+        FirefoxMonitor.recordEvent("check_btn");
       },
     });
   },
 
   get secondaryActions() {
     if (this._secondaryActions) {
       return this._secondaryActions;
     }
     return (this._secondaryActions = [
       {
         label: this.getString("fxmonitor.dismissButton.label"),
         accessKey: this.getString("fxmonitor.dismissButton.accessKey"),
         callback: () => {
-          Services.telemetry.recordEvent(
-            "fxmonitor",
-            "interaction",
-            "dismiss_btn"
-          );
+          FirefoxMonitor.recordEvent("dismiss_btn");
         },
       },
       {
         label: this.getFormattedString("fxmonitor.neverShowButton.label", [
           this.brandString,
         ]),
         accessKey: this.getString("fxmonitor.neverShowButton.accessKey"),
         callback: () => {
           FirefoxMonitor.disable();
-          Services.telemetry.recordEvent(
-            "fxmonitor",
-            "interaction",
-            "never_show_btn"
-          );
+          FirefoxMonitor.recordEvent("never_show_btn");
         },
       },
     ]);
   },
 
   refresh(site) {
     this.site = site;