OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/core/browser/credit_card.h" | 5 #include "components/autofill/core/browser/credit_card.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <ostream> | 11 #include <ostream> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/guid.h" | 14 #include "base/guid.h" |
15 #include "base/i18n/time_formatting.h" | 15 #include "base/i18n/time_formatting.h" |
16 #include "base/i18n/unicodestring.h" | 16 #include "base/i18n/unicodestring.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/string_piece.h" |
22 #include "base/strings/string_split.h" | 23 #include "base/strings/string_split.h" |
23 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
25 #include "base/time/time.h" | 26 #include "base/time/time.h" |
26 #include "build/build_config.h" | 27 #include "build/build_config.h" |
27 #include "components/autofill/core/browser/autofill_data_util.h" | 28 #include "components/autofill/core/browser/autofill_data_util.h" |
28 #include "components/autofill/core/browser/autofill_experiments.h" | 29 #include "components/autofill/core/browser/autofill_experiments.h" |
29 #include "components/autofill/core/browser/autofill_field.h" | 30 #include "components/autofill/core/browser/autofill_field.h" |
30 #include "components/autofill/core/browser/autofill_type.h" | 31 #include "components/autofill/core/browser/autofill_type.h" |
31 #include "components/autofill/core/browser/validation.h" | 32 #include "components/autofill/core/browser/validation.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 65 } |
65 | 66 |
66 // Try parsing the |year| as a number. | 67 // Try parsing the |year| as a number. |
67 if (base::StringToInt(year, num)) | 68 if (base::StringToInt(year, num)) |
68 return true; | 69 return true; |
69 | 70 |
70 *num = 0; | 71 *num = 0; |
71 return false; | 72 return false; |
72 } | 73 } |
73 | 74 |
74 base::string16 TypeForFill(const std::string& type) { | 75 base::string16 NetworkForFill(const std::string& network) { |
75 if (type == kAmericanExpressCard) | 76 if (network == kAmericanExpressCard) |
76 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX); | 77 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX); |
77 if (type == kDinersCard) | 78 if (network == kDinersCard) |
78 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS); | 79 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS); |
79 if (type == kDiscoverCard) | 80 if (network == kDiscoverCard) |
80 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER); | 81 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER); |
81 if (type == kJCBCard) | 82 if (network == kJCBCard) |
82 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB); | 83 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB); |
83 if (type == kMasterCard) | 84 if (network == kMasterCard) |
84 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD); | 85 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD); |
85 if (type == kMirCard) | 86 if (network == kMirCard) |
86 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MIR); | 87 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MIR); |
87 if (type == kUnionPay) | 88 if (network == kUnionPay) |
88 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_UNION_PAY); | 89 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_UNION_PAY); |
89 if (type == kVisaCard) | 90 if (network == kVisaCard) |
90 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); | 91 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); |
91 | 92 |
92 // If you hit this DCHECK, the above list of cases needs to be updated to | 93 // If you hit this DCHECK, the above list of cases needs to be updated to |
93 // include a new card. | 94 // include a new card. |
94 DCHECK_EQ(kGenericCard, type); | 95 DCHECK_EQ(kGenericCard, network); |
95 return base::string16(); | 96 return base::string16(); |
96 } | 97 } |
97 | 98 |
98 } // namespace | 99 } // namespace |
99 | 100 |
100 CreditCard::CreditCard(const std::string& guid, const std::string& origin) | 101 CreditCard::CreditCard(const std::string& guid, const std::string& origin) |
101 : AutofillDataModel(guid, origin), | 102 : AutofillDataModel(guid, origin), |
102 record_type_(LOCAL_CARD), | 103 record_type_(LOCAL_CARD), |
103 type_(kGenericCard), | 104 network_(kGenericCard), |
104 expiration_month_(0), | 105 expiration_month_(0), |
105 expiration_year_(0), | 106 expiration_year_(0), |
106 server_status_(OK) {} | 107 server_status_(OK) {} |
107 | 108 |
108 CreditCard::CreditCard(RecordType type, const std::string& server_id) | 109 CreditCard::CreditCard(RecordType type, const std::string& server_id) |
109 : CreditCard() { | 110 : CreditCard() { |
110 DCHECK(type == MASKED_SERVER_CARD || type == FULL_SERVER_CARD); | 111 DCHECK(type == MASKED_SERVER_CARD || type == FULL_SERVER_CARD); |
111 record_type_ = type; | 112 record_type_ = type; |
112 server_id_ = server_id; | 113 server_id_ = server_id; |
113 } | 114 } |
114 | 115 |
115 CreditCard::CreditCard() : CreditCard(base::GenerateGUID(), std::string()) {} | 116 CreditCard::CreditCard() : CreditCard(base::GenerateGUID(), std::string()) {} |
116 | 117 |
117 CreditCard::CreditCard(const CreditCard& credit_card) : CreditCard() { | 118 CreditCard::CreditCard(const CreditCard& credit_card) : CreditCard() { |
118 operator=(credit_card); | 119 operator=(credit_card); |
119 } | 120 } |
120 | 121 |
121 CreditCard::~CreditCard() {} | 122 CreditCard::~CreditCard() {} |
122 | 123 |
123 // static | 124 // static |
124 const base::string16 CreditCard::StripSeparators(const base::string16& number) { | 125 const base::string16 CreditCard::StripSeparators(const base::string16& number) { |
125 base::string16 stripped; | 126 base::string16 stripped; |
126 base::RemoveChars(number, ASCIIToUTF16("- "), &stripped); | 127 base::RemoveChars(number, ASCIIToUTF16("- "), &stripped); |
127 return stripped; | 128 return stripped; |
128 } | 129 } |
129 | 130 |
130 // static | 131 // static |
131 base::string16 CreditCard::TypeForDisplay(const std::string& type) { | 132 base::string16 CreditCard::NetworkForDisplay(const std::string& network) { |
132 if (kGenericCard == type) | 133 if (kGenericCard == network) |
133 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_GENERIC); | 134 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_GENERIC); |
134 if (kAmericanExpressCard == type) | 135 if (kAmericanExpressCard == network) |
135 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX_SHORT); | 136 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX_SHORT); |
136 | 137 |
137 return ::autofill::TypeForFill(type); | 138 return ::autofill::NetworkForFill(network); |
138 } | 139 } |
139 | 140 |
140 // static | 141 // static |
141 int CreditCard::IconResourceId(const std::string& type) { | 142 int CreditCard::IconResourceId(const std::string& network) { |
142 if (type == kAmericanExpressCard) | 143 if (network == kAmericanExpressCard) |
143 return IDR_AUTOFILL_CC_AMEX; | 144 return IDR_AUTOFILL_CC_AMEX; |
144 if (type == kDinersCard) | 145 if (network == kDinersCard) |
145 return IDR_AUTOFILL_CC_DINERS; | 146 return IDR_AUTOFILL_CC_DINERS; |
146 if (type == kDiscoverCard) | 147 if (network == kDiscoverCard) |
147 return IDR_AUTOFILL_CC_DISCOVER; | 148 return IDR_AUTOFILL_CC_DISCOVER; |
148 if (type == kJCBCard) | 149 if (network == kJCBCard) |
149 return IDR_AUTOFILL_CC_JCB; | 150 return IDR_AUTOFILL_CC_JCB; |
150 if (type == kMasterCard) | 151 if (network == kMasterCard) |
151 return IDR_AUTOFILL_CC_MASTERCARD; | 152 return IDR_AUTOFILL_CC_MASTERCARD; |
152 if (type == kMirCard) | 153 if (network == kMirCard) |
153 return IDR_AUTOFILL_CC_MIR; | 154 return IDR_AUTOFILL_CC_MIR; |
154 if (type == kUnionPay) | 155 if (network == kUnionPay) |
155 return IDR_AUTOFILL_CC_UNIONPAY; | 156 return IDR_AUTOFILL_CC_UNIONPAY; |
156 if (type == kVisaCard) | 157 if (network == kVisaCard) |
157 return IDR_AUTOFILL_CC_VISA; | 158 return IDR_AUTOFILL_CC_VISA; |
158 | 159 |
159 // If you hit this DCHECK, the above list of cases needs to be updated to | 160 // If you hit this DCHECK, the above list of cases needs to be updated to |
160 // include a new card. | 161 // include a new card. |
161 DCHECK_EQ(kGenericCard, type); | 162 DCHECK_EQ(kGenericCard, network); |
162 return IDR_AUTOFILL_CC_GENERIC; | 163 return IDR_AUTOFILL_CC_GENERIC; |
163 } | 164 } |
164 | 165 |
165 // static | 166 // static |
166 const char* CreditCard::GetCreditCardType(const base::string16& number) { | 167 const char* CreditCard::GetCardNetwork(const base::string16& number) { |
167 // Credit card number specifications taken from: | 168 // Credit card number specifications taken from: |
168 // http://en.wikipedia.org/wiki/Credit_card_numbers, | 169 // http://en.wikipedia.org/wiki/Credit_card_numbers, |
169 // http://en.wikipedia.org/wiki/List_of_Issuer_Identification_Numbers, | 170 // http://en.wikipedia.org/wiki/List_of_Issuer_Identification_Numbers, |
170 // http://www.discovernetwork.com/merchants/images/Merchant_Marketing_PDF.pdf, | 171 // http://www.discovernetwork.com/merchants/images/Merchant_Marketing_PDF.pdf, |
171 // http://www.regular-expressions.info/creditcard.html, | 172 // http://www.regular-expressions.info/creditcard.html, |
172 // http://developer.ean.com/general_info/Valid_Credit_Card_Types, | 173 // http://developer.ean.com/general_info/Valid_Credit_Card_Types, |
173 // http://www.bincodes.com/, | 174 // http://www.bincodes.com/, |
174 // http://www.fraudpractice.com/FL-binCC.html, and | 175 // http://www.fraudpractice.com/FL-binCC.html, and |
175 // http://www.beachnet.com/~hstiles/cardtype.html | 176 // http://www.beachnet.com/~hstiles/cardtype.html |
176 // | 177 // |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 250 |
250 if (first_four_digits >= 3528 && first_four_digits <= 3589) | 251 if (first_four_digits >= 3528 && first_four_digits <= 3589) |
251 return kJCBCard; | 252 return kJCBCard; |
252 | 253 |
253 if (first_four_digits == 6011) | 254 if (first_four_digits == 6011) |
254 return kDiscoverCard; | 255 return kDiscoverCard; |
255 | 256 |
256 return kGenericCard; | 257 return kGenericCard; |
257 } | 258 } |
258 | 259 |
259 void CreditCard::SetTypeForMaskedCard(const char* type) { | 260 void CreditCard::SetNetworkForMaskedCard(base::StringPiece network) { |
260 DCHECK_EQ(MASKED_SERVER_CARD, record_type()); | 261 DCHECK_EQ(MASKED_SERVER_CARD, record_type()); |
261 type_ = type; | 262 network_ = network.as_string(); |
262 } | 263 } |
263 | 264 |
264 void CreditCard::SetServerStatus(ServerStatus status) { | 265 void CreditCard::SetServerStatus(ServerStatus status) { |
265 DCHECK_NE(LOCAL_CARD, record_type()); | 266 DCHECK_NE(LOCAL_CARD, record_type()); |
266 server_status_ = status; | 267 server_status_ = status; |
267 } | 268 } |
268 | 269 |
269 CreditCard::ServerStatus CreditCard::GetServerStatus() const { | 270 CreditCard::ServerStatus CreditCard::GetServerStatus() const { |
270 DCHECK_NE(LOCAL_CARD, record_type()); | 271 DCHECK_NE(LOCAL_CARD, record_type()); |
271 return server_status_; | 272 return server_status_; |
(...skipping 30 matching lines...) Expand all Loading... |
302 | 303 |
303 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: { | 304 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: { |
304 base::string16 month = ExpirationMonthAsString(); | 305 base::string16 month = ExpirationMonthAsString(); |
305 base::string16 year = Expiration4DigitYearAsString(); | 306 base::string16 year = Expiration4DigitYearAsString(); |
306 if (!month.empty() && !year.empty()) | 307 if (!month.empty() && !year.empty()) |
307 return month + ASCIIToUTF16("/") + year; | 308 return month + ASCIIToUTF16("/") + year; |
308 return base::string16(); | 309 return base::string16(); |
309 } | 310 } |
310 | 311 |
311 case CREDIT_CARD_TYPE: | 312 case CREDIT_CARD_TYPE: |
312 return TypeForFill(); | 313 return NetworkForFill(); |
313 | 314 |
314 case CREDIT_CARD_NUMBER: | 315 case CREDIT_CARD_NUMBER: |
315 return number_; | 316 return number_; |
316 | 317 |
317 case CREDIT_CARD_VERIFICATION_CODE: | 318 case CREDIT_CARD_VERIFICATION_CODE: |
318 // Chrome doesn't store credit card verification codes. | 319 // Chrome doesn't store credit card verification codes. |
319 return base::string16(); | 320 return base::string16(); |
320 | 321 |
321 default: | 322 default: |
322 // ComputeDataPresentForArray will hit this repeatedly. | 323 // ComputeDataPresentForArray will hit this repeatedly. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 } | 374 } |
374 } | 375 } |
375 | 376 |
376 base::string16 CreditCard::GetInfo(const AutofillType& type, | 377 base::string16 CreditCard::GetInfo(const AutofillType& type, |
377 const std::string& app_locale) const { | 378 const std::string& app_locale) const { |
378 ServerFieldType storable_type = type.GetStorableType(); | 379 ServerFieldType storable_type = type.GetStorableType(); |
379 if (storable_type == CREDIT_CARD_NUMBER) { | 380 if (storable_type == CREDIT_CARD_NUMBER) { |
380 // Web pages should never actually be filled by a masked server card, | 381 // Web pages should never actually be filled by a masked server card, |
381 // but this function is used at the preview stage. | 382 // but this function is used at the preview stage. |
382 if (record_type() == MASKED_SERVER_CARD) | 383 if (record_type() == MASKED_SERVER_CARD) |
383 return TypeAndLastFourDigits(); | 384 return NetworkAndLastFourDigits(); |
384 | 385 |
385 return StripSeparators(number_); | 386 return StripSeparators(number_); |
386 } | 387 } |
387 | 388 |
388 return GetRawInfo(storable_type); | 389 return GetRawInfo(storable_type); |
389 } | 390 } |
390 | 391 |
391 bool CreditCard::SetInfo(const AutofillType& type, | 392 bool CreditCard::SetInfo(const AutofillType& type, |
392 const base::string16& value, | 393 const base::string16& value, |
393 const std::string& app_locale) { | 394 const std::string& app_locale) { |
(...skipping 30 matching lines...) Expand all Loading... |
424 return pieces.first + pieces.second; | 425 return pieces.first + pieces.second; |
425 } | 426 } |
426 | 427 |
427 const std::pair<base::string16, base::string16> CreditCard::LabelPieces() | 428 const std::pair<base::string16, base::string16> CreditCard::LabelPieces() |
428 const { | 429 const { |
429 base::string16 label; | 430 base::string16 label; |
430 // No CC number, return name only. | 431 // No CC number, return name only. |
431 if (number().empty()) | 432 if (number().empty()) |
432 return std::make_pair(name_on_card_, base::string16()); | 433 return std::make_pair(name_on_card_, base::string16()); |
433 | 434 |
434 base::string16 obfuscated_cc_number = TypeAndLastFourDigits(); | 435 base::string16 obfuscated_cc_number = NetworkAndLastFourDigits(); |
435 // No expiration date set. | 436 // No expiration date set. |
436 if (!expiration_month_ || !expiration_year_) | 437 if (!expiration_month_ || !expiration_year_) |
437 return std::make_pair(obfuscated_cc_number, base::string16()); | 438 return std::make_pair(obfuscated_cc_number, base::string16()); |
438 | 439 |
439 base::string16 formatted_date(ExpirationMonthAsString()); | 440 base::string16 formatted_date(ExpirationMonthAsString()); |
440 formatted_date.append(ASCIIToUTF16("/")); | 441 formatted_date.append(ASCIIToUTF16("/")); |
441 formatted_date.append(Expiration4DigitYearAsString()); | 442 formatted_date.append(Expiration4DigitYearAsString()); |
442 | 443 |
443 base::string16 separator = | 444 base::string16 separator = |
444 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); | 445 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 base::string16 CreditCard::LastFourDigits() const { | 491 base::string16 CreditCard::LastFourDigits() const { |
491 static const size_t kNumLastDigits = 4; | 492 static const size_t kNumLastDigits = 4; |
492 | 493 |
493 base::string16 number = StripSeparators(number_); | 494 base::string16 number = StripSeparators(number_); |
494 if (number.size() <= kNumLastDigits) | 495 if (number.size() <= kNumLastDigits) |
495 return number; | 496 return number; |
496 | 497 |
497 return number.substr(number.size() - kNumLastDigits, kNumLastDigits); | 498 return number.substr(number.size() - kNumLastDigits, kNumLastDigits); |
498 } | 499 } |
499 | 500 |
500 base::string16 CreditCard::TypeForDisplay() const { | 501 base::string16 CreditCard::NetworkForDisplay() const { |
501 return CreditCard::TypeForDisplay(type_); | 502 return CreditCard::NetworkForDisplay(network_); |
502 } | 503 } |
503 | 504 |
504 base::string16 CreditCard::TypeAndLastFourDigits() const { | 505 base::string16 CreditCard::NetworkAndLastFourDigits() const { |
505 base::string16 type = TypeForDisplay(); | 506 base::string16 network = NetworkForDisplay(); |
506 | 507 |
507 base::string16 digits = LastFourDigits(); | 508 base::string16 digits = LastFourDigits(); |
508 if (digits.empty()) | 509 if (digits.empty()) |
509 return type; | 510 return network; |
510 | 511 |
511 // TODO(estade): i18n? | 512 // TODO(estade): i18n? |
512 return type + base::string16(kMidlineEllipsis) + digits; | 513 return network + base::string16(kMidlineEllipsis) + digits; |
513 } | 514 } |
514 | 515 |
515 base::string16 CreditCard::AbbreviatedExpirationDateForDisplay() const { | 516 base::string16 CreditCard::AbbreviatedExpirationDateForDisplay() const { |
516 base::string16 month = ExpirationMonthAsString(); | 517 base::string16 month = ExpirationMonthAsString(); |
517 base::string16 year = Expiration2DigitYearAsString(); | 518 base::string16 year = Expiration2DigitYearAsString(); |
518 return month.empty() || year.empty() | 519 return month.empty() || year.empty() |
519 ? base::string16() | 520 ? base::string16() |
520 : l10n_util::GetStringFUTF16( | 521 : l10n_util::GetStringFUTF16( |
521 IDS_AUTOFILL_CREDIT_CARD_EXPIRATION_DATE_ABBR, month, year); | 522 IDS_AUTOFILL_CREDIT_CARD_EXPIRATION_DATE_ABBR, month, year); |
522 } | 523 } |
523 | 524 |
524 void CreditCard::operator=(const CreditCard& credit_card) { | 525 void CreditCard::operator=(const CreditCard& credit_card) { |
525 set_use_count(credit_card.use_count()); | 526 set_use_count(credit_card.use_count()); |
526 set_use_date(credit_card.use_date()); | 527 set_use_date(credit_card.use_date()); |
527 set_modification_date(credit_card.modification_date()); | 528 set_modification_date(credit_card.modification_date()); |
528 | 529 |
529 if (this == &credit_card) | 530 if (this == &credit_card) |
530 return; | 531 return; |
531 | 532 |
532 record_type_ = credit_card.record_type_; | 533 record_type_ = credit_card.record_type_; |
533 number_ = credit_card.number_; | 534 number_ = credit_card.number_; |
534 name_on_card_ = credit_card.name_on_card_; | 535 name_on_card_ = credit_card.name_on_card_; |
535 type_ = credit_card.type_; | 536 network_ = credit_card.network_; |
536 expiration_month_ = credit_card.expiration_month_; | 537 expiration_month_ = credit_card.expiration_month_; |
537 expiration_year_ = credit_card.expiration_year_; | 538 expiration_year_ = credit_card.expiration_year_; |
538 server_id_ = credit_card.server_id_; | 539 server_id_ = credit_card.server_id_; |
539 server_status_ = credit_card.server_status_; | 540 server_status_ = credit_card.server_status_; |
540 billing_address_id_ = credit_card.billing_address_id_; | 541 billing_address_id_ = credit_card.billing_address_id_; |
541 | 542 |
542 set_guid(credit_card.guid()); | 543 set_guid(credit_card.guid()); |
543 set_origin(credit_card.origin()); | 544 set_origin(credit_card.origin()); |
544 } | 545 } |
545 | 546 |
546 base::string16 CreditCard::GetLastUsedDateForDisplay( | 547 base::string16 CreditCard::GetLastUsedDateForDisplay( |
547 const std::string& app_locale) const { | 548 const std::string& app_locale) const { |
548 bool show_expiration_date = | 549 bool show_expiration_date = |
549 ShowExpirationDateInAutofillCreditCardLastUsedDate(); | 550 ShowExpirationDateInAutofillCreditCardLastUsedDate(); |
550 | 551 |
551 DCHECK(use_count() > 0); | 552 DCHECK_LT(0U, use_count()); |
552 // use_count() is initialized as 1 when the card is just added. | 553 // use_count() is initialized as 1 when the card is just added. |
553 if (use_count() == 1) { | 554 if (use_count() == 1U) { |
554 return show_expiration_date | 555 return show_expiration_date |
555 ? l10n_util::GetStringFUTF16( | 556 ? l10n_util::GetStringFUTF16( |
556 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_ADDED_DATE, | 557 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_ADDED_DATE, |
557 GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), | 558 GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), |
558 app_locale), | 559 app_locale), |
559 base::TimeFormatWithPattern( | 560 base::TimeFormatWithPattern( |
560 use_date(), kTimeFormatPatternNoYearShortMonthDate)) | 561 use_date(), kTimeFormatPatternNoYearShortMonthDate)) |
561 : l10n_util::GetStringFUTF16( | 562 : l10n_util::GetStringFUTF16( |
562 IDS_AUTOFILL_CREDIT_CARD_ADDED_DATE, | 563 IDS_AUTOFILL_CREDIT_CARD_ADDED_DATE, |
563 base::TimeFormatWithPattern( | 564 base::TimeFormatWithPattern( |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 if (number_.empty()) | 685 if (number_.empty()) |
685 return true; | 686 return true; |
686 | 687 |
687 return HasSameNumberAs(other); | 688 return HasSameNumberAs(other); |
688 } | 689 } |
689 | 690 |
690 bool CreditCard::HasSameNumberAs(const CreditCard& other) const { | 691 bool CreditCard::HasSameNumberAs(const CreditCard& other) const { |
691 // For masked cards, this is the best we can do to compare card numbers. | 692 // For masked cards, this is the best we can do to compare card numbers. |
692 if (record_type() == MASKED_SERVER_CARD || | 693 if (record_type() == MASKED_SERVER_CARD || |
693 other.record_type() == MASKED_SERVER_CARD) { | 694 other.record_type() == MASKED_SERVER_CARD) { |
694 return TypeAndLastFourDigits() == other.TypeAndLastFourDigits(); | 695 return NetworkAndLastFourDigits() == other.NetworkAndLastFourDigits(); |
695 } | 696 } |
696 | 697 |
697 return StripSeparators(number_) == StripSeparators(other.number_); | 698 return StripSeparators(number_) == StripSeparators(other.number_); |
698 } | 699 } |
699 | 700 |
700 bool CreditCard::operator==(const CreditCard& credit_card) const { | 701 bool CreditCard::operator==(const CreditCard& credit_card) const { |
701 return guid() == credit_card.guid() && | 702 return guid() == credit_card.guid() && |
702 origin() == credit_card.origin() && | 703 origin() == credit_card.origin() && |
703 Compare(credit_card) == 0; | 704 Compare(credit_card) == 0; |
704 } | 705 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 | 806 |
806 base::string16 month = base::IntToString16(expiration_month_); | 807 base::string16 month = base::IntToString16(expiration_month_); |
807 if (expiration_month_ >= 10) | 808 if (expiration_month_ >= 10) |
808 return month; | 809 return month; |
809 | 810 |
810 base::string16 zero = ASCIIToUTF16("0"); | 811 base::string16 zero = ASCIIToUTF16("0"); |
811 zero.append(month); | 812 zero.append(month); |
812 return zero; | 813 return zero; |
813 } | 814 } |
814 | 815 |
815 base::string16 CreditCard::TypeForFill() const { | 816 base::string16 CreditCard::NetworkForFill() const { |
816 return ::autofill::TypeForFill(type_); | 817 return ::autofill::NetworkForFill(network_); |
817 } | 818 } |
818 | 819 |
819 base::string16 CreditCard::Expiration4DigitYearAsString() const { | 820 base::string16 CreditCard::Expiration4DigitYearAsString() const { |
820 if (expiration_year_ == 0) | 821 if (expiration_year_ == 0) |
821 return base::string16(); | 822 return base::string16(); |
822 | 823 |
823 return base::IntToString16(Expiration4DigitYear()); | 824 return base::IntToString16(Expiration4DigitYear()); |
824 } | 825 } |
825 | 826 |
826 base::string16 CreditCard::Expiration2DigitYearAsString() const { | 827 base::string16 CreditCard::Expiration2DigitYearAsString() const { |
827 if (expiration_year_ == 0) | 828 if (expiration_year_ == 0) |
828 return base::string16(); | 829 return base::string16(); |
829 | 830 |
830 return base::IntToString16(Expiration2DigitYear()); | 831 return base::IntToString16(Expiration2DigitYear()); |
831 } | 832 } |
832 | 833 |
833 void CreditCard::SetNumber(const base::string16& number) { | 834 void CreditCard::SetNumber(const base::string16& number) { |
834 number_ = number; | 835 number_ = number; |
835 | 836 |
836 // Set the type based on the card number, but only for full numbers, not | 837 // Set the type based on the card number, but only for full numbers, not |
837 // when we have masked cards from the server (last 4 digits). | 838 // when we have masked cards from the server (last 4 digits). |
838 if (record_type_ != MASKED_SERVER_CARD) | 839 if (record_type_ != MASKED_SERVER_CARD) |
839 type_ = GetCreditCardType(StripSeparators(number_)); | 840 network_ = GetCardNetwork(StripSeparators(number_)); |
840 } | 841 } |
841 | 842 |
842 void CreditCard::RecordAndLogUse() { | 843 void CreditCard::RecordAndLogUse() { |
843 UMA_HISTOGRAM_COUNTS_1000("Autofill.DaysSinceLastUse.CreditCard", | 844 UMA_HISTOGRAM_COUNTS_1000("Autofill.DaysSinceLastUse.CreditCard", |
844 (AutofillClock::Now() - use_date()).InDays()); | 845 (AutofillClock::Now() - use_date()).InDays()); |
845 RecordUse(); | 846 RecordUse(); |
846 } | 847 } |
847 | 848 |
848 // static | 849 // static |
849 bool CreditCard::ConvertMonth(const base::string16& month, | 850 bool CreditCard::ConvertMonth(const base::string16& month, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 const char kDinersCard[] = "dinersCC"; | 930 const char kDinersCard[] = "dinersCC"; |
930 const char kDiscoverCard[] = "discoverCC"; | 931 const char kDiscoverCard[] = "discoverCC"; |
931 const char kGenericCard[] = "genericCC"; | 932 const char kGenericCard[] = "genericCC"; |
932 const char kJCBCard[] = "jcbCC"; | 933 const char kJCBCard[] = "jcbCC"; |
933 const char kMasterCard[] = "masterCardCC"; | 934 const char kMasterCard[] = "masterCardCC"; |
934 const char kMirCard[] = "mirCC"; | 935 const char kMirCard[] = "mirCC"; |
935 const char kUnionPay[] = "unionPayCC"; | 936 const char kUnionPay[] = "unionPayCC"; |
936 const char kVisaCard[] = "visaCC"; | 937 const char kVisaCard[] = "visaCC"; |
937 | 938 |
938 } // namespace autofill | 939 } // namespace autofill |
OLD | NEW |