Bug 1053467 - Add telemetry to measure the usage and values of the sizes attribute of <link rel=icon>. r=MattN
authorBernardo P. Rittmeyer <bernardo@rittme.com>
Wed, 20 Aug 2014 23:29:00 -0400
changeset 200824 330d323a504360f0c1605fe0ffd87dbfb2b984f9
parent 200823 abbd3bdde0ac8c93e855fa5fdbb5b8e6059be6c1
child 200825 7871ef26e0c8f4ff85b1abe64fb6614712774d3b
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersMattN
bugs1053467
milestone34.0a1
Bug 1053467 - Add telemetry to measure the usage and values of the sizes attribute of <link rel=icon>. r=MattN
browser/modules/ContentLinkHandler.jsm
toolkit/components/telemetry/Histograms.json
--- a/browser/modules/ContentLinkHandler.jsm
+++ b/browser/modules/ContentLinkHandler.jsm
@@ -13,16 +13,23 @@ this.EXPORTED_SYMBOLS = [ "ContentLinkHa
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Feeds",
   "resource:///modules/Feeds.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
   "resource://gre/modules/BrowserUtils.jsm");
 
+const SIZES_TELEMETRY_ENUM = {
+  NO_SIZES: 0,
+  ANY: 1,
+  DIMENSION: 2,
+  INVALID: 3,
+};
+
 this.ContentLinkHandler = {
   init: function(chromeGlobal) {
     chromeGlobal.addEventListener("DOMLinkAdded", (event) => {
       this.onLinkEvent(event, chromeGlobal);
     }, false);
     chromeGlobal.addEventListener("DOMLinkChanged", (event) => {
       this.onLinkEvent(event, chromeGlobal);
     }, false);
@@ -67,16 +74,45 @@ this.ContentLinkHandler = {
           if (!iconAdded) {
             if (!Services.prefs.getBoolPref("browser.chrome.site_icons"))
               break;
 
             var uri = this.getLinkIconURI(link);
             if (!uri)
               break;
 
+            // Telemetry probes for measuring the sizes attribute
+            // usage and available dimensions.
+            let sizeHistogramTypes = Services.telemetry.
+                                     getHistogramById("LINK_ICON_SIZES_ATTR_USAGE");
+            let sizeHistogramDimension = Services.telemetry.
+                                         getHistogramById("LINK_ICON_SIZES_ATTR_DIMENSION");
+            let sizesType;
+            if (link.sizes.length) {
+              for (let size of link.sizes) {
+                if (size.toLowerCase() == "any") {
+                  sizesType = SIZES_TELEMETRY_ENUM.ANY;
+                  break;
+                } else {
+                  let re = /^([1-9][0-9]*)x[1-9][0-9]*$/i;
+                  let values = re.exec(size);
+                  if (values && values.length > 1) {
+                    sizesType = SIZES_TELEMETRY_ENUM.DIMENSION;
+                    sizeHistogramDimension.add(parseInt(values[1]));
+                  } else {
+                    sizesType = SIZES_TELEMETRY_ENUM.INVALID;
+                    break;
+                  }
+                }
+              }
+            } else {
+              sizesType = SIZES_TELEMETRY_ENUM.NO_SIZES;
+            }
+            sizeHistogramTypes.add(sizesType);
+
             [iconAdded] = chromeGlobal.sendSyncMessage("Link:SetIcon", {url: uri.spec});
           }
           break;
         case "search":
           if (!searchAdded && event.type == "DOMLinkAdded") {
             var type = link.type && link.type.toLowerCase();
             type = type.replace(/^\s+|\s*(?:;.*)?$/g, "");
 
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -3074,16 +3074,29 @@
   },
   "PLACES_FAVICON_OTHER_SIZES": {
     "expires_in_version" : "never",
     "kind": "exponential",
     "high": 524288,
     "n_buckets" : 100,
     "description": "PLACES: Size of favicon files without a specific file type probe, loaded from the web (Bytes)"
   },
+  "LINK_ICON_SIZES_ATTR_USAGE": {
+    "expires_in_version" : "never",
+    "kind": "enumerated",
+    "n_values": 4,
+    "description": "The possible types of the 'sizes' attribute for <link rel=icon>. 0: Attribute not specified, 1: 'any', 2: Integer dimensions, 3: Invalid value."
+  },
+  "LINK_ICON_SIZES_ATTR_DIMENSION": {
+    "expires_in_version" : "never",
+    "kind": "linear",
+    "high": 513,
+    "n_buckets" : 64,
+    "description": "The width dimension of the 'sizes' attribute for <link rel=icon>."
+  },
   "FENNEC_DISTRIBUTION_REFERRER_INVALID": {
     "expires_in_version": "never",
     "kind": "flag",
     "description": "Whether the referrer intent specified an invalid distribution name",
     "cpp_guard": "ANDROID"
   },
   "FENNEC_DISTRIBUTION_CODE_CATEGORY": {
     "expires_in_version": "never",