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 bff1d49a681a474e32ebd9c4db61105058419a8c..501cedea3daa6848c79ef5df3f1c6111e216045c 100644 |
| --- a/components/bookmarks/browser/bookmark_utils.cc |
| +++ b/components/bookmarks/browser/bookmark_utils.cc |
| @@ -14,6 +14,7 @@ |
| #include "base/prefs/pref_service.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/time/time.h" |
| +#include "components/bookmarks/browser/bookmark_client.h" |
| #include "components/bookmarks/browser/bookmark_model.h" |
| #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" |
| #include "components/bookmarks/common/bookmark_pref_names.h" |
| @@ -203,13 +204,13 @@ void PasteFromClipboard(BookmarkModel* model, |
| CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); |
| } |
| -bool CanPasteFromClipboard(const BookmarkNode* node) { |
| - if (!node) |
| +bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { |
| + if (!node || !model->client()->CanBeEditedByUser(node)) |
| return false; |
| return BookmarkNodeData::ClipboardContainsBookmarks(); |
| } |
| -std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( |
| +std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( |
| BookmarkModel* model, |
| size_t max_count) { |
| std::vector<const BookmarkNode*> nodes; |
| @@ -218,6 +219,8 @@ std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( |
| while (iterator.has_next()) { |
| const BookmarkNode* parent = iterator.Next(); |
| + if (!model->client()->CanBeEditedByUser(parent)) |
| + continue; |
| if (parent->is_folder() && parent->date_folder_modified() > Time()) { |
| if (max_count == 0) { |
| nodes.push_back(parent); |
| @@ -242,7 +245,7 @@ std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( |
| for (int i = 0; i < root_node->child_count(); ++i) { |
| const BookmarkNode* node = root_node->GetChild(i); |
| - if (node->IsVisible() && |
| + if (node->IsVisible() && model->client()->CanBeEditedByUser(node) && |
| std::find(nodes.begin(), nodes.end(), node) == nodes.end()) { |
| nodes.push_back(node); |
| @@ -376,11 +379,8 @@ void DeleteBookmarkFolders(BookmarkModel* model, |
| void AddIfNotBookmarked(BookmarkModel* model, |
| const GURL& url, |
| const base::string16& title) { |
| - std::vector<const BookmarkNode*> bookmarks; |
| - model->GetNodesByURL(url, &bookmarks); |
| - if (!bookmarks.empty()) |
| - return; // Nothing to do, a bookmark with that url already exists. |
| - |
| + if (model->IsBookmarkedByUser(url)) |
| + return; // Nothing to do, a user bookmark with that url already exists. |
| model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded")); |
| const BookmarkNode* parent = model->GetParentForNewNodes(); |
| model->AddURL(parent, parent->child_count(), title, url); |
| @@ -390,11 +390,11 @@ void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { |
| std::vector<const BookmarkNode*> bookmarks; |
| model->GetNodesByURL(url, &bookmarks); |
| - // Remove all the bookmarks. |
| + // Remove all the user bookmarks. |
| for (size_t i = 0; i < bookmarks.size(); ++i) { |
| const BookmarkNode* node = bookmarks[i]; |
| int index = node->parent()->GetIndexOf(node); |
| - if (index > -1) |
| + if (index > -1 && model->client()->CanBeEditedByUser(node)) |
|
sky
2014/06/05 23:46:47
And coverage of this.
Joao da Silva
2014/06/06 15:41:03
Done.
|
| model->Remove(node->parent(), index); |
| } |
| } |