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 b1ad2b06659d0ed14b80e9e0f8e2a164ba3ff7ea..a575a806367104c95362f31561752850491db2ba 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" |
@@ -760,6 +761,7 @@ const std::vector<CreditCard*>& PersonalDataManager::GetCreditCards() const { |
credit_cards_.insert(credit_cards_.end(), server_credit_cards_.begin(), |
server_credit_cards_.end()); |
} |
+ |
return credit_cards_; |
} |
@@ -792,14 +794,28 @@ std::vector<Suggestion> PersonalDataManager::GetProfileSuggestions( |
continue; |
base::string16 value_canon = |
AutofillProfile::CanonicalizeProfileString(value); |
- if (StartsWith(value_canon, field_contents_canon, true)) { |
- // Prefix match, add suggestion. |
+ // CanonicalizeProfileString() returns lower-case string with all |
+ // 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. |
+ bool substring_matched_suggestion = false; |
+ if (StartsWith(value_canon, field_contents_canon, true) || |
+ (substring_matched_suggestion = |
+ ContainsTokenThatStartsWith(value, field_contents, false))) { |
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()) |
+ OrderPrefixBeforeSubstring(&suggestions); |
+ |
// Don't show two suggestions if one is a subset of the other. |
std::vector<AutofillProfile*> unique_matched_profiles; |
std::vector<Suggestion> unique_suggestions; |
@@ -848,6 +864,7 @@ std::vector<Suggestion> PersonalDataManager::GetCreditCardSuggestions( |
const AutofillType& type, |
const base::string16& field_contents) { |
std::list<const CreditCard*> cards_to_suggest; |
+ std::list<const CreditCard*> substring_matched_suggestions; |
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 = |
@@ -866,11 +883,22 @@ std::vector<Suggestion> PersonalDataManager::GetCreditCardSuggestions( |
field_contents.size() >= 6)) { |
continue; |
} |
- } else if (!StartsWith(creditcard_field_value, field_contents, false)) { |
- continue; |
+ cards_to_suggest.push_back(credit_card); |
+ } else if (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()) { |
+ cards_to_suggest.insert(cards_to_suggest.end(), |
Evan Stade
2015/06/08 23:23:38
so it seems the substring matches are not ranked i
Pritam Nikam
2015/06/09 11:39:06
Done.
|
+ substring_matched_suggestions.begin(), |
+ substring_matched_suggestions.end()); |
} |
// De-dupe card suggestions. Full server cards shadow local cards, and |
@@ -898,8 +926,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. |