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

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

Issue 2607043002: [Autofill] Credit Card Autofill Last Used Date Experiment (Closed)
Patch Set: Addressed reviewer's comments Created 3 years, 10 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 32d65452ea8b95e3a58d5643eed5d433379b4587..9ac9c5e33cad2794dbefece5e370a7360373a23a 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"
@@ -23,6 +24,7 @@
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_data_util.h"
+#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/validation.h"
@@ -49,6 +51,8 @@ const base::char16 kMidlineEllipsis[] = { 0x0020, 0x0020,
namespace {
const base::char16 kCreditCardObfuscationSymbol = '*';
+const char kTimeFormatPatternNoYearShortMonthDateAndTimeDetail[] = "MMMddjmm";
+const char kTimeFormatPatternNoYearShortMonthDate[] = "MMMdd";
bool ConvertYear(const base::string16& year, int* num) {
// If the |year| is empty, clear the stored value.
@@ -537,6 +541,72 @@ void CreditCard::operator=(const CreditCard& credit_card) {
set_origin(credit_card.origin());
}
+base::string16 CreditCard::GetLastUsedDateForDisplay(
+ const std::string& app_locale) const {
+ bool show_expiration_date =
+ ShowExpirationDateInAutofillCreditCardLastUsedDate();
+ bool show_time_detail = ShowTimeDetailInAutofillCreditCardLastUsedDate();
+
+ DCHECK(use_count() > 0);
+ // use_count() is initialized as 1 when the card is just added.
+ if (use_count() == 1) {
+ return show_expiration_date
+ ? l10n_util::GetStringFUTF16(
+ IDS_AUTOFILL_CREDIT_CARD_EXP_AND_ADDED_DATE,
+ GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR),
+ app_locale),
+ base::TimeFormatWithPattern(
+ use_date(), kTimeFormatPatternNoYearShortMonthDate))
+ : l10n_util::GetStringFUTF16(
+ IDS_AUTOFILL_CREDIT_CARD_ADDED_DATE,
+ base::TimeFormatWithPattern(
+ use_date(), kTimeFormatPatternNoYearShortMonthDate));
+ }
+
+ // use_count() > 1 when the card has been used in autofill.
+
+ // If the card was last used in autofill more than a year ago,
+ // display "last used > 1 year ago" without showing date detail.
+ if ((AutofillClock::Now() - use_date()).InDays() > 365) {
+ return show_expiration_date
+ ? l10n_util::GetStringFUTF16(
+ IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_YEAR_AGO,
+ GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR),
+ app_locale))
+ : l10n_util::GetStringUTF16(
+ IDS_AUTOFILL_CREDIT_CARD_LAST_USED_YEAR_AGO);
+ }
+
+ // If the card was last used in autofill within a year, show date information.
+ if (show_time_detail) {
+ return show_expiration_date
+ ? l10n_util::GetStringFUTF16(
+ IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE_DETAIL,
+ GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR),
+ app_locale),
+ base::TimeFormatWithPattern(
+ use_date(),
+ kTimeFormatPatternNoYearShortMonthDateAndTimeDetail))
+ : l10n_util::GetStringFUTF16(
+ IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_DETAIL,
+ base::TimeFormatWithPattern(
+ use_date(),
+ kTimeFormatPatternNoYearShortMonthDateAndTimeDetail));
+ } else {
+ return show_expiration_date
+ ? l10n_util::GetStringFUTF16(
+ IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE,
+ GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR),
+ app_locale),
+ base::TimeFormatWithPattern(
+ use_date(), kTimeFormatPatternNoYearShortMonthDate))
+ : l10n_util::GetStringFUTF16(
+ IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE,
+ base::TimeFormatWithPattern(
+ use_date(), kTimeFormatPatternNoYearShortMonthDate));
+ }
+}
+
bool CreditCard::UpdateFromImportedCard(const CreditCard& imported_card,
const std::string& app_locale) {
if (this->GetInfo(AutofillType(CREDIT_CARD_NUMBER), app_locale) !=

Powered by Google App Engine
This is Rietveld 408576698