#include "components/sync_bookmarks/bookmark_model_merger.h"
#include <algorithm>
#include <string>
#include <utility>
#include "base/containers/contains.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "base/uuid.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/bookmarks/browser/bookmark_uuids.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/hash_util.h"
#include "components/sync/protocol/bookmark_specifics.pb.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync_bookmarks/bookmark_model_view.h"
#include "components/sync_bookmarks/bookmark_specifics_conversions.h"
#include "components/sync_bookmarks/switches.h"
#include "components/sync_bookmarks/synced_bookmark_tracker.h"
#include "components/sync_bookmarks/synced_bookmark_tracker_entity.h"
#include "ui/base/models/tree_node_iterator.h"
EntityData;
UpdateResponseData;
UpdateResponseDataList;
namespace sync_bookmarks {
namespace {
static const size_t kInvalidIndex = …;
const char kBookmarkBarTag[] = …;
const char kMobileBookmarksTag[] = …;
const char kOtherBookmarksTag[] = …;
const size_t kMaxBookmarkTreeDepth = …;
UpdatesPerParentUuid;
enum class BookmarksUuidDuplicates { … };
enum class RemoteBookmarkUpdateError { … };
void LogProblematicBookmark(RemoteBookmarkUpdateError problem) { … }
void LogBookmarkReuploadNeeded(bool is_reupload_needed) { … }
const bookmarks::BookmarkNode* GetPermanentFolderForServerDefinedUniqueTag(
const BookmarkModelView* bookmark_model,
const std::string& server_defined_unique_tag) { … }
base::Uuid GetPermanentFolderUuidForServerDefinedUniqueTag(
const std::string& server_defined_unique_tag) { … }
std::string LegacyCanonicalizedTitleFromSpecifics(
const sync_pb::BookmarkSpecifics& specifics) { … }
bool NodeSemanticsMatch(const bookmarks::BookmarkNode* local_node,
const std::string& remote_canonicalized_title,
const GURL& remote_url,
sync_pb::BookmarkSpecifics::Type remote_type) { … }
BookmarksUuidDuplicates MatchBookmarksUuidDuplicates(
const UpdateResponseData& update,
const UpdateResponseData& duplicate_update) { … }
bool CompareDuplicateUpdates(const UpdateResponseData& next_update,
const UpdateResponseData& previous_update) { … }
void DeduplicateValidUpdatesByUuid(
UpdatesPerParentUuid* updates_per_parent_uuid) { … }
bool IsValidUpdate(const UpdateResponseData& update) { … }
base::Uuid GetUuidForUpdate(const UpdateResponseData& update) { … }
struct GroupedUpdates { … };
GroupedUpdates GroupValidUpdates(UpdateResponseDataList updates) { … }
int GetNumUnsyncedEntities(const SyncedBookmarkTracker* tracker) { … }
}
BookmarkModelMerger::RemoteTreeNode::RemoteTreeNode() = default;
BookmarkModelMerger::RemoteTreeNode::~RemoteTreeNode() = default;
BookmarkModelMerger::RemoteTreeNode::RemoteTreeNode(
BookmarkModelMerger::RemoteTreeNode&&) = default;
BookmarkModelMerger::RemoteTreeNode&
BookmarkModelMerger::RemoteTreeNode::operator=(
BookmarkModelMerger::RemoteTreeNode&&) = default;
void BookmarkModelMerger::RemoteTreeNode::EmplaceSelfAndDescendantsByUuid(
std::unordered_map<base::Uuid, const RemoteTreeNode*, base::UuidHash>*
uuid_to_remote_node_map) const { … }
bool BookmarkModelMerger::RemoteTreeNode::UniquePositionLessThan(
const RemoteTreeNode& lhs,
const RemoteTreeNode& rhs) { … }
BookmarkModelMerger::RemoteTreeNode
BookmarkModelMerger::RemoteTreeNode::BuildTree(
UpdateResponseData update,
size_t max_depth,
UpdatesPerParentUuid* updates_per_parent_uuid) { … }
BookmarkModelMerger::BookmarkModelMerger(
UpdateResponseDataList updates,
BookmarkModelView* bookmark_model,
favicon::FaviconService* favicon_service,
SyncedBookmarkTracker* bookmark_tracker)
: … { … }
BookmarkModelMerger::~BookmarkModelMerger() = default;
void BookmarkModelMerger::Merge() { … }
BookmarkModelMerger::RemoteForest BookmarkModelMerger::BuildRemoteForest(
syncer::UpdateResponseDataList updates,
SyncedBookmarkTracker* tracker_for_recording_ignored_updates) { … }
int BookmarkModelMerger::CountRemoteTreeNodeDescendantsForUma(
const RemoteTreeNode& node) { … }
std::unordered_map<base::Uuid, BookmarkModelMerger::GuidMatch, base::UuidHash>
BookmarkModelMerger::FindGuidMatchesOrReassignLocal(
const RemoteForest& remote_forest,
BookmarkModelView* bookmark_model) { … }
void BookmarkModelMerger::MergeSubtree(
const bookmarks::BookmarkNode* local_subtree_root,
const RemoteTreeNode& remote_node) { … }
const bookmarks::BookmarkNode* BookmarkModelMerger::FindMatchingLocalNode(
const RemoteTreeNode& remote_child,
const bookmarks::BookmarkNode* local_parent,
size_t local_child_start_index) const { … }
const bookmarks::BookmarkNode*
BookmarkModelMerger::UpdateBookmarkNodeFromSpecificsIncludingUuid(
const bookmarks::BookmarkNode* local_node,
const RemoteTreeNode& remote_node) { … }
void BookmarkModelMerger::ProcessRemoteCreation(
const RemoteTreeNode& remote_node,
const bookmarks::BookmarkNode* local_parent,
size_t index) { … }
void BookmarkModelMerger::ProcessLocalCreation(
const bookmarks::BookmarkNode* parent,
size_t index) { … }
size_t BookmarkModelMerger::FindMatchingChildBySemanticsStartingAt(
const RemoteTreeNode& remote_node,
const bookmarks::BookmarkNode* local_parent,
size_t starting_child_index) const { … }
const BookmarkModelMerger::RemoteTreeNode*
BookmarkModelMerger::FindMatchingRemoteNodeByUuid(
const bookmarks::BookmarkNode* local_node) const { … }
const bookmarks::BookmarkNode* BookmarkModelMerger::FindMatchingLocalNodeByUuid(
const RemoteTreeNode& remote_node) const { … }
syncer::UniquePosition
BookmarkModelMerger::GenerateUniquePositionForLocalCreation(
const bookmarks::BookmarkNode* parent,
size_t index,
const std::string& suffix) const { … }
void BookmarkModelMerger::ReportTimeMetrics() { … }
}