Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/i18n/case_conversion.h" | 15 #include "base/i18n/case_conversion.h" |
| 16 #include "base/i18n/time_formatting.h" | |
| 16 #include "base/i18n/timezone.h" | 17 #include "base/i18n/timezone.h" |
| 17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 18 #include "base/profiler/scoped_tracker.h" | 19 #include "base/profiler/scoped_tracker.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 23 #include "components/autofill/core/browser/address_i18n.h" | 24 #include "components/autofill/core/browser/address_i18n.h" |
| 24 #include "components/autofill/core/browser/autofill-inl.h" | 25 #include "components/autofill/core/browser/autofill-inl.h" |
| 25 #include "components/autofill/core/browser/autofill_country.h" | 26 #include "components/autofill/core/browser/autofill_country.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 37 #include "components/autofill/core/common/autofill_pref_names.h" | 38 #include "components/autofill/core/common/autofill_pref_names.h" |
| 38 #include "components/autofill/core/common/autofill_switches.h" | 39 #include "components/autofill/core/common/autofill_switches.h" |
| 39 #include "components/autofill/core/common/autofill_util.h" | 40 #include "components/autofill/core/common/autofill_util.h" |
| 40 #include "components/prefs/pref_service.h" | 41 #include "components/prefs/pref_service.h" |
| 41 #include "components/signin/core/browser/account_tracker_service.h" | 42 #include "components/signin/core/browser/account_tracker_service.h" |
| 42 #include "components/signin/core/browser/signin_manager.h" | 43 #include "components/signin/core/browser/signin_manager.h" |
| 43 #include "components/signin/core/common/signin_pref_names.h" | 44 #include "components/signin/core/common/signin_pref_names.h" |
| 44 #include "components/sync/driver/sync_service.h" | 45 #include "components/sync/driver/sync_service.h" |
| 45 #include "components/variations/variations_associated_data.h" | 46 #include "components/variations/variations_associated_data.h" |
| 46 #include "components/version_info/version_info.h" | 47 #include "components/version_info/version_info.h" |
| 48 #include "grit/components_strings.h" | |
| 47 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" | 49 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" |
| 48 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h" | 50 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h" |
| 51 #include "ui/base/l10n/l10n_util.h" | |
| 49 | 52 |
| 50 namespace autofill { | 53 namespace autofill { |
| 51 namespace { | 54 namespace { |
| 52 | 55 |
| 53 using ::i18n::addressinput::AddressField; | 56 using ::i18n::addressinput::AddressField; |
| 54 using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine; | 57 using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine; |
| 55 using ::i18n::addressinput::STREET_ADDRESS; | 58 using ::i18n::addressinput::STREET_ADDRESS; |
| 56 | 59 |
| 57 template<typename T> | 60 template<typename T> |
| 58 class FormGroupMatchesByGUIDFunctor { | 61 class FormGroupMatchesByGUIDFunctor { |
| (...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1626 suggestion->backend_id = credit_card->guid(); | 1629 suggestion->backend_id = credit_card->guid(); |
| 1627 suggestion->match = prefix_matched_suggestion | 1630 suggestion->match = prefix_matched_suggestion |
| 1628 ? Suggestion::PREFIX_MATCH | 1631 ? Suggestion::PREFIX_MATCH |
| 1629 : Suggestion::SUBSTRING_MATCH; | 1632 : Suggestion::SUBSTRING_MATCH; |
| 1630 | 1633 |
| 1631 // If the value is the card number, the label is the expiration date. | 1634 // If the value is the card number, the label is the expiration date. |
| 1632 // Otherwise the label is the card number, or if that is empty the | 1635 // Otherwise the label is the card number, or if that is empty the |
| 1633 // cardholder name. The label should never repeat the value. | 1636 // cardholder name. The label should never repeat the value. |
| 1634 if (type.GetStorableType() == CREDIT_CARD_NUMBER) { | 1637 if (type.GetStorableType() == CREDIT_CARD_NUMBER) { |
| 1635 suggestion->value = credit_card->TypeAndLastFourDigits(); | 1638 suggestion->value = credit_card->TypeAndLastFourDigits(); |
| 1636 suggestion->label = credit_card->GetInfo( | 1639 if (IsAutofillCreditCardLastUsedDateDisplayExperimentEnabled() && |
| 1637 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_); | 1640 !IsKeyboardAccessoryEnabled()) { |
| 1641 suggestion->label = GetLastUsedDateForDisplay( | |
| 1642 credit_card, ShowExpirationDateInAutofillCreditCardLastUsedDate(), | |
| 1643 ShowTimeDetailInAutofillCreditCardLastUsedDate()); | |
| 1644 } else { | |
| 1645 suggestion->label = credit_card->GetInfo( | |
| 1646 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_); | |
| 1647 } | |
| 1638 if (IsAutofillCreditCardPopupLayoutExperimentEnabled()) | 1648 if (IsAutofillCreditCardPopupLayoutExperimentEnabled()) |
| 1639 ModifyAutofillCreditCardSuggestion(suggestion); | 1649 ModifyAutofillCreditCardSuggestion(suggestion); |
| 1640 } else if (credit_card->number().empty()) { | 1650 } else if (credit_card->number().empty()) { |
| 1641 if (type.GetStorableType() != CREDIT_CARD_NAME_FULL) { | 1651 if (type.GetStorableType() != CREDIT_CARD_NAME_FULL) { |
| 1642 suggestion->label = credit_card->GetInfo( | 1652 suggestion->label = credit_card->GetInfo( |
| 1643 AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); | 1653 AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); |
| 1644 } | 1654 } |
| 1645 } else { | 1655 } else { |
| 1646 #if defined(OS_ANDROID) | 1656 #if defined(OS_ANDROID) |
| 1647 // Since Android places the label on its own row, there's more | 1657 // Since Android places the label on its own row, there's more |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1660 if (IsFeatureSubstringMatchEnabled()) { | 1670 if (IsFeatureSubstringMatchEnabled()) { |
| 1661 std::stable_sort(suggestions.begin(), suggestions.end(), | 1671 std::stable_sort(suggestions.begin(), suggestions.end(), |
| 1662 [](const Suggestion& a, const Suggestion& b) { | 1672 [](const Suggestion& a, const Suggestion& b) { |
| 1663 return a.match < b.match; | 1673 return a.match < b.match; |
| 1664 }); | 1674 }); |
| 1665 } | 1675 } |
| 1666 | 1676 |
| 1667 return suggestions; | 1677 return suggestions; |
| 1668 } | 1678 } |
| 1669 | 1679 |
| 1680 base::string16 PersonalDataManager::GetLastUsedDateForDisplay( | |
| 1681 const CreditCard* credit_card, | |
| 1682 bool show_expiration_date, | |
| 1683 bool show_time_detail) const { | |
| 1684 DCHECK(credit_card->use_count() > 0); | |
| 1685 // use_count() is initialized as 1 when the card is just added. | |
| 1686 if (credit_card->use_count() == 1) { | |
| 1687 return show_expiration_date | |
| 1688 ? l10n_util::GetStringFUTF16( | |
| 1689 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_ADDED_DATE, | |
| 1690 credit_card->GetInfo( | |
| 1691 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), | |
| 1692 app_locale_), | |
| 1693 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 1694 "MMMdd")) | |
| 1695 : l10n_util::GetStringFUTF16( | |
| 1696 IDS_AUTOFILL_CREDIT_CARD_ADDED_DATE, | |
| 1697 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 1698 "MMMdd")); | |
| 1699 } | |
| 1700 // use_count() > 1 when the card has been used in autofill. | |
| 1701 | |
| 1702 // If the card is last used in autofill more than a year/years ago, | |
| 1703 // 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.
| |
| 1704 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
| |
| 1705 return show_expiration_date | |
| 1706 ? l10n_util::GetStringFUTF16( | |
| 1707 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_YEAR_AGO, | |
| 1708 credit_card->GetInfo( | |
| 1709 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), | |
| 1710 app_locale_)) | |
| 1711 : l10n_util::GetStringUTF16( | |
| 1712 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_YEAR_AGO); | |
| 1713 } | |
| 1714 | |
| 1715 // 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.
| |
| 1716 if (show_time_detail) { | |
| 1717 return show_expiration_date | |
| 1718 ? l10n_util::GetStringFUTF16( | |
| 1719 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE_DETAIL, | |
| 1720 credit_card->GetInfo( | |
| 1721 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), | |
| 1722 app_locale_), | |
| 1723 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 1724 "MMMddjmm")) | |
| 1725 : l10n_util::GetStringFUTF16( | |
| 1726 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_DETAIL, | |
| 1727 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 1728 "MMMddjmm")); | |
| 1729 } else { | |
| 1730 return show_expiration_date | |
| 1731 ? l10n_util::GetStringFUTF16( | |
| 1732 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE, | |
| 1733 credit_card->GetInfo( | |
| 1734 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), | |
| 1735 app_locale_), | |
| 1736 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 1737 "MMMdd")) | |
| 1738 : l10n_util::GetStringFUTF16( | |
| 1739 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE, | |
| 1740 base::TimeFormatWithPattern(credit_card->use_date(), | |
| 1741 "MMMdd")); | |
| 1742 } | |
| 1743 } | |
| 1744 | |
| 1670 void PersonalDataManager::ApplyProfileUseDatesFix() { | 1745 void PersonalDataManager::ApplyProfileUseDatesFix() { |
| 1671 // Don't run if the fix has already been applied. | 1746 // Don't run if the fix has already been applied. |
| 1672 if (pref_service_->GetBoolean(prefs::kAutofillProfileUseDatesFixed)) | 1747 if (pref_service_->GetBoolean(prefs::kAutofillProfileUseDatesFixed)) |
| 1673 return; | 1748 return; |
| 1674 | 1749 |
| 1675 std::vector<AutofillProfile> profiles; | 1750 std::vector<AutofillProfile> profiles; |
| 1676 bool has_changed_data = false; | 1751 bool has_changed_data = false; |
| 1677 for (AutofillProfile* profile : web_profiles()) { | 1752 for (AutofillProfile* profile : web_profiles()) { |
| 1678 if (profile->use_date() == base::Time()) { | 1753 if (profile->use_date() == base::Time()) { |
| 1679 profile->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(14)); | 1754 profile->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(14)); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1861 } | 1936 } |
| 1862 | 1937 |
| 1863 // If the card was modified, apply the changes to the database. | 1938 // If the card was modified, apply the changes to the database. |
| 1864 if (was_modified) { | 1939 if (was_modified) { |
| 1865 database_->UpdateCreditCard(*credit_card); | 1940 database_->UpdateCreditCard(*credit_card); |
| 1866 } | 1941 } |
| 1867 } | 1942 } |
| 1868 } | 1943 } |
| 1869 | 1944 |
| 1870 } // namespace autofill | 1945 } // namespace autofill |
| OLD | NEW |