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

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

Issue 2607043002: [Autofill] Credit Card Autofill Last Used Date Experiment (Closed)
Patch Set: Add date formatter based on pattern 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..542d15b2ff69db4f4b28a290c8e4cbaf42ae7981 100644
--- a/components/autofill/core/browser/credit_card.cc
+++ b/components/autofill/core/browser/credit_card.cc
@@ -12,6 +12,7 @@
#include <string>
#include "base/guid.h"
+#include "base/i18n/time_formatting.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/metrics/histogram_macros.h"
@@ -88,6 +89,18 @@ base::string16 TypeForFill(const std::string& type) {
return base::string16();
}
+// Padding month and day info to exactly 2 digits.
+base::string16 PadTo2Digit(int32_t date_info) {
+ DCHECK(date_info > 0);
+ base::string16 date_in_2_digits = base::IntToString16(date_info);
+ if (date_info >= 10)
+ return date_in_2_digits;
+
+ base::string16 padded_date = ASCIIToUTF16("0");
+ padded_date.append(date_in_2_digits);
+ return padded_date;
jungshik at Google 2017/01/23 21:43:24 Some locales do NOT use ASCII digit. So that prepe
jiahuiguo 2017/01/26 05:46:12 Thanks for pointing this out, for the expiration d
+}
+
} // namespace
CreditCard::CreditCard(const std::string& guid, const std::string& origin)
@@ -677,16 +690,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 +789,34 @@ void CreditCard::SetNumber(const base::string16& number) {
type_ = GetCreditCardType(StripSeparators(number_));
}
+base::string16 CreditCard::GetLastUsedDateForDisplay(
+ bool show_expiration_date,
+ bool show_time_detail) const {
+ DCHECK(use_count() > 0);
+ // use_count() is initialized as 1 when the card is just added.
+ if (use_count() == 1) {
+ return l10n_util::GetStringFUTF16(
+ show_expiration_date
+ ? IDS_AUTOFILL_CREDIT_CARD_ADDED_DATE_LABEL_AND_EXP
+ : IDS_AUTOFILL_CREDIT_CARD_ADDED_DATE_LABEL,
+ base::TimeFormatWithPattern(use_date(), "MMMdd"));
+ }
+ // 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,
+ base::TimeFormatWithPattern(use_date(), "MMMddjmm"));
+ } 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,
+ base::TimeFormatWithPattern(use_date(), "MMMdd"));
jungshik at Google 2017/01/23 21:43:24 There are 4 combinations here and they're combined
jiahuiguo 2017/01/26 05:46:12 Done.
+ }
+}
+
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