Bug 1124895 - 1/2 Add password manager data to FHR. r=gps, a=lmandel
💩💩 backed out by 42877284c697 💩 💩
authorAllison Naaktgeboren <ally@mozilla.com>
Mon, 16 Mar 2015 14:51:03 -0700
changeset 250401 5ec7f3ce97d2
parent 250400 be0abc9b1af7
child 250402 42877284c697
push id4574
push userjdolske@mozilla.com
push date2015-03-16 21:51 +0000
treeherdermozilla-beta@5ec7f3ce97d2 [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
services/healthreport/docs/dataformat.rst
toolkit/components/passwordmgr/LoginManagerParent.jsm
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
@@ -11,18 +11,22 @@ 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");
+XPCOMUtils.defineLazyModuleGetter(this, "Task",
+                                  "resource://gre/modules/Task.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Metrics",
+                                  "resource://gre/modules/Metrics.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 +50,61 @@ function log(...pieces) {
   if (!gDebug)
     return;
 
   let message = generateLogMessage(pieces);
   dump(message + "\n");
   Services.console.logStringMessage(message);
 }
 
+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},
+  },
+});
+
 function prefChanged() {
   gDebug = Services.prefs.getBoolPref("signon.debug");
 }
 
 Services.prefs.addObserver("signon.debug", prefChanged, false);
 prefChanged();
 
 var LoginManagerParent = {
--- 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