| OLD | NEW |
| 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/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 static_cast<const WDResult<std::vector<base::string16> >*>(result); | 75 static_cast<const WDResult<std::vector<base::string16> >*>(result); |
| 76 std::vector<base::string16> suggestions = autofill_result->GetValue(); | 76 std::vector<base::string16> suggestions = autofill_result->GetValue(); |
| 77 SendSuggestions(&suggestions); | 77 SendSuggestions(&suggestions); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( | 80 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( |
| 81 int query_id, | 81 int query_id, |
| 82 const base::string16& name, | 82 const base::string16& name, |
| 83 const base::string16& prefix, | 83 const base::string16& prefix, |
| 84 const std::string& form_control_type, | 84 const std::string& form_control_type, |
| 85 const std::vector<base::string16>& autofill_values, | 85 const std::vector<Suggestion>& suggestions) { |
| 86 const std::vector<base::string16>& autofill_labels, | |
| 87 const std::vector<base::string16>& autofill_icons, | |
| 88 const std::vector<int>& autofill_unique_ids) { | |
| 89 CancelPendingQuery(); | 86 CancelPendingQuery(); |
| 90 | 87 |
| 91 query_id_ = query_id; | 88 query_id_ = query_id; |
| 92 autofill_values_ = autofill_values; | 89 autofill_suggestions_ = suggestions; |
| 93 autofill_labels_ = autofill_labels; | |
| 94 autofill_icons_ = autofill_icons; | |
| 95 autofill_unique_ids_ = autofill_unique_ids; | |
| 96 if (!autofill_client_->IsAutocompleteEnabled() || | 90 if (!autofill_client_->IsAutocompleteEnabled() || |
| 97 form_control_type == "textarea") { | 91 form_control_type == "textarea") { |
| 98 SendSuggestions(NULL); | 92 SendSuggestions(NULL); |
| 99 return; | 93 return; |
| 100 } | 94 } |
| 101 | 95 |
| 102 if (database_.get()) { | 96 if (database_.get()) { |
| 103 pending_query_handle_ = database_->GetFormValuesForElementName( | 97 pending_query_handle_ = database_->GetFormValuesForElementName( |
| 104 name, prefix, kMaxAutocompleteMenuItems, this); | 98 name, prefix, kMaxAutocompleteMenuItems, this); |
| 105 } | 99 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 148 |
| 155 void AutocompleteHistoryManager::CancelPendingQuery() { | 149 void AutocompleteHistoryManager::CancelPendingQuery() { |
| 156 if (pending_query_handle_) { | 150 if (pending_query_handle_) { |
| 157 if (database_.get()) | 151 if (database_.get()) |
| 158 database_->CancelRequest(pending_query_handle_); | 152 database_->CancelRequest(pending_query_handle_); |
| 159 pending_query_handle_ = 0; | 153 pending_query_handle_ = 0; |
| 160 } | 154 } |
| 161 } | 155 } |
| 162 | 156 |
| 163 void AutocompleteHistoryManager::SendSuggestions( | 157 void AutocompleteHistoryManager::SendSuggestions( |
| 164 const std::vector<base::string16>* suggestions) { | 158 const std::vector<base::string16>* autocomplete_results) { |
| 165 if (suggestions) { | 159 if (autocomplete_results) { |
| 166 // Combine Autofill and Autocomplete values into values and labels. | 160 // Combine Autofill and Autocomplete values into values and labels. |
| 167 for (size_t i = 0; i < suggestions->size(); ++i) { | 161 for (const auto& new_result : *autocomplete_results) { |
| 168 bool unique = true; | 162 bool unique = true; |
| 169 for (size_t j = 0; j < autofill_values_.size(); ++j) { | 163 for (const auto& autofill_suggestion : autofill_suggestions_) { |
| 170 // Don't add duplicate values. | 164 // Don't add duplicate values. |
| 171 if (autofill_values_[j] == (*suggestions)[i]) { | 165 if (new_result == autofill_suggestion.value) { |
| 172 unique = false; | 166 unique = false; |
| 173 break; | 167 break; |
| 174 } | 168 } |
| 175 } | 169 } |
| 176 | 170 |
| 177 if (unique) { | 171 if (unique) |
| 178 autofill_values_.push_back((*suggestions)[i]); | 172 autofill_suggestions_.push_back(Suggestion(new_result)); |
| 179 autofill_labels_.push_back(base::string16()); | |
| 180 autofill_icons_.push_back(base::string16()); | |
| 181 autofill_unique_ids_.push_back(0); // 0 means no profile. | |
| 182 } | |
| 183 } | 173 } |
| 184 } | 174 } |
| 185 | 175 |
| 186 external_delegate_->OnSuggestionsReturned(query_id_, | 176 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_); |
| 187 autofill_values_, | |
| 188 autofill_labels_, | |
| 189 autofill_icons_, | |
| 190 autofill_unique_ids_); | |
| 191 | 177 |
| 192 query_id_ = 0; | 178 query_id_ = 0; |
| 193 autofill_values_.clear(); | 179 autofill_suggestions_.clear(); |
| 194 autofill_labels_.clear(); | |
| 195 autofill_icons_.clear(); | |
| 196 autofill_unique_ids_.clear(); | |
| 197 } | 180 } |
| 198 | 181 |
| 199 } // namespace autofill | 182 } // namespace autofill |
| OLD | NEW |