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

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: Changes in BUILD.gn Created 5 years, 6 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() || pending_query_prefix_.empty()) {
88 SendSuggestions(&suggestions);
89 } else {
90 std::vector<base::string16> preferred_suggestions;
91 std::vector<base::string16> substring_matched_suggestions;
92 for (base::string16 suggestion : suggestions) {
93 if (StartsWith(suggestion, pending_query_prefix_, false)) {
94 preferred_suggestions.push_back(suggestion);
95 } else if (ContainsTokenThatStartsWith(suggestion, pending_query_prefix_,
96 false)) {
97 substring_matched_suggestions.push_back(suggestion);
98 }
99 }
100
101 // Prefix matches should precede other token matches.
102 if (IsFeatureSubstringMatchEnabled()) {
103 preferred_suggestions.insert(preferred_suggestions.end(),
104 substring_matched_suggestions.begin(),
105 substring_matched_suggestions.end());
106 }
107
108 SendSuggestions(&preferred_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 pending_query_prefix_ = 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 205 }
179 } 206 }
180 207
181 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_); 208 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_);
182 209
183 query_id_ = 0; 210 query_id_ = 0;
184 autofill_suggestions_.clear(); 211 autofill_suggestions_.clear();
185 } 212 }
186 213
187 } // namespace autofill 214 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698