mirror of
https://github.com/Alex313031/thorium.git
synced 2025-01-10 11:57:48 -03:00
Update bookmark_utils.cc
This commit is contained in:
parent
3e6df460d7
commit
fede97686f
1 changed files with 16 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2022 The Chromium Authors and Alex313031.
|
// Copyright 2022 The Chromium Authors and Alex313031
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
@ -116,12 +116,15 @@ bool HasSelectedAncestor(BookmarkModel* model,
|
||||||
return HasSelectedAncestor(model, selected_nodes, node->parent());
|
return HasSelectedAncestor(model, selected_nodes, node->parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64_t id) {
|
// Recursively searches for a node satisfying the functor |pred| . Returns
|
||||||
if (node->id() == id)
|
// nullptr if not found.
|
||||||
|
template <typename Predicate>
|
||||||
|
const BookmarkNode* FindNode(const BookmarkNode* node, Predicate pred) {
|
||||||
|
if (pred(node))
|
||||||
return node;
|
return node;
|
||||||
|
|
||||||
for (const auto& child : node->children()) {
|
for (const auto& child : node->children()) {
|
||||||
const BookmarkNode* result = GetNodeByID(child.get(), id);
|
const BookmarkNode* result = FindNode(child.get(), pred);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -558,8 +561,15 @@ bool IsBookmarkedByUser(BookmarkModel* model, const GURL& url) {
|
||||||
|
|
||||||
const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model,
|
const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model,
|
||||||
int64_t id) {
|
int64_t id) {
|
||||||
// TODO(sky): TreeNode needs a method that visits all nodes using a predicate.
|
return FindNode(model->root_node(),
|
||||||
return GetNodeByID(model->root_node(), id);
|
[id](const BookmarkNode* node) { return node->id() == id; });
|
||||||
|
}
|
||||||
|
|
||||||
|
const BookmarkNode* GetBookmarkNodeByGUID(const BookmarkModel* model,
|
||||||
|
const base::GUID& guid) {
|
||||||
|
return FindNode(model->root_node(), [&guid](const BookmarkNode* node) {
|
||||||
|
return node->guid() == guid;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDescendantOf(const BookmarkNode* node, const BookmarkNode* root) {
|
bool IsDescendantOf(const BookmarkNode* node, const BookmarkNode* root) {
|
||||||
|
|
Loading…
Reference in a new issue