add resetServer, fix schedule pref

This commit is contained in:
Dan Mills 2007-10-15 19:59:54 -07:00
Родитель 578e8848b6
Коммит 7dd8463192
2 изменённых файлов: 97 добавлений и 12 удалений

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

@ -882,7 +882,11 @@ BookmarksSyncService.prototype = {
_doSync: function BSS__doSync() {
let cont = yield;
let synced = false;
try {
this._os.notifyObservers(null, "bookmarks-sync:start", "");
if (!this._dav.lock.async(this._dav, cont))
return;
let locked = yield;
@ -896,7 +900,7 @@ BookmarksSyncService.prototype = {
// 1) Fetch server deltas
if (!this._getServerData.async(this, cont))
return
return;
let server = yield;
var localJson = this._getBookmarks();
@ -923,6 +927,7 @@ BookmarksSyncService.prototype = {
if (server.updates.length == 0 && localUpdates.length == 0) {
this._snapshotVersion = server.maxVersion;
this._log.info("Sync complete (1): no changes needed on client or server");
synced = true;
return;
}
@ -930,7 +935,7 @@ BookmarksSyncService.prototype = {
this._log.info("Reconciling client/server updates");
if (!this._reconcile.async(this, cont, localUpdates, server.updates))
return
return;
let ret = yield;
// FIXME: Need to come up with a closing protocol for generators
@ -966,6 +971,7 @@ BookmarksSyncService.prototype = {
this._snapshot = localJson;
this._snapshotVersion = server.maxVersion;
this._saveSnapshot();
synced = true;
return;
}
@ -1040,15 +1046,18 @@ BookmarksSyncService.prototype = {
}
}
this._log.info("Sync complete");
synced = true;
} finally {
if (this._dav.unlock.async(this._dav, cont)) {
let unlocked = yield;
if (unlocked)
this._log.info("Lock released");
else
this._log.error("Could not unlock DAV collection");
}
this._os.notifyObservers(null, "bookmarks-sync:end", "");
if (!this._dav.unlock.async(this._dav, cont))
return;
let unlocked = yield;
if (unlocked)
this._log.info("Lock released");
else
this._log.error("Could not unlock DAV collection");
generatorDone(this, onComplete, synced);
}
},
@ -1286,6 +1295,66 @@ BookmarksSyncService.prototype = {
}
},
_resetServer: function BSS__resetServer() {
let cont = yield;
let done = false;
try {
this._os.notifyObservers(null, "bookmarks-sync:reset-server:start", "");
if (!this._dav.lock.async(this._dav, cont))
return;
let locked = yield;
if (locked)
this._log.info("Lock acquired");
else {
this._log.warn("Could not acquire lock, aborting sync");
return;
}
this._dav.DELETE("bookmarks-status.json", cont);
let statusResp = yield;
this._dav.DELETE("bookmarks-snapshot.json", cont);
let snapshotResp = yield;
this._dav.DELETE("bookmarks-deltas.json", cont);
let deltasResp = yield;
if (statusResp.target.status < 200 || statusResp.target.status >= 300 ||
snapshotResp.target.status < 200 || snapshotResp.target.status >= 300 ||
deltasResp.target.status < 200 || deltasResp.target.status >= 300) {
this._log.error("Could delete server data, response codes " +
statusResp.target.status + ", " +
snapshotResp.target.status + ", " +
deltasResp.target.status);
return;
}
this._log.info("Server files deleted, starting sync");
this._os.notifyObservers(null, "bookmarks-sync:start", "");
if (!this._doSync.async(this, cont))
return;
done = yield;
} finally {
if (this._dav.unlock.async(this._dav, cont)) {
let unlocked = yield;
if (unlocked)
this._log.info("Lock released");
else
this._log.error("Could not unlock DAV collection");
}
if (done)
this._info("Server reset completed successfully");
else
this._info("Server reset failed: could not sync bookmarks");
this._os.notifyObservers(null, "bookmarks-sync:reset-server:end", "");
generatorDone(this, onComplete, done)
}
},
// XPCOM registration
classDescription: "Bookmarks Sync Service",
contractID: "@mozilla.org/places/sync-service;1",
@ -1336,8 +1405,8 @@ BookmarksSyncService.prototype = {
sync: function BSS_sync() {
this._log.info("Beginning sync");
this._os.notifyObservers(null, "bookmarks-sync:start", "");
this._doSync.async(this);
if (!this._doSync.async(this))
this._os.notifyObservers(null, "bookmarks-sync:end", false);
},
login: function BSS_login() {
@ -1356,6 +1425,11 @@ BookmarksSyncService.prototype = {
resetLock: function BSS_resetLock() {
this._log.info("Resetting lock");
this._dav.forceUnlock.async(this._dav, bind2(this, this._onResetLock));
},
resetServer: function BSS_resetServer() {
this._log.info("Resetting server data");
this._resetServer.async(this);
}
};
@ -1568,6 +1642,17 @@ DAVCollection.prototype = {
request.send(data);
},
DELETE: function DC_DELETE(path, onComplete, headers) {
if (!headers)
headers = {'Content-type': 'text/plain'};
if (this._auth)
headers['Authorization'] = this._auth;
if (this._token)
headers['If'] = "<" + this._bashURL + "> (<" + this._token + ">)";
let request = this._makeRequest("DELETE", path, onComplete, headers);
request.send(null);
},
// Login / Logout
login: function DC_login(onComplete) {

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

@ -4,5 +4,5 @@ pref("browser.places.sync.rememberpassword", true);
pref("browser.places.sync.autoconnect", true);
pref("browser.places.sync.enabled", true);
pref("browser.places.sync.bookmarks", true);
pref("browser.places.sync.schedule", 1)
pref("browser.places.sync.schedule", 1);
pref("browser.places.sync.lastsync", "0");