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

Side by Side Diff: components/bookmarks/browser/bookmark_utils.cc

Issue 1105413002: Avoid conversion of index to BookmarkNode pointer unnacessarily. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 7 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
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"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 filtered_nodes.push_back(nodes[i]); 240 filtered_nodes.push_back(nodes[i]);
241 241
242 BookmarkNodeData(filtered_nodes). 242 BookmarkNodeData(filtered_nodes).
243 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); 243 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE);
244 244
245 if (remove_nodes) { 245 if (remove_nodes) {
246 ScopedGroupBookmarkActions group_cut(model); 246 ScopedGroupBookmarkActions group_cut(model);
247 for (size_t i = 0; i < filtered_nodes.size(); ++i) { 247 for (size_t i = 0; i < filtered_nodes.size(); ++i) {
248 int index = filtered_nodes[i]->parent()->GetIndexOf(filtered_nodes[i]); 248 int index = filtered_nodes[i]->parent()->GetIndexOf(filtered_nodes[i]);
249 if (index > -1) 249 if (index > -1)
250 model->Remove(filtered_nodes[i]->parent(), index); 250 model->Remove(filtered_nodes[i]);
251 } 251 }
252 } 252 }
253 } 253 }
254 254
255 // Updates |title| such that |url| and |title| pair are unique among the 255 // Updates |title| such that |url| and |title| pair are unique among the
256 // children of |parent|. 256 // children of |parent|.
257 void MakeTitleUnique(const BookmarkModel* model, 257 void MakeTitleUnique(const BookmarkModel* model,
258 const BookmarkNode* parent, 258 const BookmarkNode* parent,
259 const GURL& url, 259 const GURL& url,
260 base::string16* title) { 260 base::string16* title) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 void DeleteBookmarkFolders(BookmarkModel* model, 465 void DeleteBookmarkFolders(BookmarkModel* model,
466 const std::vector<int64>& ids) { 466 const std::vector<int64>& ids) {
467 // Remove the folders that were removed. This has to be done after all the 467 // Remove the folders that were removed. This has to be done after all the
468 // other changes have been committed. 468 // other changes have been committed.
469 for (std::vector<int64>::const_iterator iter = ids.begin(); 469 for (std::vector<int64>::const_iterator iter = ids.begin();
470 iter != ids.end(); 470 iter != ids.end();
471 ++iter) { 471 ++iter) {
472 const BookmarkNode* node = GetBookmarkNodeByID(model, *iter); 472 const BookmarkNode* node = GetBookmarkNodeByID(model, *iter);
473 if (!node) 473 if (!node)
474 continue; 474 continue;
475 const BookmarkNode* parent = node->parent(); 475 model->Remove(node);
476 model->Remove(parent, parent->GetIndexOf(node));
477 } 476 }
478 } 477 }
479 478
480 void AddIfNotBookmarked(BookmarkModel* model, 479 void AddIfNotBookmarked(BookmarkModel* model,
481 const GURL& url, 480 const GURL& url,
482 const base::string16& title) { 481 const base::string16& title) {
483 if (IsBookmarkedByUser(model, url)) 482 if (IsBookmarkedByUser(model, url))
484 return; // Nothing to do, a user bookmark with that url already exists. 483 return; // Nothing to do, a user bookmark with that url already exists.
485 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded")); 484 model->client()->RecordAction(base::UserMetricsAction("BookmarkAdded"));
486 const BookmarkNode* parent = model->GetParentForNewNodes(); 485 const BookmarkNode* parent = model->GetParentForNewNodes();
487 model->AddURL(parent, parent->child_count(), title, url); 486 model->AddURL(parent, parent->child_count(), title, url);
488 } 487 }
489 488
490 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { 489 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) {
491 std::vector<const BookmarkNode*> bookmarks; 490 std::vector<const BookmarkNode*> bookmarks;
492 model->GetNodesByURL(url, &bookmarks); 491 model->GetNodesByURL(url, &bookmarks);
493 492
494 // Remove all the user bookmarks. 493 // Remove all the user bookmarks.
495 for (size_t i = 0; i < bookmarks.size(); ++i) { 494 for (size_t i = 0; i < bookmarks.size(); ++i) {
496 const BookmarkNode* node = bookmarks[i]; 495 const BookmarkNode* node = bookmarks[i];
497 int index = node->parent()->GetIndexOf(node); 496 int index = node->parent()->GetIndexOf(node);
498 if (index > -1 && model->client()->CanBeEditedByUser(node)) 497 if (index > -1 && model->client()->CanBeEditedByUser(node))
499 model->Remove(node->parent(), index); 498 model->Remove(node);
500 } 499 }
501 } 500 }
502 501
503 base::string16 CleanUpUrlForMatching( 502 base::string16 CleanUpUrlForMatching(
504 const GURL& gurl, 503 const GURL& gurl,
505 const std::string& languages, 504 const std::string& languages,
506 base::OffsetAdjuster::Adjustments* adjustments) { 505 base::OffsetAdjuster::Adjustments* adjustments) {
507 base::OffsetAdjuster::Adjustments tmp_adjustments; 506 base::OffsetAdjuster::Adjustments tmp_adjustments;
508 return base::i18n::ToLower(net::FormatUrlWithAdjustments( 507 return base::i18n::ToLower(net::FormatUrlWithAdjustments(
509 GURL(TruncateUrl(gurl.spec())), languages, 508 GURL(TruncateUrl(gurl.spec())), languages,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list, 546 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list,
548 const BookmarkNode* root) { 547 const BookmarkNode* root) {
549 for (const BookmarkNode* node : list) { 548 for (const BookmarkNode* node : list) {
550 if (IsDescendantOf(node, root)) 549 if (IsDescendantOf(node, root))
551 return true; 550 return true;
552 } 551 }
553 return false; 552 return false;
554 } 553 }
555 554
556 } // namespace bookmarks 555 } // namespace bookmarks
OLDNEW
« no previous file with comments | « components/bookmarks/browser/bookmark_model_unittest.cc ('k') | components/bookmarks/managed/managed_bookmarks_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698