Bug 480457 - Expose a resetClient API for weave service and engines. r=thunder

This commit is contained in:
Edward Lee 2009-02-26 22:36:14 -08:00
Родитель b98287b1eb
Коммит 1a083160c8
4 изменённых файлов: 70 добавлений и 35 удалений

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

@ -150,11 +150,26 @@ Engine.prototype = {
this._notify("wipe-server", this.name, this._wipeServer).async(this, onComplete);
},
/**
* Get rid of any local meta-data
*/
resetClient: function Engine_resetClient(onComplete) {
if (!this._resetClient)
throw "engine does not implement _resetClient method";
this._notify("reset-client", this.name, this._resetClient).
async(this, onComplete);
},
_wipeClient: function Engine__wipeClient() {
let self = yield;
yield this.resetClient(this.cb);
this._log.debug("Deleting all local data");
this._store.wipe();
},
wipeClient: function Engine_wipeClient(onComplete) {
this._notify("wipe-client", this.name, this._wipeClient).async(this, onComplete);
}
@ -481,5 +496,10 @@ SyncEngine.prototype = {
yield all.delete(self.cb);
let crypto = new Resource(this.cryptoMetaURL);
yield crypto.delete(self.cb);
},
_resetClient: function SyncEngine__resetClient() {
let self = yield;
this.resetLastSync();
}
};

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

@ -133,6 +133,12 @@ ClientEngine.prototype = {
}
break;
}
},
_resetClient: function ClientEngine__resetClient() {
let self = yield;
this.resetLastSync();
this._store.wipe();
}
};

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

@ -72,8 +72,13 @@ TabEngine.prototype = {
getClientById: function TabEngine_getClientById(id) {
return this._store._remoteClients[id];
}
},
_resetClient: function TabEngine__resetClient() {
let self = yield;
this.resetLastSync();
this._store.wipe();
}
};

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

@ -320,9 +320,10 @@ WeaveSvc.prototype = {
this._initLogs();
this._log.info("Weave " + WEAVE_VERSION + " initializing");
// Reset our sync id if we're upgrading, so sync knows to reset local data
if (WEAVE_VERSION != Svc.Prefs.get("lastversion")) {
this._log.warn("Wiping client from _onStartup.");
this._wipeClientMetadata();
this._log.info("Resetting client syncID from _onStartup.");
Clients.resetSyncID();
}
let ua = Cc["@mozilla.org/network/protocol;1?name=http"].
@ -619,10 +620,10 @@ WeaveSvc.prototype = {
return;
} else if (meta.payload.syncID != Clients.syncID) {
this._log.info("Resetting client because of syncID mismatch.");
this._wipeClientMetadata();
yield this.resetClient(self.cb);
this._log.info("Reset client because of syncID mismatch.");
Clients.syncID = meta.payload.syncID;
this._log.info("Cleared local caches after server wipe was detected");
this._log.info("Reset the client after a server/client sync ID mismatch");
}
let needKeys = true;
@ -819,8 +820,8 @@ WeaveSvc.prototype = {
_freshStart: function WeaveSvc__freshStart() {
let self = yield;
this._log.warn("Wiping client data from freshStart.");
this._wipeClientMetadata();
yield this.resetClient(self.cb);
this._log.info("Reset client data from freshStart.");
this._log.info("Client metadata wiped, deleting server data");
yield this._wipeServer.async(this, self.cb);
@ -838,8 +839,6 @@ WeaveSvc.prototype = {
_wipeServer: function WeaveSvc__wipeServer() {
let self = yield;
Clients.resetSyncID();
let engines = Engines.getAll();
engines.push(Clients, {name: "keys"}, {name: "crypto"});
for each (let engine in engines) {
@ -850,38 +849,43 @@ WeaveSvc.prototype = {
} catch (e) {
this._log.debug("Exception on delete: " + Utils.exceptionStr(e));
}
if (engine.resetLastSync)
engine.resetLastSync();
}
},
_wipeClientMetadata: function WeaveSvc__wipeClientMetadata() {
this.clearLogs();
this._log.info("Logs reinitialized");
/**
* Reset the client by getting rid of any local server data and client data.
*/
resetClient: function WeaveSvc_resetClient(onComplete) {
let fn = function WeaveSvc__resetClient() {
let self = yield;
PubKeys.clearCache();
PrivKeys.clearCache();
CryptoMetas.clearCache();
Records.clearCache();
// First drop old logs to track client resetting behavior
this.clearLogs();
this._log.info("Logs reinitialized for client reset");
Clients._store.wipe();
if (Engines.get("tabs"))
Engines.get("tabs")._store.wipe();
// Pretend we've never synced to the server and drop cached data
Clients.resetSyncID();
Svc.Prefs.reset("lastSync");
for each (let cache in [PubKeys, PrivKeys, CryptoMetas, Records])
cache.clearCache();
for each (let engine in Engines.getAll().push(Clients)) {
engine.resetLastSync();
}
try {
let cruft = this._dirSvc.get("ProfD", Ci.nsIFile);
cruft.QueryInterface(Ci.nsILocalFile);
cruft.append("weave");
cruft.append("snapshots");
if (cruft.exists())
cruft.remove(true);
} catch (e) {
this._log.debug("Could not remove old snapshots: " + Utils.exceptionStr(e));
// Have each engine drop any temporary meta data
for each (let engine in [Clients].concat(Engines.getAll()))
yield engine.resetClient(self.cb);
// XXX Bug 480448: Delete any snapshots from old code
try {
let cruft = this._dirSvc.get("ProfD", Ci.nsIFile);
cruft.QueryInterface(Ci.nsILocalFile);
cruft.append("weave");
cruft.append("snapshots");
if (cruft.exists())
cruft.remove(true);
} catch (e) {
this._log.debug("Could not remove old snapshots: " + Utils.exceptionStr(e));
}
}
this._catchAll(this._notify("reset-client", "", fn)).async(this, onComplete);
}
};