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

Side by Side 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: Just code rebase. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autocomplete_history_manager.h" 5 #include "components/autofill/core/browser/autocomplete_history_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/profiler/scoped_tracker.h" 10 #include "base/profiler/scoped_tracker.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "components/autofill/core/browser/autofill_client.h" 14 #include "components/autofill/core/browser/autofill_client.h"
14 #include "components/autofill/core/browser/autofill_driver.h" 15 #include "components/autofill/core/browser/autofill_driver.h"
15 #include "components/autofill/core/browser/autofill_experiments.h" 16 #include "components/autofill/core/browser/autofill_experiments.h"
16 #include "components/autofill/core/browser/autofill_external_delegate.h" 17 #include "components/autofill/core/browser/autofill_external_delegate.h"
17 #include "components/autofill/core/browser/validation.h" 18 #include "components/autofill/core/browser/validation.h"
18 #include "components/autofill/core/common/autofill_pref_names.h" 19 #include "components/autofill/core/common/autofill_pref_names.h"
20 #include "components/autofill/core/common/autofill_util.h"
19 #include "components/autofill/core/common/form_data.h" 21 #include "components/autofill/core/common/form_data.h"
20 22
21 namespace autofill { 23 namespace autofill {
22 namespace { 24 namespace {
23 25
24 // Limit on the number of suggestions to appear in the pop-up menu under an 26 // Limit on the number of suggestions to appear in the pop-up menu under an
25 // text input element in a form. 27 // text input element in a form.
26 const int kMaxAutocompleteMenuItems = 6; 28 const int kMaxAutocompleteMenuItems = 6;
27 29
28 bool IsTextField(const FormFieldData& field) { 30 bool IsTextField(const FormFieldData& field) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // See http://crbug.com/68783. 77 // See http://crbug.com/68783.
76 if (!result) { 78 if (!result) {
77 SendSuggestions(NULL); 79 SendSuggestions(NULL);
78 return; 80 return;
79 } 81 }
80 82
81 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType()); 83 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType());
82 const WDResult<std::vector<base::string16> >* autofill_result = 84 const WDResult<std::vector<base::string16> >* autofill_result =
83 static_cast<const WDResult<std::vector<base::string16> >*>(result); 85 static_cast<const WDResult<std::vector<base::string16> >*>(result);
84 std::vector<base::string16> suggestions = autofill_result->GetValue(); 86 std::vector<base::string16> suggestions = autofill_result->GetValue();
85 SendSuggestions(&suggestions); 87
88 if (!IsFeatureSubstringMatchEnabled() || pending_query_prefix_.empty()) {
89 SendSuggestions(&suggestions);
90 } else {
91 std::vector<base::string16> preferred_suggestions;
please use gerrit instead 2015/06/28 01:20:07 Wouldn't it be better to perform this logic in SQL
Pritam Nikam 2015/06/29 15:38:21 We need to pass '%<delimiter> + prefix_lower + %'.
please use gerrit instead 2015/06/29 17:06:45 Use '\_' instead?
Pritam Nikam 2015/06/30 15:05:50 ESCAPE clause worked for (_) case. SELECT value
92 std::vector<base::string16> substring_matched_suggestions;
93 for (base::string16 suggestion : suggestions) {
94 if (StartsWith(suggestion, pending_query_prefix_, false)) {
95 preferred_suggestions.push_back(suggestion);
96 } else if (ContainsTokenThatStartsWith(suggestion, pending_query_prefix_,
97 false)) {
98 substring_matched_suggestions.push_back(suggestion);
99 }
100 }
101
102 // Prefix matches should precede other token matches.
103 if (IsFeatureSubstringMatchEnabled()) {
104 preferred_suggestions.insert(preferred_suggestions.end(),
105 substring_matched_suggestions.begin(),
106 substring_matched_suggestions.end());
107 }
108
109 SendSuggestions(&preferred_suggestions);
110 }
86 } 111 }
87 112
88 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( 113 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
89 int query_id, 114 int query_id,
90 const base::string16& name, 115 const base::string16& name,
91 const base::string16& prefix, 116 const base::string16& prefix,
92 const std::string& form_control_type, 117 const std::string& form_control_type,
93 const std::vector<Suggestion>& suggestions) { 118 const std::vector<Suggestion>& suggestions) {
94 CancelPendingQuery(); 119 CancelPendingQuery();
95 120
96 query_id_ = query_id; 121 query_id_ = query_id;
97 autofill_suggestions_ = suggestions; 122 autofill_suggestions_ = suggestions;
98 if (!autofill_client_->IsAutocompleteEnabled() || 123 if (!autofill_client_->IsAutocompleteEnabled() ||
99 form_control_type == "textarea" || 124 form_control_type == "textarea" ||
100 IsInAutofillSuggestionsDisabledExperiment()) { 125 IsInAutofillSuggestionsDisabledExperiment()) {
101 SendSuggestions(NULL); 126 SendSuggestions(NULL);
102 return; 127 return;
103 } 128 }
104 129
105 if (database_.get()) { 130 if (database_.get()) {
131 pending_query_prefix_ = prefix;
106 pending_query_handle_ = database_->GetFormValuesForElementName( 132 pending_query_handle_ = database_->GetFormValuesForElementName(
107 name, prefix, kMaxAutocompleteMenuItems, this); 133 name, IsFeatureSubstringMatchEnabled() ? base::string16() : prefix,
134 kMaxAutocompleteMenuItems, this);
108 } 135 }
109 } 136 }
110 137
111 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { 138 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) {
112 if (!autofill_client_->IsAutocompleteEnabled()) 139 if (!autofill_client_->IsAutocompleteEnabled())
113 return; 140 return;
114 141
115 if (driver_->IsOffTheRecord()) 142 if (driver_->IsOffTheRecord())
116 return; 143 return;
117 144
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 207 }
181 } 208 }
182 209
183 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_); 210 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_);
184 211
185 query_id_ = 0; 212 query_id_ = 0;
186 autofill_suggestions_.clear(); 213 autofill_suggestions_.clear();
187 } 214 }
188 215
189 } // namespace autofill 216 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698