| 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> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "components/autofill/core/browser/autofill_field.h" | 27 #include "components/autofill/core/browser/autofill_field.h" |
| 28 #include "components/autofill/core/browser/autofill_metrics.h" | 28 #include "components/autofill/core/browser/autofill_metrics.h" |
| 29 #include "components/autofill/core/browser/autofill_profile_comparator.h" | 29 #include "components/autofill/core/browser/autofill_profile_comparator.h" |
| 30 #include "components/autofill/core/browser/country_data.h" | 30 #include "components/autofill/core/browser/country_data.h" |
| 31 #include "components/autofill/core/browser/country_names.h" | 31 #include "components/autofill/core/browser/country_names.h" |
| 32 #include "components/autofill/core/browser/form_structure.h" | 32 #include "components/autofill/core/browser/form_structure.h" |
| 33 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 33 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 34 #include "components/autofill/core/browser/phone_number.h" | 34 #include "components/autofill/core/browser/phone_number.h" |
| 35 #include "components/autofill/core/browser/phone_number_i18n.h" | 35 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 36 #include "components/autofill/core/browser/validation.h" | 36 #include "components/autofill/core/browser/validation.h" |
| 37 #include "components/autofill/core/common/autofill_clock.h" |
| 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" |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 void PersonalDataManager::Refresh() { | 778 void PersonalDataManager::Refresh() { |
| 778 LoadProfiles(); | 779 LoadProfiles(); |
| 779 LoadCreditCards(); | 780 LoadCreditCards(); |
| 780 } | 781 } |
| 781 | 782 |
| 782 const std::vector<AutofillProfile*> PersonalDataManager::GetProfilesToSuggest() | 783 const std::vector<AutofillProfile*> PersonalDataManager::GetProfilesToSuggest() |
| 783 const { | 784 const { |
| 784 std::vector<AutofillProfile*> profiles = GetProfiles(true); | 785 std::vector<AutofillProfile*> profiles = GetProfiles(true); |
| 785 | 786 |
| 786 // Rank the suggestions by frecency (see AutofillDataModel for details). | 787 // Rank the suggestions by frecency (see AutofillDataModel for details). |
| 787 base::Time comparison_time = base::Time::Now(); | 788 base::Time comparison_time = AutofillClock::Now(); |
| 788 std::sort(profiles.begin(), profiles.end(), | 789 std::sort(profiles.begin(), profiles.end(), |
| 789 [comparison_time](const AutofillDataModel* a, | 790 [comparison_time](const AutofillDataModel* a, |
| 790 const AutofillDataModel* b) { | 791 const AutofillDataModel* b) { |
| 791 return a->CompareFrecency(b, comparison_time); | 792 return a->CompareFrecency(b, comparison_time); |
| 792 }); | 793 }); |
| 793 | 794 |
| 794 return profiles; | 795 return profiles; |
| 795 } | 796 } |
| 796 | 797 |
| 797 std::vector<Suggestion> PersonalDataManager::GetProfileSuggestions( | 798 std::vector<Suggestion> PersonalDataManager::GetProfileSuggestions( |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 credit_cards.end()); | 902 credit_cards.end()); |
| 902 | 903 |
| 903 DedupeCreditCardToSuggest(&cards_to_dedupe); | 904 DedupeCreditCardToSuggest(&cards_to_dedupe); |
| 904 | 905 |
| 905 std::vector<CreditCard*> cards_to_suggest( | 906 std::vector<CreditCard*> cards_to_suggest( |
| 906 std::make_move_iterator(std::begin(cards_to_dedupe)), | 907 std::make_move_iterator(std::begin(cards_to_dedupe)), |
| 907 std::make_move_iterator(std::end(cards_to_dedupe))); | 908 std::make_move_iterator(std::end(cards_to_dedupe))); |
| 908 | 909 |
| 909 // Rank the cards by frecency (see AutofillDataModel for details). All expired | 910 // Rank the cards by frecency (see AutofillDataModel for details). All expired |
| 910 // cards should be suggested last, also by frecency. | 911 // cards should be suggested last, also by frecency. |
| 911 base::Time comparison_time = base::Time::Now(); | 912 base::Time comparison_time = AutofillClock::Now(); |
| 912 std::stable_sort(cards_to_suggest.begin(), cards_to_suggest.end(), | 913 std::stable_sort(cards_to_suggest.begin(), cards_to_suggest.end(), |
| 913 [comparison_time](const CreditCard* a, const CreditCard* b) { | 914 [comparison_time](const CreditCard* a, const CreditCard* b) { |
| 914 bool a_is_expired = a->IsExpired(comparison_time); | 915 bool a_is_expired = a->IsExpired(comparison_time); |
| 915 if (a_is_expired != b->IsExpired(comparison_time)) | 916 if (a_is_expired != b->IsExpired(comparison_time)) |
| 916 return !a_is_expired; | 917 return !a_is_expired; |
| 917 | 918 |
| 918 return a->CompareFrecency(b, comparison_time); | 919 return a->CompareFrecency(b, comparison_time); |
| 919 }); | 920 }); |
| 920 | 921 |
| 921 return cards_to_suggest; | 922 return cards_to_suggest; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 std::vector<std::unique_ptr<AutofillProfile>>* existing_profiles, | 985 std::vector<std::unique_ptr<AutofillProfile>>* existing_profiles, |
| 985 const std::string& app_locale, | 986 const std::string& app_locale, |
| 986 std::vector<AutofillProfile>* merged_profiles) { | 987 std::vector<AutofillProfile>* merged_profiles) { |
| 987 merged_profiles->clear(); | 988 merged_profiles->clear(); |
| 988 | 989 |
| 989 // Sort the existing profiles in decreasing order of frecency, so the "best" | 990 // Sort the existing profiles in decreasing order of frecency, so the "best" |
| 990 // profiles are checked first. Put the verified profiles last so the non | 991 // profiles are checked first. Put the verified profiles last so the non |
| 991 // verified profiles get deduped among themselves before reaching the verified | 992 // verified profiles get deduped among themselves before reaching the verified |
| 992 // profiles. | 993 // profiles. |
| 993 // TODO(crbug.com/620521): Remove the check for verified from the sort. | 994 // TODO(crbug.com/620521): Remove the check for verified from the sort. |
| 994 base::Time comparison_time = base::Time::Now(); | 995 base::Time comparison_time = AutofillClock::Now(); |
| 995 std::sort(existing_profiles->begin(), existing_profiles->end(), | 996 std::sort(existing_profiles->begin(), existing_profiles->end(), |
| 996 [comparison_time](const std::unique_ptr<AutofillProfile>& a, | 997 [comparison_time](const std::unique_ptr<AutofillProfile>& a, |
| 997 const std::unique_ptr<AutofillProfile>& b) { | 998 const std::unique_ptr<AutofillProfile>& b) { |
| 998 if (a->IsVerified() != b->IsVerified()) | 999 if (a->IsVerified() != b->IsVerified()) |
| 999 return !a->IsVerified(); | 1000 return !a->IsVerified(); |
| 1000 return a->CompareFrecency(b.get(), comparison_time); | 1001 return a->CompareFrecency(b.get(), comparison_time); |
| 1001 }); | 1002 }); |
| 1002 | 1003 |
| 1003 // Set to true if |existing_profiles| already contains an equivalent profile. | 1004 // Set to true if |existing_profiles| already contains an equivalent profile. |
| 1004 bool matching_profile_found = false; | 1005 bool matching_profile_found = false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1017 // data. If an automatically aggregated profile would overwrite a | 1018 // data. If an automatically aggregated profile would overwrite a |
| 1018 // verified profile, just drop it. | 1019 // verified profile, just drop it. |
| 1019 matching_profile_found = true; | 1020 matching_profile_found = true; |
| 1020 guid = existing_profile->guid(); | 1021 guid = existing_profile->guid(); |
| 1021 | 1022 |
| 1022 // We set the modification date so that immediate requests for profiles | 1023 // We set the modification date so that immediate requests for profiles |
| 1023 // will properly reflect the fact that this profile has been modified | 1024 // will properly reflect the fact that this profile has been modified |
| 1024 // recently. After writing to the database and refreshing the local copies | 1025 // recently. After writing to the database and refreshing the local copies |
| 1025 // the profile will have a very slightly newer time reflecting what's | 1026 // the profile will have a very slightly newer time reflecting what's |
| 1026 // actually stored in the database. | 1027 // actually stored in the database. |
| 1027 existing_profile->set_modification_date(base::Time::Now()); | 1028 existing_profile->set_modification_date(AutofillClock::Now()); |
| 1028 } | 1029 } |
| 1029 merged_profiles->push_back(*existing_profile); | 1030 merged_profiles->push_back(*existing_profile); |
| 1030 } | 1031 } |
| 1031 | 1032 |
| 1032 // If the new profile was not merged with an existing one, add it to the list. | 1033 // If the new profile was not merged with an existing one, add it to the list. |
| 1033 if (!matching_profile_found) { | 1034 if (!matching_profile_found) { |
| 1034 merged_profiles->push_back(new_profile); | 1035 merged_profiles->push_back(new_profile); |
| 1035 // Similar to updating merged profiles above, set the modification date on | 1036 // Similar to updating merged profiles above, set the modification date on |
| 1036 // new profiles. | 1037 // new profiles. |
| 1037 merged_profiles->back().set_modification_date(base::Time::Now()); | 1038 merged_profiles->back().set_modification_date(AutofillClock::Now()); |
| 1038 AutofillMetrics::LogProfileActionOnFormSubmitted( | 1039 AutofillMetrics::LogProfileActionOnFormSubmitted( |
| 1039 AutofillMetrics::NEW_PROFILE_CREATED); | 1040 AutofillMetrics::NEW_PROFILE_CREATED); |
| 1040 } | 1041 } |
| 1041 | 1042 |
| 1042 return guid; | 1043 return guid; |
| 1043 } | 1044 } |
| 1044 | 1045 |
| 1045 bool PersonalDataManager::IsCountryOfInterest(const std::string& country_code) | 1046 bool PersonalDataManager::IsCountryOfInterest(const std::string& country_code) |
| 1046 const { | 1047 const { |
| 1047 DCHECK_EQ(2U, country_code.size()); | 1048 DCHECK_EQ(2U, country_code.size()); |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1654 | 1655 |
| 1655 void PersonalDataManager::ApplyProfileUseDatesFix() { | 1656 void PersonalDataManager::ApplyProfileUseDatesFix() { |
| 1656 // Don't run if the fix has already been applied. | 1657 // Don't run if the fix has already been applied. |
| 1657 if (pref_service_->GetBoolean(prefs::kAutofillProfileUseDatesFixed)) | 1658 if (pref_service_->GetBoolean(prefs::kAutofillProfileUseDatesFixed)) |
| 1658 return; | 1659 return; |
| 1659 | 1660 |
| 1660 std::vector<AutofillProfile> profiles; | 1661 std::vector<AutofillProfile> profiles; |
| 1661 bool has_changed_data = false; | 1662 bool has_changed_data = false; |
| 1662 for (AutofillProfile* profile : web_profiles()) { | 1663 for (AutofillProfile* profile : web_profiles()) { |
| 1663 if (profile->use_date() == base::Time()) { | 1664 if (profile->use_date() == base::Time()) { |
| 1664 profile->set_use_date(base::Time::Now() - base::TimeDelta::FromDays(14)); | 1665 profile->set_use_date(AutofillClock::Now() - |
| 1666 base::TimeDelta::FromDays(14)); |
| 1665 has_changed_data = true; | 1667 has_changed_data = true; |
| 1666 } | 1668 } |
| 1667 profiles.push_back(*profile); | 1669 profiles.push_back(*profile); |
| 1668 } | 1670 } |
| 1669 | 1671 |
| 1670 // Set the pref so that this fix is never run again. | 1672 // Set the pref so that this fix is never run again. |
| 1671 pref_service_->SetBoolean(prefs::kAutofillProfileUseDatesFixed, true); | 1673 pref_service_->SetBoolean(prefs::kAutofillProfileUseDatesFixed, true); |
| 1672 | 1674 |
| 1673 if (has_changed_data) | 1675 if (has_changed_data) |
| 1674 SetProfiles(&profiles); | 1676 SetProfiles(&profiles); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1735 AutofillMetrics::LogNumberOfProfilesConsideredForDedupe( | 1737 AutofillMetrics::LogNumberOfProfilesConsideredForDedupe( |
| 1736 existing_profiles->size()); | 1738 existing_profiles->size()); |
| 1737 | 1739 |
| 1738 // Sort the profiles by frecency with all the verified profiles at the end. | 1740 // Sort the profiles by frecency with all the verified profiles at the end. |
| 1739 // That way the most relevant profiles will get merged into the less relevant | 1741 // That way the most relevant profiles will get merged into the less relevant |
| 1740 // profiles, which keeps the syntax of the most relevant profiles data. | 1742 // profiles, which keeps the syntax of the most relevant profiles data. |
| 1741 // Verified profiles are put at the end because they do not merge into other | 1743 // Verified profiles are put at the end because they do not merge into other |
| 1742 // profiles, so the loop can be stopped when we reach those. However they need | 1744 // profiles, so the loop can be stopped when we reach those. However they need |
| 1743 // to be in the vector because an unverified profile trying to merge into a | 1745 // to be in the vector because an unverified profile trying to merge into a |
| 1744 // similar verified profile will be discarded. | 1746 // similar verified profile will be discarded. |
| 1745 base::Time comparison_time = base::Time::Now(); | 1747 base::Time comparison_time = AutofillClock::Now(); |
| 1746 std::sort(existing_profiles->begin(), existing_profiles->end(), | 1748 std::sort(existing_profiles->begin(), existing_profiles->end(), |
| 1747 [comparison_time](const std::unique_ptr<AutofillProfile>& a, | 1749 [comparison_time](const std::unique_ptr<AutofillProfile>& a, |
| 1748 const std::unique_ptr<AutofillProfile>& b) { | 1750 const std::unique_ptr<AutofillProfile>& b) { |
| 1749 if (a->IsVerified() != b->IsVerified()) | 1751 if (a->IsVerified() != b->IsVerified()) |
| 1750 return !a->IsVerified(); | 1752 return !a->IsVerified(); |
| 1751 return a->CompareFrecency(b.get(), comparison_time); | 1753 return a->CompareFrecency(b.get(), comparison_time); |
| 1752 }); | 1754 }); |
| 1753 | 1755 |
| 1754 AutofillProfileComparator comparator(app_locale_); | 1756 AutofillProfileComparator comparator(app_locale_); |
| 1755 | 1757 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 if (was_modified) { | 1851 if (was_modified) { |
| 1850 if (credit_card->record_type() == CreditCard::LOCAL_CARD) | 1852 if (credit_card->record_type() == CreditCard::LOCAL_CARD) |
| 1851 database_->UpdateCreditCard(*credit_card); | 1853 database_->UpdateCreditCard(*credit_card); |
| 1852 else | 1854 else |
| 1853 database_->UpdateServerCardMetadata(*credit_card); | 1855 database_->UpdateServerCardMetadata(*credit_card); |
| 1854 } | 1856 } |
| 1855 } | 1857 } |
| 1856 } | 1858 } |
| 1857 | 1859 |
| 1858 } // namespace autofill | 1860 } // namespace autofill |
| OLD | NEW |