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

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

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unittests. Created 5 years, 9 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 <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <iterator> 9 #include <iterator>
10 10
(...skipping 11 matching lines...) Expand all
22 #include "components/autofill/core/browser/autofill_country.h" 22 #include "components/autofill/core/browser/autofill_country.h"
23 #include "components/autofill/core/browser/autofill_field.h" 23 #include "components/autofill/core/browser/autofill_field.h"
24 #include "components/autofill/core/browser/autofill_metrics.h" 24 #include "components/autofill/core/browser/autofill_metrics.h"
25 #include "components/autofill/core/browser/form_structure.h" 25 #include "components/autofill/core/browser/form_structure.h"
26 #include "components/autofill/core/browser/personal_data_manager_observer.h" 26 #include "components/autofill/core/browser/personal_data_manager_observer.h"
27 #include "components/autofill/core/browser/phone_number.h" 27 #include "components/autofill/core/browser/phone_number.h"
28 #include "components/autofill/core/browser/phone_number_i18n.h" 28 #include "components/autofill/core/browser/phone_number_i18n.h"
29 #include "components/autofill/core/browser/validation.h" 29 #include "components/autofill/core/browser/validation.h"
30 #include "components/autofill/core/common/autofill_pref_names.h" 30 #include "components/autofill/core/common/autofill_pref_names.h"
31 #include "components/autofill/core/common/autofill_switches.h" 31 #include "components/autofill/core/common/autofill_switches.h"
32 #include "components/autofill/core/common/autofill_util.h"
32 #include "components/signin/core/common/signin_pref_names.h" 33 #include "components/signin/core/common/signin_pref_names.h"
33 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" 34 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h"
34 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h" 35 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h"
35 36
36 namespace autofill { 37 namespace autofill {
37 namespace { 38 namespace {
38 39
39 using ::i18n::addressinput::AddressField; 40 using ::i18n::addressinput::AddressField;
40 using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine; 41 using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine;
41 using ::i18n::addressinput::STREET_ADDRESS; 42 using ::i18n::addressinput::STREET_ADDRESS;
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 } 824 }
824 } 825 }
825 } 826 }
826 827
827 return suggestions; 828 return suggestions;
828 } 829 }
829 830
830 std::vector<Suggestion> suggestions; 831 std::vector<Suggestion> suggestions;
831 // Match based on a prefix search. 832 // Match based on a prefix search.
832 std::vector<AutofillProfile*> matched_profiles; 833 std::vector<AutofillProfile*> matched_profiles;
834 std::vector<AutofillProfile*> substring_matched_profiles;
835 std::vector<base::string16> multi_values_for_substrings;
836 size_t prefix_match = 0;
833 for (AutofillProfile* profile : profiles) { 837 for (AutofillProfile* profile : profiles) {
834 std::vector<base::string16> values = 838 std::vector<base::string16> values =
835 GetMultiInfoInOneLine(profile, type, app_locale_); 839 GetMultiInfoInOneLine(profile, type, app_locale_);
836 for (size_t i = 0; i < values.size(); i++) { 840 for (size_t i = 0; i < values.size(); i++) {
837 if (values[i].empty()) 841 if (values[i].empty())
838 continue; 842 continue;
839 843
840 base::string16 value_canon = 844 base::string16 value_canon =
841 AutofillProfile::CanonicalizeProfileString(values[i]); 845 AutofillProfile::CanonicalizeProfileString(values[i]);
846 // Order |profile|s with pre-fix before sub-string match.
Evan Stade 2015/03/24 00:48:26 prefix, not pre-fix substring, not sub-string
Pritam Nikam 2015/03/24 11:39:36 Done.
842 if (StartsWith(value_canon, field_contents_canon, true)) { 847 if (StartsWith(value_canon, field_contents_canon, true)) {
843 // Prefix match, add suggestion. 848 // Prefix match, add suggestion.
844 matched_profiles.push_back(profile); 849 matched_profiles.push_back(profile);
845 suggestions.push_back(Suggestion(values[i])); 850 suggestions.push_back(Suggestion(values[i]));
846 suggestions.back().backend_id.guid = profile->guid(); 851 suggestions.back().backend_id.guid = profile->guid();
847 suggestions.back().backend_id.variant = i; 852 suggestions.back().backend_id.variant = i;
853 ++prefix_match;
854 } else if (IsFeatureSubStringMatchEnabled() &&
Evan Stade 2015/03/24 00:48:26 Substring (not SubString)
Pritam Nikam 2015/03/24 11:39:36 Done.
855 HasTokoneStartsWith(value_canon, field_contents_canon)) {
856 substring_matched_profiles.push_back(profile);
Evan Stade 2015/03/24 00:48:26 add a field to Suggestion to indicate if it's a pr
Pritam Nikam 2015/03/24 11:39:36 Done.
857 multi_values_for_substrings.push_back(values[i]);
848 } 858 }
849 } 859 }
850 } 860 }
851 861
862 // Now append profiles having sub-string matching.
863 for (size_t k = 0; k < substring_matched_profiles.size(); k++) {
864 matched_profiles.push_back(substring_matched_profiles[k]);
865 suggestions.push_back(Suggestion(multi_values_for_substrings[k]));
866 suggestions.back().backend_id.guid = substring_matched_profiles[k]->guid();
867 suggestions.back().backend_id.variant = k + prefix_match;
Evan Stade 2015/03/24 00:48:26 I do not understand this line at all
Pritam Nikam 2015/03/24 11:39:36 substring matched suggestion's |backend_id.variant
868 }
869
852 // Don't show two suggestions if one is a subset of the other. 870 // Don't show two suggestions if one is a subset of the other.
853 std::vector<AutofillProfile*> unique_matched_profiles; 871 std::vector<AutofillProfile*> unique_matched_profiles;
854 std::vector<Suggestion> unique_suggestions; 872 std::vector<Suggestion> unique_suggestions;
855 ServerFieldTypeSet types(other_field_types.begin(), other_field_types.end()); 873 ServerFieldTypeSet types(other_field_types.begin(), other_field_types.end());
856 for (size_t i = 0; i < matched_profiles.size(); ++i) { 874 for (size_t i = 0; i < matched_profiles.size(); ++i) {
857 bool include = true; 875 bool include = true;
858 AutofillProfile* profile_a = matched_profiles[i]; 876 AutofillProfile* profile_a = matched_profiles[i];
859 for (size_t j = 0; j < matched_profiles.size(); ++j) { 877 for (size_t j = 0; j < matched_profiles.size(); ++j) {
860 AutofillProfile* profile_b = matched_profiles[j]; 878 AutofillProfile* profile_b = matched_profiles[j];
861 // Check if profile A is a subset of profile B. If not, continue. 879 // Check if profile A is a subset of profile B. If not, continue.
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 } 1384 }
1367 if (IsExperimentalWalletIntegrationEnabled() && 1385 if (IsExperimentalWalletIntegrationEnabled() &&
1368 pref_service_->GetBoolean(prefs::kAutofillWalletImportEnabled)) { 1386 pref_service_->GetBoolean(prefs::kAutofillWalletImportEnabled)) {
1369 profiles_.insert( 1387 profiles_.insert(
1370 profiles_.end(), server_profiles_.begin(), server_profiles_.end()); 1388 profiles_.end(), server_profiles_.begin(), server_profiles_.end());
1371 } 1389 }
1372 return profiles_; 1390 return profiles_;
1373 } 1391 }
1374 1392
1375 } // namespace autofill 1393 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698