Chromium Code Reviews| Index: components/bookmarks/browser/bookmark_model.cc |
| diff --git a/components/bookmarks/browser/bookmark_model.cc b/components/bookmarks/browser/bookmark_model.cc |
| index 263fc76000e53ff5e66f4c264d95e5a9121ba6a2..e401a74683890d7082a4e537dd87b6b17b2d0c17 100644 |
| --- a/components/bookmarks/browser/bookmark_model.cc |
| +++ b/components/bookmarks/browser/bookmark_model.cc |
| @@ -150,7 +150,7 @@ void BookmarkModel::Load( |
| const BookmarkNode* BookmarkModel::GetParentForNewNodes() { |
| std::vector<const BookmarkNode*> nodes = |
| - bookmark_utils::GetMostRecentlyModifiedFolders(this, 1); |
| + bookmark_utils::GetMostRecentlyModifiedUserFolders(this, 1); |
| DCHECK(!nodes.empty()); // This list is always padded with default folders. |
| return nodes[0]; |
| } |
| @@ -503,15 +503,19 @@ void BookmarkModel::GetNodesByURL(const GURL& url, |
| } |
| } |
| -const BookmarkNode* BookmarkModel::GetMostRecentlyAddedNodeForURL( |
| +const BookmarkNode* BookmarkModel::GetMostRecentlyAddedUserNodeForURL( |
| const GURL& url) { |
| std::vector<const BookmarkNode*> nodes; |
| GetNodesByURL(url, &nodes); |
| - if (nodes.empty()) |
| - return NULL; |
| - |
| std::sort(nodes.begin(), nodes.end(), &bookmark_utils::MoreRecentlyAdded); |
| - return nodes.front(); |
| + |
| + // Look for the first node that the user can edit. |
| + for (size_t i = 0; i < nodes.size(); ++i) { |
| + if (client_->CanBeEditedByUser(nodes[i])) |
|
sky
2014/06/05 23:46:47
Add test coverage for this.
Joao da Silva
2014/06/06 15:41:03
Done.
|
| + return nodes[i]; |
| + } |
| + |
| + return NULL; |
| } |
| bool BookmarkModel::HasBookmarks() { |
| @@ -521,7 +525,12 @@ bool BookmarkModel::HasBookmarks() { |
| bool BookmarkModel::IsBookmarked(const GURL& url) { |
| base::AutoLock url_lock(url_lock_); |
| - return IsBookmarkedNoLock(url); |
| + return IsBookmarkedNoLock(url, false); |
| +} |
| + |
| +bool BookmarkModel::IsBookmarkedByUser(const GURL& url) { |
| + base::AutoLock url_lock(url_lock_); |
| + return IsBookmarkedNoLock(url, true); |
| } |
| void BookmarkModel::GetBookmarks( |
| @@ -718,10 +727,17 @@ const BookmarkPermanentNode* BookmarkModel::PermanentNode( |
| } |
| } |
| -bool BookmarkModel::IsBookmarkedNoLock(const GURL& url) { |
| +bool BookmarkModel::IsBookmarkedNoLock(const GURL& url, |
| + bool only_by_editable_nodes) { |
| BookmarkNode tmp_node(url); |
| - return (nodes_ordered_by_url_set_.find(&tmp_node) != |
| - nodes_ordered_by_url_set_.end()); |
| + typedef NodesOrderedByURLSet::const_iterator Iterator; |
| + std::pair<Iterator, Iterator> range = |
| + nodes_ordered_by_url_set_.equal_range(&tmp_node); |
| + for (Iterator it = range.first; it != range.second; ++it) { |
| + if (!only_by_editable_nodes || client_->CanBeEditedByUser(*it)) |
| + return true; |
| + } |
| + return false; |
| } |
| void BookmarkModel::RemoveNode(BookmarkNode* node, |
| @@ -856,7 +872,7 @@ void BookmarkModel::RemoveNodeAndGetRemovedUrls(BookmarkNode* node, |
| // allow duplicates we need to remove any entries that are still bookmarked. |
| for (std::set<GURL>::iterator i = removed_urls->begin(); |
| i != removed_urls->end();) { |
| - if (IsBookmarkedNoLock(*i)) { |
| + if (IsBookmarkedNoLock(*i, false)) { |
| // When we erase the iterator pointing at the erasee is |
| // invalidated, so using i++ here within the "erase" call is |
| // important as it advances the iterator before passing the |