| 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 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1611 suggestion->backend_id = credit_card->guid(); | 1614 suggestion->backend_id = credit_card->guid(); |
| 1612 suggestion->match = prefix_matched_suggestion | 1615 suggestion->match = prefix_matched_suggestion |
| 1613 ? Suggestion::PREFIX_MATCH | 1616 ? Suggestion::PREFIX_MATCH |
| 1614 : Suggestion::SUBSTRING_MATCH; | 1617 : Suggestion::SUBSTRING_MATCH; |
| 1615 | 1618 |
| 1616 // If the value is the card number, the label is the expiration date. | 1619 // If the value is the card number, the label is the expiration date. |
| 1617 // Otherwise the label is the card number, or if that is empty the | 1620 // Otherwise the label is the card number, or if that is empty the |
| 1618 // cardholder name. The label should never repeat the value. | 1621 // cardholder name. The label should never repeat the value. |
| 1619 if (type.GetStorableType() == CREDIT_CARD_NUMBER) { | 1622 if (type.GetStorableType() == CREDIT_CARD_NUMBER) { |
| 1620 suggestion->value = credit_card->TypeAndLastFourDigits(); | 1623 suggestion->value = credit_card->TypeAndLastFourDigits(); |
| 1621 suggestion->label = credit_card->GetInfo( | 1624 if (IsAutofillCreditCardLastUsedDateDisplayExperimentEnabled() && |
| 1622 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_); | 1625 !IsKeyboardAccessoryEnabled()) { |
| 1626 suggestion->label = GetLastUsedDateForDisplay( |
| 1627 credit_card, ShowExpirationDateInAutofillCreditCardLastUsedDate(), |
| 1628 ShowTimeDetailInAutofillCreditCardLastUsedDate()); |
| 1629 } else { |
| 1630 suggestion->label = credit_card->GetInfo( |
| 1631 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), app_locale_); |
| 1632 } |
| 1623 if (IsAutofillCreditCardPopupLayoutExperimentEnabled()) | 1633 if (IsAutofillCreditCardPopupLayoutExperimentEnabled()) |
| 1624 ModifyAutofillCreditCardSuggestion(suggestion); | 1634 ModifyAutofillCreditCardSuggestion(suggestion); |
| 1625 } else if (credit_card->number().empty()) { | 1635 } else if (credit_card->number().empty()) { |
| 1626 if (type.GetStorableType() != CREDIT_CARD_NAME_FULL) { | 1636 if (type.GetStorableType() != CREDIT_CARD_NAME_FULL) { |
| 1627 suggestion->label = credit_card->GetInfo( | 1637 suggestion->label = credit_card->GetInfo( |
| 1628 AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); | 1638 AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); |
| 1629 } | 1639 } |
| 1630 } else { | 1640 } else { |
| 1631 #if defined(OS_ANDROID) | 1641 #if defined(OS_ANDROID) |
| 1632 // Since Android places the label on its own row, there's more | 1642 // Since Android places the label on its own row, there's more |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1645 if (IsFeatureSubstringMatchEnabled()) { | 1655 if (IsFeatureSubstringMatchEnabled()) { |
| 1646 std::stable_sort(suggestions.begin(), suggestions.end(), | 1656 std::stable_sort(suggestions.begin(), suggestions.end(), |
| 1647 [](const Suggestion& a, const Suggestion& b) { | 1657 [](const Suggestion& a, const Suggestion& b) { |
| 1648 return a.match < b.match; | 1658 return a.match < b.match; |
| 1649 }); | 1659 }); |
| 1650 } | 1660 } |
| 1651 | 1661 |
| 1652 return suggestions; | 1662 return suggestions; |
| 1653 } | 1663 } |
| 1654 | 1664 |
| 1665 base::string16 PersonalDataManager::GetLastUsedDateForDisplay( |
| 1666 const CreditCard* credit_card, |
| 1667 bool show_expiration_date, |
| 1668 bool show_time_detail) const { |
| 1669 DCHECK(credit_card->use_count() > 0); |
| 1670 // use_count() is initialized as 1 when the card is just added. |
| 1671 if (credit_card->use_count() == 1) { |
| 1672 return show_expiration_date |
| 1673 ? l10n_util::GetStringFUTF16( |
| 1674 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_ADDED_DATE, |
| 1675 credit_card->GetInfo( |
| 1676 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), |
| 1677 app_locale_), |
| 1678 base::TimeFormatWithPattern(credit_card->use_date(), |
| 1679 "MMMdd")) |
| 1680 : l10n_util::GetStringFUTF16( |
| 1681 IDS_AUTOFILL_CREDIT_CARD_ADDED_DATE, |
| 1682 base::TimeFormatWithPattern(credit_card->use_date(), |
| 1683 "MMMdd")); |
| 1684 } |
| 1685 // use_count() > 1 when the card has been used in autofill. |
| 1686 |
| 1687 // If the card was last used in autofill more than a year ago, |
| 1688 // display "last used > 1 year ago" without showing date detail. |
| 1689 if ((base::Time::Now() - credit_card->use_date()).InDays() > 365) { |
| 1690 return show_expiration_date |
| 1691 ? l10n_util::GetStringFUTF16( |
| 1692 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_YEAR_AGO, |
| 1693 credit_card->GetInfo( |
| 1694 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), |
| 1695 app_locale_)) |
| 1696 : l10n_util::GetStringUTF16( |
| 1697 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_YEAR_AGO); |
| 1698 } |
| 1699 |
| 1700 // If the card was last used in autofill within a year, show date information. |
| 1701 if (show_time_detail) { |
| 1702 return show_expiration_date |
| 1703 ? l10n_util::GetStringFUTF16( |
| 1704 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE_DETAIL, |
| 1705 credit_card->GetInfo( |
| 1706 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), |
| 1707 app_locale_), |
| 1708 base::TimeFormatWithPattern(credit_card->use_date(), |
| 1709 "MMMddjmm")) |
| 1710 : l10n_util::GetStringFUTF16( |
| 1711 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE_DETAIL, |
| 1712 base::TimeFormatWithPattern(credit_card->use_date(), |
| 1713 "MMMddjmm")); |
| 1714 } else { |
| 1715 return show_expiration_date |
| 1716 ? l10n_util::GetStringFUTF16( |
| 1717 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE, |
| 1718 credit_card->GetInfo( |
| 1719 AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR), |
| 1720 app_locale_), |
| 1721 base::TimeFormatWithPattern(credit_card->use_date(), |
| 1722 "MMMdd")) |
| 1723 : l10n_util::GetStringFUTF16( |
| 1724 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE, |
| 1725 base::TimeFormatWithPattern(credit_card->use_date(), |
| 1726 "MMMdd")); |
| 1727 } |
| 1728 } |
| 1729 |
| 1655 void PersonalDataManager::ApplyProfileUseDatesFix() { | 1730 void PersonalDataManager::ApplyProfileUseDatesFix() { |
| 1656 // Don't run if the fix has already been applied. | 1731 // Don't run if the fix has already been applied. |
| 1657 if (pref_service_->GetBoolean(prefs::kAutofillProfileUseDatesFixed)) | 1732 if (pref_service_->GetBoolean(prefs::kAutofillProfileUseDatesFixed)) |
| 1658 return; | 1733 return; |
| 1659 | 1734 |
| 1660 std::vector<AutofillProfile> profiles; | 1735 std::vector<AutofillProfile> profiles; |
| 1661 bool has_changed_data = false; | 1736 bool has_changed_data = false; |
| 1662 for (AutofillProfile* profile : web_profiles()) { | 1737 for (AutofillProfile* profile : web_profiles()) { |
| 1663 if (profile->use_date() == base::Time()) { | 1738 if (profile->use_date() == base::Time()) { |
| 1664 profile->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(14)); | 1739 profile->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(14)); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 } | 1921 } |
| 1847 | 1922 |
| 1848 // If the card was modified, apply the changes to the database. | 1923 // If the card was modified, apply the changes to the database. |
| 1849 if (was_modified) { | 1924 if (was_modified) { |
| 1850 database_->UpdateCreditCard(*credit_card); | 1925 database_->UpdateCreditCard(*credit_card); |
| 1851 } | 1926 } |
| 1852 } | 1927 } |
| 1853 } | 1928 } |
| 1854 | 1929 |
| 1855 } // namespace autofill | 1930 } // namespace autofill |
| OLD | NEW |