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

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 as per review comments and test case added. Created 6 years, 3 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 | « no previous file | components/bookmarks/browser/bookmark_utils_unittest.cc » ('j') | 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 a60a86d0020c6eeb0f231b13e5ee0be270b581e2..528975e5c9088dc0f804c0c8d92c298b8e97ec06 100644
--- a/components/bookmarks/browser/bookmark_utils.cc
+++ b/components/bookmarks/browser/bookmark_utils.cc
@@ -13,6 +13,8 @@
#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/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "components/bookmarks/browser/bookmark_client.h"
@@ -219,6 +221,39 @@ void PasteFromClipboard(BookmarkModel* model,
if (index == -1)
index = parent->child_count();
ScopedGroupBookmarkActions group_paste(model);
+
+ if (bookmark_data.elements.size() == 1 &&
sky 2014/09/24 14:26:49 Move this into a helper function.
Deepak 2014/09/25 05:59:11 Done.
+ model->IsBookmarked(bookmark_data.elements[0].url)) {
+ std::vector<const BookmarkNode*> nodes;
sky 2014/09/24 14:26:49 AFAICT you don't need this.
Deepak 2014/09/25 05:59:11 Acknowledged.
+ std::vector<base::string16> titles;
sky 2014/09/24 14:26:49 Use a hashset.
Deepak 2014/09/25 05:59:11 For using HashSet, I have added third_party/WebKi
sky 2014/09/26 16:14:10 Don't use webkit types in chrome. Use the types in
+ std::vector<base::string16>::iterator it;
sky 2014/09/24 14:26:49 Declare where needed.
Deepak 2014/09/25 05:59:11 Done.
+ base::string16 new_title = bookmark_data.elements[0].title;
+
+ for (int i = 0; i < parent->child_count(); i++) {
+ const BookmarkNode* node = parent->GetChild(i);
+ if (node->is_url() && (bookmark_data.elements[0].url == node->url()) &&
+ (new_title == node->GetTitle() ||
+ StartsWith(node->GetTitle(), new_title, false))) {
+ titles.push_back(node->GetTitle());
+ nodes.push_back(node);
+ }
+ }
+
+ it = std::find(titles.begin(), titles.end(), new_title);
+ if (it == titles.end()) {
+ new_title = bookmark_data.elements[0].title;
+ } else {
+ for (size_t i = 0; i < nodes.size(); i++) {
+ new_title = bookmark_data.elements[0].title + base::UTF8ToUTF16("(") +
sky 2014/09/24 14:26:49 Use StringPrintf.
Deepak 2014/09/25 05:59:11 Done.
+ 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);
}
« no previous file with comments | « no previous file | components/bookmarks/browser/bookmark_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698