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

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

Issue 1943853003: [Autofill] Sort existing profiles by frecency before trying to merge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 866 // static
867 std::string PersonalDataManager::MergeProfile( 867 std::string PersonalDataManager::MergeProfile(
868 const AutofillProfile& new_profile, 868 const AutofillProfile& new_profile,
869 const std::vector<AutofillProfile*>& existing_profiles, 869 std::vector<AutofillProfile*> existing_profiles,
870 const std::string& app_locale, 870 const std::string& app_locale,
871 std::vector<AutofillProfile>* merged_profiles) { 871 std::vector<AutofillProfile>* merged_profiles) {
872 merged_profiles->clear(); 872 merged_profiles->clear();
873 873
874 // Sort the existing profiles in decreasing order of frecency, so the "best"
875 // profiles are checked first.
876 base::Time comparison_time = base::Time::Now();
877 std::sort(existing_profiles.begin(), existing_profiles.end(),
878 [comparison_time](const AutofillDataModel* a,
879 const AutofillDataModel* b) {
880 return a->CompareFrecency(b, comparison_time);
881 });
882
874 // Set to true if |existing_profiles| already contains an equivalent profile. 883 // Set to true if |existing_profiles| already contains an equivalent profile.
875 bool matching_profile_found = false; 884 bool matching_profile_found = false;
876 std::string guid = new_profile.guid(); 885 std::string guid = new_profile.guid();
877 886
878 // If we have already saved this address, merge in any missing values. 887 // If we have already saved this address, merge in any missing values.
879 // Only merge with the first match. 888 // Only merge with the first match.
880 for (AutofillProfile* existing_profile : existing_profiles) { 889 for (AutofillProfile* existing_profile : existing_profiles) {
881 if (!matching_profile_found && !new_profile.PrimaryValue().empty() && 890 if (!matching_profile_found && !new_profile.PrimaryValue().empty() &&
882 existing_profile->SaveAdditionalInfo(new_profile, app_locale)) { 891 existing_profile->SaveAdditionalInfo(new_profile, app_locale)) {
883 // Unverified profiles should always be updated with the newer data, 892 // Unverified profiles should always be updated with the newer data,
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 std::stable_sort(suggestions.begin(), suggestions.end(), 1508 std::stable_sort(suggestions.begin(), suggestions.end(),
1500 [](const Suggestion& a, const Suggestion& b) { 1509 [](const Suggestion& a, const Suggestion& b) {
1501 return a.match < b.match; 1510 return a.match < b.match;
1502 }); 1511 });
1503 } 1512 }
1504 1513
1505 return suggestions; 1514 return suggestions;
1506 } 1515 }
1507 1516
1508 } // namespace autofill 1517 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698