#include "components/sync_bookmarks/synced_bookmark_tracker.h"
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "base/base64.h"
#include "base/hash/hash.h"
#include "base/hash/sha1.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "base/uuid.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/sync/base/deletion_origin.h"
#include "components/sync/base/time.h"
#include "components/sync/protocol/bookmark_model_metadata.pb.h"
#include "components/sync/protocol/data_type_state_helper.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/proto_memory_estimations.h"
#include "components/sync/protocol/unique_position.pb.h"
#include "components/sync_bookmarks/bookmark_model_view.h"
#include "components/sync_bookmarks/switches.h"
#include "components/sync_bookmarks/synced_bookmark_tracker_entity.h"
#include "components/version_info/version_info.h"
#include "ui/base/models/tree_node_iterator.h"
namespace sync_bookmarks {
namespace {
void HashSpecifics(const sync_pb::EntitySpecifics& specifics,
std::string* hash) { … }
std::unordered_map<int64_t, const bookmarks::BookmarkNode*>
BuildIdToBookmarkNodeMap(const BookmarkModelView* model) { … }
}
syncer::ClientTagHash SyncedBookmarkTracker::GetClientTagHashFromUuid(
const base::Uuid& uuid) { … }
std::unique_ptr<SyncedBookmarkTracker> SyncedBookmarkTracker::CreateEmpty(
sync_pb::DataTypeState data_type_state) { … }
std::unique_ptr<SyncedBookmarkTracker>
SyncedBookmarkTracker::CreateFromBookmarkModelAndMetadata(
const BookmarkModelView* model,
sync_pb::BookmarkModelMetadata model_metadata) { … }
SyncedBookmarkTracker::~SyncedBookmarkTracker() = default;
void SyncedBookmarkTracker::SetBookmarksReuploaded() { … }
const SyncedBookmarkTrackerEntity* SyncedBookmarkTracker::GetEntityForSyncId(
const std::string& sync_id) const { … }
const SyncedBookmarkTrackerEntity*
SyncedBookmarkTracker::GetEntityForClientTagHash(
const syncer::ClientTagHash& client_tag_hash) const { … }
const SyncedBookmarkTrackerEntity* SyncedBookmarkTracker::GetEntityForUuid(
const base::Uuid& uuid) const { … }
SyncedBookmarkTrackerEntity* SyncedBookmarkTracker::AsMutableEntity(
const SyncedBookmarkTrackerEntity* entity) { … }
const SyncedBookmarkTrackerEntity*
SyncedBookmarkTracker::GetEntityForBookmarkNode(
const bookmarks::BookmarkNode* node) const { … }
const SyncedBookmarkTrackerEntity* SyncedBookmarkTracker::Add(
const bookmarks::BookmarkNode* bookmark_node,
const std::string& sync_id,
int64_t server_version,
base::Time creation_time,
const sync_pb::EntitySpecifics& specifics) { … }
void SyncedBookmarkTracker::Update(const SyncedBookmarkTrackerEntity* entity,
int64_t server_version,
base::Time modification_time,
const sync_pb::EntitySpecifics& specifics) { … }
void SyncedBookmarkTracker::UpdateServerVersion(
const SyncedBookmarkTrackerEntity* entity,
int64_t server_version) { … }
void SyncedBookmarkTracker::MarkCommitMayHaveStarted(
const SyncedBookmarkTrackerEntity* entity) { … }
void SyncedBookmarkTracker::MarkDeleted(
const SyncedBookmarkTrackerEntity* entity,
const base::Location& location) { … }
void SyncedBookmarkTracker::Remove(const SyncedBookmarkTrackerEntity* entity) { … }
void SyncedBookmarkTracker::IncrementSequenceNumber(
const SyncedBookmarkTrackerEntity* entity) { … }
sync_pb::BookmarkModelMetadata
SyncedBookmarkTracker::BuildBookmarkModelMetadata() const { … }
bool SyncedBookmarkTracker::HasLocalChanges() const { … }
std::vector<const SyncedBookmarkTrackerEntity*>
SyncedBookmarkTracker::GetAllEntities() const { … }
std::vector<const SyncedBookmarkTrackerEntity*>
SyncedBookmarkTracker::GetEntitiesWithLocalChanges() const { … }
SyncedBookmarkTracker::SyncedBookmarkTracker(
sync_pb::DataTypeState data_type_state,
bool bookmarks_reuploaded,
std::optional<int64_t> num_ignored_updates_due_to_missing_parent,
std::optional<int64_t>
max_version_among_ignored_updates_due_to_missing_parent)
: … { … }
SyncedBookmarkTracker::CorruptionReason
SyncedBookmarkTracker::InitEntitiesFromModelAndMetadata(
const BookmarkModelView* model,
sync_pb::BookmarkModelMetadata model_metadata) { … }
std::vector<const SyncedBookmarkTrackerEntity*>
SyncedBookmarkTracker::ReorderUnsyncedEntitiesExceptDeletions(
const std::vector<const SyncedBookmarkTrackerEntity*>& entities) const { … }
bool SyncedBookmarkTracker::ReuploadBookmarksOnLoadIfNeeded() { … }
void SyncedBookmarkTracker::RecordIgnoredServerUpdateDueToMissingParent(
int64_t server_version) { … }
std::optional<int64_t>
SyncedBookmarkTracker::GetNumIgnoredUpdatesDueToMissingParentForTest() const { … }
std::optional<int64_t> SyncedBookmarkTracker::
GetMaxVersionAmongIgnoredUpdatesDueToMissingParentForTest() const { … }
void SyncedBookmarkTracker::TraverseAndAppend(
const bookmarks::BookmarkNode* node,
std::vector<const SyncedBookmarkTrackerEntity*>* ordered_entities) const { … }
void SyncedBookmarkTracker::UpdateUponCommitResponse(
const SyncedBookmarkTrackerEntity* entity,
const std::string& sync_id,
int64_t server_version,
int64_t acked_sequence_number) { … }
void SyncedBookmarkTracker::UpdateSyncIdIfNeeded(
const SyncedBookmarkTrackerEntity* entity,
const std::string& sync_id) { … }
void SyncedBookmarkTracker::UndeleteTombstoneForBookmarkNode(
const SyncedBookmarkTrackerEntity* entity,
const bookmarks::BookmarkNode* node) { … }
void SyncedBookmarkTracker::AckSequenceNumber(
const SyncedBookmarkTrackerEntity* entity) { … }
bool SyncedBookmarkTracker::IsEmpty() const { … }
size_t SyncedBookmarkTracker::EstimateMemoryUsage() const { … }
size_t SyncedBookmarkTracker::TrackedBookmarksCount() const { … }
size_t SyncedBookmarkTracker::TrackedUncommittedTombstonesCount() const { … }
size_t SyncedBookmarkTracker::TrackedEntitiesCountForTest() const { … }
void SyncedBookmarkTracker::ClearSpecificsHashForTest(
const SyncedBookmarkTrackerEntity* entity) { … }
void SyncedBookmarkTracker::CheckAllNodesTracked(
const BookmarkModelView* bookmark_model) const { … }
}