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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/bookmarks/browser/bookmark_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/bookmarks/browser/bookmark_utils.h" 5 #include "components/bookmarks/browser/bookmark_utils.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/i18n/case_conversion.h" 12 #include "base/i18n/case_conversion.h"
13 #include "base/i18n/string_search.h" 13 #include "base/i18n/string_search.h"
14 #include "base/metrics/user_metrics_action.h" 14 #include "base/metrics/user_metrics_action.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
17 #include "base/time/time.h" 19 #include "base/time/time.h"
18 #include "components/bookmarks/browser/bookmark_client.h" 20 #include "components/bookmarks/browser/bookmark_client.h"
19 #include "components/bookmarks/browser/bookmark_model.h" 21 #include "components/bookmarks/browser/bookmark_model.h"
20 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" 22 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h"
21 #include "components/bookmarks/common/bookmark_pref_names.h" 23 #include "components/bookmarks/common/bookmark_pref_names.h"
22 #include "components/pref_registry/pref_registry_syncable.h" 24 #include "components/pref_registry/pref_registry_syncable.h"
23 #include "components/query_parser/query_parser.h" 25 #include "components/query_parser/query_parser.h"
24 #include "net/base/net_util.h" 26 #include "net/base/net_util.h"
25 #include "ui/base/clipboard/clipboard.h" 27 #include "ui/base/clipboard/clipboard.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 GURL url = GetUrlFromClipboard(); 214 GURL url = GetUrlFromClipboard();
213 if (!url.is_valid()) 215 if (!url.is_valid())
214 return; 216 return;
215 BookmarkNode node(url); 217 BookmarkNode node(url);
216 node.SetTitle(base::ASCIIToUTF16(url.spec())); 218 node.SetTitle(base::ASCIIToUTF16(url.spec()));
217 bookmark_data = BookmarkNodeData(&node); 219 bookmark_data = BookmarkNodeData(&node);
218 } 220 }
219 if (index == -1) 221 if (index == -1)
220 index = parent->child_count(); 222 index = parent->child_count();
221 ScopedGroupBookmarkActions group_paste(model); 223 ScopedGroupBookmarkActions group_paste(model);
224
225 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.
226 model->IsBookmarked(bookmark_data.elements[0].url)) {
227 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.
228 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
229 std::vector<base::string16>::iterator it;
sky 2014/09/24 14:26:49 Declare where needed.
Deepak 2014/09/25 05:59:11 Done.
230 base::string16 new_title = bookmark_data.elements[0].title;
231
232 for (int i = 0; i < parent->child_count(); i++) {
233 const BookmarkNode* node = parent->GetChild(i);
234 if (node->is_url() && (bookmark_data.elements[0].url == node->url()) &&
235 (new_title == node->GetTitle() ||
236 StartsWith(node->GetTitle(), new_title, false))) {
237 titles.push_back(node->GetTitle());
238 nodes.push_back(node);
239 }
240 }
241
242 it = std::find(titles.begin(), titles.end(), new_title);
243 if (it == titles.end()) {
244 new_title = bookmark_data.elements[0].title;
245 } else {
246 for (size_t i = 0; i < nodes.size(); i++) {
247 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.
248 base::IntToString16(i + 1) + base::UTF8ToUTF16(")");
249 it = std::find(titles.begin(), titles.end(), new_title);
250 if (it == titles.end())
251 break;
252 }
253 }
254 bookmark_data.elements[0].title = new_title;
255 }
256
222 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); 257 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true);
223 } 258 }
224 259
225 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { 260 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) {
226 if (!node || !model->client()->CanBeEditedByUser(node)) 261 if (!node || !model->client()->CanBeEditedByUser(node))
227 return false; 262 return false;
228 return (BookmarkNodeData::ClipboardContainsBookmarks() || 263 return (BookmarkNodeData::ClipboardContainsBookmarks() ||
229 GetUrlFromClipboard().is_valid()); 264 GetUrlFromClipboard().is_valid());
230 } 265 }
231 266
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 491 }
457 return false; 492 return false;
458 } 493 }
459 494
460 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { 495 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) {
461 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. 496 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate.
462 return GetNodeByID(model->root_node(), id); 497 return GetNodeByID(model->root_node(), id);
463 } 498 }
464 499
465 } // namespace bookmarks 500 } // namespace bookmarks
OLDNEW
« 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