Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: components/autofill/core/browser/credit_card.cc

Issue 2607043002: [Autofill] Credit Card Autofill Last Used Date Experiment (Closed)
Patch Set: Added variations to show expiration date and detail time info Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/credit_card.cc
diff --git a/components/autofill/core/browser/credit_card.cc b/components/autofill/core/browser/credit_card.cc
index 3b402eae9e873dbb85ae52383d1ebaa1a1e4d2bd..4b7e229625ff7a853d3cc8eeba60748d99c98613 100644
--- a/components/autofill/core/browser/credit_card.cc
+++ b/components/autofill/core/browser/credit_card.cc
@@ -677,16 +677,9 @@ void CreditCard::GetSupportedTypes(ServerFieldTypeSet* supported_types) const {
}
base::string16 CreditCard::ExpirationMonthAsString() const {
- if (expiration_month_ == 0)
- return base::string16();
-
- base::string16 month = base::IntToString16(expiration_month_);
- if (expiration_month_ >= 10)
- return month;
-
- base::string16 zero = ASCIIToUTF16("0");
- zero.append(month);
- return zero;
+ return expiration_month_ == 0
+ ? base::string16()
+ : PadTo2Digit(expiration_month_);
}
base::string16 CreditCard::TypeForFill() const {
@@ -783,6 +776,71 @@ void CreditCard::SetNumber(const base::string16& number) {
type_ = GetCreditCardType(StripSeparators(number_));
}
+base::string16 CreditCard::LastUsedDateAsString(
Mathieu 2017/01/18 14:42:15 Could we rename this GetLastUsedDataForDisplay?
jiahuiguo 2017/01/18 22:18:12 Done.
+ bool show_time_detail,
+ bool show_expiration_date,
+ const std::string& app_locale) const {
+ base::Time::Exploded exploded;
+ use_date().LocalExplode(&exploded);
+ base::string16 month = GetShortMonthLabel(exploded.month, app_locale);
+ DCHECK(use_count() > 0);
+ // 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.
+ if (use_count() == 1)
Mathieu 2017/01/18 14:42:15 put curlies {}
jiahuiguo 2017/01/18 22:18:12 Done.
+ return l10n_util::GetStringFUTF16(
+ show_expiration_date
+ ? 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.
+ : IDS_AUTOFILL_CREDIT_CARD_ADDED_TO_CHROME_DATE_LABEL,
+ month,
+ PadTo2Digit(exploded.day_of_month));
+ // use_count() > 1 when the card has been used in autofill
+ if (show_time_detail) {
+ return l10n_util::GetStringFUTF16(
+ show_expiration_date
+ ? IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_LABEL_AND_EXP_WITH_DETAIL
+ : IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_LABEL_WITH_DETAIL,
+ month,
+ PadTo2Digit(exploded.day_of_month),
+ PadTo2Digit(exploded.hour),
+ PadTo2Digit(exploded.minute));
+ } else {
+ return l10n_util::GetStringFUTF16(
+ show_expiration_date
+ ? IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_LABEL_AND_EXP_NO_DETAIL
+ : IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_LABEL_NO_DETAIL,
+ month,
+ PadTo2Digit(exploded.day_of_month));
+ }
+}
+
+base::string16 CreditCard::PadTo2Digit(int32_t date_info) const {
+ DCHECK(date_info > 0);
+ 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.
+ if (date_info >= 10)
+ return dateIn2Digit;
+
+ base::string16 padded_date = ASCIIToUTF16("0");
+ padded_date.append(dateIn2Digit);
+ return padded_date;
+}
+
+base::string16 CreditCard::GetShortMonthLabel(
+ int one_base_month,
+ const std::string& app_locale) const {
+ UErrorCode status = U_ZERO_ERROR;
+ icu::Locale locale(app_locale.c_str());
+ icu::DateFormatSymbols date_format_symbols(locale, status);
+ DCHECK(status == U_ZERO_ERROR || status == U_USING_FALLBACK_WARNING ||
+ status == U_USING_DEFAULT_WARNING);
+
+ int32_t num_months;
+ const icu::UnicodeString* months =
+ date_format_symbols.getShortMonths(num_months);
+ base::string16 short_month(
+ months[one_base_month - 1].getBuffer(),
+ static_cast<size_t>(months[one_base_month - 1].length()));
+ return short_month;
+}
+
void CreditCard::RecordAndLogUse() {
UMA_HISTOGRAM_COUNTS_1000("Autofill.DaysSinceLastUse.CreditCard",
(base::Time::Now() - use_date()).InDays());

Powered by Google App Engine
This is Rietveld 408576698