File: bookmarks_helpers.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (98 lines) | stat: -rw-r--r-- 3,439 bytes parent folder | download | duplicates (5)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_BOOKMARKS_BOOKMARKS_HELPERS_H_
#define CHROME_BROWSER_EXTENSIONS_BOOKMARKS_BOOKMARKS_HELPERS_H_

#include <stdint.h>

#include <string>
#include <vector>

#include "chrome/common/extensions/api/bookmarks.h"

namespace bookmarks {
class BookmarkModel;
class BookmarkNode;
class ManagedBookmarkService;
}  // namespace bookmarks

// Helper functions.
namespace extensions {
namespace bookmarks_helpers {

api::bookmarks::BookmarkTreeNode GetBookmarkTreeNode(
    bookmarks::BookmarkModel* model,
    bookmarks::ManagedBookmarkService* managed,
    const bookmarks::BookmarkNode* node,
    bool recurse,
    bool only_folders,
    std::optional<size_t> visible_index = std::nullopt);

// Populates `out_bookmark_tree_node` with given `node`.
// `visible_index` is the index position of this node among only the visible
// siblings in its parent folder, if not provided, will use GetAPIIndexOf() to
// calculate the index.
void PopulateBookmarkTreeNode(
    bookmarks::BookmarkModel* model,
    bookmarks::ManagedBookmarkService* managed,
    const bookmarks::BookmarkNode* node,
    bool recurse,
    bool only_folders,
    std::optional<size_t> visible_index,
    api::bookmarks::BookmarkTreeNode* out_bookmark_tree_node);

// Adds a JSON representation of `node` to the JSON `nodes`.
void AddNode(bookmarks::BookmarkModel* model,
             bookmarks::ManagedBookmarkService* managed,
             const bookmarks::BookmarkNode* node,
             std::vector<api::bookmarks::BookmarkTreeNode>* nodes,
             bool recurse);

// Adds a JSON representation of `node` of folder type to the JSON `nodes`.
void AddNodeFoldersOnly(bookmarks::BookmarkModel* model,
                        bookmarks::ManagedBookmarkService* managed,
                        const bookmarks::BookmarkNode* node,
                        std::vector<api::bookmarks::BookmarkTreeNode>* nodes,
                        bool recurse);

// Remove node of `id`.
bool RemoveNode(bookmarks::BookmarkModel* model,
                bookmarks::ManagedBookmarkService* managed,
                int64_t id,
                bool recursive,
                std::string* error);

// Get meta info from `node` and all it's children recursively.
void GetMetaInfo(const bookmarks::BookmarkNode& node,
                 base::Value::Dict& id_to_meta_info_map);

// Return the API index of `node` among its siblings on the extensions API.
//
// Nodes which are not visible (see `BookmarkNode::IsVisible()`) are not
// exposed on the extensions API. This means that the child indices of nodes as
// viewed on the extensions API differ from the BookmarkModel. For example:
//
// Model:
// - Root
//   - [0] A (visible)
//   - [1] B (not visible)
//   - [2] C (visible)
//
// Extensions API:
// - Root
//   - [0] A
//   - [1] C
size_t GetAPIIndexOf(const bookmarks::BookmarkNode& node);

// Similar to GetAPIIndexOf(node), but for the case where the node has already
// been removed from its parent.
// The parent and previous model index of the node are provided.
size_t GetAPIIndexOf(const bookmarks::BookmarkNode& parent,
                     size_t previous_model_index);

}  // namespace bookmarks_helpers
}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_BOOKMARKS_BOOKMARKS_HELPERS_H_