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

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 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 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_external_delegate.h" 16 #include "components/autofill/core/browser/autofill_external_delegate.h"
16 #include "components/autofill/core/browser/validation.h" 17 #include "components/autofill/core/browser/validation.h"
17 #include "components/autofill/core/common/autofill_pref_names.h" 18 #include "components/autofill/core/common/autofill_pref_names.h"
19 #include "components/autofill/core/common/autofill_util.h"
18 #include "components/autofill/core/common/form_data.h" 20 #include "components/autofill/core/common/form_data.h"
19 21
20 namespace autofill { 22 namespace autofill {
21 namespace { 23 namespace {
22 24
23 // Limit on the number of suggestions to appear in the pop-up menu under an 25 // Limit on the number of suggestions to appear in the pop-up menu under an
24 // text input element in a form. 26 // text input element in a form.
25 const int kMaxAutocompleteMenuItems = 6; 27 const int kMaxAutocompleteMenuItems = 6;
26 28
27 bool IsTextField(const FormFieldData& field) { 29 bool IsTextField(const FormFieldData& field) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // See http://crbug.com/68783. 76 // See http://crbug.com/68783.
75 if (!result) { 77 if (!result) {
76 SendSuggestions(NULL); 78 SendSuggestions(NULL);
77 return; 79 return;
78 } 80 }
79 81
80 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType()); 82 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType());
81 const WDResult<std::vector<base::string16> >* autofill_result = 83 const WDResult<std::vector<base::string16> >* autofill_result =
82 static_cast<const WDResult<std::vector<base::string16> >*>(result); 84 static_cast<const WDResult<std::vector<base::string16> >*>(result);
83 std::vector<base::string16> suggestions = autofill_result->GetValue(); 85 std::vector<base::string16> suggestions = autofill_result->GetValue();
84 SendSuggestions(&suggestions); 86
87 if (!IsFeatureSubStringMatchEnabled() || user_input_.empty()) {
88 SendSuggestions(&suggestions);
89 } else {
90 std::vector<base::string16> prefix_suggestions;
91 std::vector<base::string16> substring_suggestions;
92 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.
93 // Populate all suggestions with prefix matched followed by sub-string
94 // matched.
95 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
96 prefix_suggestions.push_back(suggestion);
97 } else if (HasTokoneStartsWith(suggestion, user_input_)) {
98 substring_suggestions.push_back(suggestion);
99 }
100 }
101
102 // Now append sub-string matched suggestions to the prefix matched
103 // suggestion list.
104 for (auto substring_match : substring_suggestions) {
105 prefix_suggestions.push_back(substring_match);
106 }
107
108 SendSuggestions(&prefix_suggestions);
109 }
85 } 110 }
86 111
87 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( 112 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
88 int query_id, 113 int query_id,
89 const base::string16& name, 114 const base::string16& name,
90 const base::string16& prefix, 115 const base::string16& prefix,
91 const std::string& form_control_type, 116 const std::string& form_control_type,
92 const std::vector<Suggestion>& suggestions) { 117 const std::vector<Suggestion>& suggestions) {
93 CancelPendingQuery(); 118 CancelPendingQuery();
94 119
95 query_id_ = query_id; 120 query_id_ = query_id;
96 autofill_suggestions_ = suggestions; 121 autofill_suggestions_ = suggestions;
97 if (!autofill_client_->IsAutocompleteEnabled() || 122 if (!autofill_client_->IsAutocompleteEnabled() ||
98 form_control_type == "textarea") { 123 form_control_type == "textarea") {
99 SendSuggestions(NULL); 124 SendSuggestions(NULL);
100 return; 125 return;
101 } 126 }
102 127
103 if (database_.get()) { 128 if (database_.get()) {
129 user_input_ = prefix;
104 pending_query_handle_ = database_->GetFormValuesForElementName( 130 pending_query_handle_ = database_->GetFormValuesForElementName(
105 name, prefix, kMaxAutocompleteMenuItems, this); 131 name, IsFeatureSubStringMatchEnabled() ? base::string16() : prefix,
132 kMaxAutocompleteMenuItems, this);
106 } 133 }
107 } 134 }
108 135
109 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { 136 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) {
110 if (!autofill_client_->IsAutocompleteEnabled()) 137 if (!autofill_client_->IsAutocompleteEnabled())
111 return; 138 return;
112 139
113 if (driver_->IsOffTheRecord()) 140 if (driver_->IsOffTheRecord())
114 return; 141 return;
115 142
(...skipping 64 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