login fixes; history sync fixes; make reset client actually delete all client data (useful for testing and for syncing down server data - e.g. the restore case)

This commit is contained in:
Dan Mills 2007-12-19 13:24:31 -08:00
Родитель dee6b23c4d
Коммит 87591e4c96
4 изменённых файлов: 90 добавлений и 83 удалений

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

@ -257,10 +257,6 @@ DAVCollection.prototype = {
this._log.error("Exception caught: " + (e.message? e.message : e));
} finally {
if (this._loggedIn)
this._log.info("Logged in");
else
this._log.warn("Could not log in");
generatorDone(this, self, onComplete, this._loggedIn);
yield; // onComplete is responsible for closing the generator
}

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

@ -182,9 +182,8 @@ Engine.prototype = {
this._log.debug("Resetting client state");
this._os.notifyObservers(null, this._osPrefix + "reset-client:start", "");
this._snapshot.data = {};
this._snapshot.version = -1;
this._snapshot.save();
this._snapshot.wipe();
this._store.wipe();
done = true;
} catch (e) {

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

@ -261,16 +261,19 @@ WeaveSyncService.prototype = {
_lock: function weaveSync__lock() {
if (this._locked) {
this._log.warn("Service lock failed: already locked");
this._os.notifyObservers(null, "weave:service-lock:error", "");
return false;
}
this._locked = true;
this._log.debug("Service lock acquired");
this._os.notifyObservers(null, "weave:service-lock:success", "");
return true;
},
_unlock: function WeaveSync__unlock() {
this._locked = false;
this._log.debug("Service lock released");
this._os.notifyObservers(null, "weave:service-unlock:success", "");
},
// IBookmarksSyncService internal implementation
@ -285,13 +288,11 @@ WeaveSyncService.prototype = {
if (!this.username) {
this._log.warn("No username set, login failed");
this._os.notifyObservers(null, "bookmarks-sync:login-error", "");
return;
return;
}
if (!this.password) {
this._log.warn("No password given or found in password manager");
this._os.notifyObservers(null, "bookmarks-sync:login-error", "");
return;
return;
}
this._dav.baseURL = this._serverURL + "user/" + this.userPath + "/";
@ -306,10 +307,10 @@ WeaveSyncService.prototype = {
} finally {
this._passphrase = null;
if (success) {
this._log.debug("Login successful");
//this._log.debug("Login successful"); // chrome prints this too, hm
this._os.notifyObservers(null, "bookmarks-sync:login-end", "");
} else {
this._log.debug("Login error");
//this._log.debug("Login error");
this._os.notifyObservers(null, "bookmarks-sync:login-error", "");
}
generatorDone(this, self, onComplete, success);

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

@ -62,9 +62,6 @@ Store.prototype = {
this._log = Log4Moz.Service.getLogger("Service." + this._logName);
},
wrap: function Store_wrap() {
},
applyCommands: function Store_applyCommands(commandList) {
for (var i = 0; i < commandList.length; i++) {
var command = commandList[i];
@ -86,15 +83,17 @@ Store.prototype = {
}
},
resetGUIDs: function Store_resetGUIDs() {
}
// override these in derived objects
wrap: function Store_wrap() {},
wipe: function Store_wipe() {},
resetGUIDs: function Store_resetGUIDs() {}
};
function SnapshotStore(name) {
this._init(name);
}
SnapshotStore.prototype = {
_logName: "SStore",
_logName: "SnapStore",
_filename: null,
get filename() {
@ -143,6 +142,35 @@ SnapshotStore.prototype = {
this._log = Log4Moz.Service.getLogger("Service." + this._logName);
},
_createCommand: function SStore__createCommand(command) {
this._data[command.GUID] = eval(uneval(command.data));
},
_removeCommand: function SStore__removeCommand(command) {
delete this._data[command.GUID];
},
_editCommand: function SStore__editCommand(command) {
if ("GUID" in command.data) {
// special-case guid changes
let newGUID = command.data.GUID,
oldGUID = command.GUID;
this._data[newGUID] = this._data[oldGUID];
delete this._data[oldGUID]
for (let GUID in this._data) {
if (this._data[GUID].parentGUID == oldGUID)
this._data[GUID].parentGUID = newGUID;
}
}
for (let prop in command.data) {
if (prop == "GUID")
continue;
this._data[command.GUID][prop] = command.data[prop];
}
},
save: function SStore_save() {
this._log.info("Saving snapshot to disk");
@ -217,41 +245,14 @@ SnapshotStore.prototype = {
},
wrap: function SStore_wrap() {
return this.data;
},
applyCommands: function SStore_applyCommands(commands) {
for (let i = 0; i < commands.length; i++) {
// this._log.debug("Applying cmd to obj: " + uneval(commands[i]));
switch (commands[i].action) {
case "create":
this._data[commands[i].GUID] = eval(uneval(commands[i].data));
break;
case "edit":
if ("GUID" in commands[i].data) {
// special-case guid changes
let newGUID = commands[i].data.GUID,
oldGUID = commands[i].GUID;
this._data[newGUID] = this._data[oldGUID];
delete this._data[oldGUID]
for (let GUID in this._data) {
if (this._data[GUID].parentGUID == oldGUID)
this._data[GUID].parentGUID = newGUID;
}
}
for (let prop in commands[i].data) {
if (prop == "GUID")
continue;
this._data[commands[i].GUID][prop] = commands[i].data[prop];
}
break;
case "remove":
delete this._data[commands[i].GUID];
break;
}
}
return this._data;
wipe: function SStore_wipe() {
this.data = {};
this.version = -1;
this.GUID = null;
this.save();
}
};
SnapshotStore.prototype.__proto__ = new Store();
@ -553,31 +554,16 @@ BookmarksStore.prototype = {
return filed; // (combined)
},
wipe: function BStore_wipe() {
this._bms.removeFolderChildren(this._bms.bookmarksMenuFolder);
this._bms.removeFolderChildren(this._bms.toolbarFolder);
this._bms.removeFolderChildren(this._bms.unfiledBookmarksFolder);
},
resetGUIDs: function BStore_resetGUIDs() {
this._resetGUIDsInt(this._getFolderNodes(this._bms.bookmarksMenuFolder));
this._resetGUIDsInt(this._getFolderNodes(this._bms.toolbarFolder));
this._resetGUIDsInt(this._getFolderNodes(this._bms.unfiledBookmarksFolder));
},
applyCommands: function BStore_applyCommands(commandList) {
for (var i = 0; i < commandList.length; i++) {
var command = commandList[i];
this._log.debug("Processing command: " + uneval(command));
switch (command["action"]) {
case "create":
this._createCommand(command);
break;
case "remove":
this._removeCommand(command);
break;
case "edit":
this._editCommand(command);
break;
default:
this._log.error("unknown action in command: " + command["action"]);
break;
}
}
}
};
BookmarksStore.prototype.__proto__ = new Store();
@ -596,17 +582,30 @@ HistoryStore.prototype = {
return this.__hsvc;
},
__browserHist: null,
get _browserHist() {
if (!this.__browserHist)
this.__browserHist = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsIBrowserHistory);
return this.__browserHist;
},
_createCommand: function HistStore__createCommand(command) {
this._log.info(" -> creating history entry: " + command.GUID);
this._hsvc.addVisit(makeURI(command.data.URI), command.data.time,
0, this._hsvc.TRANSITION_LINK, false, 0);
this._hsvc.addVisit(makeURI(command.data.URI), command.data.title,
command.data.accessCount, false, false);
try {
this._browserHist.addPageWithDetails(makeURI(command.GUID),
command.data.title,
command.data.time);
this._hsvc.setPageDetails(makeURI(command.GUID), command.data.title,
command.data.accessCount, false, false);
} catch (e) {
this._log.error("Exception caught: " + (e.message? e.message : e));
}
},
_removeCommand: function HistStore__removeCommand(command) {
this._log.info(" -> NOT removing history entry: " + command.GUID);
// skip removals
this._log.info(" -> removing history entry: " + command.GUID);
this._browserHist.removePage(command.GUID);
},
_editCommand: function HistStore__editCommand(command) {
@ -614,12 +613,20 @@ HistoryStore.prototype = {
// FIXME: implement!
},
wrap: function HistStore_wrap() {
let query = this._hsvc.getNewQuery();
_historyRoot: function HistStore__historyRoot() {
let query = this._hsvc.getNewQuery(),
options = this._hsvc.getNewQueryOptions();
query.minVisits = 1;
let root = this._hsvc.executeQuery(query,
this._hsvc.getNewQueryOptions()).root;
options.queryType = options.QUERY_TYPE_HISTORY;
let root = this._hsvc.executeQuery(query, options).root;
root.QueryInterface(Ci.nsINavHistoryQueryResultNode);
return root;
},
wrap: function HistStore_wrap() {
let root = this._historyRoot();
root.containerOpen = true;
let items = {};
for (let i = 0; i < root.childCount; i++) {
@ -633,6 +640,10 @@ HistoryStore.prototype = {
};
}
return items;
},
wipe: function HistStore_wipe() {
this._browserHist.removeAllPages();
}
};
HistoryStore.prototype.__proto__ = new Store();