#include "components/sync/model/client_tag_based_data_type_processor.h"
#include <optional>
#include <set>
#include <utility>
#include <vector>
#include "base/auto_reset.h"
#include "base/debug/alias.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/sequenced_task_runner.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "base/trace_event/trace_event.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/data_type_histogram.h"
#include "components/sync/base/hash_util.h"
#include "components/sync/base/time.h"
#include "components/sync/base/unique_position.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/client_tag_based_remote_update_handler.h"
#include "components/sync/model/data_type_local_change_processor.h"
#include "components/sync/model/processor_entity.h"
#include "components/sync/model/type_entities_count.h"
#include "components/sync/protocol/data_type_state.pb.h"
#include "components/sync/protocol/data_type_state_helper.h"
#include "components/sync/protocol/entity_data.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/proto_value_conversions.h"
#include "components/sync/protocol/unique_position.pb.h"
namespace syncer {
namespace {
const char kErrorSiteHistogramPrefix[] = …;
size_t CountDuplicateClientTags(const EntityMetadataMap& metadata_map) { … }
void RecordDataTypeNumUnsyncedEntitiesOnModelReady(
DataType data_type,
const ProcessorEntityTracker& entity_tracker) { … }
bool ShouldReuseTrackedUniquePositionFor(const ProcessorEntity* target_entity,
const UniquePosition& position_before,
const UniquePosition& position_after) { … }
}
ClientTagBasedDataTypeProcessor::ClientTagBasedDataTypeProcessor(
DataType type,
const base::RepeatingClosure& dump_stack)
: … { … }
ClientTagBasedDataTypeProcessor::~ClientTagBasedDataTypeProcessor() { … }
void ClientTagBasedDataTypeProcessor::OnSyncStarting(
const DataTypeActivationRequest& request,
StartCallback start_callback) { … }
void ClientTagBasedDataTypeProcessor::OnModelStarting(
DataTypeSyncBridge* bridge) { … }
void ClientTagBasedDataTypeProcessor::ModelReadyToSync(
std::unique_ptr<MetadataBatch> batch) { … }
bool ClientTagBasedDataTypeProcessor::IsAllowingChanges() const { … }
void ClientTagBasedDataTypeProcessor::ConnectIfReady() { … }
bool ClientTagBasedDataTypeProcessor::IsConnected() const { … }
void ClientTagBasedDataTypeProcessor::OnSyncStopping(
SyncStopMetadataFate metadata_fate) { … }
void ClientTagBasedDataTypeProcessor::ClearAllTrackedMetadataAndResetState() { … }
void ClientTagBasedDataTypeProcessor::ClearAllProvidedMetadataAndResetState(
const EntityMetadataMap& metadata_map) { … }
void ClientTagBasedDataTypeProcessor::ClearAllMetadataAndResetStateImpl(
std::unique_ptr<MetadataChangeList> change_list) { … }
bool ClientTagBasedDataTypeProcessor::IsTrackingMetadata() const { … }
std::string ClientTagBasedDataTypeProcessor::TrackedAccountId() const { … }
std::string ClientTagBasedDataTypeProcessor::TrackedCacheGuid() const { … }
void ClientTagBasedDataTypeProcessor::ReportError(const ModelError& error) { … }
void ClientTagBasedDataTypeProcessor::ReportErrorImpl(const ModelError& error,
ErrorSite site) { … }
std::optional<ModelError> ClientTagBasedDataTypeProcessor::GetError() const { … }
base::WeakPtr<DataTypeControllerDelegate>
ClientTagBasedDataTypeProcessor::GetControllerDelegate() { … }
void ClientTagBasedDataTypeProcessor::ConnectSync(
std::unique_ptr<CommitQueue> worker) { … }
void ClientTagBasedDataTypeProcessor::DisconnectSync() { … }
void ClientTagBasedDataTypeProcessor::Put(
const std::string& storage_key,
std::unique_ptr<EntityData> data,
MetadataChangeList* metadata_change_list) { … }
void ClientTagBasedDataTypeProcessor::Delete(
const std::string& storage_key,
const DeletionOrigin& origin,
MetadataChangeList* metadata_change_list) { … }
void ClientTagBasedDataTypeProcessor::UpdateStorageKey(
const EntityData& entity_data,
const std::string& storage_key,
MetadataChangeList* metadata_change_list) { … }
void ClientTagBasedDataTypeProcessor::UntrackEntityForStorageKey(
const std::string& storage_key) { … }
void ClientTagBasedDataTypeProcessor::UntrackEntityForClientTagHash(
const ClientTagHash& client_tag_hash) { … }
std::vector<std::string>
ClientTagBasedDataTypeProcessor::GetAllTrackedStorageKeys() const { … }
bool ClientTagBasedDataTypeProcessor::IsEntityUnsynced(
const std::string& storage_key) const { … }
base::Time ClientTagBasedDataTypeProcessor::GetEntityCreationTime(
const std::string& storage_key) const { … }
base::Time ClientTagBasedDataTypeProcessor::GetEntityModificationTime(
const std::string& storage_key) const { … }
void ClientTagBasedDataTypeProcessor::NudgeForCommitIfNeeded() { … }
void ClientTagBasedDataTypeProcessor::GetLocalChanges(
size_t max_entries,
GetLocalChangesCallback callback) { … }
void ClientTagBasedDataTypeProcessor::OnCommitCompleted(
const sync_pb::DataTypeState& data_type_state,
const CommitResponseDataList& committed_response_list,
const FailedCommitResponseDataList& error_response_list) { … }
bool HasClearAllDirective(
const std::optional<sync_pb::GarbageCollectionDirective>& gc_directive) { … }
void ClientTagBasedDataTypeProcessor::OnCommitFailed(
SyncCommitError commit_error) { … }
void ClientTagBasedDataTypeProcessor::OnUpdateReceived(
const sync_pb::DataTypeState& data_type_state,
UpdateResponseDataList updates,
std::optional<sync_pb::GarbageCollectionDirective> gc_directive) { … }
void ClientTagBasedDataTypeProcessor::StorePendingInvalidations(
std::vector<sync_pb::DataTypeState::Invalidation> invalidations_to_store) { … }
bool ClientTagBasedDataTypeProcessor::ValidateUpdate(
const sync_pb::DataTypeState& data_type_state,
const UpdateResponseDataList& updates,
const std::optional<sync_pb::GarbageCollectionDirective>& gc_directive) { … }
std::optional<ModelError> ClientTagBasedDataTypeProcessor::OnFullUpdateReceived(
const sync_pb::DataTypeState& data_type_state,
UpdateResponseDataList updates,
std::optional<sync_pb::GarbageCollectionDirective> gc_directive) { … }
std::optional<ModelError>
ClientTagBasedDataTypeProcessor::OnIncrementalUpdateReceived(
const sync_pb::DataTypeState& data_type_state,
UpdateResponseDataList updates,
std::optional<sync_pb::GarbageCollectionDirective> gc_directive) { … }
void ClientTagBasedDataTypeProcessor::ConsumeDataBatch(
std::unordered_set<std::string> storage_keys_to_load,
std::unique_ptr<DataBatch> data_batch) { … }
void ClientTagBasedDataTypeProcessor::CommitLocalChanges(
size_t max_entries,
GetLocalChangesCallback callback) { … }
size_t ClientTagBasedDataTypeProcessor::EstimateMemoryUsage() const { … }
bool ClientTagBasedDataTypeProcessor::HasLocalChangesForTest() const { … }
bool ClientTagBasedDataTypeProcessor::IsTrackingEntityForTest(
const std::string& storage_key) const { … }
bool ClientTagBasedDataTypeProcessor::IsModelReadyToSyncForTest() const { … }
void ClientTagBasedDataTypeProcessor::ExpireAllEntries(
MetadataChangeList* metadata_changes) { … }
void ClientTagBasedDataTypeProcessor::RemoveEntity(
const std::string& storage_key,
MetadataChangeList* metadata_change_list) { … }
void ClientTagBasedDataTypeProcessor::ResetState(
SyncStopMetadataFate metadata_fate) { … }
void ClientTagBasedDataTypeProcessor::HasUnsyncedData(
base::OnceCallback<void(bool)> callback) { … }
void ClientTagBasedDataTypeProcessor::GetAllNodesForDebugging(
AllNodesCallback callback) { … }
bool ClientTagBasedDataTypeProcessor::ClearPersistedMetadataIfInvalid(
const MetadataBatch& metadata) { … }
void ClientTagBasedDataTypeProcessor::
ClearPersistedMetadataIfInconsistentWithActivationRequest() { … }
void ClientTagBasedDataTypeProcessor::GetTypeEntitiesCountForDebugging(
base::OnceCallback<void(const TypeEntitiesCount&)> callback) const { … }
void ClientTagBasedDataTypeProcessor::RecordMemoryUsageAndCountsHistograms() { … }
const sync_pb::EntitySpecifics&
ClientTagBasedDataTypeProcessor::GetPossiblyTrimmedRemoteSpecifics(
const std::string& storage_key) const { … }
sync_pb::UniquePosition ClientTagBasedDataTypeProcessor::UniquePositionAfter(
const std::string& storage_key_before,
const ClientTagHash& target_client_tag_hash) const { … }
sync_pb::UniquePosition ClientTagBasedDataTypeProcessor::UniquePositionBefore(
const std::string& storage_key_after,
const ClientTagHash& target_client_tag_hash) const { … }
sync_pb::UniquePosition ClientTagBasedDataTypeProcessor::UniquePositionBetween(
const std::string& storage_key_before,
const std::string& storage_key_after,
const ClientTagHash& target_client_tag_hash) const { … }
sync_pb::UniquePosition
ClientTagBasedDataTypeProcessor::UniquePositionForInitialEntity(
const ClientTagHash& target_client_tag_hash) const { … }
sync_pb::UniquePosition
ClientTagBasedDataTypeProcessor::GetUniquePositionForStorageKey(
const std::string& storage_key) const { … }
base::WeakPtr<DataTypeLocalChangeProcessor>
ClientTagBasedDataTypeProcessor::GetWeakPtr() { … }
void ClientTagBasedDataTypeProcessor::ClearMetadataIfStopped() { … }
void ClientTagBasedDataTypeProcessor::ReportBridgeErrorForTest() { … }
}