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