зеркало из https://github.com/mozilla/gecko-dev.git
Bug 480457 - Expose a resetClient API for weave service and engines. r=thunder
This commit is contained in:
Родитель
b98287b1eb
Коммит
1a083160c8
|
@ -150,11 +150,26 @@ Engine.prototype = {
|
||||||
this._notify("wipe-server", this.name, this._wipeServer).async(this, onComplete);
|
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() {
|
_wipeClient: function Engine__wipeClient() {
|
||||||
let self = yield;
|
let self = yield;
|
||||||
|
|
||||||
|
yield this.resetClient(this.cb);
|
||||||
|
|
||||||
this._log.debug("Deleting all local data");
|
this._log.debug("Deleting all local data");
|
||||||
this._store.wipe();
|
this._store.wipe();
|
||||||
},
|
},
|
||||||
|
|
||||||
wipeClient: function Engine_wipeClient(onComplete) {
|
wipeClient: function Engine_wipeClient(onComplete) {
|
||||||
this._notify("wipe-client", this.name, this._wipeClient).async(this, onComplete);
|
this._notify("wipe-client", this.name, this._wipeClient).async(this, onComplete);
|
||||||
}
|
}
|
||||||
|
@ -481,5 +496,10 @@ SyncEngine.prototype = {
|
||||||
yield all.delete(self.cb);
|
yield all.delete(self.cb);
|
||||||
let crypto = new Resource(this.cryptoMetaURL);
|
let crypto = new Resource(this.cryptoMetaURL);
|
||||||
yield crypto.delete(self.cb);
|
yield crypto.delete(self.cb);
|
||||||
|
},
|
||||||
|
|
||||||
|
_resetClient: function SyncEngine__resetClient() {
|
||||||
|
let self = yield;
|
||||||
|
this.resetLastSync();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -133,6 +133,12 @@ ClientEngine.prototype = {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_resetClient: function ClientEngine__resetClient() {
|
||||||
|
let self = yield;
|
||||||
|
this.resetLastSync();
|
||||||
|
this._store.wipe();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,13 @@ TabEngine.prototype = {
|
||||||
|
|
||||||
getClientById: function TabEngine_getClientById(id) {
|
getClientById: function TabEngine_getClientById(id) {
|
||||||
return this._store._remoteClients[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._initLogs();
|
||||||
this._log.info("Weave " + WEAVE_VERSION + " initializing");
|
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")) {
|
if (WEAVE_VERSION != Svc.Prefs.get("lastversion")) {
|
||||||
this._log.warn("Wiping client from _onStartup.");
|
this._log.info("Resetting client syncID from _onStartup.");
|
||||||
this._wipeClientMetadata();
|
Clients.resetSyncID();
|
||||||
}
|
}
|
||||||
|
|
||||||
let ua = Cc["@mozilla.org/network/protocol;1?name=http"].
|
let ua = Cc["@mozilla.org/network/protocol;1?name=http"].
|
||||||
|
@ -619,10 +620,10 @@ WeaveSvc.prototype = {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else if (meta.payload.syncID != Clients.syncID) {
|
} else if (meta.payload.syncID != Clients.syncID) {
|
||||||
this._log.info("Resetting client because of syncID mismatch.");
|
yield this.resetClient(self.cb);
|
||||||
this._wipeClientMetadata();
|
this._log.info("Reset client because of syncID mismatch.");
|
||||||
Clients.syncID = meta.payload.syncID;
|
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;
|
let needKeys = true;
|
||||||
|
@ -819,8 +820,8 @@ WeaveSvc.prototype = {
|
||||||
|
|
||||||
_freshStart: function WeaveSvc__freshStart() {
|
_freshStart: function WeaveSvc__freshStart() {
|
||||||
let self = yield;
|
let self = yield;
|
||||||
this._log.warn("Wiping client data from freshStart.");
|
yield this.resetClient(self.cb);
|
||||||
this._wipeClientMetadata();
|
this._log.info("Reset client data from freshStart.");
|
||||||
this._log.info("Client metadata wiped, deleting server data");
|
this._log.info("Client metadata wiped, deleting server data");
|
||||||
yield this._wipeServer.async(this, self.cb);
|
yield this._wipeServer.async(this, self.cb);
|
||||||
|
|
||||||
|
@ -838,8 +839,6 @@ WeaveSvc.prototype = {
|
||||||
_wipeServer: function WeaveSvc__wipeServer() {
|
_wipeServer: function WeaveSvc__wipeServer() {
|
||||||
let self = yield;
|
let self = yield;
|
||||||
|
|
||||||
Clients.resetSyncID();
|
|
||||||
|
|
||||||
let engines = Engines.getAll();
|
let engines = Engines.getAll();
|
||||||
engines.push(Clients, {name: "keys"}, {name: "crypto"});
|
engines.push(Clients, {name: "keys"}, {name: "crypto"});
|
||||||
for each (let engine in engines) {
|
for each (let engine in engines) {
|
||||||
|
@ -850,38 +849,43 @@ WeaveSvc.prototype = {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this._log.debug("Exception on delete: " + Utils.exceptionStr(e));
|
this._log.debug("Exception on delete: " + Utils.exceptionStr(e));
|
||||||
}
|
}
|
||||||
if (engine.resetLastSync)
|
|
||||||
engine.resetLastSync();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_wipeClientMetadata: function WeaveSvc__wipeClientMetadata() {
|
/**
|
||||||
this.clearLogs();
|
* Reset the client by getting rid of any local server data and client data.
|
||||||
this._log.info("Logs reinitialized");
|
*/
|
||||||
|
resetClient: function WeaveSvc_resetClient(onComplete) {
|
||||||
|
let fn = function WeaveSvc__resetClient() {
|
||||||
|
let self = yield;
|
||||||
|
|
||||||
PubKeys.clearCache();
|
// First drop old logs to track client resetting behavior
|
||||||
PrivKeys.clearCache();
|
this.clearLogs();
|
||||||
CryptoMetas.clearCache();
|
this._log.info("Logs reinitialized for client reset");
|
||||||
Records.clearCache();
|
|
||||||
|
|
||||||
Clients._store.wipe();
|
// Pretend we've never synced to the server and drop cached data
|
||||||
if (Engines.get("tabs"))
|
Clients.resetSyncID();
|
||||||
Engines.get("tabs")._store.wipe();
|
Svc.Prefs.reset("lastSync");
|
||||||
|
for each (let cache in [PubKeys, PrivKeys, CryptoMetas, Records])
|
||||||
|
cache.clearCache();
|
||||||
|
|
||||||
for each (let engine in Engines.getAll().push(Clients)) {
|
// Have each engine drop any temporary meta data
|
||||||
engine.resetLastSync();
|
for each (let engine in [Clients].concat(Engines.getAll()))
|
||||||
}
|
yield engine.resetClient(self.cb);
|
||||||
|
|
||||||
try {
|
// XXX Bug 480448: Delete any snapshots from old code
|
||||||
let cruft = this._dirSvc.get("ProfD", Ci.nsIFile);
|
try {
|
||||||
cruft.QueryInterface(Ci.nsILocalFile);
|
let cruft = this._dirSvc.get("ProfD", Ci.nsIFile);
|
||||||
cruft.append("weave");
|
cruft.QueryInterface(Ci.nsILocalFile);
|
||||||
cruft.append("snapshots");
|
cruft.append("weave");
|
||||||
if (cruft.exists())
|
cruft.append("snapshots");
|
||||||
cruft.remove(true);
|
if (cruft.exists())
|
||||||
} catch (e) {
|
cruft.remove(true);
|
||||||
this._log.debug("Could not remove old snapshots: " + Utils.exceptionStr(e));
|
} catch (e) {
|
||||||
|
this._log.debug("Could not remove old snapshots: " + Utils.exceptionStr(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
this._catchAll(this._notify("reset-client", "", fn)).async(this, onComplete);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче