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

Unified Diff: components/autofill/core/browser/autocomplete_history_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 unittests. 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/autocomplete_history_manager.cc
diff --git a/components/autofill/core/browser/autocomplete_history_manager.cc b/components/autofill/core/browser/autocomplete_history_manager.cc
index 79d75b8c18d257b686c4121a9dbc5f7dedc8772a..537cf7932de822e1e83944cc8ca16d4334db1ab9 100644
--- a/components/autofill/core/browser/autocomplete_history_manager.cc
+++ b/components/autofill/core/browser/autocomplete_history_manager.cc
@@ -9,12 +9,14 @@
#include "base/prefs/pref_service.h"
#include "base/profiler/scoped_tracker.h"
#include "base/strings/string16.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/autofill_driver.h"
#include "components/autofill/core/browser/autofill_external_delegate.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_pref_names.h"
+#include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/form_data.h"
namespace autofill {
@@ -81,7 +83,30 @@ void AutocompleteHistoryManager::OnWebDataServiceRequestDone(
const WDResult<std::vector<base::string16> >* autofill_result =
static_cast<const WDResult<std::vector<base::string16> >*>(result);
std::vector<base::string16> suggestions = autofill_result->GetValue();
- SendSuggestions(&suggestions);
+
+ if (!IsFeatureSubStringMatchEnabled() || user_input_.empty()) {
+ SendSuggestions(&suggestions);
+ } else {
+ std::vector<base::string16> prefix_suggestions;
+ std::vector<base::string16> substring_suggestions;
+ for (auto suggestion : suggestions) {
Evan Stade 2015/03/24 00:48:26 please don't use auto for simple types like base::
Pritam Nikam 2015/03/24 11:39:36 Done.
+ // Populate all suggestions with prefix matched followed by sub-string
+ // matched.
+ if (StartsWith(suggestion, user_input_, false)) {
Evan Stade 2015/03/24 00:48:26 I feel like you should be using sql for this, as i
Pritam Nikam 2015/03/24 11:39:36 In my opinion, doing it in SQL will be bit difficu
+ prefix_suggestions.push_back(suggestion);
+ } else if (HasTokoneStartsWith(suggestion, user_input_)) {
+ substring_suggestions.push_back(suggestion);
+ }
+ }
+
+ // Now append sub-string matched suggestions to the prefix matched
+ // suggestion list.
+ for (auto substring_match : substring_suggestions) {
+ prefix_suggestions.push_back(substring_match);
+ }
+
+ SendSuggestions(&prefix_suggestions);
+ }
}
void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
@@ -101,8 +126,10 @@ void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
}
if (database_.get()) {
+ user_input_ = prefix;
pending_query_handle_ = database_->GetFormValuesForElementName(
- name, prefix, kMaxAutocompleteMenuItems, this);
+ name, IsFeatureSubStringMatchEnabled() ? base::string16() : prefix,
+ kMaxAutocompleteMenuItems, this);
}
}

Powered by Google App Engine
This is Rietveld 408576698