#include "components/sync_bookmarks/bookmark_data_type_processor.h"
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/data_type_histogram.h"
#include "components/sync/base/time.h"
#include "components/sync/engine/commit_queue.h"
#include "components/sync/engine/data_type_activation_response.h"
#include "components/sync/engine/data_type_processor_metrics.h"
#include "components/sync/engine/data_type_processor_proxy.h"
#include "components/sync/model/data_type_activation_request.h"
#include "components/sync/model/type_entities_count.h"
#include "components/sync/protocol/bookmark_model_metadata.pb.h"
#include "components/sync/protocol/data_type_state.pb.h"
#include "components/sync/protocol/data_type_state_helper.h"
#include "components/sync/protocol/proto_value_conversions.h"
#include "components/sync_bookmarks/bookmark_local_changes_builder.h"
#include "components/sync_bookmarks/bookmark_model_merger.h"
#include "components/sync_bookmarks/bookmark_model_observer_impl.h"
#include "components/sync_bookmarks/bookmark_model_view.h"
#include "components/sync_bookmarks/bookmark_remote_updates_handler.h"
#include "components/sync_bookmarks/bookmark_specifics_conversions.h"
#include "components/sync_bookmarks/parent_guid_preprocessing.h"
#include "components/sync_bookmarks/synced_bookmark_tracker.h"
#include "components/sync_bookmarks/synced_bookmark_tracker_entity.h"
#include "components/undo/bookmark_undo_utils.h"
#include "ui/base/models/tree_node_iterator.h"
namespace sync_bookmarks {
namespace {
constexpr size_t kDefaultMaxBookmarksTillSyncEnabled = …;
class ScopedRemoteUpdateBookmarks { … };
std::string ComputeServerDefinedUniqueTagForDebugging(
const bookmarks::BookmarkNode* node,
BookmarkModelView* model) { … }
size_t CountSyncableBookmarksFromModel(BookmarkModelView* model) { … }
void RecordDataTypeNumUnsyncedEntitiesOnModelReadyForBookmarks(
const SyncedBookmarkTracker& tracker) { … }
}
BookmarkDataTypeProcessor::BookmarkDataTypeProcessor(
BookmarkUndoService* bookmark_undo_service,
syncer::WipeModelUponSyncDisabledBehavior
wipe_model_upon_sync_disabled_behavior)
: … { … }
BookmarkDataTypeProcessor::~BookmarkDataTypeProcessor() { … }
void BookmarkDataTypeProcessor::ConnectSync(
std::unique_ptr<syncer::CommitQueue> worker) { … }
void BookmarkDataTypeProcessor::DisconnectSync() { … }
void BookmarkDataTypeProcessor::GetLocalChanges(
size_t max_entries,
GetLocalChangesCallback callback) { … }
void BookmarkDataTypeProcessor::OnCommitCompleted(
const sync_pb::DataTypeState& type_state,
const syncer::CommitResponseDataList& committed_response_list,
const syncer::FailedCommitResponseDataList& error_response_list) { … }
void BookmarkDataTypeProcessor::OnUpdateReceived(
const sync_pb::DataTypeState& data_type_state,
syncer::UpdateResponseDataList updates,
std::optional<sync_pb::GarbageCollectionDirective> gc_directive) { … }
void BookmarkDataTypeProcessor::StorePendingInvalidations(
std::vector<sync_pb::DataTypeState::Invalidation> invalidations_to_store) { … }
bool BookmarkDataTypeProcessor::IsTrackingMetadata() const { … }
const SyncedBookmarkTracker* BookmarkDataTypeProcessor::GetTrackerForTest()
const { … }
bool BookmarkDataTypeProcessor::IsConnectedForTest() const { … }
std::string BookmarkDataTypeProcessor::EncodeSyncMetadata() const { … }
void BookmarkDataTypeProcessor::ModelReadyToSync(
const std::string& metadata_str,
const base::RepeatingClosure& schedule_save_closure,
BookmarkModelView* model) { … }
void BookmarkDataTypeProcessor::SetFaviconService(
favicon::FaviconService* favicon_service) { … }
size_t BookmarkDataTypeProcessor::EstimateMemoryUsage() const { … }
base::WeakPtr<syncer::DataTypeControllerDelegate>
BookmarkDataTypeProcessor::GetWeakPtr() { … }
void BookmarkDataTypeProcessor::OnSyncStarting(
const syncer::DataTypeActivationRequest& request,
StartCallback start_callback) { … }
void BookmarkDataTypeProcessor::ConnectIfReady() { … }
void BookmarkDataTypeProcessor::OnSyncStopping(
syncer::SyncStopMetadataFate metadata_fate) { … }
void BookmarkDataTypeProcessor::NudgeForCommitIfNeeded() { … }
void BookmarkDataTypeProcessor::OnBookmarkModelBeingDeleted() { … }
void BookmarkDataTypeProcessor::OnInitialUpdateReceived(
const sync_pb::DataTypeState& data_type_state,
syncer::UpdateResponseDataList updates) { … }
void BookmarkDataTypeProcessor::StartTrackingMetadata() { … }
void BookmarkDataTypeProcessor::HasUnsyncedData(
base::OnceCallback<void(bool)> callback) { … }
void BookmarkDataTypeProcessor::GetAllNodesForDebugging(
AllNodesCallback callback) { … }
void BookmarkDataTypeProcessor::AppendNodeAndChildrenForDebugging(
const bookmarks::BookmarkNode* node,
int index,
base::Value::List* all_nodes) const { … }
void BookmarkDataTypeProcessor::GetTypeEntitiesCountForDebugging(
base::OnceCallback<void(const syncer::TypeEntitiesCount&)> callback) const { … }
void BookmarkDataTypeProcessor::RecordMemoryUsageAndCountsHistograms() { … }
void BookmarkDataTypeProcessor::SetMaxBookmarksTillSyncEnabledForTest(
size_t limit) { … }
void BookmarkDataTypeProcessor::ClearMetadataIfStopped() { … }
void BookmarkDataTypeProcessor::ReportBridgeErrorForTest() { … }
void BookmarkDataTypeProcessor::StopTrackingMetadataAndResetTracker() { … }
void BookmarkDataTypeProcessor::TriggerWipeModelUponSyncDisabledBehavior() { … }
}