Commit f0eb5c25 authored by Siyu An's avatar Siyu An Committed by Commit Bot

[Autofill Offer] Handle metadata in offer sync bridge

1. Implemented CreateMetadataChangeList function.
2. Load metadata and notify processor ready to sync in the bridge
initializer.

Bug: 1112095
Change-Id: Id510d65145085d55676a4fc492e560fd194ac292
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2399818
Commit-Queue: Siyu An <siyua@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805488}
parent 49630b01
......@@ -9,8 +9,11 @@
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "components/autofill/core/browser/data_model/autofill_offer_data.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_backend.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/sync/model_impl/client_tag_based_model_type_processor.h"
#include "components/sync/model_impl/sync_metadata_store_change_list.h"
namespace autofill {
......@@ -56,16 +59,22 @@ syncer::ModelTypeSyncBridge* AutofillWalletOfferSyncBridge::FromWebDataService(
AutofillWalletOfferSyncBridge::AutofillWalletOfferSyncBridge(
std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor,
AutofillWebDataBackend* web_data_backend)
: ModelTypeSyncBridge(std::move(change_processor)) {
DCHECK(web_data_backend);
: ModelTypeSyncBridge(std::move(change_processor)),
web_data_backend_(web_data_backend) {
DCHECK(web_data_backend_);
LoadAutofillOfferMetadata();
}
AutofillWalletOfferSyncBridge::~AutofillWalletOfferSyncBridge() = default;
AutofillWalletOfferSyncBridge::~AutofillWalletOfferSyncBridge() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
std::unique_ptr<syncer::MetadataChangeList>
AutofillWalletOfferSyncBridge::CreateMetadataChangeList() {
NOTIMPLEMENTED();
return nullptr;
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return std::make_unique<syncer::SyncMetadataStoreChangeList>(
GetAutofillTable(), syncer::AUTOFILL_WALLET_OFFER);
}
base::Optional<syncer::ModelError> AutofillWalletOfferSyncBridge::MergeSyncData(
......@@ -116,4 +125,26 @@ void AutofillWalletOfferSyncBridge::ApplyStopSyncChanges(
NOTIMPLEMENTED();
}
AutofillTable* AutofillWalletOfferSyncBridge::GetAutofillTable() {
return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase());
}
void AutofillWalletOfferSyncBridge::LoadAutofillOfferMetadata() {
if (!web_data_backend_->GetDatabase() || !GetAutofillTable()) {
change_processor()->ReportError(
{FROM_HERE, "Failed to load Autofill table."});
return;
}
auto batch = std::make_unique<syncer::MetadataBatch>();
if (!GetAutofillTable()->GetAllSyncMetadata(syncer::AUTOFILL_WALLET_OFFER,
batch.get())) {
change_processor()->ReportError(
{FROM_HERE,
"Failed reading autofill offer metadata from WebDatabase."});
return;
}
change_processor()->ModelReadyToSync(std::move(batch));
}
} // namespace autofill
......@@ -16,7 +16,7 @@
#include "components/sync/model/model_type_sync_bridge.h"
namespace autofill {
class AutofillTable;
class AutofillWebDataBackend;
class AutofillWebDataService;
......@@ -62,6 +62,17 @@ class AutofillWalletOfferSyncBridge : public base::SupportsUserData::Data,
delete_metadata_change_list) override;
private:
// Returns the table associated with the |web_data_backend_|.
AutofillTable* GetAutofillTable();
// Synchronously load sync metadata from the autofill table and pass it to the
// processor so that it can start tracking changes.
void LoadAutofillOfferMetadata();
// AutofillWalletOfferSyncBridge is owned by |web_data_backend_| through
// SupportsUserData, so it's guaranteed to outlive |this|.
AutofillWebDataBackend* const web_data_backend_;
// The bridge should be used on the same sequence where it is constructed.
SEQUENCE_CHECKER(sequence_checker_);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment