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

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: 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 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 5441a475b7da657346d9603ce00b82bb4c6251dc..efdc5b408b04b59f3109a3dafb34eec34fae4fd6 100644
--- a/components/autofill/core/browser/personal_data_manager.cc
+++ b/components/autofill/core/browser/personal_data_manager.cc
@@ -29,6 +29,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/common/signin_pref_names.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_formatter.h"
@@ -229,6 +230,13 @@ bool RankByMfu(const AutofillDataModel* a, const AutofillDataModel* b) {
return a->use_date() > b->use_date();
}
+// Helper function to order prefix matched suggestions prior to substring
+// matched.
+bool OrderPrefixBeforeSubstring(const Suggestion& suggestion1,
+ const Suggestion& suggestion2) {
+ return suggestion1.match < suggestion2.match;
+}
+
} // namespace
PersonalDataManager::PersonalDataManager(const std::string& app_locale)
@@ -837,18 +845,28 @@ std::vector<Suggestion> PersonalDataManager::GetProfileSuggestions(
if (values[i].empty())
continue;
+ bool substring_token_matched = false;
base::string16 value_canon =
AutofillProfile::CanonicalizeProfileString(values[i]);
- if (StartsWith(value_canon, field_contents_canon, true)) {
- // Prefix match, add suggestion.
+ if (StartsWith(value_canon, field_contents_canon, true) ||
+ (substring_token_matched =
+ IsFeatureSubstringMatchEnabled() &&
+ HasTokenStartsWith(value_canon, field_contents_canon))) {
matched_profiles.push_back(profile);
suggestions.push_back(Suggestion(values[i]));
suggestions.back().backend_id.guid = profile->guid();
suggestions.back().backend_id.variant = i;
+ suggestions.back().match = substring_token_matched
+ ? Suggestion::SUBSTRING_MATCH
+ : Suggestion::PREFIX_MATCH;
}
}
}
+ // Now sort profiles with prefix matched suggestions order befor substring
+ // matched suggestions.
+ std::sort(suggestions.begin(), suggestions.end(), OrderPrefixBeforeSubstring);
+
// Don't show two suggestions if one is a subset of the other.
std::vector<AutofillProfile*> unique_matched_profiles;
std::vector<Suggestion> unique_suggestions;

Powered by Google App Engine
This is Rietveld 408576698