blob: 1ca96cadea4b7a8319649919413b1db0526f8a6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/enhanced_bookmarks/enhanced_bookmark_utils.h"
#include "components/bookmarks/browser/bookmark_model.h"
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
namespace enhanced_bookmarks {
std::vector<const BookmarkNode*> PrimaryPermanentNodes(BookmarkModel* model) {
DCHECK(model->loaded());
std::vector<const BookmarkNode*> nodes;
nodes.push_back(model->mobile_node());
nodes.push_back(model->bookmark_bar_node());
nodes.push_back(model->other_node());
return nodes;
}
std::vector<const BookmarkNode*> RootLevelFolders(BookmarkModel* model) {
std::vector<const BookmarkNode*> root_level_folders;
// Find the direct folder children of the primary permanent nodes.
std::vector<const BookmarkNode*> primary_permanent_nodes =
PrimaryPermanentNodes(model);
for (const BookmarkNode* parent : primary_permanent_nodes) {
int child_count = parent->child_count();
for (int i = 0; i < child_count; ++i) {
const BookmarkNode* node = parent->GetChild(i);
if (node->is_folder() && node->IsVisible())
root_level_folders.push_back(node);
}
}
return root_level_folders;
}
bool IsPrimaryPermanentNode(const BookmarkNode* node, BookmarkModel* model) {
std::vector<const BookmarkNode*> primary_nodes(PrimaryPermanentNodes(model));
if (std::find(primary_nodes.begin(), primary_nodes.end(), node) !=
primary_nodes.end()) {
return true;
}
return false;
}
const BookmarkNode* RootLevelFolderForNode(const BookmarkNode* node,
BookmarkModel* model) {
// This helper function doesn't work for managed bookmarks. This checks that
// |node| is editable by the user, which currently covers all the other
// bookmarks except the managed bookmarks.
DCHECK(model->client()->CanBeEditedByUser(node));
const std::vector<const BookmarkNode*> root_folders(RootLevelFolders(model));
const BookmarkNode* top = node;
while (top &&
std::find(root_folders.begin(), root_folders.end(), top) ==
root_folders.end()) {
top = top->parent();
}
return top;
}
} // namespace enhanced_bookmarks
|