mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-05 00:02:37 +00:00
Bug 624982 - Merge fx-sync to mozilla-central. a=blockers
This commit is contained in:
commit
e4d2ecc139
@ -466,18 +466,13 @@ SyncEngine.prototype = {
|
||||
try {
|
||||
try {
|
||||
item.decrypt();
|
||||
} catch (ex) {
|
||||
if (Utils.isHMACMismatch(ex) &&
|
||||
this.handleHMACMismatch()) {
|
||||
// Let's try handling it.
|
||||
// If the callback returns true, try decrypting again, because
|
||||
// we've got new keys.
|
||||
this._log.info("Trying decrypt again...");
|
||||
item.decrypt();
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
} catch (ex if (Utils.isHMACMismatch(ex) &&
|
||||
this.handleHMACMismatch())) {
|
||||
// Let's try handling it.
|
||||
// If the callback returns true, try decrypting again, because
|
||||
// we've got new keys.
|
||||
this._log.info("Trying decrypt again...");
|
||||
item.decrypt();
|
||||
}
|
||||
|
||||
if (this._reconcile(item)) {
|
||||
@ -488,14 +483,7 @@ SyncEngine.prototype = {
|
||||
count.reconciled++;
|
||||
this._log.trace("Skipping reconciled incoming item " + item.id);
|
||||
}
|
||||
}
|
||||
catch(ex) {
|
||||
|
||||
if (!Utils.isHMACMismatch(ex)) {
|
||||
// Rethrow anything we shouldn't handle.
|
||||
throw ex;
|
||||
}
|
||||
|
||||
} catch (ex if (Utils.isHMACMismatch(ex))) {
|
||||
this._log.warn("Error processing record: " + Utils.exceptionStr(ex));
|
||||
|
||||
// Upload a new record to replace the bad one if we have it
|
||||
|
@ -46,7 +46,6 @@ const Cu = Components.utils;
|
||||
|
||||
const GUID_ANNO = "sync/guid";
|
||||
const PARENT_ANNO = "sync/parent";
|
||||
const CHILDREN_ANNO = "sync/children";
|
||||
const SERVICE_NOT_SUPPORTED = "Service not supported on this platform";
|
||||
const FOLDER_SORTINDEX = 1000000;
|
||||
|
||||
@ -589,9 +588,6 @@ BookmarksStore.prototype = {
|
||||
case "feedUri":
|
||||
this._ls.setFeedURI(itemId, Utils.makeURI(val));
|
||||
break;
|
||||
case "children":
|
||||
Utils.anno(itemId, CHILDREN_ANNO, val.join(","));
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -614,48 +610,9 @@ BookmarksStore.prototype = {
|
||||
this._log.debug("Could not move item " + children[idx] + ": " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the children annotation. If there were mismatches due to local
|
||||
// changes, we'll have to regenerate it from scratch, otherwise we can
|
||||
// just use the incoming value.
|
||||
let folderid = this.idForGUID(guid);
|
||||
if (delta) {
|
||||
this._updateChildrenAnno(folderid);
|
||||
} else {
|
||||
Utils.anno(folderid, CHILDREN_ANNO, children.join(","));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_updateChildrenAnno: function _updateChildrenAnno(itemid) {
|
||||
let node = node = this._getNode(itemid);
|
||||
let childids = [];
|
||||
|
||||
if (node.type == node.RESULT_TYPE_FOLDER &&
|
||||
!this._ls.isLivemark(node.itemId)) {
|
||||
node.QueryInterface(Ci.nsINavHistoryQueryResultNode);
|
||||
node.containerOpen = true;
|
||||
for (var i = 0; i < node.childCount; i++)
|
||||
childids.push(node.getChild(i).itemId);
|
||||
}
|
||||
let childGUIDs = childids.map(this.GUIDForId, this);
|
||||
Utils.anno(itemid, CHILDREN_ANNO, childGUIDs.join(","));
|
||||
return childGUIDs;
|
||||
},
|
||||
|
||||
get _removeAllChildrenAnnosStm() {
|
||||
let stmt = this._getStmt(
|
||||
"DELETE FROM moz_items_annos " +
|
||||
"WHERE anno_attribute_id = " +
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = :anno_name)");
|
||||
stmt.params.anno_name = CHILDREN_ANNO;
|
||||
return stmt;
|
||||
},
|
||||
|
||||
_removeAllChildrenAnnos: function _removeAllChildrenAnnos() {
|
||||
Utils.queryAsync(this._removeAllChildrenAnnosStm);
|
||||
},
|
||||
|
||||
changeItemID: function BStore_changeItemID(oldID, newID) {
|
||||
this._log.debug("Changing GUID " + oldID + " to " + newID);
|
||||
|
||||
@ -665,10 +622,6 @@ BookmarksStore.prototype = {
|
||||
return;
|
||||
|
||||
this._setGUID(itemId, newID);
|
||||
|
||||
// Update parent
|
||||
let parentid = this._bms.getFolderIdForItem(itemId);
|
||||
this._updateChildrenAnno(parentid);
|
||||
},
|
||||
|
||||
_getNode: function BStore__getNode(folder) {
|
||||
@ -707,17 +660,44 @@ BookmarksStore.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
_getChildGUIDsForId: function _getChildGUIDsForId(itemid) {
|
||||
let anno;
|
||||
try {
|
||||
anno = Utils.anno(itemid, CHILDREN_ANNO);
|
||||
} catch(ex) {
|
||||
// Ignore
|
||||
__childGUIDsStm: null,
|
||||
get _childGUIDsStm() {
|
||||
if (this.__childGUIDsStm) {
|
||||
return this.__childGUIDsStm;
|
||||
}
|
||||
if (anno)
|
||||
return anno.split(",");
|
||||
|
||||
return this._updateChildrenAnno(itemid);
|
||||
let stmt;
|
||||
if (this._haveGUIDColumn) {
|
||||
stmt = this._getStmt(
|
||||
"SELECT id AS item_id, guid " +
|
||||
"FROM moz_bookmarks " +
|
||||
"WHERE parent = :parent " +
|
||||
"ORDER BY position");
|
||||
} else {
|
||||
stmt = this._getStmt(
|
||||
"SELECT b.id AS item_id, " +
|
||||
"(SELECT id FROM moz_anno_attributes WHERE name = '" + GUID_ANNO + "') AS name_id," +
|
||||
"a.content AS guid " +
|
||||
"FROM moz_bookmarks b " +
|
||||
"LEFT JOIN moz_items_annos a ON a.item_id = b.id " +
|
||||
"AND a.anno_attribute_id = name_id " +
|
||||
"WHERE b.parent = :parent " +
|
||||
"ORDER BY b.position");
|
||||
}
|
||||
return this.__childGUIDsStm = stmt;
|
||||
},
|
||||
|
||||
_getChildGUIDsForId: function _getChildGUIDsForId(itemid) {
|
||||
let stmt = this._childGUIDsStm;
|
||||
stmt.params.parent = itemid;
|
||||
let rows = Utils.queryAsync(stmt, ["item_id", "guid"]);
|
||||
return rows.map(function (row) {
|
||||
if (row.guid) {
|
||||
return row.guid;
|
||||
}
|
||||
// A GUID hasn't been assigned to this item yet, do this now.
|
||||
return this.GUIDForId(row.item_id);
|
||||
}, this);
|
||||
},
|
||||
|
||||
// Create a record starting from the weave id (places guid)
|
||||
@ -1136,12 +1116,6 @@ BookmarksTracker.prototype = {
|
||||
this.__ls = null;
|
||||
this.__bms = null;
|
||||
break;
|
||||
case "weave:service:start-over":
|
||||
// User has decided to stop syncing, we're going to stop tracking soon.
|
||||
// This means we have to clean up the children annotations so that they
|
||||
// won't be out of sync with reality if/when we start tracking again.
|
||||
Engines.get("bookmarks")._store._removeAllChildrenAnnos();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
@ -1172,10 +1146,6 @@ BookmarksTracker.prototype = {
|
||||
return Engines.get("bookmarks")._store.GUIDForId(item_id);
|
||||
},
|
||||
|
||||
_updateChildrenAnno: function _updateChildrenAnno(itemid) {
|
||||
return Engines.get("bookmarks")._store._updateChildrenAnno(itemid);
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a bookmark (places) id to be uploaded and bump up the sync score
|
||||
*
|
||||
@ -1238,7 +1208,6 @@ BookmarksTracker.prototype = {
|
||||
|
||||
this._log.trace("onItemAdded: " + itemId);
|
||||
this._addId(itemId);
|
||||
this._updateChildrenAnno(folder);
|
||||
this._addId(folder);
|
||||
},
|
||||
|
||||
@ -1249,7 +1218,6 @@ BookmarksTracker.prototype = {
|
||||
this._log.trace("onBeforeItemRemoved: " + itemId);
|
||||
this._addId(itemId);
|
||||
let folder = Svc.Bookmark.getFolderIdForItem(itemId);
|
||||
this._updateChildrenAnno(folder);
|
||||
this._addId(folder);
|
||||
},
|
||||
|
||||
@ -1314,11 +1282,9 @@ BookmarksTracker.prototype = {
|
||||
return;
|
||||
|
||||
this._log.trace("onItemMoved: " + itemId);
|
||||
this._updateChildrenAnno(oldParent);
|
||||
this._addId(oldParent);
|
||||
if (oldParent != newParent) {
|
||||
this._addId(itemId);
|
||||
this._updateChildrenAnno(newParent);
|
||||
this._addId(newParent);
|
||||
}
|
||||
|
||||
|
@ -1416,6 +1416,18 @@ let Utils = {
|
||||
return true;
|
||||
},
|
||||
|
||||
// If Master Password is enabled and locked, present a dialog to unlock it.
|
||||
// Return whether the system is unlocked.
|
||||
ensureMPUnlocked: function ensureMPUnlocked() {
|
||||
sdr = Cc["@mozilla.org/security/sdr;1"].getService(Ci.nsISecretDecoderRing);
|
||||
var ok = false;
|
||||
try {
|
||||
sdr.encryptString("bacon");
|
||||
ok = true;
|
||||
} catch(e) {}
|
||||
return ok;
|
||||
},
|
||||
|
||||
__prefs: null,
|
||||
get prefs() {
|
||||
if (!this.__prefs) {
|
||||
|
@ -72,7 +72,7 @@ function test_folder_create() {
|
||||
_("Have the store create a new record object. Verify that it has the same data.");
|
||||
let newrecord = store.createRecord(folder.id);
|
||||
do_check_true(newrecord instanceof BookmarkFolder);
|
||||
for each (let property in ["title","title", "parentName", "parentid"])
|
||||
for each (let property in ["title", "parentName", "parentid"])
|
||||
do_check_eq(newrecord[property], folder[property]);
|
||||
|
||||
_("Folders have high sort index to ensure they're synced first.");
|
||||
@ -83,6 +83,39 @@ function test_folder_create() {
|
||||
}
|
||||
}
|
||||
|
||||
function test_folder_createRecord() {
|
||||
try {
|
||||
_("Create a folder.");
|
||||
let folder1_id = Svc.Bookmark.createFolder(
|
||||
Svc.Bookmark.toolbarFolder, "Folder1", 0);
|
||||
let folder1_guid = store.GUIDForId(folder1_id);
|
||||
|
||||
_("Create two bookmarks in that folder without assigning them GUIDs.");
|
||||
let bmk1_id = Svc.Bookmark.insertBookmark(
|
||||
folder1_id, fxuri, Svc.Bookmark.DEFAULT_INDEX, "Get Firefox!");
|
||||
let bmk2_id = Svc.Bookmark.insertBookmark(
|
||||
folder1_id, tburi, Svc.Bookmark.DEFAULT_INDEX, "Get Thunderbird!");
|
||||
|
||||
_("Create a record for the folder and verify basic properties.");
|
||||
let record = store.createRecord(folder1_guid);
|
||||
do_check_true(record instanceof BookmarkFolder);
|
||||
do_check_eq(record.title, "Folder1");
|
||||
do_check_eq(record.parentid, "toolbar");
|
||||
do_check_eq(record.parentName, "Bookmarks Toolbar");
|
||||
|
||||
_("Verify the folder's children. Ensures that the bookmarks were given GUIDs.");
|
||||
let bmk1_guid = store.GUIDForId(bmk1_id);
|
||||
let bmk2_guid = store.GUIDForId(bmk2_id);
|
||||
do_check_eq(record.children.length, 2);
|
||||
do_check_eq(record.children[0], bmk1_guid);
|
||||
do_check_eq(record.children[1], bmk2_guid);
|
||||
|
||||
} finally {
|
||||
_("Clean up.");
|
||||
store.wipe();
|
||||
}
|
||||
}
|
||||
|
||||
function test_move_folder() {
|
||||
try {
|
||||
_("Create two folders and a bookmark in one of them.");
|
||||
@ -130,7 +163,6 @@ function test_move_order() {
|
||||
do_check_eq(Svc.Bookmark.getItemIndex(bmk1_id), 0);
|
||||
do_check_eq(Svc.Bookmark.getItemIndex(bmk2_id), 1);
|
||||
let toolbar = store.createRecord("toolbar");
|
||||
dump(JSON.stringify(toolbar.cleartext));
|
||||
do_check_eq(toolbar.children.length, 2);
|
||||
do_check_eq(toolbar.children[0], bmk1_guid);
|
||||
do_check_eq(toolbar.children[1], bmk2_guid);
|
||||
@ -159,6 +191,7 @@ function test_move_order() {
|
||||
function run_test() {
|
||||
test_bookmark_create();
|
||||
test_folder_create();
|
||||
test_folder_createRecord();
|
||||
test_move_folder();
|
||||
test_move_order();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user