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 88096ec268add4bf40bbdcdcd09c9135b5dddcf2..8e563e0268dfbca49130f0360bcef703d5d5da52 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 { |
| @@ -248,6 +251,74 @@ bool IsValidSuggestionForFieldContents(base::string16 suggestion_canon, |
| return false; |
| } |
| +// Returns the date when the credit card was last used in autofill. Shows |
| +// expiration date if |show_expiration_date| is true, and shows time detail |
| +// if |show_time_detail| is true. |
| +base::string16 GetLastUsedDateForDisplay(const CreditCard* credit_card, |
|
Mathieu
2017/01/27 15:01:44
I would put this function in AutofillDataModel (wh
|
| + bool show_expiration_date, |
| + bool show_time_detail, |
| + const std::string& app_locale) { |
| + 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")) |
|
Mathieu
2017/01/27 15:01:44
Since we are ever only using two patterns (with ti
jiahuiguo
2017/02/03 07:11:17
Done.
|
| + : 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")); |
| + } |
| +} |
| + |
| } // namespace |
| const char kFrecencyFieldTrialName[] = "AutofillProfileOrderByFrecency"; |
| @@ -1618,8 +1689,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( |
|
Mathieu
2017/01/27 15:01:44
using the suggestion above, you will be able to do
jiahuiguo
2017/02/03 07:11:17
Done.
|
| + credit_card, ShowExpirationDateInAutofillCreditCardLastUsedDate(), |
| + ShowTimeDetailInAutofillCreditCardLastUsedDate(), app_locale_); |
| + } 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()) { |