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

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

Issue 13973004: Convert string16 -> base::string16 in components/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/autocomplete_history_manager.h" 5 #include "components/autofill/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/string16.h" 10 #include "base/string16.h"
(...skipping 15 matching lines...) Expand all
26 26
27 namespace { 27 namespace {
28 28
29 // Limit on the number of suggestions to appear in the pop-up menu under an 29 // Limit on the number of suggestions to appear in the pop-up menu under an
30 // text input element in a form. 30 // text input element in a form.
31 const int kMaxAutocompleteMenuItems = 6; 31 const int kMaxAutocompleteMenuItems = 6;
32 32
33 // The separator characters for SSNs. 33 // The separator characters for SSNs.
34 const char16 kSSNSeparators[] = {' ', '-', 0}; 34 const char16 kSSNSeparators[] = {' ', '-', 0};
35 35
36 bool IsSSN(const string16& text) { 36 bool IsSSN(const base::string16& text) {
37 string16 number_string; 37 base::string16 number_string;
38 RemoveChars(text, kSSNSeparators, &number_string); 38 RemoveChars(text, kSSNSeparators, &number_string);
39 39
40 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S = 40 // A SSN is of the form AAA-GG-SSSS (A = area number, G = group number, S =
41 // serial number). The validation we do here is simply checking if the area, 41 // serial number). The validation we do here is simply checking if the area,
42 // group, and serial numbers are valid. 42 // group, and serial numbers are valid.
43 // 43 //
44 // Historically, the area number was assigned per state, with the group number 44 // Historically, the area number was assigned per state, with the group number
45 // ascending in an alternating even/odd sequence. With that scheme it was 45 // ascending in an alternating even/odd sequence. With that scheme it was
46 // possible to check for validity by referencing a table that had the highest 46 // possible to check for validity by referencing a table that had the highest
47 // group number assigned for a given area number. (This was something that 47 // group number assigned for a given area number. (This was something that
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 DCHECK(result); 150 DCHECK(result);
151 // Returning early here if |result| is NULL. We've seen this happen on 151 // Returning early here if |result| is NULL. We've seen this happen on
152 // Linux due to NFS dismounting and causing sql failures. 152 // Linux due to NFS dismounting and causing sql failures.
153 // See http://crbug.com/68783. 153 // See http://crbug.com/68783.
154 if (!result) { 154 if (!result) {
155 SendSuggestions(NULL); 155 SendSuggestions(NULL);
156 return; 156 return;
157 } 157 }
158 158
159 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType()); 159 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType());
160 const WDResult<std::vector<string16> >* autofill_result = 160 const WDResult<std::vector<base::string16> >* autofill_result =
161 static_cast<const WDResult<std::vector<string16> >*>(result); 161 static_cast<const WDResult<std::vector<base::string16> >*>(result);
162 std::vector<string16> suggestions = autofill_result->GetValue(); 162 std::vector<base::string16> suggestions = autofill_result->GetValue();
163 SendSuggestions(&suggestions); 163 SendSuggestions(&suggestions);
164 } 164 }
165 165
166 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( 166 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
167 int query_id, 167 int query_id,
168 const string16& name, 168 const base::string16& name,
169 const string16& prefix, 169 const base::string16& prefix,
170 const std::vector<string16>& autofill_values, 170 const std::vector<base::string16>& autofill_values,
171 const std::vector<string16>& autofill_labels, 171 const std::vector<base::string16>& autofill_labels,
172 const std::vector<string16>& autofill_icons, 172 const std::vector<string16>& autofill_icons,
173 const std::vector<int>& autofill_unique_ids) { 173 const std::vector<int>& autofill_unique_ids) {
174 CancelPendingQuery(); 174 CancelPendingQuery();
175 175
176 query_id_ = query_id; 176 query_id_ = query_id;
177 autofill_values_ = autofill_values; 177 autofill_values_ = autofill_values;
178 autofill_labels_ = autofill_labels; 178 autofill_labels_ = autofill_labels;
179 autofill_icons_ = autofill_icons; 179 autofill_icons_ = autofill_icons;
180 autofill_unique_ids_ = autofill_unique_ids; 180 autofill_unique_ids_ = autofill_unique_ids;
181 if (!*autofill_enabled_) { 181 if (!*autofill_enabled_) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 !IsSSN(iter->value)) { 217 !IsSSN(iter->value)) {
218 values.push_back(*iter); 218 values.push_back(*iter);
219 } 219 }
220 } 220 }
221 221
222 if (!values.empty() && autofill_data_.get()) 222 if (!values.empty() && autofill_data_.get())
223 autofill_data_->AddFormFields(values); 223 autofill_data_->AddFormFields(values);
224 } 224 }
225 225
226 void AutocompleteHistoryManager::OnRemoveAutocompleteEntry( 226 void AutocompleteHistoryManager::OnRemoveAutocompleteEntry(
227 const string16& name, const string16& value) { 227 const base::string16& name, const base::string16& value) {
228 if (autofill_data_.get()) 228 if (autofill_data_.get())
229 autofill_data_->RemoveFormValueForElementName(name, value); 229 autofill_data_->RemoveFormValueForElementName(name, value);
230 } 230 }
231 231
232 void AutocompleteHistoryManager::SetExternalDelegate( 232 void AutocompleteHistoryManager::SetExternalDelegate(
233 AutofillExternalDelegate* delegate) { 233 AutofillExternalDelegate* delegate) {
234 external_delegate_ = delegate; 234 external_delegate_ = delegate;
235 } 235 }
236 236
237 void AutocompleteHistoryManager::CancelPendingQuery() { 237 void AutocompleteHistoryManager::CancelPendingQuery() {
238 if (pending_query_handle_) { 238 if (pending_query_handle_) {
239 if (autofill_data_) 239 if (autofill_data_)
240 autofill_data_->CancelRequest(pending_query_handle_); 240 autofill_data_->CancelRequest(pending_query_handle_);
241 pending_query_handle_ = 0; 241 pending_query_handle_ = 0;
242 } 242 }
243 } 243 }
244 244
245 void AutocompleteHistoryManager::SendSuggestions( 245 void AutocompleteHistoryManager::SendSuggestions(
246 const std::vector<string16>* suggestions) { 246 const std::vector<base::string16>* suggestions) {
247 if (suggestions) { 247 if (suggestions) {
248 // Combine Autofill and Autocomplete values into values and labels. 248 // Combine Autofill and Autocomplete values into values and labels.
249 for (size_t i = 0; i < suggestions->size(); ++i) { 249 for (size_t i = 0; i < suggestions->size(); ++i) {
250 bool unique = true; 250 bool unique = true;
251 for (size_t j = 0; j < autofill_values_.size(); ++j) { 251 for (size_t j = 0; j < autofill_values_.size(); ++j) {
252 // Don't add duplicate values. 252 // Don't add duplicate values.
253 if (autofill_values_[j] == (*suggestions)[i]) { 253 if (autofill_values_[j] == (*suggestions)[i]) {
254 unique = false; 254 unique = false;
255 break; 255 break;
256 } 256 }
257 } 257 }
258 258
259 if (unique) { 259 if (unique) {
260 autofill_values_.push_back((*suggestions)[i]); 260 autofill_values_.push_back((*suggestions)[i]);
261 autofill_labels_.push_back(string16()); 261 autofill_labels_.push_back(base::string16());
262 autofill_icons_.push_back(string16()); 262 autofill_icons_.push_back(base::string16());
263 autofill_unique_ids_.push_back(0); // 0 means no profile. 263 autofill_unique_ids_.push_back(0); // 0 means no profile.
264 } 264 }
265 } 265 }
266 } 266 }
267 267
268 if (external_delegate_) { 268 if (external_delegate_) {
269 external_delegate_->OnSuggestionsReturned( 269 external_delegate_->OnSuggestionsReturned(
270 query_id_, 270 query_id_,
271 autofill_values_, 271 autofill_values_,
272 autofill_labels_, 272 autofill_labels_,
273 autofill_icons_, 273 autofill_icons_,
274 autofill_unique_ids_); 274 autofill_unique_ids_);
275 } else { 275 } else {
276 Send(new AutofillMsg_SuggestionsReturned(routing_id(), 276 Send(new AutofillMsg_SuggestionsReturned(routing_id(),
277 query_id_, 277 query_id_,
278 autofill_values_, 278 autofill_values_,
279 autofill_labels_, 279 autofill_labels_,
280 autofill_icons_, 280 autofill_icons_,
281 autofill_unique_ids_)); 281 autofill_unique_ids_));
282 } 282 }
283 283
284 query_id_ = 0; 284 query_id_ = 0;
285 autofill_values_.clear(); 285 autofill_values_.clear();
286 autofill_labels_.clear(); 286 autofill_labels_.clear();
287 autofill_icons_.clear(); 287 autofill_icons_.clear();
288 autofill_unique_ids_.clear(); 288 autofill_unique_ids_.clear();
289 } 289 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698