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

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: Added comments in autocomplete_history_manager.cc. 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;
92 std::vector<base::string16> substring_matched_suggestions;
93 for (base::string16 suggestion : suggestions) {
please use gerrit instead 2015/06/29 22:06:28 const base::string16&
Pritam Nikam 2015/06/30 15:05:50 Done.
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 // TODO(pritam.nikam): Prensently there is unavailability of SQL solutions
132 // to handle '_' along LIKE operator on Chromium Linux bot. Patterns like
133 // '%s\_foo%' and '%[_]foo%' are not working. Revisit below code snippet in
134 // future so that logic can be handled in SQL query instead.
please use gerrit instead 2015/06/29 22:06:28 No need for "Revisit.." sentence and TODO marker.
Pritam Nikam 2015/06/30 15:05:50 With ESCAPE clause its working. I've modified |Aut
135 pending_query_prefix_ = prefix;
106 pending_query_handle_ = database_->GetFormValuesForElementName( 136 pending_query_handle_ = database_->GetFormValuesForElementName(
107 name, prefix, kMaxAutocompleteMenuItems, this); 137 name, IsFeatureSubstringMatchEnabled() ? base::string16() : prefix,
138 kMaxAutocompleteMenuItems, this);
108 } 139 }
109 } 140 }
110 141
111 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { 142 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) {
112 if (!autofill_client_->IsAutocompleteEnabled()) 143 if (!autofill_client_->IsAutocompleteEnabled())
113 return; 144 return;
114 145
115 if (driver_->IsOffTheRecord()) 146 if (driver_->IsOffTheRecord())
116 return; 147 return;
117 148
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 211 }
181 } 212 }
182 213
183 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_); 214 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_);
184 215
185 query_id_ = 0; 216 query_id_ = 0;
186 autofill_suggestions_.clear(); 217 autofill_suggestions_.clear();
187 } 218 }
188 219
189 } // namespace autofill 220 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698