#include "components/autofill/core/browser/webdata/payments/autofill_wallet_metadata_sync_bridge.h"
#include <map>
#include <optional>
#include <unordered_set>
#include <utility>
#include <vector>
#include "base/base64.h"
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/notreached.h"
#include "base/pickle.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/data_model/payments_metadata.h"
#include "components/autofill/core/browser/webdata/autofill_sync_metadata_table.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/browser/webdata/payments/payments_autofill_table.h"
#include "components/autofill/core/browser/webdata/payments/payments_sync_bridge_util.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/deletion_origin.h"
#include "components/sync/model/client_tag_based_data_type_processor.h"
#include "components/sync/model/mutable_data_batch.h"
#include "components/sync/model/sync_metadata_store_change_list.h"
#include "components/sync/protocol/entity_data.h"
namespace autofill {
namespace {
WalletMetadataSpecifics;
EntityChange;
EntityChangeList;
EntityData;
MetadataChangeList;
static int kAutofillWalletMetadataSyncBridgeUserDataKey = …;
std::string GetClientTagForSpecificsId(WalletMetadataSpecifics::Type type,
const std::string& specifics_id) { … }
std::string GetSpecificsIdForMetadataId(const std::string& metadata_id) { … }
std::string GetMetadataIdForSpecificsId(const std::string& specifics_id) { … }
std::string GetStorageKeyForWalletMetadataTypeAndId(
WalletMetadataSpecifics::Type type,
const std::string& metadata_id) { … }
struct TypeAndMetadataId { … };
TypeAndMetadataId ParseWalletMetadataStorageKey(
const std::string& storage_key) { … }
std::unique_ptr<EntityData> CreateEntityDataFromPaymentsMetadata(
WalletMetadataSpecifics::Type type,
const PaymentsMetadata& local_metadata) { … }
PaymentsMetadata CreatePaymentsMetadataFromWalletMetadataSpecifics(
const WalletMetadataSpecifics& specifics) { … }
bool HasLocalBillingAddress(const PaymentsMetadata& metadata) { … }
bool IsNewerBillingAddressEqualOrBetter(const PaymentsMetadata& older,
const PaymentsMetadata& newer) { … }
PaymentsMetadata MergeMetadata(WalletMetadataSpecifics::Type type,
const PaymentsMetadata& local,
const PaymentsMetadata& remote) { … }
bool IsMetadataWorthUpdating(PaymentsMetadata existing_entry,
PaymentsMetadata new_entry) { … }
bool IsAnyMetadataDeletable(
const std::map<std::string, PaymentsMetadata>& metadata_map) { … }
bool AddServerMetadata(PaymentsAutofillTable* table,
WalletMetadataSpecifics::Type type,
const PaymentsMetadata& metadata) { … }
bool RemoveServerMetadata(PaymentsAutofillTable* table,
WalletMetadataSpecifics::Type type,
const std::string& id) { … }
bool UpdateServerMetadata(PaymentsAutofillTable* table,
WalletMetadataSpecifics::Type type,
const PaymentsMetadata& metadata) { … }
bool IsSyncedWalletCard(const CreditCard& card) { … }
}
void AutofillWalletMetadataSyncBridge::CreateForWebDataServiceAndBackend(
const std::string& app_locale,
AutofillWebDataBackend* web_data_backend,
AutofillWebDataService* web_data_service) { … }
AutofillWalletMetadataSyncBridge*
AutofillWalletMetadataSyncBridge::FromWebDataService(
AutofillWebDataService* web_data_service) { … }
AutofillWalletMetadataSyncBridge::AutofillWalletMetadataSyncBridge(
std::unique_ptr<syncer::DataTypeLocalChangeProcessor> change_processor,
AutofillWebDataBackend* web_data_backend)
: … { … }
AutofillWalletMetadataSyncBridge::~AutofillWalletMetadataSyncBridge() { … }
std::unique_ptr<syncer::MetadataChangeList>
AutofillWalletMetadataSyncBridge::CreateMetadataChangeList() { … }
std::optional<syncer::ModelError>
AutofillWalletMetadataSyncBridge::MergeFullSyncData(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_data) { … }
std::optional<syncer::ModelError>
AutofillWalletMetadataSyncBridge::ApplyIncrementalSyncChanges(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_data) { … }
std::unique_ptr<syncer::DataBatch>
AutofillWalletMetadataSyncBridge::GetDataForCommit(
StorageKeyList storage_keys) { … }
std::unique_ptr<syncer::DataBatch>
AutofillWalletMetadataSyncBridge::GetAllDataForDebugging() { … }
std::string AutofillWalletMetadataSyncBridge::GetClientTag(
const syncer::EntityData& entity_data) { … }
std::string AutofillWalletMetadataSyncBridge::GetStorageKey(
const syncer::EntityData& entity_data) { … }
void AutofillWalletMetadataSyncBridge::ApplyDisableSyncChanges(
std::unique_ptr<syncer::MetadataChangeList> delete_metadata_change_list) { … }
void AutofillWalletMetadataSyncBridge::CreditCardChanged(
const CreditCardChange& change) { … }
void AutofillWalletMetadataSyncBridge::IbanChanged(const IbanChange& change) { … }
PaymentsAutofillTable* AutofillWalletMetadataSyncBridge::GetAutofillTable() { … }
AutofillSyncMetadataTable*
AutofillWalletMetadataSyncBridge::GetSyncMetadataStore() { … }
void AutofillWalletMetadataSyncBridge::LoadDataCacheAndMetadata() { … }
void AutofillWalletMetadataSyncBridge::DeleteOldOrphanMetadata() { … }
std::unique_ptr<syncer::DataBatch>
AutofillWalletMetadataSyncBridge::GetDataImpl(
std::optional<std::unordered_set<std::string>> storage_keys_set) { … }
void AutofillWalletMetadataSyncBridge::UploadInitialLocalData(
syncer::MetadataChangeList* metadata_change_list,
const syncer::EntityChangeList& entity_data) { … }
std::optional<syncer::ModelError>
AutofillWalletMetadataSyncBridge::MergeRemoteChanges(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_data) { … }
template <typename DataType, typename KeyType>
void AutofillWalletMetadataSyncBridge::LocalMetadataChanged(
WalletMetadataSpecifics::Type type,
AutofillDataModelChange<DataType, KeyType> change) { … }
}