From f7911b974601f824a7f64bd0ecf2b07a6da6aa78 Mon Sep 17 00:00:00 2001 From: Anant Narayanan Date: Mon, 30 Jun 2008 11:19:07 -0700 Subject: [PATCH] Primitive password tracking support (bug 435320, r=thunder) --- services/sync/modules/engines/passwords.js | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/services/sync/modules/engines/passwords.js b/services/sync/modules/engines/passwords.js index a2c3d1df4f3..792e5abeddc 100644 --- a/services/sync/modules/engines/passwords.js +++ b/services/sync/modules/engines/passwords.js @@ -198,3 +198,48 @@ PasswordStore.prototype = { }; PasswordStore.prototype.__proto__ = new Store(); +function PasswordTracker() { + this._init(); +} +PasswordTracker.prototype = { + _logName: "PasswordTracker", + + __loginManager : null, + get _loginManager() { + if (!this.__loginManager) + this.__loginManager = Cc["@mozilla.org/login-manager;1"]. + getService(Ci.nsILoginManager); + return this.__loginManager; + }, + + /* We use nsILoginManager's countLogins() method, as it is + * the only method that doesn't require the user to enter + * a master password, but still gives us an idea of how much + * info has changed. + * + * FIXME: This does not track edits of passwords, so we + * artificially add 30 to every score. We should move to + * using the LoginManager shim at some point. + * + * Each addition/removal is worth 15 points. + */ + _loginCount: 0, + get score() { + var count = this._loginManager.countLogins("", "", ""); + var score = Math.abs(this._loginCount - count) * 15; + + if (score >= 100) + return 100; + else + return score + 30; + }, + + resetScore: function PasswordTracker_resetScore() { + this._loginCount = this._loginManager.countLogins("", "", ""); + }, + + _init: function PasswordTracker__init() { + this._log = Log4Moz.Service.getLogger("Service." this._logName); + this._loginCount = this._loginManager.countLogins("", "", ""); + } +}