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

Side by Side Diff: components/autofill/core/browser/autocomplete_history_manager.cc

Issue 772253003: Create an autofill Suggestion class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review 2 Created 6 years 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"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 static_cast<const WDResult<std::vector<base::string16> >*>(result); 81 static_cast<const WDResult<std::vector<base::string16> >*>(result);
82 std::vector<base::string16> suggestions = autofill_result->GetValue(); 82 std::vector<base::string16> suggestions = autofill_result->GetValue();
83 SendSuggestions(&suggestions); 83 SendSuggestions(&suggestions);
84 } 84 }
85 85
86 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( 86 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
87 int query_id, 87 int query_id,
88 const base::string16& name, 88 const base::string16& name,
89 const base::string16& prefix, 89 const base::string16& prefix,
90 const std::string& form_control_type, 90 const std::string& form_control_type,
91 const std::vector<base::string16>& autofill_values, 91 const std::vector<Suggestion>& suggestions) {
92 const std::vector<base::string16>& autofill_labels,
93 const std::vector<base::string16>& autofill_icons,
94 const std::vector<int>& autofill_unique_ids) {
95 CancelPendingQuery(); 92 CancelPendingQuery();
96 93
97 query_id_ = query_id; 94 query_id_ = query_id;
98 autofill_values_ = autofill_values; 95 autofill_suggestions_ = suggestions;
99 autofill_labels_ = autofill_labels;
100 autofill_icons_ = autofill_icons;
101 autofill_unique_ids_ = autofill_unique_ids;
102 if (!autofill_client_->IsAutocompleteEnabled() || 96 if (!autofill_client_->IsAutocompleteEnabled() ||
103 form_control_type == "textarea") { 97 form_control_type == "textarea") {
104 SendSuggestions(NULL); 98 SendSuggestions(NULL);
105 return; 99 return;
106 } 100 }
107 101
108 if (database_.get()) { 102 if (database_.get()) {
109 pending_query_handle_ = database_->GetFormValuesForElementName( 103 pending_query_handle_ = database_->GetFormValuesForElementName(
110 name, prefix, kMaxAutocompleteMenuItems, this); 104 name, prefix, kMaxAutocompleteMenuItems, this);
111 } 105 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 154
161 void AutocompleteHistoryManager::CancelPendingQuery() { 155 void AutocompleteHistoryManager::CancelPendingQuery() {
162 if (pending_query_handle_) { 156 if (pending_query_handle_) {
163 if (database_.get()) 157 if (database_.get())
164 database_->CancelRequest(pending_query_handle_); 158 database_->CancelRequest(pending_query_handle_);
165 pending_query_handle_ = 0; 159 pending_query_handle_ = 0;
166 } 160 }
167 } 161 }
168 162
169 void AutocompleteHistoryManager::SendSuggestions( 163 void AutocompleteHistoryManager::SendSuggestions(
170 const std::vector<base::string16>* suggestions) { 164 const std::vector<base::string16>* new_results) {
Evan Stade 2014/12/10 23:11:14 s/new_results/autocomplete_results imo
171 if (suggestions) { 165 if (new_results) {
172 // Combine Autofill and Autocomplete values into values and labels. 166 // Combine Autofill and Autocomplete values into values and labels.
173 for (size_t i = 0; i < suggestions->size(); ++i) { 167 for (const auto& new_result : *new_results) {
174 bool unique = true; 168 bool unique = true;
175 for (size_t j = 0; j < autofill_values_.size(); ++j) { 169 for (const auto& autofill_suggestion : autofill_suggestions_) {
176 // Don't add duplicate values. 170 // Don't add duplicate values.
177 if (autofill_values_[j] == (*suggestions)[i]) { 171 if (new_result == autofill_suggestion.value) {
178 unique = false; 172 unique = false;
179 break; 173 break;
180 } 174 }
181 } 175 }
182 176
183 if (unique) { 177 if (unique)
184 autofill_values_.push_back((*suggestions)[i]); 178 autofill_suggestions_.push_back(Suggestion(new_result));
185 autofill_labels_.push_back(base::string16());
186 autofill_icons_.push_back(base::string16());
187 autofill_unique_ids_.push_back(0); // 0 means no profile.
188 }
189 } 179 }
190 } 180 }
191 181
192 external_delegate_->OnSuggestionsReturned(query_id_, 182 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_);
193 autofill_values_,
194 autofill_labels_,
195 autofill_icons_,
196 autofill_unique_ids_);
197 183
198 query_id_ = 0; 184 query_id_ = 0;
199 autofill_values_.clear(); 185 autofill_suggestions_.clear();
200 autofill_labels_.clear();
201 autofill_icons_.clear();
202 autofill_unique_ids_.clear();
203 } 186 }
204 187
205 } // namespace autofill 188 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698