Bug 1444094 - Remove remaining support for the places/excludeFromBackup annotation. r?mak
MozReview-Commit-ID: 56dWvia8yIC
--- a/browser/components/extensions/ext-bookmarks.js
+++ b/browser/components/extensions/ext-bookmarks.js
@@ -66,22 +66,17 @@ const getTree = (rootGuid, onlyChildren)
? node.children.map(child => convert(child, node))
: [];
}
}
return treenode;
}
- return PlacesUtils.promiseBookmarksTree(rootGuid, {
- excludeItemsCallback: item => {
- return item.annos &&
- item.annos.find(a => a.name == PlacesUtils.EXCLUDE_FROM_BACKUP_ANNO);
- },
- }).then(root => {
+ return PlacesUtils.promiseBookmarksTree(rootGuid).then(root => {
if (onlyChildren) {
let children = root.children || [];
return children.map(child => convert(child, root));
}
let treenode = convert(root, null);
treenode.parentId = root.parentGuid;
// It seems like the array always just contains the root node.
return [treenode];
--- a/services/sync/tests/unit/test_bookmark_validator.js
+++ b/services/sync/tests/unit/test_bookmark_validator.js
@@ -275,32 +275,20 @@ add_task(async function test_cswc_differ
});
add_task(async function test_cswc_serverUnexpected() {
let {server, client} = getDummyServerAndClient();
client.children.push({
"guid": "dddddddddddd",
"title": "",
"id": 2000,
- "annos": [{
- "name": "places/excludeFromBackup",
- "flags": 0,
- "expires": 4,
- "value": 1
- }],
"type": "text/x-moz-place-container",
"children": [{
"guid": "eeeeeeeeeeee",
"title": "History",
- "annos": [{
- "name": "places/excludeFromBackup",
- "flags": 0,
- "expires": 4,
- "value": 1
- }],
"type": "text/x-moz-place",
"uri": "place:type=3&sort=4"
}]
});
server.push({
id: "dddddddddddd",
parentid: "places",
parentName: "",
--- a/toolkit/components/places/BookmarkJSONUtils.jsm
+++ b/toolkit/components/places/BookmarkJSONUtils.jsm
@@ -66,18 +66,16 @@ var BookmarkJSONUtils = Object.freeze({
} catch (ex) {
Cu.reportError("Failed to restore bookmarks from " + aSpec + ": " + ex);
notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_FAILED, aReplace);
}
},
/**
* Restores bookmarks and tags from a JSON file.
- * @note any item annotated with "places/excludeFromBackup" won't be removed
- * before executing the restore.
*
* @param aFilePath
* OS.File path string of bookmarks in JSON or JSONlz4 format to be restored.
* @param [options.replace]
* Whether we should erase existing bookmarks before importing.
* @param [options.source]
* The bookmark change source, used to determine the sync status for
* imported bookmarks. Defaults to `RESTORE` if `replace = true`, or
@@ -243,17 +241,17 @@ BookmarkImporter.prototype = {
}
// Change to nodes[0].children as we don't import the root, and also filter
// out any obsolete "tagsFolder" sections.
nodes = nodes[0].children.filter(node => !node.root || node.root != "tagsFolder");
// If we're replacing, then erase existing bookmarks first.
if (this._replace) {
- await PlacesBackups.eraseEverythingIncludingUserRoots({ source: this._source });
+ await PlacesUtils.bookmarks.eraseEverything({ source: this._source });
}
let folderIdToGuidMap = {};
let searchGuids = [];
// Now do some cleanup on the imported nodes so that the various guids
// match what we need for insertTree, and we also have mappings of folders
// so we can repair any searches after inserting the bookmarks (see bug 824502).
--- a/toolkit/components/places/PlacesBackups.jsm
+++ b/toolkit/components/places/PlacesBackups.jsm
@@ -64,39 +64,16 @@ function getBackupFileForSameDate(aFilen
for (let backupFile of backupFiles) {
if (isFilenameWithSameDate(OS.Path.basename(backupFile), aFilename))
return backupFile;
}
return null;
})();
}
-/**
- * Returns the top-level bookmark folders ids and guids.
- *
- * @return {Promise} Resolve with an array of objects containing id and guid
- * when the query is complete.
- */
-async function getTopLevelFolderIds() {
- let db = await PlacesUtils.promiseDBConnection();
- let rows = await db.execute(
- "SELECT id, guid FROM moz_bookmarks WHERE parent = :parentId",
- { parentId: PlacesUtils.placesRootId }
- );
-
- let guids = [];
- for (let row of rows) {
- guids.push({
- id: row.getResultByName("id"),
- guid: row.getResultByName("guid")
- });
- }
- return guids;
-}
-
var PlacesBackups = {
/**
* Matches the backup filename:
* 0: file name
* 1: date in form Y-m-d
* 2: bookmarks count
* 3: contents hash
* 4: file extension
@@ -239,18 +216,16 @@ var PlacesBackups = {
}
}
return null;
})();
},
/**
* Serializes bookmarks using JSON, and writes to the supplied file.
- * Note: any item that should not be backed up must be annotated with
- * "places/excludeFromBackup".
*
* @param aFilePath
* OS.File path for the "bookmarks.json" file to be created.
* @return {Promise}
* @resolves the number of serialized uri nodes.
*/
async saveBookmarksToJSONFile(aFilePath) {
let { count: nodeCount, hash: hash } =
@@ -298,18 +273,16 @@ var PlacesBackups = {
}
return nodeCount;
},
/**
* Creates a dated backup in <profile>/bookmarkbackups.
* Stores the bookmarks using a lz4 compressed JSON file.
- * Note: any item that should not be backed up must be annotated with
- * "places/excludeFromBackup".
*
* @param [optional] int aMaxBackups
* The maximum number of backups to keep. If set to 0
* all existing backups are removed and aForceBackup is
* ignored, so a new one won't be created.
* @param [optional] bool aForceBackup
* Forces creating a backup even if one was already
* created that day (overwrites).
@@ -411,19 +384,17 @@ var PlacesBackups = {
let matches = filename.match(filenamesRegex);
if (matches && matches[2])
count = matches[2];
return count;
},
/**
* Gets a bookmarks tree representation usable to create backups in different
- * file formats. The root or the tree is PlacesUtils.placesRootId.
- * Items annotated with PlacesUtils.EXCLUDE_FROM_BACKUP_ANNO and all of their
- * descendants are excluded.
+ * file formats. The root or the tree is PlacesUtils.bookmarks.rootGuid.
*
* @return an object representing a tree with the places root as its root.
* Each bookmark is represented by an object having these properties:
* * id: the item id (make this not enumerable after bug 824502)
* * title: the title
* * guid: unique id
* * parent: item id of the parent folder, not enumerable
* * index: the position in the parent
@@ -438,64 +409,21 @@ var PlacesBackups = {
* * charset: last known charset
* * tags: csv string of tags
* * root: string describing whether this represents a root
* * children: array of child items in a folder
*/
async getBookmarksTree() {
let startTime = Date.now();
let root = await PlacesUtils.promiseBookmarksTree(PlacesUtils.bookmarks.rootGuid, {
- excludeItemsCallback: aItem => {
- return aItem.annos &&
- aItem.annos.find(a => a.name == PlacesUtils.EXCLUDE_FROM_BACKUP_ANNO);
- },
includeItemIds: true
});
try {
Services.telemetry
.getHistogramById("PLACES_BACKUPS_BOOKMARKSTREE_MS")
.add(Date.now() - startTime);
} catch (ex) {
Cu.reportError("Unable to report telemetry.");
}
return [root, root.itemsCount];
},
-
- /**
- * Wrapper for PlacesUtils.bookmarks.eraseEverything that removes non-default
- * roots.
- *
- * Note that default roots are preserved, only their children will be removed.
- *
- * TODO Ideally we wouldn't need to worry about non-default roots. However,
- * until bug 1310299 is fixed, we still need to manage them.
- *
- * @param {Object} [options={}]
- * Additional options. Currently supports the following properties:
- * - source: The change source, forwarded to all bookmark observers.
- * Defaults to nsINavBookmarksService::SOURCE_DEFAULT.
- *
- * @return {Promise} resolved when the removal is complete.
- * @resolves once the removal is complete.
- */
- async eraseEverythingIncludingUserRoots(options = {}) {
- if (!options.source) {
- options.source = PlacesUtils.bookmarks.SOURCES.DEFAULT;
- }
-
- let excludeItems =
- PlacesUtils.annotations.getItemsWithAnnotation(PlacesUtils.EXCLUDE_FROM_BACKUP_ANNO);
-
- let rootFolderChildren = await getTopLevelFolderIds();
-
- // We only need to do top-level roots here.
- for (let child of rootFolderChildren) {
- if (!PlacesUtils.bookmarks.userContentRoots.includes(child.guid) &&
- child.guid != PlacesUtils.bookmarks.tagsGuid &&
- !excludeItems.includes(child.id)) {
- await PlacesUtils.bookmarks.remove(child.guid, {source: options.source});
- }
- }
-
- return PlacesUtils.bookmarks.eraseEverything(options);
- },
};
--- a/toolkit/components/places/PlacesUtils.jsm
+++ b/toolkit/components/places/PlacesUtils.jsm
@@ -318,17 +318,16 @@ var PlacesUtils = {
TYPE_X_MOZ_URL: "text/x-moz-url",
// Place entries formatted as HTML anchors
TYPE_HTML: "text/html",
// Place entries as raw URL text
TYPE_UNICODE: "text/unicode",
// Used to track the action that populated the clipboard.
TYPE_X_MOZ_PLACE_ACTION: "text/x-moz-place-action",
- EXCLUDE_FROM_BACKUP_ANNO: "places/excludeFromBackup",
LMANNO_FEEDURI: "livemark/feedURI",
LMANNO_SITEURI: "livemark/siteURI",
POST_DATA_ANNO: "bookmarkProperties/POSTData",
READ_ONLY_ANNO: "placesInternal/READ_ONLY",
CHARSET_ANNO: "URIProperties/characterSet",
MOBILE_ROOT_ANNO: "mobile/bookmarksRoot",
TOPIC_SHUTDOWN: "places-shutdown",
--- a/toolkit/components/places/tests/sync/test_sync_utils.js
+++ b/toolkit/components/places/tests/sync/test_sync_utils.js
@@ -84,23 +84,16 @@ var populateTree = async function popula
Object.assign(guids, await populate(guid, ...item.children));
}
break;
default:
throw new Error(`Unsupported item type: ${item.type}`);
}
- if (item.exclude) {
- let itemId = await PlacesUtils.promiseItemId(guid);
- PlacesUtils.annotations.setItemAnnotation(
- itemId, PlacesUtils.EXCLUDE_FROM_BACKUP_ANNO, "Don't back this up", 0,
- PlacesUtils.annotations.EXPIRE_NEVER);
- }
-
guids[item.title] = guid;
}
return guids;
};
var recordIdToId = async function recordIdToId(recordId) {
let guid = await PlacesSyncUtils.bookmarks.recordIdToGuid(recordId);