2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-07 21:47:43 +04:00
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.EXPORTED_SYMBOLS = ["Status"];
|
2009-10-07 21:47:43 +04:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2010-06-17 01:30:08 +04:00
|
|
|
Cu.import("resource://services-sync/constants.js");
|
2013-08-26 22:55:58 +04:00
|
|
|
Cu.import("resource://gre/modules/Log.jsm");
|
2012-03-23 02:49:50 +04:00
|
|
|
Cu.import("resource://services-sync/identity.js");
|
2014-01-29 05:51:09 +04:00
|
|
|
Cu.import("resource://services-sync/browserid_identity.js");
|
2011-10-16 02:29:11 +04:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2014-01-29 05:51:09 +04:00
|
|
|
Cu.import("resource://services-common/async.js");
|
2009-10-07 21:47:43 +04:00
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.Status = {
|
2013-08-26 22:55:58 +04:00
|
|
|
_log: Log.repository.getLogger("Sync.Status"),
|
2014-01-29 05:51:09 +04:00
|
|
|
__authManager: null,
|
2011-02-18 00:41:13 +03:00
|
|
|
ready: false,
|
|
|
|
|
2014-01-29 05:51:09 +04:00
|
|
|
get _authManager() {
|
|
|
|
if (this.__authManager) {
|
|
|
|
return this.__authManager;
|
|
|
|
}
|
|
|
|
let service = Components.classes["@mozilla.org/weave/service;1"]
|
|
|
|
.getService(Components.interfaces.nsISupports)
|
|
|
|
.wrappedJSObject;
|
|
|
|
let idClass = service.fxAccountsEnabled ? BrowserIDManager : IdentityManager;
|
|
|
|
this.__authManager = new idClass();
|
|
|
|
// .initialize returns a promise, so we need to spin until it resolves.
|
|
|
|
let cb = Async.makeSpinningCallback();
|
|
|
|
this.__authManager.initialize().then(cb, cb);
|
|
|
|
cb.wait();
|
|
|
|
return this.__authManager;
|
|
|
|
},
|
|
|
|
|
2011-10-16 02:29:11 +04:00
|
|
|
get service() {
|
|
|
|
return this._service;
|
|
|
|
},
|
|
|
|
|
|
|
|
set service(code) {
|
|
|
|
this._log.debug("Status.service: " + this._service + " => " + code);
|
|
|
|
this._service = code;
|
|
|
|
},
|
|
|
|
|
|
|
|
get login() {
|
|
|
|
return this._login;
|
|
|
|
},
|
|
|
|
|
2009-10-07 21:47:43 +04:00
|
|
|
set login(code) {
|
2011-10-16 02:29:11 +04:00
|
|
|
this._log.debug("Status.login: " + this._login + " => " + code);
|
2009-10-07 21:47:43 +04:00
|
|
|
this._login = code;
|
|
|
|
|
2012-03-23 02:49:50 +04:00
|
|
|
if (code == LOGIN_FAILED_NO_USERNAME ||
|
|
|
|
code == LOGIN_FAILED_NO_PASSWORD ||
|
2011-10-16 02:29:11 +04:00
|
|
|
code == LOGIN_FAILED_NO_PASSPHRASE) {
|
2012-03-23 02:49:50 +04:00
|
|
|
this.service = CLIENT_NOT_CONFIGURED;
|
2011-10-16 02:29:11 +04:00
|
|
|
} else if (code != LOGIN_SUCCEEDED) {
|
2009-10-07 21:47:43 +04:00
|
|
|
this.service = LOGIN_FAILED;
|
2011-10-16 02:29:11 +04:00
|
|
|
} else {
|
2009-10-07 21:47:43 +04:00
|
|
|
this.service = STATUS_OK;
|
2011-10-16 02:29:11 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get sync() {
|
|
|
|
return this._sync;
|
2009-10-07 21:47:43 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
set sync(code) {
|
2011-10-16 02:29:11 +04:00
|
|
|
this._log.debug("Status.sync: " + this._sync + " => " + code);
|
2009-10-07 21:47:43 +04:00
|
|
|
this._sync = code;
|
2010-03-26 00:24:41 +03:00
|
|
|
this.service = code == SYNC_SUCCEEDED ? STATUS_OK : SYNC_FAILED;
|
2009-10-07 21:47:43 +04:00
|
|
|
},
|
|
|
|
|
2013-09-04 03:11:46 +04:00
|
|
|
get eol() {
|
|
|
|
let modePref = PREFS_BRANCH + "errorhandler.alert.mode";
|
|
|
|
try {
|
|
|
|
return Services.prefs.getCharPref(modePref) == "hard-eol";
|
|
|
|
} catch (ex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-10-16 02:29:11 +04:00
|
|
|
get engines() {
|
|
|
|
return this._engines;
|
|
|
|
},
|
|
|
|
|
2009-10-07 21:47:43 +04:00
|
|
|
set engines([name, code]) {
|
2011-10-16 02:29:11 +04:00
|
|
|
this._log.debug("Status for engine " + name + ": " + code);
|
2009-10-07 21:47:43 +04:00
|
|
|
this._engines[name] = code;
|
|
|
|
|
2011-10-16 02:29:11 +04:00
|
|
|
if (code != ENGINE_SUCCEEDED) {
|
2009-10-07 21:47:43 +04:00
|
|
|
this.service = SYNC_FAILED_PARTIAL;
|
2011-10-16 02:29:11 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// 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 + ">";
|
2009-10-07 21:47:43 +04:00
|
|
|
},
|
|
|
|
|
2010-08-26 02:49:45 +04:00
|
|
|
checkSetup: function checkSetup() {
|
2012-03-23 02:49:50 +04:00
|
|
|
let result = this._authManager.currentAuthState;
|
|
|
|
if (result == STATUS_OK) {
|
|
|
|
Status.service = result;
|
|
|
|
return result;
|
2010-08-26 02:49:45 +04:00
|
|
|
}
|
|
|
|
|
2012-03-23 02:49:50 +04:00
|
|
|
Status.login = result;
|
|
|
|
return Status.service;
|
2010-08-26 02:49:45 +04:00
|
|
|
},
|
|
|
|
|
2009-10-07 21:47:43 +04:00
|
|
|
resetBackoff: function resetBackoff() {
|
|
|
|
this.enforceBackoff = false;
|
|
|
|
this.backoffInterval = 0;
|
|
|
|
this.minimumNextSync = 0;
|
|
|
|
},
|
2011-10-16 02:29:11 +04:00
|
|
|
|
2009-10-07 21:47:43 +04:00
|
|
|
resetSync: function resetSync() {
|
2011-10-16 02:29:11 +04:00
|
|
|
// Logger setup.
|
|
|
|
let logPref = PREFS_BRANCH + "log.logger.status";
|
|
|
|
let logLevel = "Trace";
|
|
|
|
try {
|
|
|
|
logLevel = Services.prefs.getCharPref(logPref);
|
|
|
|
} catch (ex) {
|
|
|
|
// Use default.
|
|
|
|
}
|
2013-08-26 22:55:58 +04:00
|
|
|
this._log.level = Log.Level[logLevel];
|
2011-10-16 02:29:11 +04:00
|
|
|
|
|
|
|
this._log.info("Resetting Status.");
|
2010-06-02 02:12:25 +04:00
|
|
|
this.service = STATUS_OK;
|
|
|
|
this._login = LOGIN_SUCCEEDED;
|
|
|
|
this._sync = SYNC_SUCCEEDED;
|
2009-10-07 21:47:43 +04:00
|
|
|
this._engines = {};
|
|
|
|
this.partial = false;
|
2011-10-16 02:29:11 +04:00
|
|
|
}
|
2009-10-07 21:47:43 +04:00
|
|
|
};
|
|
|
|
|
2011-10-16 02:29:11 +04:00
|
|
|
// Initialize various status values.
|
2009-10-07 21:47:43 +04:00
|
|
|
Status.resetBackoff();
|
|
|
|
Status.resetSync();
|