Bug 1038248 - Add UITelemetry to count the number and type of searches. r=mconley
authorBlake Winton <bwinton@latte.ca>
Thu, 17 Jul 2014 11:37:22 -0400
changeset 216580 0bf3196d00f3f0f7654261511dd18def3b8de63c
parent 216579 661a00579db9709b21dc72a6d63073f04452b511
child 216581 acdd788c6f8f7c8df70012844c6423890415e498
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1038248
milestone33.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 1038248 - Add UITelemetry to count the number and type of searches. r=mconley
browser/base/content/browser.js
browser/components/nsBrowserGlue.js
browser/modules/BrowserUITelemetry.jsm
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -6,16 +6,18 @@
 let Ci = Components.interfaces;
 let Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/NotificationDB.jsm");
 Cu.import("resource:///modules/RecentWindow.jsm");
 Cu.import("resource://gre/modules/WindowsPrefSync.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "BrowserUITelemetry",
+                                  "resource:///modules/BrowserUITelemetry.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
                                   "resource://gre/modules/BrowserUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Task",
                                   "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "CharsetMenu",
                                   "resource://gre/modules/CharsetMenu.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ShortcutUtils",
                                   "resource://gre/modules/ShortcutUtils.jsm");
@@ -3090,16 +3092,17 @@ const BrowserSearch = {
    *
    * @param engine
    *        (nsISearchEngine) The engine handling the search.
    * @param source
    *        (string) Where the search originated from. See the FHR
    *        SearchesProvider for allowed values.
    */
   recordSearchInHealthReport: function (engine, source) {
+    BrowserUITelemetry.countSearchEvent(source);
 #ifdef MOZ_SERVICES_HEALTHREPORT
     let reporter = Cc["@mozilla.org/datareporting/service;1"]
                      .getService()
                      .wrappedJSObject
                      .healthReporter;
 
     // This can happen if the FHR component of the data reporting service is
     // disabled. This is controlled by a pref that most will never use.
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -316,22 +316,24 @@ BrowserGlue.prototype = {
         }
         break;
       case "profile-before-change":
          // Any component depending on Places should be finalized in
          // _onPlacesShutdown.  Any component that doesn't need to act after
          // the UI has gone should be finalized in _onQuitApplicationGranted.
         this._dispose();
         break;
-#ifdef MOZ_SERVICES_HEALTHREPORT
       case "keyword-search":
         // This is very similar to code in
         // browser.js:BrowserSearch.recordSearchInHealthReport(). The code could
         // be consolidated if there is will. We need the observer in
         // nsBrowserGlue to prevent double counting.
+        let win = this.getMostRecentBrowserWindow();
+        BrowserUITelemetry.countSearchEvent("urlbar", win.gURLBar.value);
+#ifdef MOZ_SERVICES_HEALTHREPORT
         let reporter = Cc["@mozilla.org/datareporting/service;1"]
                          .getService()
                          .wrappedJSObject
                          .healthReporter;
 
         if (!reporter) {
           return;
         }
@@ -339,18 +341,18 @@ BrowserGlue.prototype = {
         reporter.onInit().then(function record() {
           try {
             let engine = subject.QueryInterface(Ci.nsISearchEngine);
             reporter.getProvider("org.mozilla.searches").recordSearch(engine, "urlbar");
           } catch (ex) {
             Cu.reportError(ex);
           }
         });
+#endif
         break;
-#endif
       case "browser-search-engine-modified":
         if (data != "engine-default" && data != "engine-current") {
           break;
         }
         // Enforce that the search service's defaultEngine is always equal to
         // its currentEngine. The search service will notify us any time either
         // of them are changed (either by directly setting the relevant prefs,
         // i.e. if add-ons try to change this directly, or if the
--- a/browser/modules/BrowserUITelemetry.jsm
+++ b/browser/modules/BrowserUITelemetry.jsm
@@ -546,16 +546,23 @@ this.BrowserUITelemetry = {
     result.durations = this._durations;
     return result;
   },
 
   countCustomizationEvent: function(aEventType) {
     this._countEvent(["customize", aEventType]);
   },
 
+  countSearchEvent: function(source, query) {
+    this._countEvent(["search", source]);
+    if ((/^[a-zA-Z]+:[^\/\\]/).test(query)) {
+      this._countEvent(["search", "urlbar-keyword"]);
+    }
+  },
+
   _durations: {
     customization: [],
   },
 
   onCustomizeStart: function(aWindow) {
     this._countEvent(["customize", "start"]);
     let durationMap = WINDOW_DURATION_MAP.get(aWindow);
     if (!durationMap) {