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: Added comments in autocomplete_history_manager.cc. Created 5 years, 6 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 ca41fd5b5cf8a22f8287fdc02fb3bdc74b62855d..e99118217db1896f69795c4a3da680015e1d00af 100644
--- a/components/autofill/core/browser/personal_data_manager.cc
+++ b/components/autofill/core/browser/personal_data_manager.cc
@@ -30,6 +30,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"
@@ -795,14 +796,32 @@ std::vector<Suggestion> PersonalDataManager::GetProfileSuggestions(
continue;
base::string16 value_canon =
AutofillProfile::CanonicalizeProfileString(value);
- if (base::StartsWith(value_canon, field_contents_canon, true)) {
- // Prefix match, add suggestion.
+ // CanonicalizeProfileString() returns lower-case string with all
please use gerrit instead 2015/06/29 22:06:29 CanonicalizeProfileString() does not replace "all
Pritam Nikam 2015/06/30 15:05:50 Done. I reffered it from here [1]. [1]. https:/
+ // separator substituted by whitespaces and trims off trailing whitespace
+ // if any. Passing |value_canon| and |field_contents_canon| to
+ // ContainsTokenThatStartsWith() may lead to unexpected result, hence
+ // preferred passing |values[i]| and |field_contents| instead.
please use gerrit instead 2015/06/29 22:06:29 This part of the comment is outdated. There's no v
Pritam Nikam 2015/06/30 15:05:50 Done.
+ bool substring_matched_suggestion = false;
+ if (base::StartsWith(value_canon, field_contents_canon, true) ||
+ (substring_matched_suggestion =
+ ContainsTokenThatStartsWith(value, field_contents, false))) {
please use gerrit instead 2015/06/29 22:06:29 It's rare in Chromium code to assign a variable in
Pritam Nikam 2015/06/30 15:05:50 Done. Changes to: bool prefix_matched_sugg
please use gerrit instead 2015/06/30 19:06:22 Nice.
matched_profiles.push_back(profile);
suggestions.push_back(Suggestion(value));
suggestions.back().backend_id = profile->guid();
+ suggestions.back().match = substring_matched_suggestion
+ ? Suggestion::SUBSTRING_MATCH
+ : Suggestion::PREFIX_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;
+ });
please use gerrit instead 2015/06/29 22:06:29 Is this clang formatted?
Pritam Nikam 2015/06/30 15:05:50 Yes.
+ }
+
// Don't show two suggestions if one is a subset of the other.
std::vector<AutofillProfile*> unique_matched_profiles;
std::vector<Suggestion> unique_suggestions;
@@ -854,6 +873,7 @@ std::vector<Suggestion> PersonalDataManager::GetCreditCardSuggestions(
return std::vector<Suggestion>();
std::list<const CreditCard*> cards_to_suggest;
+ std::list<const CreditCard*> substring_matched_suggestions;
please use gerrit instead 2015/06/29 22:06:29 s/substring_matched_suggestions/substring_matched_
Pritam Nikam 2015/06/30 15:05:50 Done.
for (const CreditCard* credit_card : GetCreditCards()) {
// The value of the stored data for this field type in the |credit_card|.
base::string16 creditcard_field_value =
@@ -872,12 +892,24 @@ std::vector<Suggestion> PersonalDataManager::GetCreditCardSuggestions(
field_contents.size() >= 6)) {
continue;
}
- } else if (!base::StartsWith(creditcard_field_value, field_contents,
- false)) {
- continue;
+ cards_to_suggest.push_back(credit_card);
+ } else if (base::StartsWith(creditcard_field_value, field_contents,
+ false)) {
+ cards_to_suggest.push_back(credit_card);
+ } else if (ContainsTokenThatStartsWith(creditcard_field_value,
+ field_contents, false)) {
+ substring_matched_suggestions.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_suggestions.sort(RankByMfu);
+ cards_to_suggest.insert(cards_to_suggest.end(),
+ substring_matched_suggestions.begin(),
+ substring_matched_suggestions.end());
}
// De-dupe card suggestions. Full server cards shadow local cards, and
@@ -905,8 +937,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.

Powered by Google App Engine
This is Rietveld 408576698