Skip to content

Commit

Permalink
Bug 787273 - Part 7: Expose Status an an instance variable on Service…
Browse files Browse the repository at this point in the history
…; r=rnewman

The global Status is still there. But Service and its derived objects
avoid the singleton lookup.

There are likely a few lingering tests that reference Status when they
should reference Service.status. These will be dealt with when Status is
refactored.
  • Loading branch information
indygreg committed Sep 14, 2012
1 parent 0868fb1 commit 4172ab0
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 118 deletions.
64 changes: 32 additions & 32 deletions services/sync/modules/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ Sync11Service.prototype = {
throw new Error("Status or Status._authManager not initialized.");
}

this.status = Status;
this.identity = Status._authManager;

this.collectionKeys = new CollectionKeyManager();

this.errorHandler = new ErrorHandler(this);
Expand Down Expand Up @@ -361,16 +361,16 @@ Sync11Service.prototype = {
// synchronously so that observers can import this module before
// registering an observer.
Utils.nextTick(function onNextTick() {
Status.ready = true;
this.status.ready = true;
Svc.Obs.notify("weave:service:ready");
});
}.bind(this));
},

_checkSetup: function _checkSetup() {
if (!this.enabled) {
return Status.service = STATUS_DISABLED;
return this.status.service = STATUS_DISABLED;
}
return Status.checkSetup();
return this.status.checkSetup();
},

_migratePrefs: function _migratePrefs() {
Expand Down Expand Up @@ -528,17 +528,17 @@ Sync11Service.prototype = {
// and fail if that assumption is invalidated.

if (!this.identity.syncKey) {
Status.login = LOGIN_FAILED_NO_PASSPHRASE;
Status.sync = CREDENTIALS_CHANGED;
this.status.login = LOGIN_FAILED_NO_PASSPHRASE;
this.status.sync = CREDENTIALS_CHANGED;
return false;
}

let syncKeyBundle = this.identity.syncKeyBundle;
if (!syncKeyBundle) {
this._log.error("Sync Key Bundle not set. Invalid Sync Key?");

Status.login = LOGIN_FAILED_INVALID_PASSPHRASE;
Status.sync = CREDENTIALS_CHANGED;
this.status.login = LOGIN_FAILED_INVALID_PASSPHRASE;
this.status.sync = CREDENTIALS_CHANGED;
return false;
}

Expand All @@ -549,7 +549,7 @@ Sync11Service.prototype = {
// This only applies when the server is already at version 4.
if (infoResponse.status != 200) {
this._log.warn("info/collections returned non-200 response. Failing key fetch.");
Status.login = LOGIN_FAILED_SERVER_ERROR;
this.status.login = LOGIN_FAILED_SERVER_ERROR;
this.errorHandler.checkServerError(infoResponse);
return false;
}
Expand Down Expand Up @@ -583,7 +583,7 @@ Sync11Service.prototype = {
}
else {
// Some other problem.
Status.login = LOGIN_FAILED_SERVER_ERROR;
this.status.login = LOGIN_FAILED_SERVER_ERROR;
this.errorHandler.checkServerError(cryptoResp);
this._log.warn("Got status " + cryptoResp.status + " fetching crypto keys.");
return false;
Expand All @@ -595,13 +595,13 @@ Sync11Service.prototype = {

// One kind of exception: HMAC failure.
if (Utils.isHMACMismatch(ex)) {
Status.login = LOGIN_FAILED_INVALID_PASSPHRASE;
Status.sync = CREDENTIALS_CHANGED;
this.status.login = LOGIN_FAILED_INVALID_PASSPHRASE;
this.status.sync = CREDENTIALS_CHANGED;
}
else {
// In the absence of further disambiguation or more precise
// failure constants, just report failure.
Status.login = LOGIN_FAILED;
this.status.login = LOGIN_FAILED;
}
return false;
}
Expand Down Expand Up @@ -641,7 +641,7 @@ Sync11Service.prototype = {
verifyLogin: function verifyLogin() {
if (!this.identity.username) {
this._log.warn("No username in verifyLogin.");
Status.login = LOGIN_FAILED_NO_USERNAME;
this.status.login = LOGIN_FAILED_NO_USERNAME;
return false;
}

Expand All @@ -655,7 +655,7 @@ Sync11Service.prototype = {
} catch (ex) {
this._log.debug("Fetching passphrase threw " + ex +
"; assuming master password locked.");
Status.login = MASTER_PASSWORD_LOCKED;
this.status.login = MASTER_PASSWORD_LOCKED;
return false;
}

Expand All @@ -664,7 +664,7 @@ Sync11Service.prototype = {
// This is a little weird, if we don't get a node we pretend
// to succeed, since that probably means we just don't have storage.
if (this.clusterURL == "" && !this._clusterManager.setCluster()) {
Status.sync = NO_SYNC_NODE_FOUND;
this.status.sync = NO_SYNC_NODE_FOUND;
Svc.Obs.notify("weave:service:sync:delayed");
return true;
}
Expand All @@ -681,15 +681,15 @@ Sync11Service.prototype = {
// Just make the most trivial checks.
if (!this.identity.syncKey) {
this._log.warn("No passphrase in verifyLogin.");
Status.login = LOGIN_FAILED_NO_PASSPHRASE;
this.status.login = LOGIN_FAILED_NO_PASSPHRASE;
return false;
}

// Go ahead and do remote setup, so that we can determine
// conclusively that our passphrase is correct.
if (this._remoteSetup()) {
// Username/password verified.
Status.login = LOGIN_SUCCEEDED;
this.status.login = LOGIN_SUCCEEDED;
return true;
}

Expand All @@ -708,19 +708,19 @@ Sync11Service.prototype = {
}

// We must have the right cluster, but the server doesn't expect us
Status.login = LOGIN_FAILED_LOGIN_REJECTED;
this.status.login = LOGIN_FAILED_LOGIN_REJECTED;
return false;

default:
// Server didn't respond with something that we expected
Status.login = LOGIN_FAILED_SERVER_ERROR;
this.status.login = LOGIN_FAILED_SERVER_ERROR;
this.errorHandler.checkServerError(test);
return false;
}
} catch (ex) {
// Must have failed on some network issue
this._log.debug("verifyLogin failed: " + Utils.exceptionStr(ex));
Status.login = LOGIN_FAILED_NETWORK_ERROR;
this.status.login = LOGIN_FAILED_NETWORK_ERROR;
this.errorHandler.checkServerError(ex);
return false;
}
Expand Down Expand Up @@ -830,13 +830,13 @@ Sync11Service.prototype = {
startOver: function startOver() {
this._log.trace("Invoking Service.startOver.");
Svc.Obs.notify("weave:engine:stop-tracking");
Status.resetSync();
this.status.resetSync();

// We want let UI consumers of the following notification know as soon as
// possible, so let's fake for the CLIENT_NOT_CONFIGURED status for now
// by emptying the passphrase (we still need the password).
this.identity.syncKey = null;
Status.login = LOGIN_FAILED_NO_PASSPHRASE;
this.status.login = LOGIN_FAILED_NO_PASSPHRASE;
this.logout();
Svc.Obs.notify("weave:service:start-over");

Expand All @@ -858,7 +858,7 @@ Sync11Service.prototype = {
// Reset all engines and clear keys.
this.resetClient();
this.collectionKeys.clear();
Status.resetBackoff();
this.status.resetBackoff();

// Reset Weave prefs.
this._ignorePrefObserver = true;
Expand All @@ -882,7 +882,7 @@ Sync11Service.prototype = {
function onNotify() {
this._loggedIn = false;
if (Services.io.offline) {
Status.login = LOGIN_FAILED_NETWORK_ERROR;
this.status.login = LOGIN_FAILED_NETWORK_ERROR;
throw "Application is offline, login should not be called";
}

Expand Down Expand Up @@ -913,7 +913,7 @@ Sync11Service.prototype = {

if (!this.verifyLogin()) {
// verifyLogin sets the failure states here.
throw "Login failed: " + Status.login;
throw "Login failed: " + this.status.login;
}

this._loggedIn = true;
Expand Down Expand Up @@ -1038,7 +1038,7 @@ Sync11Service.prototype = {
// abort the server wipe if the GET status was anything other than 404 or 200
let status = this.recordManager.response.status;
if (status != 200 && status != 404) {
Status.sync = METARECORD_DOWNLOAD_FAIL;
this.status.sync = METARECORD_DOWNLOAD_FAIL;
this.errorHandler.checkServerError(this.recordManager.response);
this._log.warn("Unknown error while downloading metadata record. " +
"Aborting sync.");
Expand All @@ -1064,7 +1064,7 @@ Sync11Service.prototype = {
return true;
}
else if (remoteVersion > STORAGE_VERSION) {
Status.sync = VERSION_OUT_OF_DATE;
this.status.sync = VERSION_OUT_OF_DATE;
this._log.warn("Upgrade required to access newer storage version.");
return false;
}
Expand All @@ -1088,7 +1088,7 @@ Sync11Service.prototype = {

// bug 545725 - re-verify creds and fail sanely
if (!this.verifyLogin()) {
Status.sync = CREDENTIALS_CHANGED;
this.status.sync = CREDENTIALS_CHANGED;
this._log.info("Credentials have changed, aborting sync and forcing re-login.");
return false;
}
Expand Down Expand Up @@ -1137,9 +1137,9 @@ Sync11Service.prototype = {
reason = kSyncWeaveDisabled;
else if (Services.io.offline)
reason = kSyncNetworkOffline;
else if (Status.minimumNextSync > Date.now())
else if (this.status.minimumNextSync > Date.now())
reason = kSyncBackoffNotMet;
else if ((Status.login == MASTER_PASSWORD_LOCKED) &&
else if ((this.status.login == MASTER_PASSWORD_LOCKED) &&
Utils.mpLocked())
reason = kSyncMasterPasswordLocked;
else if (Svc.Prefs.get("firstSync") == "notReady")
Expand Down
5 changes: 2 additions & 3 deletions services/sync/modules/stages/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const {utils: Cu} = Components;
Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/policies.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");

/**
Expand Down Expand Up @@ -43,7 +42,7 @@ ClusterManager.prototype = {
let node = res.get();
switch (node.status) {
case 400:
Status.login = LOGIN_FAILED_LOGIN_REJECTED;
this.service.status.login = LOGIN_FAILED_LOGIN_REJECTED;
fail = "Find cluster denied: " + this.service.errorHandler.errorStr(node);
break;
case 404:
Expand All @@ -63,7 +62,7 @@ ClusterManager.prototype = {
}
} catch (e) {
this._log.debug("Network error on findCluster");
Status.login = LOGIN_FAILED_NETWORK_ERROR;
this.service.status.login = LOGIN_FAILED_NETWORK_ERROR;
this.service.errorHandler.checkServerError(e);
fail = e;
}
Expand Down
15 changes: 7 additions & 8 deletions services/sync/modules/stages/enginesync.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/policies.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");

/**
Expand All @@ -39,13 +38,13 @@ EngineSynchronizer.prototype = {

let startTime = Date.now();

Status.resetSync();
this.service.status.resetSync();

// Make sure we should sync or record why we shouldn't.
let reason = this.service._checkSync();
if (reason) {
if (reason == kSyncNetworkOffline) {
Status.sync = LOGIN_FAILED_NETWORK_ERROR;
this.service.status.sync = LOGIN_FAILED_NETWORK_ERROR;
}

// this is a purposeful abort rather than a failure, so don't set
Expand All @@ -57,7 +56,7 @@ EngineSynchronizer.prototype = {

// If we don't have a node, get one. If that fails, retry in 10 minutes.
if (!this.service.clusterURL && !this.service._clusterManager.setCluster()) {
Status.sync = NO_SYNC_NODE_FOUND;
this.service.status.sync = NO_SYNC_NODE_FOUND;
this._log.info("No cluster URL found. Cannot sync.");
this.onComplete(null);
return;
Expand Down Expand Up @@ -111,7 +110,7 @@ EngineSynchronizer.prototype = {
if (this.service.clientsEngine.localCommands) {
try {
if (!(this.service.clientsEngine.processIncomingCommands())) {
Status.sync = ABORT_SYNC_COMMAND;
this.service.status.sync = ABORT_SYNC_COMMAND;
this.onComplete(new Error("Processed command aborted sync."));
return;
}
Expand Down Expand Up @@ -145,7 +144,7 @@ EngineSynchronizer.prototype = {
try {
for each (let engine in this.service.engineManager.getEnabled()) {
// If there's any problems with syncing the engine, report the failure
if (!(this._syncEngine(engine)) || Status.enforceBackoff) {
if (!(this._syncEngine(engine)) || this.service.status.enforceBackoff) {
this._log.info("Aborting sync for failure in " + engine.name);
break;
}
Expand All @@ -170,9 +169,9 @@ EngineSynchronizer.prototype = {
}

// If there were no sync engine failures
if (Status.service != SYNC_FAILED_PARTIAL) {
if (this.service.status.service != SYNC_FAILED_PARTIAL) {
Svc.Prefs.set("lastSync", new Date().toString());
Status.sync = SYNC_SUCCEEDED;
this.service.status.sync = SYNC_SUCCEEDED;
}
} finally {
Svc.Prefs.reset("firstSync");
Expand Down
1 change: 0 additions & 1 deletion services/sync/tests/unit/test_service_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");

function test_urls() {
Expand Down
11 changes: 5 additions & 6 deletions services/sync/tests/unit/test_service_detect_upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Cu.import("resource://services-sync/keys.js");
Cu.import("resource://services-sync/engines/tabs.js");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");

Service.engineManager.register(TabEngine);
Expand Down Expand Up @@ -62,7 +61,7 @@ add_test(function v4_upgrade() {
getBrowserState: function () JSON.stringify(myTabs)
};

Status.resetSync();
Service.status.resetSync();

_("Logging in.");
Service.serverURL = TEST_SERVER_URL;
Expand All @@ -85,7 +84,7 @@ add_test(function v4_upgrade() {
}
catch (ex) {
}
do_check_eq(Status.sync, VERSION_OUT_OF_DATE);
do_check_eq(Service.status.sync, VERSION_OUT_OF_DATE);
}

// See what happens when we bump the storage version.
Expand Down Expand Up @@ -235,7 +234,7 @@ add_test(function v5_upgrade() {
getBrowserState: function () JSON.stringify(myTabs)
};

Status.resetSync();
Service.status.resetSync();

setBasicCredentials("johndoe", "ilovejane", passphrase);
Service.serverURL = TEST_SERVER_URL;
Expand Down Expand Up @@ -279,9 +278,9 @@ add_test(function v5_upgrade() {
catch (e) {
_("Exception: " + e);
}
_("Status: " + Status);
_("Status: " + Service.status);
do_check_false(Service.isLoggedIn);
do_check_eq(VERSION_OUT_OF_DATE, Status.sync);
do_check_eq(VERSION_OUT_OF_DATE, Service.status.sync);

// Clean up.
Service.startOver();
Expand Down
Loading

0 comments on commit 4172ab0

Please sign in to comment.