Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: components/autofill/core/browser/personal_data_manager.cc

Issue 1989173005: [Autofill] Dedupe similar profiles on insertion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 if (profile.IsPresentButInvalid(ADDRESS_HOME_STATE)) 856 if (profile.IsPresentButInvalid(ADDRESS_HOME_STATE))
857 return false; 857 return false;
858 858
859 // Reject profiles with invalid US zip information. 859 // Reject profiles with invalid US zip information.
860 if (profile.IsPresentButInvalid(ADDRESS_HOME_ZIP)) 860 if (profile.IsPresentButInvalid(ADDRESS_HOME_ZIP))
861 return false; 861 return false;
862 862
863 return true; 863 return true;
864 } 864 }
865 865
866 // static
867 std::string PersonalDataManager::MergeProfile( 866 std::string PersonalDataManager::MergeProfile(
Mathieu 2016/06/08 18:32:24 It feels weird to remove the static property here.
sebsg 2016/06/08 21:58:46 I like the idea. Would you mind if I did it in ano
868 const AutofillProfile& new_profile, 867 const AutofillProfile& new_profile,
869 std::vector<AutofillProfile*> existing_profiles, 868 std::vector<AutofillProfile*> existing_profiles,
870 const std::string& app_locale, 869 const std::string& app_locale,
871 std::vector<AutofillProfile>* merged_profiles) { 870 std::vector<AutofillProfile>* merged_profiles) {
872 merged_profiles->clear(); 871 merged_profiles->clear();
873 872
874 // Sort the existing profiles in decreasing order of frecency, so the "best" 873 // Sort the existing profiles in decreasing order of frecency, so the "best"
875 // profiles are checked first. 874 // profiles are checked first.
876 base::Time comparison_time = base::Time::Now(); 875 base::Time comparison_time = base::Time::Now();
877 std::sort(existing_profiles.begin(), existing_profiles.end(), 876 std::sort(existing_profiles.begin(), existing_profiles.end(),
(...skipping 11 matching lines...) Expand all
889 for (AutofillProfile* existing_profile : existing_profiles) { 888 for (AutofillProfile* existing_profile : existing_profiles) {
890 if (!matching_profile_found && !new_profile.PrimaryValue().empty() && 889 if (!matching_profile_found && !new_profile.PrimaryValue().empty() &&
891 existing_profile->SaveAdditionalInfo(new_profile, app_locale)) { 890 existing_profile->SaveAdditionalInfo(new_profile, app_locale)) {
892 // Unverified profiles should always be updated with the newer data, 891 // Unverified profiles should always be updated with the newer data,
893 // whereas verified profiles should only ever be overwritten by verified 892 // whereas verified profiles should only ever be overwritten by verified
894 // data. If an automatically aggregated profile would overwrite a 893 // data. If an automatically aggregated profile would overwrite a
895 // verified profile, just drop it. 894 // verified profile, just drop it.
896 matching_profile_found = true; 895 matching_profile_found = true;
897 guid = existing_profile->guid(); 896 guid = existing_profile->guid();
898 897
898 // Look for duplicates of |existing_profile| to merge into.
899 FindMergeAndDeleteDuplicateProfiles(existing_profiles, existing_profile,
900 app_locale);
901
899 // We set the modification date so that immediate requests for profiles 902 // We set the modification date so that immediate requests for profiles
900 // will properly reflect the fact that this profile has been modified 903 // will properly reflect the fact that this profile has been modified
901 // recently. After writing to the database and refreshing the local copies 904 // recently. After writing to the database and refreshing the local copies
902 // the profile will have a very slightly newer time reflecting what's 905 // the profile will have a very slightly newer time reflecting what's
903 // actually stored in the database. 906 // actually stored in the database.
904 existing_profile->set_modification_date(base::Time::Now()); 907 existing_profile->set_modification_date(base::Time::Now());
905 } 908 }
906 merged_profiles->push_back(*existing_profile); 909 merged_profiles->push_back(*existing_profile);
907 } 910 }
908 911
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 if (IsFeatureSubstringMatchEnabled()) { 1508 if (IsFeatureSubstringMatchEnabled()) {
1506 std::stable_sort(suggestions.begin(), suggestions.end(), 1509 std::stable_sort(suggestions.begin(), suggestions.end(),
1507 [](const Suggestion& a, const Suggestion& b) { 1510 [](const Suggestion& a, const Suggestion& b) {
1508 return a.match < b.match; 1511 return a.match < b.match;
1509 }); 1512 });
1510 } 1513 }
1511 1514
1512 return suggestions; 1515 return suggestions;
1513 } 1516 }
1514 1517
1518 void PersonalDataManager::FindMergeAndDeleteDuplicateProfiles(
1519 const std::vector<AutofillProfile*>& existing_profiles,
1520 AutofillProfile* profile_to_merge,
1521 const std::string& app_locale) {
1522 std::vector<std::string> profile_guids_to_delete;
1523
1524 FindAndMergeDuplicateProfiles(existing_profiles, profile_to_merge,
1525 &profile_guids_to_delete, app_locale);
1526
1527 // Delete the duplicate profiles.
1528 for (std::string profile_guid_to_delete : profile_guids_to_delete) {
1529 RemoveByGUID(profile_guid_to_delete);
1530 }
1531 }
1532
1533 void PersonalDataManager::FindAndMergeDuplicateProfiles(
1534 const std::vector<AutofillProfile*>& existing_profiles,
1535 AutofillProfile* profile_to_merge,
1536 std::vector<std::string>* profile_guids_to_delete,
1537 const std::string& app_locale) {
1538 for (AutofillProfile* existing_profile : existing_profiles) {
1539 // Don't try to merge a profile with itself or with any profile with a
1540 // different PrimaryValue.
1541 if (existing_profile->guid() != profile_to_merge->guid() &&
1542 AutofillProfile::CanonicalizeProfileString(
Mathieu 2016/06/08 18:32:24 Using the expanded PrimaryValue feels like a hack
sebsg 2016/06/08 21:58:46 The reason why I changed PrimaryValue was to fix a
1543 existing_profile->PrimaryValue()) ==
1544 AutofillProfile::CanonicalizeProfileString(
1545 profile_to_merge->PrimaryValue())) {
1546 if (existing_profile->SaveAdditionalInfo(*profile_to_merge, app_locale)) {
1547 // Since |profile_to_merge| was a duplicate of |existing_profile| and
1548 // was merged sucessfully, it can now be deleted.
1549 profile_guids_to_delete->push_back(profile_to_merge->guid());
1550
1551 // Now try to merge the new resulting profile with the rest of the
1552 // existing profiles.
1553 profile_to_merge = existing_profile;
1554 }
1555 }
1556 }
1557 }
1558
1515 } // namespace autofill 1559 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698