| 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 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 // TODO(crbug.com/618448): Refactor MergeProfile to not depend on class | 892 // TODO(crbug.com/618448): Refactor MergeProfile to not depend on class |
| 893 // variables. | 893 // variables. |
| 894 std::string PersonalDataManager::MergeProfile( | 894 std::string PersonalDataManager::MergeProfile( |
| 895 const AutofillProfile& new_profile, | 895 const AutofillProfile& new_profile, |
| 896 std::vector<AutofillProfile*> existing_profiles, | 896 std::vector<AutofillProfile*> existing_profiles, |
| 897 const std::string& app_locale, | 897 const std::string& app_locale, |
| 898 std::vector<AutofillProfile>* merged_profiles) { | 898 std::vector<AutofillProfile>* merged_profiles) { |
| 899 merged_profiles->clear(); | 899 merged_profiles->clear(); |
| 900 | 900 |
| 901 // Sort the existing profiles in decreasing order of frecency, so the "best" | 901 // Sort the existing profiles in decreasing order of frecency, so the "best" |
| 902 // profiles are checked first. | 902 // profiles are checked first. Put the verified profiles last so the non |
| 903 // verified profiles get deduped among themselves before reaching the verified |
| 904 // profiles. |
| 905 // TODO(crbug.com/620521): Remove the check for verified from the sort. |
| 903 base::Time comparison_time = base::Time::Now(); | 906 base::Time comparison_time = base::Time::Now(); |
| 904 std::sort(existing_profiles.begin(), existing_profiles.end(), | 907 std::sort(existing_profiles.begin(), existing_profiles.end(), |
| 905 [comparison_time](const AutofillDataModel* a, | 908 [comparison_time](const AutofillDataModel* a, |
| 906 const AutofillDataModel* b) { | 909 const AutofillDataModel* b) { |
| 910 if (a->IsVerified() != b->IsVerified()) |
| 911 return !a->IsVerified(); |
| 907 return a->CompareFrecency(b, comparison_time); | 912 return a->CompareFrecency(b, comparison_time); |
| 908 }); | 913 }); |
| 909 | 914 |
| 910 // Set to true if |existing_profiles| already contains an equivalent profile. | 915 // Set to true if |existing_profiles| already contains an equivalent profile. |
| 911 bool matching_profile_found = false; | 916 bool matching_profile_found = false; |
| 912 std::string guid = new_profile.guid(); | 917 std::string guid = new_profile.guid(); |
| 913 | 918 |
| 914 // If we have already saved this address, merge in any missing values. | 919 // If we have already saved this address, merge in any missing values. |
| 915 // Only merge with the first match. | 920 // Only merge with the first match. |
| 916 for (AutofillProfile* existing_profile : existing_profiles) { | 921 for (AutofillProfile* existing_profile : existing_profiles) { |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 // Don't try to merge a profile with itself or with any profile with a | 1574 // Don't try to merge a profile with itself or with any profile with a |
| 1570 // different PrimaryValue. | 1575 // different PrimaryValue. |
| 1571 if (existing_profile->guid() != profile_to_merge->guid() && | 1576 if (existing_profile->guid() != profile_to_merge->guid() && |
| 1572 AutofillProfile::CanonicalizeProfileString( | 1577 AutofillProfile::CanonicalizeProfileString( |
| 1573 existing_profile->PrimaryValue(app_locale_)) == | 1578 existing_profile->PrimaryValue(app_locale_)) == |
| 1574 AutofillProfile::CanonicalizeProfileString( | 1579 AutofillProfile::CanonicalizeProfileString( |
| 1575 profile_to_merge->PrimaryValue(app_locale_))) { | 1580 profile_to_merge->PrimaryValue(app_locale_))) { |
| 1576 if (existing_profile->SaveAdditionalInfo(*profile_to_merge, | 1581 if (existing_profile->SaveAdditionalInfo(*profile_to_merge, |
| 1577 app_locale_)) { | 1582 app_locale_)) { |
| 1578 // Since |profile_to_merge| was a duplicate of |existing_profile| and | 1583 // Since |profile_to_merge| was a duplicate of |existing_profile| and |
| 1579 // was merged sucessfully, it can now be deleted. | 1584 // was merged sucessfully, it can now be deleted. The only exception is |
| 1580 profile_guids_to_delete->push_back(profile_to_merge->guid()); | 1585 // if |profile_to_merge| is verified and |existing_profile| is not. |
| 1586 // Verified profiles only merge with other verified profiles. |
| 1587 if (!profile_to_merge->IsVerified() || existing_profile->IsVerified()) |
| 1588 profile_guids_to_delete->push_back(profile_to_merge->guid()); |
| 1581 | 1589 |
| 1582 // Now try to merge the new resulting profile with the rest of the | 1590 // Now try to merge the new resulting profile with the rest of the |
| 1583 // existing profiles. | 1591 // existing profiles. |
| 1584 profile_to_merge = existing_profile; | 1592 profile_to_merge = existing_profile; |
| 1585 } | 1593 } |
| 1586 } | 1594 } |
| 1587 } | 1595 } |
| 1588 | 1596 |
| 1589 AutofillMetrics::LogNumberOfProfilesRemovedDuringDedupe( | 1597 AutofillMetrics::LogNumberOfProfilesRemovedDuringDedupe( |
| 1590 profile_guids_to_delete->size()); | 1598 profile_guids_to_delete->size()); |
| 1591 } | 1599 } |
| 1592 | 1600 |
| 1593 } // namespace autofill | 1601 } // namespace autofill |
| OLD | NEW |