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 <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <iterator> | 9 #include <iterator> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
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 Loading... |
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 Loading... |
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 IsContentsPrefixOfSuggestionToken( |
| 855 value_canon, field_contents_canon, CASE_SENSITIVE))) { |
844 matched_profiles.push_back(profile); | 856 matched_profiles.push_back(profile); |
845 suggestions.push_back(Suggestion(values[i])); | 857 suggestions.push_back(Suggestion(values[i])); |
846 suggestions.back().backend_id.guid = profile->guid(); | 858 suggestions.back().backend_id.guid = profile->guid(); |
847 suggestions.back().backend_id.variant = i; | 859 suggestions.back().backend_id.variant = i; |
| 860 suggestions.back().match = substring_token_matched |
| 861 ? Suggestion::SUBSTRING_MATCH |
| 862 : Suggestion::PREFIX_MATCH; |
848 } | 863 } |
849 } | 864 } |
850 } | 865 } |
851 | 866 |
| 867 // Now sort profiles with prefix matched suggestions order before substring |
| 868 // matched suggestions. |
| 869 std::sort(suggestions.begin(), suggestions.end(), OrderPrefixBeforeSubstring); |
| 870 |
852 // Don't show two suggestions if one is a subset of the other. | 871 // Don't show two suggestions if one is a subset of the other. |
853 std::vector<AutofillProfile*> unique_matched_profiles; | 872 std::vector<AutofillProfile*> unique_matched_profiles; |
854 std::vector<Suggestion> unique_suggestions; | 873 std::vector<Suggestion> unique_suggestions; |
855 ServerFieldTypeSet types(other_field_types.begin(), other_field_types.end()); | 874 ServerFieldTypeSet types(other_field_types.begin(), other_field_types.end()); |
856 for (size_t i = 0; i < matched_profiles.size(); ++i) { | 875 for (size_t i = 0; i < matched_profiles.size(); ++i) { |
857 bool include = true; | 876 bool include = true; |
858 AutofillProfile* profile_a = matched_profiles[i]; | 877 AutofillProfile* profile_a = matched_profiles[i]; |
859 for (size_t j = 0; j < matched_profiles.size(); ++j) { | 878 for (size_t j = 0; j < matched_profiles.size(); ++j) { |
860 AutofillProfile* profile_b = matched_profiles[j]; | 879 AutofillProfile* profile_b = matched_profiles[j]; |
861 // Check if profile A is a subset of profile B. If not, continue. | 880 // 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 Loading... |
1371 } | 1390 } |
1372 if (IsExperimentalWalletIntegrationEnabled() && | 1391 if (IsExperimentalWalletIntegrationEnabled() && |
1373 pref_service_->GetBoolean(prefs::kAutofillWalletImportEnabled)) { | 1392 pref_service_->GetBoolean(prefs::kAutofillWalletImportEnabled)) { |
1374 profiles_.insert( | 1393 profiles_.insert( |
1375 profiles_.end(), server_profiles_.begin(), server_profiles_.end()); | 1394 profiles_.end(), server_profiles_.begin(), server_profiles_.end()); |
1376 } | 1395 } |
1377 return profiles_; | 1396 return profiles_; |
1378 } | 1397 } |
1379 | 1398 |
1380 } // namespace autofill | 1399 } // namespace autofill |
OLD | NEW |