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

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

Issue 242823002: Extract GetNodeByID() method from BookmarkModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert a change in bookmarks_helper.cc that colides with a wstring and cq does not like that Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/bookmarks/bookmark_utils.h" 5 #include "chrome/browser/bookmarks/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/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (!node || model->is_permanent_node(node)) 104 if (!node || model->is_permanent_node(node))
105 return false; 105 return false;
106 106
107 for (size_t i = 0; i < selected_nodes.size(); ++i) 107 for (size_t i = 0; i < selected_nodes.size(); ++i)
108 if (node->id() == selected_nodes[i]->id()) 108 if (node->id() == selected_nodes[i]->id())
109 return true; 109 return true;
110 110
111 return HasSelectedAncestor(model, selected_nodes, node->parent()); 111 return HasSelectedAncestor(model, selected_nodes, node->parent());
112 } 112 }
113 113
114 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id) {
115 if (node->id() == id)
116 return node;
117
118 for (int i = 0, child_count = node->child_count(); i < child_count; ++i) {
119 const BookmarkNode* result = GetNodeByID(node->GetChild(i), id);
120 if (result)
121 return result;
122 }
123 return NULL;
124 }
125
114 } // namespace 126 } // namespace
115 127
116 namespace bookmark_utils { 128 namespace bookmark_utils {
117 129
118 QueryFields::QueryFields() {} 130 QueryFields::QueryFields() {}
119 QueryFields::~QueryFields() {} 131 QueryFields::~QueryFields() {}
120 132
121 void CloneBookmarkNode(BookmarkModel* model, 133 void CloneBookmarkNode(BookmarkModel* model,
122 const std::vector<BookmarkNodeData::Element>& elements, 134 const std::vector<BookmarkNodeData::Element>& elements,
123 const BookmarkNode* parent, 135 const BookmarkNode* parent,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 return real_parent; 345 return real_parent;
334 } 346 }
335 347
336 void DeleteBookmarkFolders(BookmarkModel* model, 348 void DeleteBookmarkFolders(BookmarkModel* model,
337 const std::vector<int64>& ids) { 349 const std::vector<int64>& ids) {
338 // Remove the folders that were removed. This has to be done after all the 350 // Remove the folders that were removed. This has to be done after all the
339 // other changes have been committed. 351 // other changes have been committed.
340 for (std::vector<int64>::const_iterator iter = ids.begin(); 352 for (std::vector<int64>::const_iterator iter = ids.begin();
341 iter != ids.end(); 353 iter != ids.end();
342 ++iter) { 354 ++iter) {
343 const BookmarkNode* node = model->GetNodeByID(*iter); 355 const BookmarkNode* node = GetBookmarkNodeByID(model, *iter);
344 if (!node) 356 if (!node)
345 continue; 357 continue;
346 const BookmarkNode* parent = node->parent(); 358 const BookmarkNode* parent = node->parent();
347 model->Remove(parent, parent->GetIndexOf(node)); 359 model->Remove(parent, parent->GetIndexOf(node));
348 } 360 }
349 } 361 }
350 362
351 void AddIfNotBookmarked(BookmarkModel* model, 363 void AddIfNotBookmarked(BookmarkModel* model,
352 const GURL& url, 364 const GURL& url,
353 const base::string16& title) { 365 const base::string16& title) {
(...skipping 14 matching lines...) Expand all
368 // Remove all the bookmarks. 380 // Remove all the bookmarks.
369 for (size_t i = 0; i < bookmarks.size(); ++i) { 381 for (size_t i = 0; i < bookmarks.size(); ++i) {
370 const BookmarkNode* node = bookmarks[i]; 382 const BookmarkNode* node = bookmarks[i];
371 int index = node->parent()->GetIndexOf(node); 383 int index = node->parent()->GetIndexOf(node);
372 if (index > -1) 384 if (index > -1)
373 model->Remove(node->parent(), index); 385 model->Remove(node->parent(), index);
374 } 386 }
375 } 387 }
376 388
377 } // namespace bookmark_utils 389 } // namespace bookmark_utils
390
391 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) {
392 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate.
393 return GetNodeByID(model->root_node(), id);
394 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698