Chromium Code Reviews| 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> |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 670 supported_types->insert(CREDIT_CARD_NUMBER); | 670 supported_types->insert(CREDIT_CARD_NUMBER); |
| 671 supported_types->insert(CREDIT_CARD_TYPE); | 671 supported_types->insert(CREDIT_CARD_TYPE); |
| 672 supported_types->insert(CREDIT_CARD_EXP_MONTH); | 672 supported_types->insert(CREDIT_CARD_EXP_MONTH); |
| 673 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); | 673 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); |
| 674 supported_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR); | 674 supported_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
| 675 supported_types->insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR); | 675 supported_types->insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR); |
| 676 supported_types->insert(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR); | 676 supported_types->insert(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR); |
| 677 } | 677 } |
| 678 | 678 |
| 679 base::string16 CreditCard::ExpirationMonthAsString() const { | 679 base::string16 CreditCard::ExpirationMonthAsString() const { |
| 680 if (expiration_month_ == 0) | 680 return expiration_month_ == 0 |
| 681 return base::string16(); | 681 ? base::string16() |
| 682 | 682 : PadTo2Digit(expiration_month_); |
| 683 base::string16 month = base::IntToString16(expiration_month_); | |
| 684 if (expiration_month_ >= 10) | |
| 685 return month; | |
| 686 | |
| 687 base::string16 zero = ASCIIToUTF16("0"); | |
| 688 zero.append(month); | |
| 689 return zero; | |
| 690 } | 683 } |
| 691 | 684 |
| 692 base::string16 CreditCard::TypeForFill() const { | 685 base::string16 CreditCard::TypeForFill() const { |
| 693 return ::autofill::TypeForFill(type_); | 686 return ::autofill::TypeForFill(type_); |
| 694 } | 687 } |
| 695 | 688 |
| 696 base::string16 CreditCard::Expiration4DigitYearAsString() const { | 689 base::string16 CreditCard::Expiration4DigitYearAsString() const { |
| 697 if (expiration_year_ == 0) | 690 if (expiration_year_ == 0) |
| 698 return base::string16(); | 691 return base::string16(); |
| 699 | 692 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 | 769 |
| 777 void CreditCard::SetNumber(const base::string16& number) { | 770 void CreditCard::SetNumber(const base::string16& number) { |
| 778 number_ = number; | 771 number_ = number; |
| 779 | 772 |
| 780 // Set the type based on the card number, but only for full numbers, not | 773 // Set the type based on the card number, but only for full numbers, not |
| 781 // when we have masked cards from the server (last 4 digits). | 774 // when we have masked cards from the server (last 4 digits). |
| 782 if (record_type_ != MASKED_SERVER_CARD) | 775 if (record_type_ != MASKED_SERVER_CARD) |
| 783 type_ = GetCreditCardType(StripSeparators(number_)); | 776 type_ = GetCreditCardType(StripSeparators(number_)); |
| 784 } | 777 } |
| 785 | 778 |
| 779 base::string16 CreditCard::LastUsedDateAsString( | |
|
Mathieu
2017/01/18 14:42:15
Could we rename this GetLastUsedDataForDisplay?
jiahuiguo
2017/01/18 22:18:12
Done.
| |
| 780 bool show_time_detail, | |
| 781 bool show_expiration_date, | |
| 782 const std::string& app_locale) const { | |
| 783 base::Time::Exploded exploded; | |
| 784 use_date().LocalExplode(&exploded); | |
| 785 base::string16 month = GetShortMonthLabel(exploded.month, app_locale); | |
| 786 DCHECK(use_count() > 0); | |
| 787 // use_count() is initialized as 1 when the card is just added | |
|
Jared Saul
2017/01/18 18:43:44
nit: Here and in the other comment on line 795, ad
jiahuiguo
2017/01/18 22:18:13
Done.
| |
| 788 if (use_count() == 1) | |
|
Mathieu
2017/01/18 14:42:15
put curlies {}
jiahuiguo
2017/01/18 22:18:12
Done.
| |
| 789 return l10n_util::GetStringFUTF16( | |
| 790 show_expiration_date | |
| 791 ? IDS_AUTOFILL_CREDIT_CARD_ADDED_TO_CHROME_DATE_LABEL_AND_EXP | |
|
Mathieu
2017/01/18 14:42:15
let's not mention Chrome in the label name. "IDS_A
Jared Saul
2017/01/18 18:43:44
(But with s/ADDED__DATE/ADDED_DATE)
jiahuiguo
2017/01/18 22:18:12
Done.
jiahuiguo
2017/01/18 22:18:12
Done.
| |
| 792 : IDS_AUTOFILL_CREDIT_CARD_ADDED_TO_CHROME_DATE_LABEL, | |
| 793 month, | |
| 794 PadTo2Digit(exploded.day_of_month)); | |
| 795 // use_count() > 1 when the card has been used in autofill | |
| 796 if (show_time_detail) { | |
| 797 return l10n_util::GetStringFUTF16( | |
| 798 show_expiration_date | |
| 799 ? IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_LABEL_AND_EXP_WITH_DETAIL | |
| 800 : IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_LABEL_WITH_DETAIL, | |
| 801 month, | |
| 802 PadTo2Digit(exploded.day_of_month), | |
| 803 PadTo2Digit(exploded.hour), | |
| 804 PadTo2Digit(exploded.minute)); | |
| 805 } else { | |
| 806 return l10n_util::GetStringFUTF16( | |
| 807 show_expiration_date | |
| 808 ? IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_LABEL_AND_EXP_NO_DETAIL | |
| 809 : IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_LABEL_NO_DETAIL, | |
| 810 month, | |
| 811 PadTo2Digit(exploded.day_of_month)); | |
| 812 } | |
| 813 } | |
| 814 | |
| 815 base::string16 CreditCard::PadTo2Digit(int32_t date_info) const { | |
| 816 DCHECK(date_info > 0); | |
| 817 base::string16 dateIn2Digit = base::IntToString16(date_info); | |
|
Mathieu
2017/01/18 14:42:15
nit: C++ style is no camel-case
jiahuiguo
2017/01/18 22:18:13
Done.
| |
| 818 if (date_info >= 10) | |
| 819 return dateIn2Digit; | |
| 820 | |
| 821 base::string16 padded_date = ASCIIToUTF16("0"); | |
| 822 padded_date.append(dateIn2Digit); | |
| 823 return padded_date; | |
| 824 } | |
| 825 | |
| 826 base::string16 CreditCard::GetShortMonthLabel( | |
| 827 int one_base_month, | |
| 828 const std::string& app_locale) const { | |
| 829 UErrorCode status = U_ZERO_ERROR; | |
| 830 icu::Locale locale(app_locale.c_str()); | |
| 831 icu::DateFormatSymbols date_format_symbols(locale, status); | |
| 832 DCHECK(status == U_ZERO_ERROR || status == U_USING_FALLBACK_WARNING || | |
| 833 status == U_USING_DEFAULT_WARNING); | |
| 834 | |
| 835 int32_t num_months; | |
| 836 const icu::UnicodeString* months = | |
| 837 date_format_symbols.getShortMonths(num_months); | |
| 838 base::string16 short_month( | |
| 839 months[one_base_month - 1].getBuffer(), | |
| 840 static_cast<size_t>(months[one_base_month - 1].length())); | |
| 841 return short_month; | |
| 842 } | |
| 843 | |
| 786 void CreditCard::RecordAndLogUse() { | 844 void CreditCard::RecordAndLogUse() { |
| 787 UMA_HISTOGRAM_COUNTS_1000("Autofill.DaysSinceLastUse.CreditCard", | 845 UMA_HISTOGRAM_COUNTS_1000("Autofill.DaysSinceLastUse.CreditCard", |
| 788 (base::Time::Now() - use_date()).InDays()); | 846 (base::Time::Now() - use_date()).InDays()); |
| 789 RecordUse(); | 847 RecordUse(); |
| 790 } | 848 } |
| 791 | 849 |
| 792 // static | 850 // static |
| 793 bool CreditCard::ConvertMonth(const base::string16& month, | 851 bool CreditCard::ConvertMonth(const base::string16& month, |
| 794 const std::string& app_locale, | 852 const std::string& app_locale, |
| 795 int* num) { | 853 int* num) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 872 const char kDinersCard[] = "dinersCC"; | 930 const char kDinersCard[] = "dinersCC"; |
| 873 const char kDiscoverCard[] = "discoverCC"; | 931 const char kDiscoverCard[] = "discoverCC"; |
| 874 const char kGenericCard[] = "genericCC"; | 932 const char kGenericCard[] = "genericCC"; |
| 875 const char kJCBCard[] = "jcbCC"; | 933 const char kJCBCard[] = "jcbCC"; |
| 876 const char kMasterCard[] = "masterCardCC"; | 934 const char kMasterCard[] = "masterCardCC"; |
| 877 const char kMirCard[] = "mirCC"; | 935 const char kMirCard[] = "mirCC"; |
| 878 const char kUnionPay[] = "unionPayCC"; | 936 const char kUnionPay[] = "unionPayCC"; |
| 879 const char kVisaCard[] = "visaCC"; | 937 const char kVisaCard[] = "visaCC"; |
| 880 | 938 |
| 881 } // namespace autofill | 939 } // namespace autofill |
| OLD | NEW |