Bug 785225 - Part 5: Partial removal of Clients singleton; r=rnewman

Clients was being exported and used as a singleton. We still use Clients
as a singleton in some places, but only in test code. The preferred
method to access Clients is now through a service instance.
Weave.Clients is no longer exposed. Callers go through Weave.Service
now.
This commit is contained in:
Gregory Szorc 2012-08-29 14:43:40 -07:00
Родитель 864a6551e8
Коммит 19432e05ab
9 изменённых файлов: 58 добавлений и 57 удалений

Просмотреть файл

@ -155,7 +155,7 @@ let RemoteTabViewer = {
let attrs = {
type: "client",
clientName: client.clientName,
class: Weave.Clients.isMobile(client.id) ? "mobile" : "desktop"
class: Weave.Service.clientsEngine.isMobile(client.id) ? "mobile" : "desktop"
};
let clientEnt = this.createItem(attrs);
list.appendChild(clientEnt);
@ -211,8 +211,8 @@ let RemoteTabViewer = {
}
// if Clients hasn't synced yet this session, need to sync it as well
if (Weave.Clients.lastSync == 0)
Weave.Clients.sync();
if (Weave.Service.clientsEngine.lastSync == 0)
Weave.Service.clientsEngine.sync();
// Force a sync only for the tabs engine
let engine = Weave.Service.engineManager.get("tabs");

Просмотреть файл

@ -400,7 +400,7 @@ var gSyncSetup = {
this.wizard.getButton("back").hidden = true;
this.wizard.getButton("cancel").hidden = !this._resettingSync;
this.wizard.getButton("extra1").hidden = true;
document.getElementById("syncComputerName").value = Weave.Clients.localName;
document.getElementById("syncComputerName").value = Weave.Service.clientsEngine.localName;
document.getElementById("syncOptions").collapsed = this._resettingSync;
document.getElementById("mergeOptions").collapsed = this._settingUpNew;
break;
@ -943,9 +943,9 @@ var gSyncSetup = {
box.appendChild(node);
}
for each (let name in Weave.Clients.stats.names) {
for each (let name in Weave.Service.clientsEngine.stats.names) {
// Don't list the current client
if (name == Weave.Clients.localName)
if (name == Weave.Service.clientsEngine.localName)
continue;
// Only show the first several client names

Просмотреть файл

@ -27,8 +27,8 @@ let gSyncUtils = {
changeName: function changeName(input) {
// Make sure to update to a modified name, e.g., empty-string -> default
Weave.Clients.localName = input.value;
input.value = Weave.Clients.localName;
Weave.Service.clientsEngine.localName = input.value;
input.value = Weave.Service.clientsEngine.localName;
},
openChange: function openChange(type, duringSetup) {

Просмотреть файл

@ -66,7 +66,7 @@ let gSyncPane = {
} else {
this.page = PAGE_HAS_ACCOUNT;
document.getElementById("accountName").value = Weave.Identity.account;
document.getElementById("syncComputerName").value = Weave.Clients.localName;
document.getElementById("syncComputerName").value = Weave.Service.clientsEngine.localName;
document.getElementById("tosPP").hidden = this._usingCustomServer;
}
},

Просмотреть файл

@ -67,7 +67,7 @@ let gSyncPane = {
} else {
this.page = PAGE_HAS_ACCOUNT;
document.getElementById("accountName").value = Weave.Identity.account;
document.getElementById("syncComputerName").value = Weave.Clients.localName;
document.getElementById("syncComputerName").value = Weave.Service.clientsEngine.localName;
document.getElementById("tosPP").hidden = this._usingCustomServer;
}
},

Просмотреть файл

@ -7,7 +7,6 @@ const EXPORTED_SYMBOLS = ['Weave'];
let Weave = {};
Components.utils.import("resource://services-sync/constants.js", Weave);
let lazies = {
"engines/clients.js": ["Clients"],
"identity.js": ["Identity"],
"jpakeclient.js": ["JPAKEClient"],
"notifications.js": ["Notifications", "Notification", "NotificationButton"],

Просмотреть файл

@ -417,6 +417,9 @@ WeaveSvc.prototype = {
engines = pref.split(",");
}
// TODO Singleton (bug 785225).
this.clientsEngine = Clients;
for (let name of engines) {
if (!name in ENGINE_MODULES) {
this._log.info("Do not know about engine: " + name);
@ -818,7 +821,7 @@ WeaveSvc.prototype = {
// Deletion doesn't make sense if we aren't set up yet!
if (this.clusterURL != "") {
// Clear client-specific data from the server, including disabled engines.
for each (let engine in [Clients].concat(this.engineManager.getAll())) {
for each (let engine in [this.clientsEngine].concat(this.engineManager.getAll())) {
try {
engine.removeClientData();
} catch(ex) {
@ -1237,7 +1240,7 @@ WeaveSvc.prototype = {
Records.set(this.metaURL, meta);
// Wipe everything we know about except meta because we just uploaded it
let engines = [Clients].concat(this.engineManager.getAll());
let engines = [this.clientsEngine].concat(this.engineManager.getAll());
let collections = [engine.name for each (engine in engines)];
// Generate, upload, and download new keys. Do this last so we don't wipe
@ -1311,7 +1314,7 @@ WeaveSvc.prototype = {
// Clear out any service data
this.resetService();
engines = [Clients].concat(this.engineManager.getAll());
engines = [this.clientsEngine].concat(this.engineManager.getAll());
}
// Convert the array of names into engines
else {
@ -1346,15 +1349,15 @@ WeaveSvc.prototype = {
// Only wipe the engines provided.
if (engines) {
engines.forEach(function(e) Clients.sendCommand("wipeEngine", [e]), this);
engines.forEach(function(e) this.clientsEngine.sendCommand("wipeEngine", [e]), this);
}
// Tell the remote machines to wipe themselves.
else {
Clients.sendCommand("wipeAll", []);
this.clientsEngine.sendCommand("wipeAll", []);
}
// Make sure the changed clients get updated.
Clients.sync();
this.clientsEngine.sync();
} catch (ex) {
this.errorHandler.checkServerError(ex);
throw ex;
@ -1387,7 +1390,7 @@ WeaveSvc.prototype = {
// Clear out any service data
this.resetService();
engines = [Clients].concat(this.engineManager.getAll());
engines = [this.clientsEngine].concat(this.engineManager.getAll());
}
// Convert the array of names into engines
else {

Просмотреть файл

@ -13,7 +13,6 @@ const {utils: Cu} = Components;
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/engines/clients.js");
Cu.import("resource://services-sync/policies.js");
Cu.import("resource://services-sync/record.js");
Cu.import("resource://services-sync/resource.js");
@ -79,7 +78,7 @@ EngineSynchronizer.prototype = {
let info = this.service._fetchInfo(infoURL);
// Convert the response to an object and read out the modified times
for (let engine of [Clients].concat(this.service.engineManager.getAll())) {
for (let engine of [this.service.clientsEngine].concat(this.service.engineManager.getAll())) {
engine.lastModified = info.obj[engine.name] || 0;
}
@ -90,7 +89,7 @@ EngineSynchronizer.prototype = {
// Make sure we have an up-to-date list of clients before sending commands
this._log.debug("Refreshing client list.");
if (!this._syncEngine(Clients)) {
if (!this._syncEngine(this.service.clientsEngine)) {
// Clients is an engine like any other; it can fail with a 401,
// and we can elect to abort the sync.
this._log.warn("Client engine sync failed. Aborting.");
@ -111,9 +110,9 @@ EngineSynchronizer.prototype = {
break;
}
if (Clients.localCommands) {
if (this.service.clientsEngine.localCommands) {
try {
if (!(Clients.processIncomingCommands())) {
if (!(this.service.clientsEngine.processIncomingCommands())) {
Status.sync = ABORT_SYNC_COMMAND;
this.onComplete(new Error("Processed command aborted sync."));
return;
@ -130,7 +129,7 @@ EngineSynchronizer.prototype = {
// without commands).
// Note that we don't abort here; if there's a 401 because we've
// been reassigned, we'll handle it around another engine.
this._syncEngine(Clients);
this._syncEngine(this.service.clientsEngine);
}
}

Просмотреть файл

@ -1,12 +1,12 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://services-sync/main.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/keys.js");
Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/util.js");
function run_test() {
let logger = Log4Moz.repository.rootLogger;
@ -64,52 +64,52 @@ function run_test() {
try {
_("Log in.");
Weave.Service.serverURL = TEST_SERVER_URL;
Weave.Service.clusterURL = TEST_CLUSTER_URL;
Service.serverURL = TEST_SERVER_URL;
Service.clusterURL = TEST_CLUSTER_URL;
_("Checking Status.sync with no credentials.");
Weave.Service.verifyAndFetchSymmetricKeys();
Service.verifyAndFetchSymmetricKeys();
do_check_eq(Status.sync, CREDENTIALS_CHANGED);
do_check_eq(Status.login, LOGIN_FAILED_NO_PASSPHRASE);
_("Log in with an old secret phrase, is upgraded to Sync Key.");
Weave.Service.login("johndoe", "ilovejane", "my old secret phrase!!1!");
Service.login("johndoe", "ilovejane", "my old secret phrase!!1!");
_("End of login");
do_check_true(Weave.Service.isLoggedIn);
do_check_true(Service.isLoggedIn);
do_check_true(Utils.isPassphrase(Identity.syncKey));
let syncKey = Identity.syncKey;
Weave.Service.startOver();
Service.startOver();
Weave.Service.serverURL = TEST_SERVER_URL;
Weave.Service.clusterURL = TEST_CLUSTER_URL;
Weave.Service.login("johndoe", "ilovejane", syncKey);
do_check_true(Weave.Service.isLoggedIn);
Service.serverURL = TEST_SERVER_URL;
Service.clusterURL = TEST_CLUSTER_URL;
Service.login("johndoe", "ilovejane", syncKey);
do_check_true(Service.isLoggedIn);
_("Checking that remoteSetup returns true when credentials have changed.");
Records.get(Weave.Service.metaURL).payload.syncID = "foobar";
do_check_true(Weave.Service._remoteSetup());
Records.get(Service.metaURL).payload.syncID = "foobar";
do_check_true(Service._remoteSetup());
_("Do an initial sync.");
let beforeSync = Date.now()/1000;
Weave.Service.sync();
Service.sync();
_("Checking that remoteSetup returns true.");
do_check_true(Weave.Service._remoteSetup());
do_check_true(Service._remoteSetup());
_("Verify that the meta record was uploaded.");
do_check_eq(meta_global.data.syncID, Weave.Service.syncID);
do_check_eq(meta_global.data.storageVersion, Weave.STORAGE_VERSION);
do_check_eq(meta_global.data.engines.clients.version, Weave.Clients.version);
do_check_eq(meta_global.data.engines.clients.syncID, Weave.Clients.syncID);
do_check_eq(meta_global.data.syncID, Service.syncID);
do_check_eq(meta_global.data.storageVersion, STORAGE_VERSION);
do_check_eq(meta_global.data.engines.clients.version, Service.clientsEngine.version);
do_check_eq(meta_global.data.engines.clients.syncID, Service.clientsEngine.syncID);
_("Set the collection info hash so that sync() will remember the modified times for future runs.");
collections.meta = Weave.Clients.lastSync;
collections.clients = Weave.Clients.lastSync;
Weave.Service.sync();
collections.meta = Service.clientsEngine.lastSync;
collections.clients = Service.clientsEngine.lastSync;
Service.sync();
_("Sync again and verify that meta/global wasn't downloaded again");
meta_global.wasCalled = false;
Weave.Service.sync();
Service.sync();
do_check_false(meta_global.wasCalled);
_("Fake modified records. This will cause a redownload, but not reupload since it hasn't changed.");
@ -118,25 +118,25 @@ function run_test() {
let metaModified = meta_global.modified;
Weave.Service.sync();
Service.sync();
do_check_true(meta_global.wasCalled);
do_check_eq(metaModified, meta_global.modified);
_("Checking bad passphrases.");
let pp = Identity.syncKey;
Identity.syncKey = "notvalid";
do_check_false(Weave.Service.verifyAndFetchSymmetricKeys());
do_check_false(Service.verifyAndFetchSymmetricKeys());
do_check_eq(Status.sync, CREDENTIALS_CHANGED);
do_check_eq(Status.login, LOGIN_FAILED_INVALID_PASSPHRASE);
Identity.syncKey = pp;
do_check_true(Weave.Service.verifyAndFetchSymmetricKeys());
do_check_true(Service.verifyAndFetchSymmetricKeys());
// changePassphrase wipes our keys, and they're regenerated on next sync.
_("Checking changed passphrase.");
let existingDefault = CollectionKeys.keyForCollection();
let existingKeysPayload = keysWBO.payload;
let newPassphrase = "bbbbbabcdeabcdeabcdeabcdea";
Weave.Service.changePassphrase(newPassphrase);
Service.changePassphrase(newPassphrase);
_("Local key cache is full, but different.");
do_check_true(!!CollectionKeys._default);
@ -156,13 +156,13 @@ function run_test() {
b.generateRandom();
collections.crypto = keys.modified = 100 + (Date.now()/1000); // Future modification time.
keys.encrypt(b);
keys.upload(Weave.Service.cryptoKeysURL);
keys.upload(Service.cryptoKeysURL);
do_check_false(Weave.Service.verifyAndFetchSymmetricKeys());
do_check_false(Service.verifyAndFetchSymmetricKeys());
do_check_eq(Status.login, LOGIN_FAILED_INVALID_PASSPHRASE);
} finally {
Weave.Svc.Prefs.resetBranch("");
Svc.Prefs.resetBranch("");
server.stop(do_test_finished);
}
}