Bug 1313429 - Store button presses on the Mac Touch Bar in a histogram. r=gfritzsche draft
authorHarry Twyford <htwyford@mozilla.com>
Fri, 20 Jul 2018 14:25:23 -0400
changeset 823208 d50256d6c01689b3ac4d11d0a650b5fe073de327
parent 823207 22ecb19cb2937a9e749ce049657becf076fcfa60
push id117610
push userbmo:htwyford@mozilla.com
push dateThu, 26 Jul 2018 20:33:17 +0000
reviewersgfritzsche
bugs1313429
milestone63.0a1
Bug 1313429 - Store button presses on the Mac Touch Bar in a histogram. r=gfritzsche MozReview-Commit-ID: 7hboXElf4n5
browser/components/touchbar/MacTouchBar.js
toolkit/components/telemetry/Histograms.json
widget/cocoa/nsTouchBar.mm
--- a/browser/components/touchbar/MacTouchBar.js
+++ b/browser/components/touchbar/MacTouchBar.js
@@ -6,17 +6,20 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
   PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
 });
 
-function execCommand(aCommandName) {
+function execCommand(aCommandName, aTelemetryKey) {
+  let telemetry =
+    Services.telemetry.getHistogramById("TOUCHBAR_BUTTON_PRESSES");
+  telemetry.add(aTelemetryKey);
   let win = BrowserWindowTracker.getTopWindow();
   let command = win.document.getElementById(aCommandName);
   if (command) {
     command.doCommand();
   }
 }
 
 /**
@@ -37,84 +40,84 @@ TouchBarHelper.prototype = {
   /**
    * An object containing all implemented TouchBarInput objects.
    */
   _implementedInputs: {
     "Back": {
       title: "back",
       image: "back.pdf",
       type: "button",
-      callback: () => execCommand("Browser:Back")
+      callback: () => execCommand("Browser:Back", "Back")
     },
     "Forward": {
       title: "forward",
       image: "forward.pdf",
       type: "button",
-      callback: () => execCommand("Browser:Forward"),
+      callback: () => execCommand("Browser:Forward", "Forward"),
     },
     "Reload": {
       title: "reload",
       image: "refresh.pdf",
       type: "button",
-      callback: () => execCommand("Browser:Reload"),
+      callback: () => execCommand("Browser:Reload", "Reload"),
     },
     "Home": {
       title: "home",
       image: "home.pdf",
       type: "button",
-      callback: () => execCommand("Browser:Home"),
+      callback: () => execCommand("Browser:Home", "Home"),
     },
     "Fullscreen": {
       title: "fullScreen",
       image: "fullscreen.pdf",
       type: "button",
-      callback: () => execCommand("View:FullScreen"),
+      callback: () => execCommand("View:FullScreen", "Fullscreen"),
     },
     "Find": {
       title: "find",
       image: "search.pdf",
       type: "button",
-      callback: () => execCommand("cmd_find"),
+      callback: () => execCommand("cmd_find", "Find"),
     },
     "NewTab": {
       title: "newTab",
       image: "new.pdf",
       type: "button",
-      callback: () => execCommand("cmd_newNavigatorTabNoEvent"),
+      callback: () => execCommand("cmd_newNavigatorTabNoEvent", "NewTab"),
     },
     "Sidebar": {
       title: "openBookmarksSidebar",
       image: "sidebar-left.pdf",
       type: "button",
-      callback: () => execCommand("viewBookmarksSidebar"),
+      callback: () => execCommand("viewBookmarksSidebar", "Sidebar"),
     },
     "AddBookmark": {
       title: "addBookmark",
       image: "bookmark.pdf",
       type: "button",
-      callback: () => execCommand("Browser:AddBookmarkAs"),
+      callback: () => execCommand("Browser:AddBookmarkAs", "AddBookmark"),
     },
     "ReaderView": {
       title: "readerView",
       image: "reader-mode.pdf",
       type: "button",
-      callback: () => execCommand("View:ReaderView"),
+      callback: () => execCommand("View:ReaderView", "ReaderView"),
       disabled: true,  // Updated when the page is found to be Reader View-able
     },
     "OpenLocation": {
       title: "openLocation",
       image: "search.pdf",
       type: "mainButton",
-      callback: () => execCommand("Browser:OpenLocation"),
+      callback: () => execCommand("Browser:OpenLocation", "OpenLocation"),
     },
     "Focus": {
       title: "focus",
       image: "private-browsing.pdf",
       type: "mainButton",
-      callback: () => execCommand("cmd_closeWindow"),
+      callback: () => execCommand("cmd_closeWindow", "Focus"),
       color: "#8000D7",
       context: () => {
         let name;
         if (PrivateBrowsingUtils.isWindowPrivate(
             BrowserWindowTracker.getTopWindow())) {
           name = "Focus";
         }
         return name;
@@ -134,17 +137,17 @@ TouchBarHelper.prototype = {
       },
     },
     // This is a special-case `type: "scrubber"` element.
     // Scrubbers are not yet generally implemented.
     "Share": {
       title: "share",
       type: "scrubber",
       image: "share.pdf",
-      callback: () => execCommand("cmd_share"),
+      callback: () => execCommand("cmd_share", "Share"),
     },
   },
 
   get activeTitle() {
     let tabbrowser = this.window.ownerGlobal.gBrowser;
     let activeTitle;
     if (tabbrowser) {
       activeTitle = tabbrowser.selectedBrowser.contentTitle;
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -13891,10 +13891,20 @@
     "record_in_processes": ["main", "gpu"],
     "alert_emails": ["kgupta@mozilla.com"],
     "bug_numbers": [1470901],
     "expires_in_version": "never",
     "kind": "exponential",
     "high": 1000,
     "n_buckets": 50,
     "description": "WebRender render time in milliseconds"
+  },
+  "TOUCHBAR_BUTTON_PRESSES": {
+    "record_in_processes": ["main"],
+    "alert_emails": ["htwyford@mozilla.com"],
+    "bug_numbers": [1313429],
+    "expires_in_version": "65",
+    "kind": "categorical",
+    "labels": ["Back", "Forward", "Reload", "Home",  "Fullscreen", "Find", "NewTab", "ReaderView", "AddBookmark", "OpenLocation", "Focus", "Share", "Sidebar"],
+    "releaseChannelCollection": "opt-out",
+    "description": "What buttons are pressed most often on the Mac Touch Bar?"
   }
 }
--- a/widget/cocoa/nsTouchBar.mm
+++ b/widget/cocoa/nsTouchBar.mm
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsTouchBar.h"
 
 #include "nsDirectoryServiceDefs.h"
 #include "nsIArray.h"
 #include "nsArrayUtils.h"
 #include "mozilla/MacStringHelpers.h"
+#include "mozilla/Telemetry.h"
 
 @implementation nsTouchBar
 
 static NSTouchBarItemIdentifier CustomButtonIdentifier =
     @"com.mozilla.firefox.touchbar.button";
 static NSTouchBarItemIdentifier CustomMainButtonIdentifier =
     @"com.mozilla.firefox.touchbar.mainbutton";
 static NSTouchBarItemIdentifier ScrubberIdentifier =
@@ -278,16 +279,19 @@ if ([aIdentifier hasPrefix:CustomButtonI
     if (!NS_FAILED(rv)) {
       urlToShare = [NSURL URLWithString:nsCocoaUtils::ToNSString(url)];
     }
     if (!NS_FAILED(rv2)) {
       titleToShare = nsCocoaUtils::ToNSString(title);
     }
   }
 
+  // If the user has gotten this far, they have clicked the share button so its logged
+  Telemetry::AccumulateCategorical(Telemetry::LABELS_TOUCHBAR_BUTTON_PRESSES::Share);
+
   return @[urlToShare, titleToShare];
 }
 
 - (NSArray<NSSharingService*>*)sharingServicePicker:
                            (NSSharingServicePicker*)aSharingServicePicker
                             sharingServicesForItems:
                                           (NSArray*)aItems
                             proposedSharingServices: