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

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: Fixed comment and new empty check 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..53b97d835d3d364387571e1d4b1d8b25f8167c7d 100644
--- a/components/bookmarks/browser/bookmark_utils.cc
+++ b/components/bookmarks/browser/bookmark_utils.cc
@@ -498,7 +498,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 +569,29 @@ bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list,
return false;
}
+bool HasUserCreatedBookmarks(BookmarkModel* model) {
sky 2016/10/11 19:13:39 Move this to anonymous namespace.
kraush 2016/10/11 21:22:39 Will do.
+ 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->IsVisible() && model->client()->CanBeEditedByUser(node) &&
sky 2016/10/11 19:13:39 Can't you just check child_count() here?
kraush 2016/10/11 21:22:39 I wanted to be super-safe, but it's probably unnec
+ node->child_count() > 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+const BookmarkNode* GetParentForNewNodes(BookmarkModel* model) {
+#if defined(OS_ANDROID)
+ if (!HasUserCreatedBookmarks(model)) {
sky 2016/10/11 19:13:39 no {} (see style guide)
kraush 2016/10/11 21:22:39 Removed.
+ 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