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

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: removing changes from header file. 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..73acae50d823ba8779f9de94058e8d92598eda0a 100644
--- a/components/bookmarks/browser/bookmark_utils.cc
+++ b/components/bookmarks/browser/bookmark_utils.cc
@@ -8,11 +8,14 @@
#include "base/basictypes.h"
#include "base/bind.h"
+#include "base/containers/hash_tables.h"
#include "base/files/file_path.h"
#include "base/i18n/case_conversion.h"
#include "base/i18n/string_search.h"
#include "base/metrics/user_metrics_action.h"
#include "base/prefs/pref_service.h"
+#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "components/bookmarks/browser/bookmark_client.h"
@@ -201,6 +204,36 @@ void CopyToClipboard(BookmarkModel* model,
}
}
+// This function will returns new title for the bookmark if some bookmark with
+// same |title|and |url| is already exist as sibling, else returns original
+// |title|.
+base::string16 UpdateCopiedBookmarkTitle(const BookmarkModel* model,
+ const BookmarkNode* parent,
+ const GURL& url,
+ const base::string16& title) {
sky 2014/10/01 19:28:26 This should be a pointer and modified in place.
Deepak 2014/10/02 07:19:45 Done.
+ base::hash_set<base::string16> titles;
+ base::string16 new_title = title;
+ for (int i = 0; i < parent->child_count(); i++) {
+ const BookmarkNode* node = parent->GetChild(i);
+ if (node->is_url() && (url == node->url()) &&
+ (new_title == node->GetTitle() ||
sky 2014/10/01 19:28:25 Doesn't the StartsWith cover this case too?
Deepak 2014/10/02 07:19:45 Done.
+ StartsWith(node->GetTitle(), new_title, false))) {
+ titles.insert(node->GetTitle());
+ }
+ }
+
+ if (titles.find(new_title) == titles.end())
+ return new_title;
+
+ for (size_t i = 0; i < titles.size(); i++) {
+ new_title = base::UTF8ToUTF16(
+ base::StringPrintf("%s(%lu)", base::UTF16ToUTF8(title).c_str(), i + 1));
sky 2014/10/01 19:28:26 Add a space here.
sky 2014/10/01 19:28:26 All this conversion is ugly. Can you do just one c
Deepak 2014/10/02 07:19:45 Done.
Deepak 2014/10/02 07:19:45 As I am creating a new title everytime by changing
+ if (titles.find(new_title) == titles.end())
+ break;
sky 2014/10/01 19:28:26 You can return here, right?
Deepak 2014/10/02 07:19:45 Done.
+ }
+ return new_title;
+}
+
void PasteFromClipboard(BookmarkModel* model,
const BookmarkNode* parent,
int index) {
@@ -219,6 +252,16 @@ 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)) {
+ bookmark_data.elements[0].title =
+ UpdateCopiedBookmarkTitle(model,
+ parent,
+ bookmark_data.elements[0].url,
+ bookmark_data.elements[0].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