Bug 854761 - Part 1: Remove previous bookmark calls from PlacesUtils - Toolkit. r=mak

This commit is contained in:
Andres Hernandez 2013-06-04 00:20:11 +08:00
parent b6a69dc435
commit e89af5938a
3 changed files with 71 additions and 5 deletions

View File

@ -94,6 +94,42 @@ this.BookmarkJSONUtils = Object.freeze({
}
}, Ci.nsIThread.DISPATCH_NORMAL);
return deferred.promise;
},
/**
* Serializes the given node (and all its descendents) as JSON
* and writes the serialization to the given output stream.
*
* @param aNode
* An nsINavHistoryResultNode
* @param aStream
* An nsIOutputStream. NOTE: it only uses the write(str, len)
* method of nsIOutputStream. The caller is responsible for
* closing the stream.
* @param aIsUICommand
* Boolean - If true, modifies serialization so that each node self-contained.
* For Example, tags are serialized inline with each bookmark.
* @param aResolveShortcuts
* Converts folder shortcuts into actual folders.
* @param aExcludeItems
* An array of item ids that should not be written to the backup.
* @return {Promise}
* @resolves When node have been serialized and wrote to output stream.
* @rejects JavaScript exception.
*/
serializeNodeAsJSONToOutputStream: function BJU_serializeNodeAsJSONToOutputStream(
aNode, aStream, aIsUICommand, aResolveShortcuts, aExcludeItems) {
let deferred = Promise.defer();
Services.tm.mainThread.dispatch(function() {
try {
BookmarkNode.serializeAsJSONToOutputStream(
aNode, aStream, aIsUICommand, aResolveShortcuts, aExcludeItems);
deferred.resolve();
} catch (ex) {
deferred.reject(ex);
}
}, Ci.nsIThread.DISPATCH_NORMAL);
return deferred.promise;
}
});

View File

@ -559,7 +559,7 @@ this.PlacesUtils = {
};
let [node, shouldClose] = convertNode(aNode);
this.serializeNodeAsJSONToOutputStream(node, writer, true, aForceCopy);
this._serializeNodeAsJSONToOutputStream(node, writer, true, aForceCopy);
if (shouldClose)
node.containerOpen = false;
@ -1326,8 +1326,8 @@ this.PlacesUtils = {
* @param aExcludeItems
* An array of item ids that should not be written to the backup.
*/
serializeNodeAsJSONToOutputStream:
function PU_serializeNodeAsJSONToOutputStream(aNode, aStream, aIsUICommand,
_serializeNodeAsJSONToOutputStream:
function PU__serializeNodeAsJSONToOutputStream(aNode, aStream, aIsUICommand,
aResolveShortcuts,
aExcludeItems) {
function addGenericProperties(aPlacesNode, aJSNode) {
@ -1520,6 +1520,36 @@ this.PlacesUtils = {
}
},
/**
* Serializes the given node (and all its descendents) as JSON
* and writes the serialization to the given output stream.
*
* @param aNode
* An nsINavHistoryResultNode
* @param aStream
* An nsIOutputStream. NOTE: it only uses the write(str, len)
* method of nsIOutputStream. The caller is responsible for
* closing the stream.
* @param aIsUICommand
* Boolean - If true, modifies serialization so that each node self-contained.
* For Example, tags are serialized inline with each bookmark.
* @param aResolveShortcuts
* Converts folder shortcuts into actual folders.
* @param aExcludeItems
* An array of item ids that should not be written to the backup.
*/
serializeNodeAsJSONToOutputStream:
function PU_serializeNodeAsJSONToOutputStream(aNode, aStream, aIsUICommand,
aResolveShortcuts,
aExcludeItems) {
Deprecated.warning(
"serializeNodeAsJSONToOutputStream is deprecated and will be removed in a future version",
"https://bugzilla.mozilla.org/show_bug.cgi?id=854761");
this._serializeNodeAsJSONToOutputStream(aNode, aStream, aIsUICommand,
aResolveShortcuts, aExcludeItems);
},
/**
* Restores bookmarks and tags from a JSON file.
* WARNING: This method *removes* any bookmarks in the collection before

View File

@ -83,14 +83,14 @@ add_task(function test_force_copy() {
this._str += aData;
}
};
PlacesUtils.serializeNodeAsJSONToOutputStream(queryNode, stream, false, true);
Cu.import("resource://gre/modules/BookmarkJSONUtils.jsm");
yield BookmarkJSONUtils.serializeNodeAsJSONToOutputStream(queryNode, stream, false, true);
LOG("SERIALIZED: " + stream._str);
PlacesUtils.bookmarks.removeItem(queryId);
// import
Cu.import("resource://gre/modules/BookmarkJSONUtils.jsm");
yield BookmarkJSONUtils.importJSONNode(stream._str, PlacesUtils.toolbarFolderId, -1);
// query for node