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

Unified 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: Incorporated Vaclav's review comments. Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/personal_data_manager.cc
diff --git a/components/autofill/core/browser/personal_data_manager.cc b/components/autofill/core/browser/personal_data_manager.cc
index 980448b98868129f949124ac3467abcc36370eb8..da9a59f3de30923486ae96f5155b48b9c917696c 100644
--- a/components/autofill/core/browser/personal_data_manager.cc
+++ b/components/autofill/core/browser/personal_data_manager.cc
@@ -31,6 +31,7 @@
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_pref_names.h"
#include "components/autofill/core/common/autofill_switches.h"
+#include "components/autofill/core/common/autofill_util.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/common/signin_pref_names.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
@@ -796,15 +797,28 @@ std::vector<Suggestion> PersonalDataManager::GetProfileSuggestions(
continue;
base::string16 value_canon =
AutofillProfile::CanonicalizeProfileString(value);
- if (base::StartsWith(value_canon, field_contents_canon,
- base::CompareCase::SENSITIVE)) {
- // Prefix match, add suggestion.
+ bool prefix_matched_suggestion = base::StartsWith(
+ value_canon, field_contents_canon, base::CompareCase::SENSITIVE);
+ if (prefix_matched_suggestion ||
+ FieldIsSuggestionSubstringStartingOnTokenBoundary(value, field_contents,
+ false)) {
matched_profiles.push_back(profile);
suggestions.push_back(Suggestion(value));
suggestions.back().backend_id = profile->guid();
+ suggestions.back().match = prefix_matched_suggestion
+ ? Suggestion::PREFIX_MATCH
+ : Suggestion::SUBSTRING_MATCH;
}
}
+ // Prefix matches should precede other token matches.
+ if (IsFeatureSubstringMatchEnabled()) {
+ std::stable_sort(suggestions.begin(), suggestions.end(),
+ [](const Suggestion& a, const Suggestion& b) {
+ return a.match < b.match;
+ });
+ }
+
// Don't show two suggestions if one is a subset of the other.
std::vector<AutofillProfile*> unique_matched_profiles;
std::vector<Suggestion> unique_suggestions;
@@ -856,6 +870,7 @@ std::vector<Suggestion> PersonalDataManager::GetCreditCardSuggestions(
return std::vector<Suggestion>();
std::list<const CreditCard*> cards_to_suggest;
+ std::list<const CreditCard*> substring_matched_cards;
base::string16 field_contents_lower = base::i18n::ToLower(field_contents);
for (const CreditCard* credit_card : GetCreditCards()) {
// The value of the stored data for this field type in the |credit_card|.
@@ -878,12 +893,24 @@ std::vector<Suggestion> PersonalDataManager::GetCreditCardSuggestions(
field_contents.size() >= 6)) {
continue;
}
- } else if (!base::StartsWith(creditcard_field_lower, field_contents_lower,
- base::CompareCase::SENSITIVE)) {
- continue;
+ cards_to_suggest.push_back(credit_card);
+ } else if (base::StartsWith(creditcard_field_lower, field_contents_lower,
+ base::CompareCase::SENSITIVE)) {
+ cards_to_suggest.push_back(credit_card);
+ } else if (FieldIsSuggestionSubstringStartingOnTokenBoundary(
+ creditcard_field_lower, field_contents_lower, true)) {
+ substring_matched_cards.push_back(credit_card);
}
+ }
- cards_to_suggest.push_back(credit_card);
+ cards_to_suggest.sort(RankByMfu);
+
+ // Prefix matches should precede other token matches.
+ if (IsFeatureSubstringMatchEnabled()) {
+ substring_matched_cards.sort(RankByMfu);
+ cards_to_suggest.insert(cards_to_suggest.end(),
+ substring_matched_cards.begin(),
+ substring_matched_cards.end());
}
// De-dupe card suggestions. Full server cards shadow local cards, and
@@ -911,8 +938,6 @@ std::vector<Suggestion> PersonalDataManager::GetCreditCardSuggestions(
}
}
- cards_to_suggest.sort(RankByMfu);
-
std::vector<Suggestion> suggestions;
for (const CreditCard* credit_card : cards_to_suggest) {
// Make a new suggestion.
« no previous file with comments | « components/autofill/core/browser/autofill_manager_unittest.cc ('k') | components/autofill/core/browser/suggestion.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698