Chromium Code Reviews| Index: components/autofill/core/browser/personal_data_manager.cc |
| diff --git a/components/autofill/core/browser/personal_data_manager.cc b/components/autofill/core/browser/personal_data_manager.cc |
| index d2a931c0d2b3453dd07752fa471eedb3d55e245c..a2114a0040179ca562c87cf561a025bf930024dd 100644 |
| --- a/components/autofill/core/browser/personal_data_manager.cc |
| +++ b/components/autofill/core/browser/personal_data_manager.cc |
| @@ -13,6 +13,7 @@ |
| #include <utility> |
| #include "base/i18n/case_conversion.h" |
| +#include "base/i18n/time_formatting.h" |
| #include "base/i18n/timezone.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/profiler/scoped_tracker.h" |
| @@ -44,8 +45,10 @@ |
| #include "components/sync/driver/sync_service.h" |
| #include "components/variations/variations_associated_data.h" |
| #include "components/version_info/version_info.h" |
| +#include "grit/components_strings.h" |
| #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h" |
| #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_formatter.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| namespace autofill { |
| namespace { |
| @@ -1633,8 +1636,15 @@ std::vector<Suggestion> PersonalDataManager::GetSuggestionsForCards( |
| // cardholder name. The label should never repeat the value. |
| if (type.GetStorableType() == CREDIT_CARD_NUMBER) { |
| suggestion->value = credit_card->TypeAndLastFourDigits(); |
| - suggestion->label = credit_card->GetInfo( |
| - AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_); |
| + if (IsAutofillCreditCardLastUsedDateDisplayExperimentEnabled() && |
| + !IsKeyboardAccessoryEnabled()) { |
| + suggestion->label = GetLastUsedDateForDisplay( |
| + credit_card, ShowExpirationDateInAutofillCreditCardLastUsedDate(), |
| + ShowTimeDetailInAutofillCreditCardLastUsedDate()); |
| + } else { |
| + suggestion->label = credit_card->GetInfo( |
| + AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_); |
| + } |
| if (IsAutofillCreditCardPopupLayoutExperimentEnabled()) |
| ModifyAutofillCreditCardSuggestion(suggestion); |
| } else if (credit_card->number().empty()) { |
| @@ -1667,6 +1677,71 @@ std::vector<Suggestion> PersonalDataManager::GetSuggestionsForCards( |
| return suggestions; |
| } |
| +base::string16 PersonalDataManager::GetLastUsedDateForDisplay( |
| + const CreditCard* credit_card, |
| + bool show_expiration_date, |
| + bool show_time_detail) const { |
| + DCHECK(credit_card->use_count() > 0); |
| + // use_count() is initialized as 1 when the card is just added. |
| + if (credit_card->use_count() == 1) { |
| + return show_expiration_date |
| + ? l10n_util::GetStringFUTF16( |
| + IDS_AUTOFILL_CREDIT_CARD_EXP_AND_ADDED_DATE, |
| + credit_card->GetInfo( |
| + AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), |
| + app_locale_), |
| + base::TimeFormatWithPattern(credit_card->use_date(), |
| + "MMMdd")) |
| + : l10n_util::GetStringFUTF16( |
| + IDS_AUTOFILL_CREDIT_CARD_ADDED_DATE, |
| + base::TimeFormatWithPattern(credit_card->use_date(), |
| + "MMMdd")); |
| + } |
| + // use_count() > 1 when the card has been used in autofill. |
| + |
| + // If the card is last used in autofill more than a year/years ago, |
| + // indicate "last used > 1 year" without showing date detail. |
|
Jared Saul
2017/01/25 18:22:17
nit wording:
// If the card was last used in au
jiahuiguo
2017/01/26 05:46:13
Done.
|
| + if ((base::Time::Now() - credit_card->use_date()).InDays() > 365) { |
|
Jared Saul
2017/01/25 18:22:17
Just wondering, but is there a InYears() instead o
jiahuiguo
2017/01/26 05:46:13
No
|
| + return show_expiration_date |
| + ? l10n_util::GetStringFUTF16( |
| + IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_YEAR_AGO, |
| + credit_card->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 is last used in autofill within a year, show date information. |
|
Jared Saul
2017/01/25 18:22:17
nit: s/is/was
jiahuiguo
2017/01/26 05:46:13
Done.
|
| + if (show_time_detail) { |
| + return show_expiration_date |
| + ? l10n_util::GetStringFUTF16( |
| + IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE_DETAIL, |
| + credit_card->GetInfo( |
| + AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), |
| + app_locale_), |
| + base::TimeFormatWithPattern(credit_card->use_date(), |
| + "MMMddjmm")) |
| + : l10n_util::GetStringFUTF16( |
| + IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_DETAIL, |
| + base::TimeFormatWithPattern(credit_card->use_date(), |
| + "MMMddjmm")); |
| + } else { |
| + return show_expiration_date |
| + ? l10n_util::GetStringFUTF16( |
| + IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE, |
| + credit_card->GetInfo( |
| + AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), |
| + app_locale_), |
| + base::TimeFormatWithPattern(credit_card->use_date(), |
| + "MMMdd")) |
| + : l10n_util::GetStringFUTF16( |
| + IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE, |
| + base::TimeFormatWithPattern(credit_card->use_date(), |
| + "MMMdd")); |
| + } |
| +} |
| + |
| void PersonalDataManager::ApplyProfileUseDatesFix() { |
| // Don't run if the fix has already been applied. |
| if (pref_service_->GetBoolean(prefs::kAutofillProfileUseDatesFixed)) |