Commit 9406a154 authored by Sujie Zhu's avatar Sujie Zhu Committed by Commit Bot

[AF][Nickname] Add nickname to credit card class

Add base::string16 nickname to credit card class. Also update Compare()
function (which is used in sync bridge to calculate the diff between
existing cards and new synced cards) to ensure that any updates on
nickname will be stored in autofill table.

We use base::string16 type because it's a UI string.

The follow up will be:
1. update masked_credit_card table schema with
nickname column
2. store the nickname from sync response.

Bug: 1059087
Change-Id: Ib01e30aa905559aee90608ddda702218d361d58b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2091716
Commit-Queue: Sujie Zhu <sujiezhu@google.com>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748336}
parent fca67456
...@@ -502,6 +502,7 @@ void CreditCard::operator=(const CreditCard& credit_card) { ...@@ -502,6 +502,7 @@ void CreditCard::operator=(const CreditCard& credit_card) {
bank_name_ = credit_card.bank_name_; bank_name_ = credit_card.bank_name_;
temp_card_first_name_ = credit_card.temp_card_first_name_; temp_card_first_name_ = credit_card.temp_card_first_name_;
temp_card_last_name_ = credit_card.temp_card_last_name_; temp_card_last_name_ = credit_card.temp_card_last_name_;
nickname_ = credit_card.nickname_;
set_guid(credit_card.guid()); set_guid(credit_card.guid());
set_origin(credit_card.origin()); set_origin(credit_card.origin());
...@@ -574,6 +575,10 @@ int CreditCard::Compare(const CreditCard& credit_card) const { ...@@ -574,6 +575,10 @@ int CreditCard::Compare(const CreditCard& credit_card) const {
if (comparison != 0) if (comparison != 0)
return comparison; return comparison;
comparison = nickname_.compare(credit_card.nickname_);
if (comparison != 0)
return comparison;
if (static_cast<int>(server_status_) < if (static_cast<int>(server_status_) <
static_cast<int>(credit_card.server_status_)) static_cast<int>(credit_card.server_status_))
return -1; return -1;
...@@ -923,7 +928,8 @@ std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) { ...@@ -923,7 +928,8 @@ std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) {
<< " " << credit_card.bank_name() << " " << " " << credit_card.bank_name() << " "
<< " " << credit_card.record_type() << " " << " " << credit_card.record_type() << " "
<< credit_card.use_count() << " " << credit_card.use_date() << " " << credit_card.use_count() << " " << credit_card.use_date() << " "
<< credit_card.billing_address_id(); << credit_card.billing_address_id() << " "
<< credit_card.nickname();
} }
void CreditCard::SetNameOnCardFromSeparateParts() { void CreditCard::SetNameOnCardFromSeparateParts() {
......
...@@ -132,6 +132,9 @@ class CreditCard : public AutofillDataModel { ...@@ -132,6 +132,9 @@ class CreditCard : public AutofillDataModel {
const std::string& server_id() const { return server_id_; } const std::string& server_id() const { return server_id_; }
void set_server_id(const std::string& server_id) { server_id_ = server_id; } void set_server_id(const std::string& server_id) { server_id_ = server_id; }
const base::string16& nickname() const { return nickname_; }
void set_nickname(const base::string16& nickname) { nickname_ = nickname; }
// For use in STL containers. // For use in STL containers.
void operator=(const CreditCard& credit_card); void operator=(const CreditCard& credit_card);
...@@ -325,6 +328,9 @@ class CreditCard : public AutofillDataModel { ...@@ -325,6 +328,9 @@ class CreditCard : public AutofillDataModel {
// Info of tokenizized credit card if available. // Info of tokenizized credit card if available.
sync_pb::CloudTokenData cloud_token_data_; sync_pb::CloudTokenData cloud_token_data_;
// The nickname of the card. May be empty when nickname is not set.
base::string16 nickname_;
}; };
// So we can compare CreditCards with EXPECT_EQ(). // So we can compare CreditCards with EXPECT_EQ().
......
...@@ -576,6 +576,15 @@ TEST(CreditCardTest, Compare) { ...@@ -576,6 +576,15 @@ TEST(CreditCardTest, Compare) {
b.set_record_type(FULL_SERVER_CARD); b.set_record_type(FULL_SERVER_CARD);
EXPECT_EQ(0, a.Compare(b)); EXPECT_EQ(0, a.Compare(b));
// Difference in nickname counts.
a.set_nickname(ASCIIToUTF16("My Visa Card"));
b.set_nickname(ASCIIToUTF16("Grocery Cashback Card"));
EXPECT_LT(0, a.Compare(b));
// Reset the nickname to empty, empty nickname cards are the same.
a.set_nickname(ASCIIToUTF16(""));
b.set_nickname(ASCIIToUTF16(""));
EXPECT_EQ(0, a.Compare(b));
// Local is different from server. // Local is different from server.
a.set_record_type(LOCAL_CARD); a.set_record_type(LOCAL_CARD);
b.set_record_type(FULL_SERVER_CARD); b.set_record_type(FULL_SERVER_CARD);
......
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