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

Unified Diff: components/bookmarks/browser/bookmark_utils.cc

Issue 2367533003: Always add bookmarks to the mobile node on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Put new method into ifdef Created 4 years, 2 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 | « components/bookmarks/browser/bookmark_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/bookmarks/browser/bookmark_utils.cc
diff --git a/components/bookmarks/browser/bookmark_utils.cc b/components/bookmarks/browser/bookmark_utils.cc
index 6fef26dca622b878efc9909c23a3e94531a3d0b1..a2e114a561fd9d8d04f4c6df96af173d0f72240d 100644
--- a/components/bookmarks/browser/bookmark_utils.cc
+++ b/components/bookmarks/browser/bookmark_utils.cc
@@ -206,6 +206,21 @@ void GetBookmarksMatchingPropertiesImpl(
}
}
+#if defined(OS_ANDROID)
+// Returns whether or not a bookmark model contains any bookmarks aside of the
+// permanent nodes.
+bool HasUserCreatedBookmarks(BookmarkModel* model) {
+ const BookmarkNode* root_node = model->root_node();
+
+ for (int i = 0; i < root_node->child_count(); ++i) {
+ const BookmarkNode* node = root_node->GetChild(i);
+ if (node->child_count() > 0)
+ return true;
+ }
+ return false;
+}
+#endif
+
} // namespace
QueryFields::QueryFields() {}
@@ -498,7 +513,7 @@ void AddIfNotBookmarked(BookmarkModel* model,
if (IsBookmarkedByUser(model, url))
return; // Nothing to do, a user bookmark with that url already exists.
model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded"));
- const BookmarkNode* parent = model->GetParentForNewNodes();
+ const BookmarkNode* parent = GetParentForNewNodes(model);
model->AddURL(parent, parent->child_count(), title, url);
}
@@ -569,4 +584,15 @@ bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list,
return false;
}
+const BookmarkNode* GetParentForNewNodes(BookmarkModel* model) {
+#if defined(OS_ANDROID)
+ if (!HasUserCreatedBookmarks(model))
Ian Wen 2016/10/12 17:40:06 This is a bit confusing because even if it is labe
+ return model->mobile_node();
+#endif
+ std::vector<const BookmarkNode*> nodes =
+ GetMostRecentlyModifiedUserFolders(model, 1);
+ DCHECK(!nodes.empty()); // This list is always padded with default folders.
+ return nodes[0];
+}
+
} // namespace bookmarks
« no previous file with comments | « components/bookmarks/browser/bookmark_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698