File: bookmark_load_details.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 (173 lines) | stat: -rw-r--r-- 6,540 bytes parent folder | download | duplicates (6)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_LOAD_DETAILS_H_
#define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_LOAD_DETAILS_H_

#include <map>
#include <memory>
#include <string>

#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/bookmarks/browser/uuid_index.h"

namespace base {
class TimeTicks;
}

namespace bookmarks {

class BookmarkPermanentNode;
class TitledUrlIndex;
class UrlIndex;
struct UserFolderLoadStats;

// BookmarkLoadDetails represents the outcome of loading and parsing the JSON
// file containing bookmarks. It is produced by ModelLoader in the backend task
// runner, including the generation of indices, and posted to the UI thread to
// finalize the loading of BookmarkModel.
class BookmarkLoadDetails {
 public:
  BookmarkLoadDetails();
  ~BookmarkLoadDetails();

  BookmarkLoadDetails(const BookmarkLoadDetails&) = delete;
  BookmarkLoadDetails& operator=(const BookmarkLoadDetails&) = delete;

  // Local-or-syncable permanent nodes (never null).
  BookmarkPermanentNode* bb_node() { return bb_node_; }
  BookmarkPermanentNode* mobile_folder_node() { return mobile_folder_node_; }
  BookmarkPermanentNode* other_folder_node() { return other_folder_node_; }

  // Account permanent nodes (null unless `AddAccountPermanentNodes()` is
  // called).
  BookmarkPermanentNode* account_bb_node() { return account_bb_node_; }
  BookmarkPermanentNode* account_mobile_folder_node() {
    return account_mobile_folder_node_;
  }
  BookmarkPermanentNode* account_other_folder_node() {
    return account_other_folder_node_;
  }

  std::unique_ptr<TitledUrlIndex> owned_titled_url_index() {
    return std::move(titled_url_index_);
  }

  UuidIndex owned_local_or_syncable_uuid_index() {
    return std::move(local_or_syncable_uuid_index_);
  }

  UuidIndex owned_account_uuid_index() {
    return std::move(account_uuid_index_);
  }

  // Max id of the nodes.
  void set_max_id(int64_t max_id) { max_id_ = max_id; }
  int64_t max_id() const { return max_id_; }

  // The required-recovery bit represents whether the on-disk state was corrupt
  // and had to be recovered. Scenarios include ID or UUID collisions and
  // checksum mismatches.
  void set_required_recovery(bool value) { required_recovery_ = value; }
  bool required_recovery() const { return required_recovery_; }

  // Whether ids were reassigned. IDs are reassigned during decoding if the
  // checksum of the file doesn't match, some IDs are missing or not
  // unique. Basically, if the user modified the bookmarks directly we'll
  // reassign the ids to ensure they are unique.
  void set_ids_reassigned(bool value) { ids_reassigned_ = value; }
  bool ids_reassigned() const { return ids_reassigned_; }

  // If IDs are reassigned during decoding, this represents the mapping from old
  // (i.e. on-disk) ID to the newly-assigned ones.
  const std::multimap<int64_t, int64_t>&
  local_or_syncable_reassigned_ids_per_old_id() const {
    return local_or_syncable_reassigned_ids_per_old_id_;
  }
  void set_local_or_syncable_reassigned_ids_per_old_id(
      std::multimap<int64_t, int64_t> value) {
    local_or_syncable_reassigned_ids_per_old_id_ = std::move(value);
  }

  // Returns the string blob representing the sync metadata in the json file.
  // The string blob is set during decode time upon the call to Bookmark::Load.
  void set_local_or_syncable_sync_metadata_str(std::string sync_metadata_str) {
    local_or_syncable_sync_metadata_str_ = std::move(sync_metadata_str);
  }

  const std::string& local_or_syncable_sync_metadata_str() const {
    return local_or_syncable_sync_metadata_str_;
  }

  // Same as above but for account bookmarks.
  void set_account_sync_metadata_str(std::string sync_metadata_str) {
    account_sync_metadata_str_ = std::move(sync_metadata_str);
  }
  const std::string& account_sync_metadata_str() const {
    return account_sync_metadata_str_;
  }

  // Adds account bookmarks. May be called at most once.
  void AddAccountPermanentNodes(
      std::unique_ptr<BookmarkPermanentNode> account_bb_node,
      std::unique_ptr<BookmarkPermanentNode> account_other_folder_node,
      std::unique_ptr<BookmarkPermanentNode> account_mobile_folder_node);

  // Assigns node IDs for local-or-syncable permanent nodes if not previously
  // assigned/decoded.
  void PopulateNodeIdsForLocalOrSyncablePermanentNodes();

  // Adds managed nodes. May be called at most once.
  // PopulateNodeIdsForLocalOrSyncablePermanentNodes() must have been invoked
  // before this function.
  void AddManagedNode(std::unique_ptr<BookmarkPermanentNode> managed_node);

  void CreateIndices();

  void ResetPermanentNodePointers();

  const scoped_refptr<UrlIndex>& url_index() { return url_index_; }
  const UrlIndex* url_index() const { return url_index_.get(); }

  base::TimeTicks load_start() { return load_start_; }

  const BookmarkNode* RootNodeForTest() const;

  UserFolderLoadStats ComputeUserFolderStats() const;

 private:
  // Adds node to the various indices, recursing through all children as well.
  void AddNodeToIndexRecursive(BookmarkNode* node, UuidIndex& uuid_index);

  const BookmarkNode* GetRootNode() const;

  std::unique_ptr<BookmarkNode> root_node_;
  std::unique_ptr<TitledUrlIndex> titled_url_index_;
  UuidIndex local_or_syncable_uuid_index_;
  UuidIndex account_uuid_index_;
  int64_t max_id_ = 1;
  bool ids_reassigned_ = false;
  std::multimap<int64_t, int64_t> local_or_syncable_reassigned_ids_per_old_id_;
  bool required_recovery_ = false;
  scoped_refptr<UrlIndex> url_index_;
  raw_ptr<BookmarkPermanentNode> bb_node_;
  raw_ptr<BookmarkPermanentNode> other_folder_node_;
  raw_ptr<BookmarkPermanentNode> mobile_folder_node_;
  raw_ptr<BookmarkPermanentNode> account_bb_node_;
  raw_ptr<BookmarkPermanentNode> account_other_folder_node_;
  raw_ptr<BookmarkPermanentNode> account_mobile_folder_node_;
  bool has_managed_node_ = false;
  // String blob representing the sync metadata stored in the json file, one
  // per storage type (local-or-syncable or account bookmarks). In normal
  // circumstances, only one of them may be non-empty.
  std::string local_or_syncable_sync_metadata_str_;
  std::string account_sync_metadata_str_;
  base::TimeTicks load_start_;
};

}  // namespace bookmarks

#endif  // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_LOAD_DETAILS_H_