Bug 694728 - Sync: Log Status transitions. r=philikon

This commit is contained in:
Richard Newman 2011-10-15 15:29:11 -07:00
parent 31b5110792
commit 37eb32a9e6
3 changed files with 63 additions and 12 deletions

View File

@ -17,6 +17,7 @@
*
* Contributor(s):
* Edward Lee <edilee@mozilla.com> (original author)
* Richard Newman <rnewman@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of either
* the GNU General Public License Version 2 or later (the "GPL"), or the GNU
@ -40,36 +41,71 @@ const Cr = Components.results;
const Cu = Components.utils;
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/log4moz.js");
Cu.import("resource://gre/modules/Services.jsm");
let Status = {
_log: Log4Moz.repository.getLogger("Sync.Status"),
ready: false,
get login() this._login,
get service() {
return this._service;
},
set service(code) {
this._log.debug("Status.service: " + this._service + " => " + code);
this._service = code;
},
get login() {
return this._login;
},
set login(code) {
this._log.debug("Status.login: " + this._login + " => " + code);
this._login = code;
if (code == LOGIN_FAILED_NO_USERNAME ||
code == LOGIN_FAILED_NO_PASSWORD ||
code == LOGIN_FAILED_NO_PASSPHRASE)
code == LOGIN_FAILED_NO_PASSPHRASE) {
this.service = CLIENT_NOT_CONFIGURED;
else if (code != LOGIN_SUCCEEDED)
} else if (code != LOGIN_SUCCEEDED) {
this.service = LOGIN_FAILED;
else
} else {
this.service = STATUS_OK;
}
},
get sync() {
return this._sync;
},
get sync() this._sync,
set sync(code) {
this._log.debug("Status.sync: " + this._sync + " => " + code);
this._sync = code;
this.service = code == SYNC_SUCCEEDED ? STATUS_OK : SYNC_FAILED;
},
get engines() this._engines,
get engines() {
return this._engines;
},
set engines([name, code]) {
this._log.debug("Status for engine " + name + ": " + code);
this._engines[name] = code;
if (code != ENGINE_SUCCEEDED)
if (code != ENGINE_SUCCEEDED) {
this.service = SYNC_FAILED_PARTIAL;
}
},
// Implement toString because adding a logger introduces a cyclic object
// value, so we can't trivially debug-print Status as JSON.
toString: function toString() {
return "<Status" +
": login: " + Status.login +
", service: " + Status.service +
", sync: " + Status.sync + ">";
},
checkSetup: function checkSetup() {
@ -92,8 +128,9 @@ let Status = {
Cu.import("resource://services-sync/record.js");
if (!Utils.mpLocked()) {
let id = ID.get("WeaveID");
if (!id)
if (!id) {
id = ID.set("WeaveID", new Identity(PWDMGR_PASSWORD_REALM, username));
}
if (!id.password) {
Status.login = LOGIN_FAILED_NO_PASSWORD;
@ -101,9 +138,10 @@ let Status = {
}
id = ID.get("WeaveCryptoID");
if (!id)
if (!id) {
id = ID.set("WeaveCryptoID",
new SyncKeyBundle(PWDMGR_PASSPHRASE_REALM, username));
}
if (!id.keyStr) {
Status.login = LOGIN_FAILED_NO_PASSPHRASE;
@ -118,15 +156,27 @@ let Status = {
this.backoffInterval = 0;
this.minimumNextSync = 0;
},
resetSync: function resetSync() {
// Logger setup.
let logPref = PREFS_BRANCH + "log.logger.status";
let logLevel = "Trace";
try {
logLevel = Services.prefs.getCharPref(logPref);
} catch (ex) {
// Use default.
}
this._log.level = Log4Moz.Level[logLevel];
this._log.info("Resetting Status.");
this.service = STATUS_OK;
this._login = LOGIN_SUCCEEDED;
this._sync = SYNC_SUCCEEDED;
this._engines = {};
this.partial = false;
},
}
};
// Initialize various status values
// Initialize various status values.
Status.resetBackoff();
Status.resetSync();

View File

@ -38,6 +38,7 @@ pref("services.sync.log.appender.file.logOnSuccess", false);
pref("services.sync.log.appender.file.maxErrorAge", 864000); // 10 days
pref("services.sync.log.rootLogger", "Debug");
pref("services.sync.log.logger.service.main", "Debug");
pref("services.sync.log.logger.status", "Debug");
pref("services.sync.log.logger.authenticator", "Debug");
pref("services.sync.log.logger.network.resources", "Debug");
pref("services.sync.log.logger.service.jpakeclient", "Debug");

View File

@ -283,7 +283,7 @@ add_test(function v5_upgrade() {
catch (e) {
_("Exception: " + e);
}
_("Status: " + JSON.stringify(Status));
_("Status: " + Status);
do_check_false(Weave.Service.isLoggedIn);
do_check_eq(VERSION_OUT_OF_DATE, Status.sync);