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

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: Addresses Vaclav's & Evan's Inputs. 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // which is probably not what we want. TODO(estade): figure out relative ranking 223 // which is probably not what we want. TODO(estade): figure out relative ranking
223 // of server data. 224 // of server data.
224 bool RankByMfu(const AutofillDataModel* a, const AutofillDataModel* b) { 225 bool RankByMfu(const AutofillDataModel* a, const AutofillDataModel* b) {
225 if (a->use_count() != b->use_count()) 226 if (a->use_count() != b->use_count())
226 return a->use_count() > b->use_count(); 227 return a->use_count() > b->use_count();
227 228
228 // Ties are broken by MRU. 229 // Ties are broken by MRU.
229 return a->use_date() > b->use_date(); 230 return a->use_date() > b->use_date();
230 } 231 }
231 232
233 // Helper function to order prefix matched suggestions prior to substring
234 // matched.
235 bool OrderPrefixBeforeSubstring(const Suggestion& suggestion1,
236 const Suggestion& suggestion2) {
237 return suggestion1.match < suggestion2.match;
238 }
239
232 } // namespace 240 } // namespace
233 241
234 PersonalDataManager::PersonalDataManager(const std::string& app_locale) 242 PersonalDataManager::PersonalDataManager(const std::string& app_locale)
235 : database_(NULL), 243 : database_(NULL),
236 is_data_loaded_(false), 244 is_data_loaded_(false),
237 pending_profiles_query_(0), 245 pending_profiles_query_(0),
238 pending_server_profiles_query_(0), 246 pending_server_profiles_query_(0),
239 pending_creditcards_query_(0), 247 pending_creditcards_query_(0),
240 pending_server_creditcards_query_(0), 248 pending_server_creditcards_query_(0),
241 app_locale_(app_locale), 249 app_locale_(app_locale),
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 std::vector<Suggestion> suggestions; 838 std::vector<Suggestion> suggestions;
831 // Match based on a prefix search. 839 // Match based on a prefix search.
832 std::vector<AutofillProfile*> matched_profiles; 840 std::vector<AutofillProfile*> matched_profiles;
833 for (AutofillProfile* profile : profiles) { 841 for (AutofillProfile* profile : profiles) {
834 std::vector<base::string16> values = 842 std::vector<base::string16> values =
835 GetMultiInfoInOneLine(profile, type, app_locale_); 843 GetMultiInfoInOneLine(profile, type, app_locale_);
836 for (size_t i = 0; i < values.size(); i++) { 844 for (size_t i = 0; i < values.size(); i++) {
837 if (values[i].empty()) 845 if (values[i].empty())
838 continue; 846 continue;
839 847
848 bool substring_token_matched = false;
840 base::string16 value_canon = 849 base::string16 value_canon =
841 AutofillProfile::CanonicalizeProfileString(values[i]); 850 AutofillProfile::CanonicalizeProfileString(values[i]);
842 if (StartsWith(value_canon, field_contents_canon, true)) { 851 if (StartsWith(value_canon, field_contents_canon, true) ||
843 // Prefix match, add suggestion. 852 (substring_token_matched =
853 IsFeatureSubstringMatchEnabled() &&
854 HasTokenStartsWith(value_canon, field_contents_canon))) {
844 matched_profiles.push_back(profile); 855 matched_profiles.push_back(profile);
845 suggestions.push_back(Suggestion(values[i])); 856 suggestions.push_back(Suggestion(values[i]));
846 suggestions.back().backend_id.guid = profile->guid(); 857 suggestions.back().backend_id.guid = profile->guid();
847 suggestions.back().backend_id.variant = i; 858 suggestions.back().backend_id.variant = i;
859 suggestions.back().match = substring_token_matched
860 ? Suggestion::SUBSTRING_MATCH
861 : Suggestion::PREFIX_MATCH;
848 } 862 }
849 } 863 }
850 } 864 }
851 865
866 // Now sort profiles with prefix matched suggestions order befor substring
867 // matched suggestions.
868 std::sort(suggestions.begin(), suggestions.end(), OrderPrefixBeforeSubstring);
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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 } 1389 }
1372 if (IsExperimentalWalletIntegrationEnabled() && 1390 if (IsExperimentalWalletIntegrationEnabled() &&
1373 pref_service_->GetBoolean(prefs::kAutofillWalletImportEnabled)) { 1391 pref_service_->GetBoolean(prefs::kAutofillWalletImportEnabled)) {
1374 profiles_.insert( 1392 profiles_.insert(
1375 profiles_.end(), server_profiles_.begin(), server_profiles_.end()); 1393 profiles_.end(), server_profiles_.begin(), server_profiles_.end());
1376 } 1394 }
1377 return profiles_; 1395 return profiles_;
1378 } 1396 }
1379 1397
1380 } // namespace autofill 1398 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698