Chromium Code Reviews| 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 |