Bug 1388145 - Make Master Password telemetry only run once per session (and not per window), and run it after an idle period. r=MattN draft
authorFelipe Gomes <felipc@gmail.com>
Wed, 09 Aug 2017 15:43:10 -0300
changeset 643422 40596aaaf9f01fe6a565d5ebf1357951c928a863
parent 643421 3e426e84ca2acbbf76ef55c75c6560f8afc9ecfa
child 643423 e047cfb5415658d732359e569f42572e0fb40bec
push id73095
push userfelipc@gmail.com
push dateWed, 09 Aug 2017 18:46:00 +0000
reviewersMattN
bugs1388145
milestone57.0a1
Bug 1388145 - Make Master Password telemetry only run once per session (and not per window), and run it after an idle period. r=MattN MozReview-Commit-ID: 1Ecy94TGGar
browser/base/content/browser.js
browser/components/nsBrowserGlue.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1742,31 +1742,16 @@ var gBrowserInit = {
       }
 
       // Enable the Restore Last Session command if needed
       RestoreLastSessionObserver.init();
 
       SidebarUI.startDelayedLoad();
       SocialUI.init();
 
-      // Telemetry for master-password - we do this after 5 seconds as it
-      // can cause IO if NSS/PSM has not already initialized.
-      setTimeout(() => {
-        if (window.closed) {
-          return;
-        }
-        let tokenDB = Cc["@mozilla.org/security/pk11tokendb;1"]
-                        .getService(Ci.nsIPK11TokenDB);
-        let token = tokenDB.getInternalKeyToken();
-        let mpEnabled = token.hasPassword;
-        if (mpEnabled) {
-          Services.telemetry.getHistogramById("MASTER_PASSWORD_ENABLED").add(mpEnabled);
-        }
-      }, 5000);
-
       PanicButtonNotifier.init();
     });
 
     gBrowser.tabContainer.addEventListener("TabSelect", function() {
       for (let panel of document.querySelectorAll("panel[tabspecific='true']")) {
         if (panel.state == "open") {
           panel.hidePopup();
         }
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -1156,16 +1156,28 @@ BrowserGlue.prototype = {
    * Note: this function may never be called if the user is never idle for the
    * full length of the period of time specified. But given a reasonably low
    * value, this is unlikely.
    */
   _scheduleArbitrarilyLateIdleTasks() {
     Services.tm.idleDispatchToMainThread(() => {
       this._sendMediaTelemetry();
     });
+
+    Services.tm.idleDispatchToMainThread(() => {
+      // Telemetry for master-password - we do this after a delay as it
+      // can cause IO if NSS/PSM has not already initialized.
+      let tokenDB = Cc["@mozilla.org/security/pk11tokendb;1"]
+                .getService(Ci.nsIPK11TokenDB);
+      let token = tokenDB.getInternalKeyToken();
+      let mpEnabled = token.hasPassword;
+      if (mpEnabled) {
+        Services.telemetry.getHistogramById("MASTER_PASSWORD_ENABLED").add(mpEnabled);
+      }
+    });
   },
 
   _createExtraDefaultProfile() {
     if (!AppConstants.MOZ_DEV_EDITION) {
       return;
     }
     // If Developer Edition is the only installed Firefox version and no other
     // profiles are present, create a second one for use by other versions.