| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/autocomplete_history_manager.h" | 5 #include "chrome/browser/autocomplete_history_manager.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 form.fields.begin(); | 120 form.fields.begin(); |
| 121 iter != form.fields.end(); ++iter) { | 121 iter != form.fields.end(); ++iter) { |
| 122 if (!iter->value().empty() && | 122 if (!iter->value().empty() && |
| 123 !iter->name().empty() && | 123 !iter->name().empty() && |
| 124 iter->form_control_type() == ASCIIToUTF16("text") && | 124 iter->form_control_type() == ASCIIToUTF16("text") && |
| 125 !CreditCard::IsCreditCardNumber(iter->value()) && | 125 !CreditCard::IsCreditCardNumber(iter->value()) && |
| 126 !IsSSN(iter->value())) | 126 !IsSSN(iter->value())) |
| 127 values.push_back(*iter); | 127 values.push_back(*iter); |
| 128 } | 128 } |
| 129 | 129 |
| 130 if (!values.empty() && web_data_service_) | 130 if (!values.empty() && web_data_service_.get()) |
| 131 web_data_service_->AddFormFields(values); | 131 web_data_service_->AddFormFields(values); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void AutocompleteHistoryManager::OnRemoveAutocompleteEntry( | 134 void AutocompleteHistoryManager::OnRemoveAutocompleteEntry( |
| 135 const string16& name, const string16& value) { | 135 const string16& name, const string16& value) { |
| 136 web_data_service_->RemoveFormValueForElementName(name, value); | 136 if (web_data_service_.get()) |
| 137 web_data_service_->RemoveFormValueForElementName(name, value); |
| 137 } | 138 } |
| 138 | 139 |
| 139 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( | 140 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( |
| 140 int query_id, | 141 int query_id, |
| 141 const string16& name, | 142 const string16& name, |
| 142 const string16& prefix, | 143 const string16& prefix, |
| 143 const std::vector<string16>& autofill_values, | 144 const std::vector<string16>& autofill_values, |
| 144 const std::vector<string16>& autofill_labels, | 145 const std::vector<string16>& autofill_labels, |
| 145 const std::vector<string16>& autofill_icons, | 146 const std::vector<string16>& autofill_icons, |
| 146 const std::vector<int>& autofill_unique_ids) { | 147 const std::vector<int>& autofill_unique_ids) { |
| 147 CancelPendingQuery(); | 148 CancelPendingQuery(); |
| 148 | 149 |
| 149 query_id_ = query_id; | 150 query_id_ = query_id; |
| 150 autofill_values_ = autofill_values; | 151 autofill_values_ = autofill_values; |
| 151 autofill_labels_ = autofill_labels; | 152 autofill_labels_ = autofill_labels; |
| 152 autofill_icons_ = autofill_icons; | 153 autofill_icons_ = autofill_icons; |
| 153 autofill_unique_ids_ = autofill_unique_ids; | 154 autofill_unique_ids_ = autofill_unique_ids; |
| 154 if (!*autofill_enabled_) { | 155 if (!*autofill_enabled_) { |
| 155 SendSuggestions(NULL); | 156 SendSuggestions(NULL); |
| 156 return; | 157 return; |
| 157 } | 158 } |
| 158 | 159 |
| 159 pending_query_handle_ = web_data_service_->GetFormValuesForElementName( | 160 if (web_data_service_.get()) { |
| 160 name, prefix, kMaxAutocompleteMenuItems, this); | 161 pending_query_handle_ = web_data_service_->GetFormValuesForElementName( |
| 162 name, prefix, kMaxAutocompleteMenuItems, this); |
| 163 } |
| 161 } | 164 } |
| 162 | 165 |
| 163 void AutocompleteHistoryManager::OnWebDataServiceRequestDone( | 166 void AutocompleteHistoryManager::OnWebDataServiceRequestDone( |
| 164 WebDataService::Handle h, | 167 WebDataService::Handle h, |
| 165 const WDTypedResult* result) { | 168 const WDTypedResult* result) { |
| 166 DCHECK(pending_query_handle_); | 169 DCHECK(pending_query_handle_); |
| 167 pending_query_handle_ = 0; | 170 pending_query_handle_ = 0; |
| 168 | 171 |
| 169 if (!*autofill_enabled_) { | 172 if (!*autofill_enabled_) { |
| 170 SendSuggestions(NULL); | 173 SendSuggestions(NULL); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 185 web_data_service_(wds), | 188 web_data_service_(wds), |
| 186 pending_query_handle_(0), | 189 pending_query_handle_(0), |
| 187 query_id_(0) { | 190 query_id_(0) { |
| 188 autofill_enabled_.Init( | 191 autofill_enabled_.Init( |
| 189 prefs::kAutoFillEnabled, profile_->GetPrefs(), NULL); | 192 prefs::kAutoFillEnabled, profile_->GetPrefs(), NULL); |
| 190 } | 193 } |
| 191 | 194 |
| 192 void AutocompleteHistoryManager::CancelPendingQuery() { | 195 void AutocompleteHistoryManager::CancelPendingQuery() { |
| 193 if (pending_query_handle_) { | 196 if (pending_query_handle_) { |
| 194 SendSuggestions(NULL); | 197 SendSuggestions(NULL); |
| 195 web_data_service_->CancelRequest(pending_query_handle_); | 198 if (web_data_service_.get()) |
| 199 web_data_service_->CancelRequest(pending_query_handle_); |
| 196 pending_query_handle_ = 0; | 200 pending_query_handle_ = 0; |
| 197 } | 201 } |
| 198 } | 202 } |
| 199 | 203 |
| 200 void AutocompleteHistoryManager::SendSuggestions( | 204 void AutocompleteHistoryManager::SendSuggestions( |
| 201 const std::vector<string16>* suggestions) { | 205 const std::vector<string16>* suggestions) { |
| 202 if (suggestions) { | 206 if (suggestions) { |
| 203 // Combine AutoFill and Autocomplete values into values and labels. | 207 // Combine AutoFill and Autocomplete values into values and labels. |
| 204 for (size_t i = 0; i < suggestions->size(); ++i) { | 208 for (size_t i = 0; i < suggestions->size(); ++i) { |
| 205 bool unique = true; | 209 bool unique = true; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 229 autofill_icons_, | 233 autofill_icons_, |
| 230 autofill_unique_ids_)); | 234 autofill_unique_ids_)); |
| 231 } | 235 } |
| 232 | 236 |
| 233 query_id_ = 0; | 237 query_id_ = 0; |
| 234 autofill_values_.clear(); | 238 autofill_values_.clear(); |
| 235 autofill_labels_.clear(); | 239 autofill_labels_.clear(); |
| 236 autofill_icons_.clear(); | 240 autofill_icons_.clear(); |
| 237 autofill_unique_ids_.clear(); | 241 autofill_unique_ids_.clear(); |
| 238 } | 242 } |
| OLD | NEW |