This commit is contained in:
jonathandicarlo@h-221.office.mozilla.org 2009-01-13 16:45:01 -08:00
commit 2fc545ece1
3 changed files with 50 additions and 49 deletions

View File

@ -274,8 +274,6 @@ SyncEngine.prototype = {
let outnum = [i for (i in this._tracker.changedIDs)].length;
this._log.info(outnum + " outgoing items pre-reconciliation");
this._tracker.disable(); // FIXME: need finer-grained ignoring
},
// Generate outgoing records
@ -389,12 +387,15 @@ SyncEngine.prototype = {
let self = yield;
this._log.trace("Incoming:\n" + item);
try {
this._tracker.ignoreID(item.id);
yield this._store.applyIncoming(self.cb, item);
if (this._lastSyncTmp < item.modified)
this._lastSyncTmp = item.modified;
} catch (e) {
this._log.warn("Error while applying incoming record: " +
(e.message? e.message : e));
} finally {
this._tracker.unignoreID(item.id);
}
},
@ -451,7 +452,6 @@ SyncEngine.prototype = {
let self = yield;
this._log.debug("Finishing up sync");
this._tracker.resetScore();
this._tracker.enable();
},
_sync: function SyncEngine__sync() {
@ -467,9 +467,6 @@ SyncEngine.prototype = {
this._log.warn("Sync failed");
throw e;
}
finally {
this._tracker.enable();
}
},
_wipeServer: function SyncEngine__wipeServer() {

View File

@ -539,6 +539,15 @@ BookmarksStore.prototype = {
return record;
},
_createMiniRecord: function BStore__createMiniRecord(placesId, depthIndex) {
let foo = {id: this._bms.getItemGUID(placesId)};
if (depthIndex) {
foo.depth = this._itemDepth(placesId);
foo.sortindex = this._bms.getItemIndex(placesId);
}
return foo;
},
_getWeaveParentIdForItem: function BStore__getWeaveParentIdForItem(itemId) {
let parentid = this._bms.getFolderIdForItem(itemId);
if (parentid == -1) {
@ -562,11 +571,7 @@ BookmarksStore.prototype = {
node.containerOpen = true;
for (var i = 0; i < node.childCount; i++) {
let child = node.getChild(i);
let foo = {id: this._bms.getItemGUID(child.itemId)};
if (depthIndex) {
foo.depth = this._itemDepth(child.itemId);
foo.sortindex = this._bms.getItemIndex(child.itemId);
}
let foo = this._createMiniRecord(child.itemId);
items[foo.id] = foo;
this._getChildren(child, depthIndex, items);
}
@ -586,11 +591,7 @@ BookmarksStore.prototype = {
for (var i = 0; i < parent.childCount; i++) {
let child = parent.getChild(i);
let foo = {id: this._bms.getItemGUID(child.itemId)};
if (depthIndex) {
foo.depth = this._itemDepth(child.itemId);
foo.sortindex = this._bms.getItemIndex(child.itemId);
}
let foo = this._createMiniRecord(child.itemId);
items[foo.id] = foo;
}
@ -599,9 +600,9 @@ BookmarksStore.prototype = {
getAllIDs: function BStore_getAllIDs() {
let items = {};
this._getChildren(this._getNode(this._bms.bookmarksMenuFolder), true, items);
this._getChildren(this._getNode(this._bms.toolbarFolder), true, items);
this._getChildren(this._getNode(this._bms.unfiledBookmarksFolder), true, items);
this._getChildren("menu", true, items);
this._getChildren("toolbar", true, items);
this._getChildren("unfiled", true, items);
return items;
},
@ -652,38 +653,39 @@ BookmarksTracker.prototype = {
this._all[this._bms.getItemIdForGUID(guid)] = guid;
}
// ignore changes to the three roots
// we use special names for them, so ignore their "real" places guid
// as well as ours, just in case
this.ignoreID("menu");
this.ignoreID("toolbar");
this.ignoreID("unfiled");
this.ignoreID(this._all[this._bms.bookmarksMenuFolder]);
this.ignoreID(this._all[this._bms.toolbarFolder]);
this.ignoreID(this._all[this._bms.unfiledBookmarksFolder]);
this._bms.addObserver(this, false);
},
/* Every add/remove/change is worth 10 points */
_upScore: function BMT__upScore() {
if (!this.enabled)
return;
this._score += 10;
},
onItemAdded: function BMT_onEndUpdateBatch(itemId, folder, index) {
this._all[itemId] = this._bms.getItemGUID(itemId);
//if (!this.enabled)
//return;
this._log.trace("onItemAdded: " + itemId);
this.addChangedID(this._all[itemId]);
this._upScore();
},
onItemRemoved: function BMT_onItemRemoved(itemId, folder, index) {
let guid = this._all[itemId];
delete this._all[itemId];
if (!this.enabled)
return;
this._log.trace("onItemRemoved: " + itemId);
this.addChangedID(guid);
this.addChangedID(this._all[itemId]);
delete this._all[itemId];
this._upScore();
},
onItemChanged: function BMT_onItemChanged(itemId, property, isAnnotationProperty, value) {
if (!this.enabled)
return;
this._log.trace("onItemChanged: " + itemId + ", property: " + property +
", isAnno: " + isAnnotationProperty + ", value: " + value);
@ -704,8 +706,6 @@ BookmarksTracker.prototype = {
},
onItemMoved: function BMT_onItemMoved(itemId, oldParent, oldIndex, newParent, newIndex) {
if (!this.enabled)
return;
this._log.trace("onItemMoved: " + itemId);
this.addChangedID(this._all[itemId]);
this._upScore();

View File

@ -76,22 +76,11 @@ Tracker.prototype = {
_init: function T__init() {
this._log = Log4Moz.repository.getLogger(this._logName);
this._score = 0;
this._ignored = [];
this.loadChangedIDs();
this.enable();
},
get enabled() {
return this._enabled;
},
enable: function T_enable() {
this._enabled = true;
},
disable: function T_disable() {
this._enabled = false;
},
/*
* Score can be called as often as desired to decide which engines to sync
*
@ -163,13 +152,28 @@ Tracker.prototype = {
}
},
// ignore/unignore specific IDs. Useful for ignoring items that are
// being processed, or that shouldn't be synced.
// But note: not persisted to disk
ignoreID: function T_ignoreID(id) {
this.unignoreID(id);
this._ignored.push(id);
},
unignoreID: function T_unignoreID(id) {
let index = this._ignored.indexOf(id);
if (index != -1)
this._ignored.splice(index, 1);
},
addChangedID: function T_addChangedID(id) {
if (!this.enabled)
return;
if (!id) {
this._log.warn("Attempted to add undefined ID to tracker");
return;
}
if (id in this._ignored)
return;
this._log.debug("Adding changed ID " + id);
if (!this.changedIDs[id]) {
this.changedIDs[id] = true;
@ -178,12 +182,12 @@ Tracker.prototype = {
},
removeChangedID: function T_removeChangedID(id) {
if (!this.enabled)
return;
if (!id) {
this._log.warn("Attempted to remove undefined ID from tracker");
this._log.warn("Attempted to remove undefined ID to tracker");
return;
}
if (id in this._ignored)
return;
this._log.debug("Removing changed ID " + id);
if (this.changedIDs[id]) {
delete this.changedIDs[id];