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

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

Issue 446003002: Title: Same Bookmark url is getting pasted on the Bookmarkbar with same title. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes done as per reviewer comments. Created 6 years, 4 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
Index: components/bookmarks/browser/bookmark_utils.cc
diff --git a/components/bookmarks/browser/bookmark_utils.cc b/components/bookmarks/browser/bookmark_utils.cc
index 304d2befbd07d5b36d3286e8b1e24010a393f884..01dcf609a47c365768596b124463e912a216a85e 100644
--- a/components/bookmarks/browser/bookmark_utils.cc
+++ b/components/bookmarks/browser/bookmark_utils.cc
@@ -12,6 +12,7 @@
#include "base/i18n/string_search.h"
#include "base/metrics/user_metrics_action.h"
#include "base/prefs/pref_service.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "components/bookmarks/browser/bookmark_client.h"
@@ -201,6 +202,34 @@ void PasteFromClipboard(BookmarkModel* model,
if (index == -1)
index = parent->child_count();
ScopedGroupBookmarkActions group_paste(model);
+
+ if (bookmark_data.elements.size() == 1 &&
+ model->IsBookmarked(bookmark_data.elements[0].url)) {
sky 2014/08/18 16:15:21 It's not IsBookmarked you sure care about, rather
Deepak 2014/08/19 11:42:19 IsBookmarked() will tell me weather a Bookmark wit
sky 2014/08/19 16:38:31 You should do the same as we do for downloads, and
+ std::vector<const BookmarkNode*> nodes;
+ std::vector<base::string16> titles;
+ std::vector<base::string16>::iterator it;
+ base::string16 new_title = bookmark_data.elements[0].title;
+ model->GetNodesByURLAndTitle(bookmark_data.elements[0].url,
+ bookmark_data.elements[0].title,
+ parent,
+ &nodes,
+ &titles);
+ size_t i = 0;
+ it = std::find(titles.begin(), titles.end(), new_title);
+ if (it == titles.end()) {
+ new_title = bookmark_data.elements[0].title;
+ } else {
+ for (i = 0; i < nodes.size(); i++) {
+ new_title = bookmark_data.elements[0].title +
+ base::UTF8ToUTF16("-Copy(") + base::IntToString16(i + 1) +
+ base::UTF8ToUTF16(")");
+ it = std::find(titles.begin(), titles.end(), new_title);
+ if (it == titles.end())
+ break;
+ }
+ }
+ bookmark_data.elements[0].title = new_title;
+ }
CloneBookmarkNode(model, bookmark_data.elements, parent, index, true);
}

Powered by Google App Engine
This is Rietveld 408576698