Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3694)

Unified Diff: chrome/browser/resources/md_bookmarks/command_manager.js

Issue 2850763002: MD Bookmarks: Update Delete command to only delete the minimal set of nodes (Closed)
Patch Set: Review comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/webui/md_bookmarks/command_manager_test.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/md_bookmarks/command_manager.js
diff --git a/chrome/browser/resources/md_bookmarks/command_manager.js b/chrome/browser/resources/md_bookmarks/command_manager.js
index 9c5e564f818e49a55d772090ca5eca27c29fd571..a21c9c471868ec0e2bdcb6484d27bb132b9670f8 100644
--- a/chrome/browser/resources/md_bookmarks/command_manager.js
+++ b/chrome/browser/resources/md_bookmarks/command_manager.js
@@ -103,21 +103,41 @@ Polymer({
});
break;
case Command.DELETE:
- // TODO(tsergeant): Filter IDs so we don't try to delete children of
- // something else already being deleted.
chrome.bookmarkManagerPrivate.removeTrees(
- Array.from(itemIds), function() {
+ Array.from(this.minimizeDeletionSet_(itemIds)), function() {
// TODO(jiaxi): Add toast later.
});
break;
}
-
},
////////////////////////////////////////////////////////////////////////////
// Private functions:
/**
+ * Minimize the set of |itemIds| by removing any node which has an ancestor
+ * node already in the set. This ensures that instead of trying to delete both
+ * a node and its descendant, we will only try to delete the topmost node,
+ * preventing an error in the bookmarkManagerPrivate.removeTrees API call.
+ * @param {!Set<string>} itemIds
+ * @return {!Set<string>}
+ */
+ minimizeDeletionSet_: function(itemIds) {
+ var minimizedSet = new Set();
+ var nodes = this.getState().nodes;
+ itemIds.forEach(function(itemId) {
+ var currentId = itemId;
+ while (currentId != ROOT_NODE_ID) {
+ currentId = assert(nodes[currentId].parentId);
+ if (itemIds.has(currentId))
+ return;
+ }
+ minimizedSet.add(itemId);
+ });
+ return minimizedSet;
+ },
+
+ /**
* @param {!Set<string>} itemIds
* @param {function(BookmarkNode):boolean} predicate
* @return {boolean} True if any node in |itemIds| returns true for
« no previous file with comments | « no previous file | chrome/test/data/webui/md_bookmarks/command_manager_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698