Bug 1124895 - 1/2 Add password manager data to FHR. r=gps, a=lmandel (relanding the correct patch)
authorAllison Naaktgeboren <ally@mozilla.com>
Tue, 10 Mar 2015 16:24:48 -0700
changeset 250403 fe5932c2b378
parent 250402 42877284c697
child 250404 bb7b546e6188
push id4575
push userjdolske@mozilla.com
push date2015-03-16 23:21 +0000
treeherdermozilla-beta@fe5932c2b378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps, lmandel
bugs1124895
milestone37.0
Bug 1124895 - 1/2 Add password manager data to FHR. r=gps, a=lmandel (relanding the correct patch)
services/healthreport/docs/dataformat.rst
toolkit/components/passwordmgr/LoginManagerParent.jsm
toolkit/components/passwordmgr/moz.build
toolkit/components/passwordmgr/passwordmgr.manifest
--- a/services/healthreport/docs/dataformat.rst
+++ b/services/healthreport/docs/dataformat.rst
@@ -1894,8 +1894,35 @@ Example
       "treatment": [
         "optin",
         "optin-DNT"
       ],
       "another-tag": [
         "foobar-value"
       ]
     }
+
+org.mozilla.passwordmgr.passwordmgr
+-----------------------------------
+
+Daily measurement reporting information about the Password Manager
+
+Version 1
+^^^^^^^^^
+
+Property:
+
+numSavedPasswords
+    number of passwords saved in the Password Manager
+
+enabled
+    Whether or not the user has disabled the Password Manager in prefernces
+
+Example
+^^^^^^^
+
+::
+
+    "org.mozilla.passwordmgr.passwordmgr": {
+      "_v": 1,
+      "numSavedPasswords": 5,
+      "enabled": 0,
+    }
--- a/toolkit/components/passwordmgr/LoginManagerParent.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerParent.jsm
@@ -12,17 +12,17 @@ const Cc = Components.classes;
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "UserAutoCompleteResult",
                                   "resource://gre/modules/LoginManagerContent.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "AutoCompleteE10S",
                                   "resource://gre/modules/AutoCompleteE10S.jsm");
 
-this.EXPORTED_SYMBOLS = [ "LoginManagerParent" ];
+this.EXPORTED_SYMBOLS = [ "LoginManagerParent", "PasswordsMetricsProvider" ];
 
 var gDebug;
 
 function log(...pieces) {
   function generateLogMessage(args) {
     let strings = ['Login Manager (parent):'];
 
     args.forEach(function(arg) {
@@ -46,16 +46,71 @@ function log(...pieces) {
   if (!gDebug)
     return;
 
   let message = generateLogMessage(pieces);
   dump(message + "\n");
   Services.console.logStringMessage(message);
 }
 
+#ifndef ANDROID
+#ifdef MOZ_SERVICES_HEALTHREPORT
+XPCOMUtils.defineLazyModuleGetter(this, "Metrics",
+                                  "resource://gre/modules/Metrics.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Task",
+                                  "resource://gre/modules/Task.jsm");
+
+this.PasswordsMetricsProvider = function() {
+  Metrics.Provider.call(this);
+}
+
+PasswordsMetricsProvider.prototype = Object.freeze({
+  __proto__: Metrics.Provider.prototype,
+
+  name: "org.mozilla.passwordmgr",
+
+  measurementTypes: [
+    PasswordsMeasurement1,
+  ],
+
+  pullOnly: true,
+
+  collectDailyData: function* () {
+    return this.storage.enqueueTransaction(this._recordDailyPasswordData.bind(this));
+  },
+
+  _recordDailyPasswordData: function() {
+    let m = this.getMeasurement(PasswordsMeasurement1.prototype.name,
+                                PasswordsMeasurement1.prototype.version);
+    let enabled = Services.prefs.getBoolPref("signon.rememberSignons");
+    yield m.setDailyLastNumeric("enabled", enabled ? 1 : 0);
+
+    let loginsCount = Services.logins.countLogins("", "", "");
+    yield m.setDailyLastNumeric("numSavedPasswords", loginsCount);
+
+  },
+});
+
+function PasswordsMeasurement1() {
+  Metrics.Measurement.call(this);
+}
+
+PasswordsMeasurement1.prototype = Object.freeze({
+  __proto__: Metrics.Measurement.prototype,
+  name: "passwordmgr",
+  version: 1,
+  fields: {
+    enabled: {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC},
+    numSavedPasswords: {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC},
+  },
+});
+
+#endif
+#endif
+
 function prefChanged() {
   gDebug = Services.prefs.getBoolPref("signon.debug");
 }
 
 Services.prefs.addObserver("signon.debug", prefChanged, false);
 prefChanged();
 
 var LoginManagerParent = {
--- a/toolkit/components/passwordmgr/moz.build
+++ b/toolkit/components/passwordmgr/moz.build
@@ -26,16 +26,20 @@ EXTRA_COMPONENTS += [
     'nsLoginManagerPrompter.js',
 ]
 
 EXTRA_PP_COMPONENTS += [
     'nsLoginManager.js',
     'passwordmgr.manifest',
 ]
 
+EXTRA_PP_JS_MODULES += [
+    'LoginManagerParent.jsm',
+]
+
 EXTRA_JS_MODULES += [
     'InsecurePasswordUtils.jsm',
     'LoginHelper.jsm',
     'LoginManagerContent.jsm',
     'LoginManagerParent.jsm',
 ]
 
 if CONFIG['OS_TARGET'] == 'Android':
--- a/toolkit/components/passwordmgr/passwordmgr.manifest
+++ b/toolkit/components/passwordmgr/passwordmgr.manifest
@@ -10,8 +10,9 @@ contract @mozilla.org/login-manager/logi
 component {8c2023b9-175c-477e-9761-44ae7b549756} storage-mozStorage.js
 contract @mozilla.org/login-manager/storage/mozStorage;1 {8c2023b9-175c-477e-9761-44ae7b549756}
 #else
 component {c00c432d-a0c9-46d7-bef6-9c45b4d07341} storage-json.js
 contract @mozilla.org/login-manager/storage/json;1 {c00c432d-a0c9-46d7-bef6-9c45b4d07341}
 #endif
 component {dc6c2976-0f73-4f1f-b9ff-3d72b4e28309} crypto-SDR.js
 contract @mozilla.org/login-manager/crypto/SDR;1 {dc6c2976-0f73-4f1f-b9ff-3d72b4e28309}
+category healthreport-js-provider-default PasswordsMetricsProvider resource://gre/modules/LoginManagerParent.jsm
\ No newline at end of file