Commit 31940f63 authored by siyua's avatar siyua Committed by Commit Bot

[Autofill CloudToken] Modify AutofillWalletSpecifics proto

Move cloud token data out of WalletMaskedCreditCard and make it a
separate sync data type.

Reason is: In the future, one actual card can have multiple sets of
cloud token data so we need to change this field to a repeated one,
but converting a sync data type with repeated field to data that
can be stored in the autofill table is pretty complex. There is no reason
to do that since the cloud token data will be stored in a separate table
anyway. As long as there is a server id that can be used to match the
actual card and the cloud token data of the card, we should be fine.

Bug: 1020740
Change-Id: I1595d3dccf2b154b3fcaea59e710b75d07a692ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1897004
Commit-Queue: Siyu An <siyua@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Reviewed-by: default avatarChristos Froussios <cfroussios@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714075}
parent 5d489a14
......@@ -367,6 +367,9 @@ void PopulateWalletTypesFromSyncData(
customer_data->push_back(
CustomerDataFromSpecifics(autofill_specifics.customer_data()));
break;
case sync_pb::AutofillWalletSpecifics::CREDIT_CARD_CLOUD_TOKEN_DATA:
// TODO(crbug.com/1020740): Implement this type.
break;
case sync_pb::AutofillWalletSpecifics::UNKNOWN:
// Just ignore new entry types that the client doesn't know about.
break;
......
......@@ -46,6 +46,8 @@ std::string GetSpecificsIdFromAutofillWalletSpecifics(
return specifics.address().id();
case AutofillWalletSpecifics::CUSTOMER_DATA:
return specifics.customer_data().id();
case AutofillWalletSpecifics::CREDIT_CARD_CLOUD_TOKEN_DATA:
return specifics.cloud_token_data().masked_card_id();
case AutofillWalletSpecifics::UNKNOWN:
NOTREACHED();
return std::string();
......
......@@ -143,6 +143,10 @@ std::string AutofillWalletSpecificsAsDebugString(
case sync_pb::AutofillWalletSpecifics_WalletInfoType::
AutofillWalletSpecifics_WalletInfoType_CUSTOMER_DATA:
return "CustomerData";
case sync_pb::AutofillWalletSpecifics_WalletInfoType::
AutofillWalletSpecifics_WalletInfoType_CREDIT_CARD_CLOUD_TOKEN_DATA:
// TODO(crbug.com/1020740): Implement for this type.
return "CloudTokenData";
case sync_pb::AutofillWalletSpecifics_WalletInfoType::
AutofillWalletSpecifics_WalletInfoType_UNKNOWN:
return "Unknown";
......
......@@ -86,6 +86,8 @@ message AutofillSpecifics {
// optional AutofillCreditCardSpecifics deprecated_credit_card = 6;
}
// TODO(crbug.com/1020740): Deprecated, remove this once dependent change is
// done. Use WalletCreditCardCloudTokenData instead.
message CloudTokenData {
// Last 4-5 digits of the Cloud Primary Account Number (CPAN).
optional string suffix = 1;
......@@ -158,7 +160,10 @@ message WalletMaskedCreditCard {
// Issuing Bank name which is internationalized (e.g. "Chase", "工商银行")
optional string bank_name = 10;
// This field will be set if a cloud token is available for the instrument.
// TODO(crbug.com/1020740): Deprecated, remove this once dependent change is
// done.
// Use WalletCreditCardCloudTokenData instead. This field will be set if
// a cloud token is available for the instrument.
optional CloudTokenData cloud_token_data = 11;
}
......@@ -209,12 +214,38 @@ message PaymentsCustomerData {
optional string id = 1;
}
// Contains information about the cloud token data of server credit cards.
message WalletCreditCardCloudTokenData {
// Server-generated ID string for the card this cloud token data is related
// to. This should match the id in WalletMaskedCreditCard for to fetch the
// corresponding actual card data. Note this is not unique across all cloud
// token data, which means one card can have multiple sets of cloud token data
// with the same masked_card_id.
optional string masked_card_id = 1;
// Last 4-5 digits of the Cloud Primary Account Number (CPAN).
optional string suffix = 2;
// CPAN Month number 1-12.
optional int32 exp_month = 3;
// CPAN Four-digit year (e.g. 2017).
optional int32 exp_year = 4;
// URL of the card art to be displayed for CPAN.
optional string art_fife_url = 5;
// Opaque identifier for the cloud token.
optional string instrument_token = 6;
}
message AutofillWalletSpecifics {
enum WalletInfoType {
UNKNOWN = 0;
MASKED_CREDIT_CARD = 1;
POSTAL_ADDRESS = 2;
CUSTOMER_DATA = 3;
CREDIT_CARD_CLOUD_TOKEN_DATA = 4;
}
optional WalletInfoType type = 1;
......@@ -228,6 +259,10 @@ message AutofillWalletSpecifics {
// This field exists if and only if the "type" field equals to CUSTOMER_DATA.
optional PaymentsCustomerData customer_data = 4;
// This field exists if and only if the "type" field equals to
// CREDIT_CARD_CLOUD_TOKEN_DATA.
optional WalletCreditCardCloudTokenData cloud_token_data = 5;
}
// Wallet card and address usage information that can be synced.
......
......@@ -48,12 +48,13 @@ 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,
CUSTOMER_DATA);
CREDIT_CARD_CLOUD_TOKEN_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);
ENUM_CASE(sync_pb::AutofillWalletSpecifics, CREDIT_CARD_CLOUD_TOKEN_DATA);
}
NOTREACHED();
return "";
......
......@@ -217,6 +217,10 @@ class ToValueVisitor {
if (proto.type() != sync_pb::AutofillWalletSpecifics::CUSTOMER_DATA) {
value->Remove("customer_data", nullptr);
}
if (proto.type() !=
sync_pb::AutofillWalletSpecifics::CREDIT_CARD_CLOUD_TOKEN_DATA) {
value->Remove("cloud_token_data", nullptr);
}
return value;
}
......@@ -354,6 +358,7 @@ IMPLEMENT_PROTO_TO_VALUE(TypedUrlSpecifics)
IMPLEMENT_PROTO_TO_VALUE(UrlDirective)
IMPLEMENT_PROTO_TO_VALUE(UserConsentSpecifics)
IMPLEMENT_PROTO_TO_VALUE(UserEventSpecifics)
IMPLEMENT_PROTO_TO_VALUE(WalletCreditCardCloudTokenData)
IMPLEMENT_PROTO_TO_VALUE(WalletMaskedCreditCard)
IMPLEMENT_PROTO_TO_VALUE(WalletMetadataSpecifics)
IMPLEMENT_PROTO_TO_VALUE(WalletPostalAddress)
......
......@@ -69,6 +69,7 @@ class TypedUrlSpecifics;
class UrlDirective;
class UserConsentSpecifics;
class UserEventSpecifics;
class WalletCreditCardCloudTokenData;
class WalletMaskedCreditCard;
class WalletMetadataSpecifics;
class WalletPostalAddress;
......@@ -249,6 +250,9 @@ std::unique_ptr<base::DictionaryValue> UserConsentSpecificsToValue(
std::unique_ptr<base::DictionaryValue> UserEventSpecificsToValue(
const sync_pb::UserEventSpecifics& user_event_specifics);
std::unique_ptr<base::DictionaryValue> WalletCreditCardCloudTokenDataToValue(
const sync_pb::WalletCreditCardCloudTokenData& cloud_token_data);
std::unique_ptr<base::DictionaryValue> WalletMaskedCreditCardToValue(
const sync_pb::WalletMaskedCreditCard& wallet_masked_card);
......
......@@ -139,30 +139,43 @@ TEST(ProtoValueConversionsTest, AutofillWalletSpecificsToValue) {
specifics.mutable_masked_card()->set_name_on_card("Igloo");
specifics.mutable_address()->set_recipient_name("John");
specifics.mutable_customer_data()->set_id("123456");
specifics.mutable_cloud_token_data()->set_masked_card_id("1111");
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));
EXPECT_FALSE(value->Get("cloud_token_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));
EXPECT_FALSE(value->Get("cloud_token_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));
EXPECT_FALSE(value->Get("cloud_token_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));
EXPECT_FALSE(value->Get("cloud_token_data", nullptr));
specifics.set_type(
sync_pb::AutofillWalletSpecifics::CREDIT_CARD_CLOUD_TOKEN_DATA);
value = AutofillWalletSpecificsToValue(specifics);
EXPECT_FALSE(value->Get("masked_card", nullptr));
EXPECT_FALSE(value->Get("address", nullptr));
EXPECT_FALSE(value->Get("customer_data", nullptr));
EXPECT_TRUE(value->Get("cloud_token_data", nullptr));
}
TEST(ProtoValueConversionsTest, BookmarkSpecificsData) {
......
......@@ -173,6 +173,7 @@ VISIT_PROTO_FIELDS(const sync_pb::AutofillWalletSpecifics& proto) {
VISIT(masked_card);
VISIT(address);
VISIT(customer_data);
VISIT(cloud_token_data);
}
VISIT_PROTO_FIELDS(const sync_pb::BookmarkSpecifics& proto) {
......@@ -1078,6 +1079,15 @@ VISIT_PROTO_FIELDS(const sync_pb::PaymentsCustomerData& proto) {
VISIT(id);
}
VISIT_PROTO_FIELDS(const sync_pb::WalletCreditCardCloudTokenData& proto) {
VISIT(masked_card_id);
VISIT(suffix);
VISIT(exp_month);
VISIT(exp_year);
VISIT(art_fife_url);
VISIT(instrument_token);
}
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