Commit b1874334 authored by sebsg's avatar sebsg Committed by Commit Bot

[Sync] Fix an encoding issue that caused sync-internals to crash.

Some of the ids comming from payments needed to be converted before
they could be displayed.

This should only affect the sync internals page, no feature code.

Bug: 879556
Change-Id: I423580564574ea5f883044d4a4e08bf0e8c9b1e7
Reviewed-on: https://chromium-review.googlesource.com/1205192
Commit-Queue: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarJan Krcal <jkrcal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589279}
parent 18605eed
......@@ -115,10 +115,14 @@ CreditCard::CardType CardTypeFromWalletCardClass(
} // namespace
std::string GetBase64EncodedServerId(const std::string& server_id) {
std::string encoded_id;
base::Base64Encode(server_id, &encoded_id);
return encoded_id;
}
std::string GetSpecificsIdForEntryServerId(const std::string& server_id) {
std::string specifics_id;
base::Base64Encode(server_id, &specifics_id);
return specifics_id;
return GetBase64EncodedServerId(server_id);
}
std::string GetStorageKeyForSpecificsId(const std::string& specifics_id) {
......
......@@ -18,6 +18,9 @@ class AutofillTable;
class CreditCard;
struct PaymentsCustomerData;
// Returns the specified |server_id| encoded in base 64.
std::string GetBase64EncodedServerId(const std::string& server_id);
// Returns the wallet specifics id for the specified |server_id|.
std::string GetSpecificsIdForEntryServerId(const std::string& server_id);
......
......@@ -146,14 +146,34 @@ void AutofillWalletSyncBridge::GetAllDataForDebugging(DataCallback callback) {
return;
}
// Convert all non base 64 strings so that they can be displayed properly.
auto batch = std::make_unique<syncer::MutableDataBatch>();
for (const std::unique_ptr<AutofillProfile>& entry : profiles) {
std::unique_ptr<EntityData> entity_data =
CreateEntityDataFromAutofillServerProfile(*entry);
sync_pb::WalletPostalAddress* wallet_address =
entity_data->specifics.mutable_autofill_wallet()->mutable_address();
wallet_address->set_id(GetBase64EncodedServerId(wallet_address->id()));
batch->Put(GetStorageKeyForEntryServerId(entry->server_id()),
CreateEntityDataFromAutofillServerProfile(*entry));
std::move(entity_data));
}
for (const std::unique_ptr<CreditCard>& entry : cards) {
std::unique_ptr<EntityData> entity_data = CreateEntityDataFromCard(*entry);
sync_pb::WalletMaskedCreditCard* wallet_card =
entity_data->specifics.mutable_autofill_wallet()->mutable_masked_card();
wallet_card->set_id(GetBase64EncodedServerId(wallet_card->id()));
// The billing address id might refer to a local profile guid which doesn't
// need to be encoded.
if (!base::IsStringUTF8(wallet_card->billing_address_id())) {
wallet_card->set_billing_address_id(
GetBase64EncodedServerId(wallet_card->billing_address_id()));
}
batch->Put(GetStorageKeyForEntryServerId(entry->server_id()),
CreateEntityDataFromCard(*entry));
std::move(entity_data));
}
if (customer_data) {
......@@ -198,6 +218,37 @@ AutofillWalletSyncBridge::ApplyStopSyncChanges(
return StopSyncResponse::kModelStillReadyToSync;
}
void AutofillWalletSyncBridge::GetAllDataForTesting(DataCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::vector<std::unique_ptr<AutofillProfile>> profiles;
std::vector<std::unique_ptr<CreditCard>> cards;
std::unique_ptr<PaymentsCustomerData> customer_data;
if (!GetAutofillTable()->GetServerProfiles(&profiles) ||
!GetAutofillTable()->GetServerCreditCards(&cards) ||
!GetAutofillTable()->GetPaymentsCustomerData(&customer_data)) {
change_processor()->ReportError(
{FROM_HERE, "Failed to load entries from table."});
return;
}
auto batch = std::make_unique<syncer::MutableDataBatch>();
for (const std::unique_ptr<AutofillProfile>& entry : profiles) {
batch->Put(GetStorageKeyForEntryServerId(entry->server_id()),
CreateEntityDataFromAutofillServerProfile(*entry));
}
for (const std::unique_ptr<CreditCard>& entry : cards) {
batch->Put(GetStorageKeyForEntryServerId(entry->server_id()),
CreateEntityDataFromCard(*entry));
}
if (customer_data) {
batch->Put(GetStorageKeyForEntryServerId(customer_data->customer_id),
CreateEntityDataFromPaymentsCustomerData(*customer_data));
}
std::move(callback).Run(std::move(batch));
}
void AutofillWalletSyncBridge::SetSyncData(
const syncer::EntityChangeList& entity_data) {
bool wallet_data_changed = false;
......
......@@ -67,6 +67,10 @@ class AutofillWalletSyncBridge : public base::SupportsUserData::Data,
std::unique_ptr<syncer::MetadataChangeList> delete_metadata_change_list)
override;
// Sends all Wallet Data to the |callback| and keeps all the strings in their
// original format.
void GetAllDataForTesting(DataCallback callback);
private:
struct AutofillWalletDiff {
int items_added = 0;
......
......@@ -243,7 +243,7 @@ class AutofillWalletSyncBridgeTest : public testing::Test {
std::vector<AutofillWalletSpecifics> data;
// Perform an async call synchronously for testing.
base::RunLoop loop;
bridge()->GetAllDataForDebugging(base::BindLambdaForTesting(
bridge()->GetAllDataForTesting(base::BindLambdaForTesting(
[&loop, &data](std::unique_ptr<DataBatch> batch) {
ExtractAutofillWalletSpecificsFromDataBatch(std::move(batch), &data);
loop.Quit();
......
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