| 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 88096ec268add4bf40bbdcdcd09c9135b5dddcf2..a8ac7e6ad057a94145a3b94742c3433df27a65b1 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 {
|
| @@ -1618,8 +1621,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()) {
|
| @@ -1652,6 +1662,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 was last used in autofill more than a year ago,
|
| + // display "last used > 1 year ago" without showing date detail.
|
| + if ((base::Time::Now() - credit_card->use_date()).InDays() > 365) {
|
| + 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 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,
|
| + 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))
|
|
|