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 174 175 176 177 178 179 180 181 182
|
// Copyright 2025 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_SYNC_BOOKMARKS_BOOKMARK_MODEL_MERGER_COMPARISON_METRICS_H_
#define COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_MODEL_MERGER_COMPARISON_METRICS_H_
#include "base/containers/flat_set.h"
#include "base/uuid.h"
#include "components/sync/base/previously_syncing_gaia_id_info_for_metrics.h"
#include "components/sync_bookmarks/bookmark_model_merger.h"
#include "url/gurl.h"
namespace sync_bookmarks {
class BookmarkModelView;
namespace metrics {
// Enum representing which subtree of the bookmark model was used when
// comparing local bookmarks with account bookmarks. This enum is used as
// infix when recording metrics.
enum class SubtreeSelection {
kConsideringAllBookmarks,
kUnderBookmarksBar,
};
// Enum representing the method or criterion used as uniqueness key when
// comparing local bookmarks with account bookmarks. This enum is used as
// infix when recording metrics.
enum class GroupingKeyInfix {
kByUrl,
kByUrlAndTitle,
kByUrlAndUuid,
kByUrlAndTitleAndPath,
kByUrlAndTitleAndPathAndUuid,
};
// Result of comparing two datasets for the purpose of logging metrics. Note
// that enum values listed first take precedence (are evaluated earlier) than
// those following.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused. Keep in sync with the homonym enum
// in tools/metrics/histograms/metadata/sync/enums.xml.
// Exposed in the header file for testing.
// LINT.IfChange(BookmarkSetComparisonOutcome)
enum class SetComparisonOutcome {
kBothEmpty = 0,
kLocalDataEmpty = 1,
kAccountDataEmpty = 2,
kExactMatchNonEmpty = 3,
kLocalDataIsStrictSubsetOfAccountData = 4,
kIntersectionBetween99And100Percent = 5,
kIntersectionBetween95And99Percent = 6,
kIntersectionBetween90And95Percent = 7,
kIntersectionBetween50And90Percent = 8,
kIntersectionBetween10And50Percent = 9,
kIntersectionBelow10PercentExcludingZero = 10,
kIntersectionEmpty = 11,
kMaxValue = kIntersectionEmpty
};
// LINT.ThenChange(/tools/metrics/histograms/metadata/sync/enums.xml:BookmarkSetComparisonOutcome)
struct UrlOnly {
static constexpr GroupingKeyInfix kGroupingKeyInfix =
GroupingKeyInfix::kByUrl;
auto operator<=>(const UrlOnly&) const = default;
GURL url;
};
struct UrlAndTitle {
static constexpr GroupingKeyInfix kGroupingKeyInfix =
GroupingKeyInfix::kByUrlAndTitle;
auto operator<=>(const UrlAndTitle&) const = default;
GURL url;
std::u16string title;
};
struct UrlAndUuid {
static constexpr GroupingKeyInfix kGroupingKeyInfix =
GroupingKeyInfix::kByUrlAndUuid;
auto operator<=>(const UrlAndUuid&) const = default;
GURL url;
base::Uuid uuid;
};
struct UrlAndTitleAndPath {
static constexpr GroupingKeyInfix kGroupingKeyInfix =
GroupingKeyInfix::kByUrlAndTitleAndPath;
auto operator<=>(const UrlAndTitleAndPath&) const = default;
GURL url;
std::u16string title;
// Ancestor folder titles concatenated with '/'.
std::u16string path;
};
struct UrlAndTitleAndPathAndUuid {
static constexpr GroupingKeyInfix kGroupingKeyInfix =
GroupingKeyInfix::kByUrlAndTitleAndPathAndUuid;
UrlAndTitleAndPathAndUuid();
UrlAndTitleAndPathAndUuid(const GURL& url,
const std::u16string& title,
const std::u16string& path,
const base::Uuid& uuid);
UrlAndTitleAndPathAndUuid(const UrlAndTitleAndPathAndUuid&);
UrlAndTitleAndPathAndUuid(UrlAndTitleAndPathAndUuid&&);
~UrlAndTitleAndPathAndUuid();
UrlAndTitleAndPathAndUuid& operator=(const UrlAndTitleAndPathAndUuid&);
UrlAndTitleAndPathAndUuid& operator=(UrlAndTitleAndPathAndUuid&&);
auto operator<=>(const UrlAndTitleAndPathAndUuid&) const = default;
GURL url;
std::u16string title;
// Ancestor folder titles concatenated with '/'.
std::u16string path;
base::Uuid uuid;
};
// Test-only functions to verify the logic related to extracting local data.
base::flat_set<UrlOnly> ExtractUniqueLocalNodesByUrlForTesting(
const BookmarkModelView& all_local_data,
SubtreeSelection subtree_selection);
base::flat_set<UrlAndTitle> ExtractUniqueLocalNodesByUrlAndTitleForTesting(
const BookmarkModelView& all_local_data,
SubtreeSelection subtree_selection);
base::flat_set<UrlAndUuid> ExtractUniqueLocalNodesByUrlAndUuidForTesting(
const BookmarkModelView& all_local_data,
SubtreeSelection subtree_selection);
base::flat_set<UrlAndTitleAndPath>
ExtractUniqueLocalNodesByUrlAndTitleAndPathForTesting(
const BookmarkModelView& all_local_data,
SubtreeSelection subtree_selection);
base::flat_set<UrlAndTitleAndPathAndUuid>
ExtractUniqueLocalNodesByUrlAndTitleAndPathAndUuidForTesting(
const BookmarkModelView& all_local_data,
SubtreeSelection subtree_selection);
// Test-only functions to verify the logic related to extracting account data.
base::flat_set<UrlOnly> ExtractUniqueAccountNodesByUrlForTesting(
const BookmarkModelMerger::RemoteForest& all_account_data,
SubtreeSelection subtree_selection);
base::flat_set<UrlAndTitle> ExtractUniqueAccountNodesByUrlAndTitleForTesting(
const BookmarkModelMerger::RemoteForest& all_account_data,
SubtreeSelection subtree_selection);
base::flat_set<UrlAndUuid> ExtractUniqueAccountNodesByUrlAndUuidForTesting(
const BookmarkModelMerger::RemoteForest& all_account_data,
SubtreeSelection subtree_selection);
base::flat_set<UrlAndTitleAndPath>
ExtractUniqueAccountNodesByUrlAndTitleAndPathForTesting(
const BookmarkModelMerger::RemoteForest& all_account_data,
SubtreeSelection subtree_selection);
base::flat_set<UrlAndTitleAndPathAndUuid>
ExtractUniqueAccountNodesByUrlAndTitleAndPathAndUuidForTesting(
const BookmarkModelMerger::RemoteForest& all_account_data,
SubtreeSelection subtree_selection);
// Test-only function to compare two sets.
SetComparisonOutcome CompareSetsForTesting(
const base::flat_set<int>& account_data,
const base::flat_set<int>& local_data);
void CompareBookmarkModelAndLogHistograms(
const BookmarkModelView& all_local_data,
const BookmarkModelMerger::RemoteForest& all_account_data,
syncer::PreviouslySyncingGaiaIdInfoForMetrics
previously_syncing_gaia_id_info);
} // namespace metrics
} // namespace sync_bookmarks
#endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_MODEL_MERGER_COMPARISON_METRICS_H_
|