Commit 3b2eb593 authored by Mathieu Perreault's avatar Mathieu Perreault Committed by Commit Bot

[Sync] Autofill Specifics: Add the PaymentsCustomerData type

Will contain Payments account information, initially customer ID.

Bug: 870936
Test: none
Change-Id: I0b7310b4ed66f3f50af627f93bef8fb75d32bea0
Reviewed-on: https://chromium-review.googlesource.com/1162947
Commit-Queue: Mathieu Perreault <mathp@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580841}
parent 6c31ebb1
......@@ -29,6 +29,8 @@ std::string GetStorageKeyFromAutofillWalletSpecifics(
return specifics.masked_card().id();
case AutofillWalletSpecifics::POSTAL_ADDRESS:
return specifics.address().id();
case AutofillWalletSpecifics::CUSTOMER_DATA:
return specifics.customer_data().id();
case AutofillWalletSpecifics::UNKNOWN:
NOTREACHED();
return std::string();
......@@ -109,6 +111,8 @@ std::string AutofillWalletSyncBridge::GetClientTag(
return "address-" + GetStorageKey(entity_data);
case sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD:
return "card-" + GetStorageKey(entity_data);
case sync_pb::AutofillWalletSpecifics::CUSTOMER_DATA:
return "customer-" + GetStorageKey(entity_data);
case sync_pb::AutofillWalletSpecifics::UNKNOWN:
NOTREACHED();
return std::string();
......
......@@ -285,6 +285,7 @@ void AutofillWalletSyncableService::PopulateWalletCardsAndAddresses(
ids[autofill_specifics.address().id()] =
wallet_addresses->back().server_id();
break;
case sync_pb::AutofillWalletSpecifics::CUSTOMER_DATA:
case sync_pb::AutofillWalletSpecifics::UNKNOWN:
// Just ignore new entry types that the client doesn't know about.
break;
......
......@@ -175,11 +175,18 @@ message WalletPostalAddress {
optional string phone_number = 13;
}
// Contains information about a Payments Customer.
message PaymentsCustomerData {
// The billable customer ID associated with the account.
optional string id = 1;
}
message AutofillWalletSpecifics {
enum WalletInfoType {
UNKNOWN = 0;
MASKED_CREDIT_CARD = 1;
POSTAL_ADDRESS = 2;
CUSTOMER_DATA = 3;
}
optional WalletInfoType type = 1;
......@@ -190,6 +197,9 @@ message AutofillWalletSpecifics {
// This field exists if and only if the "type" field equals to ADDRESS.
optional WalletPostalAddress address = 3;
// This field exists if and only if the "type" field equals to CUSTOMER_DATA.
optional PaymentsCustomerData customer_data = 4;
}
// Wallet card and address usage information that can be synced.
......
......@@ -48,11 +48,12 @@ const char* ProtoEnumToString(sync_pb::AppSpecifics::LaunchType launch_type) {
const char* ProtoEnumToString(
sync_pb::AutofillWalletSpecifics::WalletInfoType wallet_info_type) {
ASSERT_ENUM_BOUNDS(sync_pb::AutofillWalletSpecifics, WalletInfoType, UNKNOWN,
POSTAL_ADDRESS);
CUSTOMER_DATA);
switch (wallet_info_type) {
ENUM_CASE(sync_pb::AutofillWalletSpecifics, UNKNOWN);
ENUM_CASE(sync_pb::AutofillWalletSpecifics, MASKED_CREDIT_CARD);
ENUM_CASE(sync_pb::AutofillWalletSpecifics, POSTAL_ADDRESS);
ENUM_CASE(sync_pb::AutofillWalletSpecifics, CUSTOMER_DATA);
}
NOTREACHED();
return "";
......
......@@ -214,6 +214,9 @@ class ToValueVisitor {
if (proto.type() != sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD) {
value->Remove("masked_card", nullptr);
}
if (proto.type() != sync_pb::AutofillWalletSpecifics::CUSTOMER_DATA) {
value->Remove("customer_data", nullptr);
}
return value;
}
......@@ -333,6 +336,7 @@ IMPLEMENT_PROTO_TO_VALUE(NavigationRedirect)
IMPLEMENT_PROTO_TO_VALUE(NigoriSpecifics)
IMPLEMENT_PROTO_TO_VALUE(PasswordSpecifics)
IMPLEMENT_PROTO_TO_VALUE(PasswordSpecificsData)
IMPLEMENT_PROTO_TO_VALUE(PaymentsCustomerData)
IMPLEMENT_PROTO_TO_VALUE(PreferenceSpecifics)
IMPLEMENT_PROTO_TO_VALUE(PrinterPPDReference)
IMPLEMENT_PROTO_TO_VALUE(PrinterSpecifics)
......
......@@ -51,6 +51,7 @@ class NavigationRedirect;
class NigoriSpecifics;
class PasswordSpecifics;
class PasswordSpecificsData;
class PaymentsCustomerData;
class PreferenceSpecifics;
class PrinterPPDReference;
class PrinterSpecifics;
......@@ -200,6 +201,9 @@ std::unique_ptr<base::DictionaryValue> PasswordSpecificsToValue(
std::unique_ptr<base::DictionaryValue> PasswordSpecificsDataToValue(
const sync_pb::PasswordSpecificsData& password_specifics_data);
std::unique_ptr<base::DictionaryValue> PaymentsCustomerDataToValue(
const sync_pb::PaymentsCustomerData& payments_customer_data);
std::unique_ptr<base::DictionaryValue> PreferenceSpecificsToValue(
const sync_pb::PreferenceSpecifics& password_specifics);
......
......@@ -142,21 +142,31 @@ TEST(ProtoValueConversionsTest, AutofillWalletSpecificsToValue) {
sync_pb::AutofillWalletSpecifics specifics;
specifics.mutable_masked_card()->set_name_on_card("Igloo");
specifics.mutable_address()->set_recipient_name("John");
specifics.mutable_customer_data()->set_id("123456");
specifics.set_type(sync_pb::AutofillWalletSpecifics::UNKNOWN);
auto value = AutofillWalletSpecificsToValue(specifics);
EXPECT_FALSE(value->Get("masked_card", nullptr));
EXPECT_FALSE(value->Get("address", nullptr));
EXPECT_FALSE(value->Get("customer_data", nullptr));
specifics.set_type(sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD);
value = AutofillWalletSpecificsToValue(specifics);
EXPECT_TRUE(value->Get("masked_card", nullptr));
EXPECT_FALSE(value->Get("address", nullptr));
EXPECT_FALSE(value->Get("customer_data", nullptr));
specifics.set_type(sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS);
value = AutofillWalletSpecificsToValue(specifics);
EXPECT_FALSE(value->Get("masked_card", nullptr));
EXPECT_TRUE(value->Get("address", nullptr));
EXPECT_FALSE(value->Get("customer_data", nullptr));
specifics.set_type(sync_pb::AutofillWalletSpecifics::CUSTOMER_DATA);
value = AutofillWalletSpecificsToValue(specifics);
EXPECT_FALSE(value->Get("masked_card", nullptr));
EXPECT_FALSE(value->Get("address", nullptr));
EXPECT_TRUE(value->Get("customer_data", nullptr));
}
TEST(ProtoValueConversionsTest, BookmarkSpecificsData) {
......
......@@ -188,6 +188,7 @@ VISIT_PROTO_FIELDS(const sync_pb::AutofillWalletSpecifics& proto) {
VISIT_ENUM(type);
VISIT(masked_card);
VISIT(address);
VISIT(customer_data);
}
VISIT_PROTO_FIELDS(const sync_pb::BookmarkSpecifics& proto) {
......@@ -1025,6 +1026,10 @@ VISIT_PROTO_FIELDS(const sync_pb::WalletPostalAddress& proto) {
VISIT(language_code);
}
VISIT_PROTO_FIELDS(const sync_pb::PaymentsCustomerData& proto) {
VISIT(id);
}
VISIT_PROTO_FIELDS(const sync_pb::WalletSyncFlags& proto) {
VISIT(enabled);
}
......
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