File: bookmark_client.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 (140 lines) | stat: -rw-r--r-- 6,178 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
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
// Copyright 2014 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_CLIENT_H_
#define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_

#include <cstdint>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>

#include "base/functional/callback_forward.h"
#include "base/task/cancelable_task_tracker.h"
#include "components/bookmarks/common/bookmark_metrics.h"
#include "components/favicon_base/favicon_callback.h"
#include "components/keyed_service/core/keyed_service.h"

class GURL;

namespace bookmarks {

class BookmarkModel;
class BookmarkNode;
class BookmarkPermanentNode;

// A callback that generates a std::unique_ptr<BookmarkPermanentNode>, given a
// max ID to use. The max ID argument will be updated after if a new node has
// been created and assigned an ID.
using LoadManagedNodeCallback =
    base::OnceCallback<std::unique_ptr<BookmarkPermanentNode>(int64_t*)>;

// This class abstracts operations that depends on the embedder's environment,
// e.g. Chrome.
class BookmarkClient {
 public:
  // Type representing a mapping from URLs to the number of times the URL has
  // been typed by the user in the Omnibox.
  using UrlTypedCountMap = std::unordered_map<const GURL*, int>;

  virtual ~BookmarkClient() = default;

  // Called during initialization of BookmarkModel.
  virtual void Init(BookmarkModel* model);

  // Called when loading from disk triggered some recovery, meaning that IDs or
  // UUIDs could have been reassigned. If IDs were reassigned, which is not
  // always the case, `local_or_syncable_reassigned_ids_per_old_id` contains
  // the mapping from old IDs (before reassignment) to new ones.
  virtual void RequiredRecoveryToLoad(
      const std::multimap<int64_t, int64_t>&
          local_or_syncable_reassigned_ids_per_old_id);

  // Gets a bookmark folder that the provided URL can be saved to. If nullptr is
  // returned, the bookmark is saved to the default location (usually this is
  // the last modified folder). This affords features the option to override the
  // default folder if relevant for the URL.
  virtual const BookmarkNode* GetSuggestedSaveLocation(const GURL& url);

  // Requests a favicon from the history cache for the web page at `page_url`
  // for icon type favicon_base::IconType::kFavicon. `callback` is run when the
  // favicon has been fetched, which returns gfx::Image is a multi-resolution
  // image of gfx::kFaviconSize DIP width and height. The data from the history
  // cache is resized if need be.
  virtual base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL(
      const GURL& page_url,
      favicon_base::FaviconImageCallback callback,
      base::CancelableTaskTracker* tracker);

  // Returns true if the embedder supports typed count for URL.
  virtual bool SupportsTypedCountForUrls();

  // Retrieves the number of times each bookmark URL has been typed in
  // the Omnibox by the user. For each key (URL) in `url_typed_count_map`,
  // the corresponding value will be updated with the typed count of that URL.
  // `url_typed_count_map` must not be null.
  virtual void GetTypedCountForUrls(UrlTypedCountMap* url_typed_count_map);

  // Returns a task that will be used to load a managed root node. This task
  // will be invoked in the Profile's IO task runner.
  virtual LoadManagedNodeCallback GetLoadManagedNodeCallback() = 0;

  // Returns whether sync-the-feature is currently on, for the purpose of
  // logging metrics and influence predicates such
  // `BookmarkModel::IsLocalOnlyNode()`.
  virtual bool IsSyncFeatureEnabledIncludingBookmarks() = 0;

  // Returns true if the `permanent_node` can have its title updated.
  virtual bool CanSetPermanentNodeTitle(const BookmarkNode* permanent_node) = 0;

  // Returns true if `node` is considered a managed node.
  virtual bool IsNodeManaged(const BookmarkNode* node) = 0;

  // Encodes the bookmark sync data into a string blob. It's used by the
  // bookmark model to persist the sync metadata together with the bookmark
  // model. It comes with two variants: the blob corresponding to the
  // local-or-syncable bookmarks and the one for account bookmarks. In
  // normal circumnstances, at most one of them is non-empty.
  virtual std::string EncodeLocalOrSyncableBookmarkSyncMetadata() = 0;
  virtual std::string EncodeAccountBookmarkSyncMetadata() = 0;

  // Decodes a string representing the sync metadata stored in `metadata_str`.
  // Same as with encoding, it comes with two variants, one for
  // local-or-syncable bookmarks and one for account bookmarks. The model calls
  // this method after it has loaded the model data. `schedule_save_closure` is
  // a repeating call back to trigger a model and metadata persistence process.
  virtual void DecodeLocalOrSyncableBookmarkSyncMetadata(
      const std::string& metadata_str,
      const base::RepeatingClosure& schedule_save_closure) = 0;

  // Decoding of sync metadata corresponding to account bookmarks may result in
  // metadata being invalidated. In this case, account bookmarks are also
  // deleted automatically.
  enum class DecodeAccountBookmarkSyncMetadataResult {
    kSuccess,
    kMustRemoveAccountPermanentFolders,
  };
  virtual DecodeAccountBookmarkSyncMetadataResult
  DecodeAccountBookmarkSyncMetadata(
      const std::string& metadata_str,
      const base::RepeatingClosure& schedule_save_closure) = 0;

  // Similar to BookmarkModelObserver::BookmarkNodeRemoved(), but transfers
  // ownership of BookmarkNode, which allows undoing the operation.
  virtual void OnBookmarkNodeRemovedUndoable(
      const BookmarkNode* parent,
      size_t index,
      std::unique_ptr<BookmarkNode> node) = 0;

  // Creates a persistent timer that allows recording metrics periodically
  // (every 24hrs or on next startup). `metrics_callback` contains the logic to
  // compute the metrics to be logged.
  virtual void SchedulePersistentTimerForDailyMetrics(
      base::RepeatingClosure metrics_callback) = 0;
};

}  // namespace bookmarks

#endif  // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_