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

Side by Side Diff: chrome/browser/autofill/personal_data_manager.cc

Issue 6877130: These changes *are* for review :) (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
dhollowa 2011/05/13 18:55:35 personal_data_manager_mac.cc needs to be fixed. I
GeorgeY 2011/05/18 17:41:45 Commented it out for now, could you, please, fix i
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/autofill/personal_data_manager.h" 5 #include "chrome/browser/autofill/personal_data_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/autofill/autofill-inl.h" 13 #include "chrome/browser/autofill/autofill-inl.h"
14 #include "chrome/browser/autofill/autofill_field.h" 14 #include "chrome/browser/autofill/autofill_field.h"
15 #include "chrome/browser/autofill/autofill_metrics.h" 15 #include "chrome/browser/autofill/autofill_metrics.h"
16 #include "chrome/browser/autofill/form_structure.h" 16 #include "chrome/browser/autofill/form_structure.h"
17 #include "chrome/browser/autofill/phone_number.h" 17 #include "chrome/browser/autofill/phone_number.h"
18 #include "chrome/browser/autofill/phone_number_i18n.h"
18 #include "chrome/browser/autofill/select_control_handler.h" 19 #include "chrome/browser/autofill/select_control_handler.h"
19 #include "chrome/browser/prefs/pref_service.h" 20 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/sync/profile_sync_service.h" 22 #include "chrome/browser/sync/profile_sync_service.h"
22 #include "chrome/browser/webdata/web_data_service.h" 23 #include "chrome/browser/webdata/web_data_service.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
24 #include "content/browser/browser_thread.h" 25 #include "content/browser/browser_thread.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRegularExpression. h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRegularExpression. h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
27 28
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); 196 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard);
196 197
197 // Parse the form and construct a profile based on the information that is 198 // Parse the form and construct a profile based on the information that is
198 // possible to import. 199 // possible to import.
199 int importable_credit_card_fields = 0; 200 int importable_credit_card_fields = 0;
200 std::vector<const FormStructure*>::const_iterator iter; 201 std::vector<const FormStructure*>::const_iterator iter;
201 202
202 // Detect and discard forms with multiple fields of the same type. 203 // Detect and discard forms with multiple fields of the same type.
203 std::set<AutofillFieldType> types_seen; 204 std::set<AutofillFieldType> types_seen;
204 205
206 // We only set complete phone, so aggregate phone parts in these vars and set
dhollowa 2011/05/13 18:55:35 The phone/fax specific logic in this function is g
GeorgeY 2011/05/18 17:41:45 simplified it (see code)
207 // complete at the end.
208 string16 home_number;
209 string16 home_city_code;
210 string16 home_country_code;
211 string16 fax_number;
212 string16 fax_city_code;
213 string16 fax_country_code;
214
205 for (size_t i = 0; i < form.field_count(); ++i) { 215 for (size_t i = 0; i < form.field_count(); ++i) {
206 const AutofillField* field = form.field(i); 216 const AutofillField* field = form.field(i);
207 string16 value = CollapseWhitespace(field->value, false); 217 string16 value = CollapseWhitespace(field->value, false);
208 218
209 // If we don't know the type of the field, or the user hasn't entered any 219 // If we don't know the type of the field, or the user hasn't entered any
210 // information into the field, then skip it. 220 // information into the field, then skip it.
211 if (!field->IsFieldFillable() || value.empty()) 221 if (!field->IsFieldFillable() || value.empty())
212 continue; 222 continue;
213 223
214 AutofillFieldType field_type = field->type(); 224 AutofillFieldType field_type = field->type();
(...skipping 23 matching lines...) Expand all
238 } else { 248 } else {
239 if (field_type == CREDIT_CARD_NUMBER) { 249 if (field_type == CREDIT_CARD_NUMBER) {
240 // Clean up any imported credit card numbers. 250 // Clean up any imported credit card numbers.
241 value = CreditCard::StripSeparators(value); 251 value = CreditCard::StripSeparators(value);
242 } 252 }
243 local_imported_credit_card->SetInfo(field_type, value); 253 local_imported_credit_card->SetInfo(field_type, value);
244 } 254 }
245 ++importable_credit_card_fields; 255 ++importable_credit_card_fields;
246 } 256 }
247 } else { 257 } else {
248 // In the case of a phone number, if the whole phone number was entered
249 // into a single field, then parse it and set the sub components.
250 if (AutofillType(field_type).subgroup() ==
251 AutofillType::PHONE_WHOLE_NUMBER) {
252 string16 number;
253 string16 city_code;
254 string16 country_code;
255 PhoneNumber::ParsePhoneNumber(value,
256 &number,
257 &city_code,
258 &country_code);
259 if (number.empty())
260 continue;
261
262 if (group == AutofillType::PHONE_HOME) {
263 imported_profile->SetInfo(PHONE_HOME_COUNTRY_CODE, country_code);
264 imported_profile->SetInfo(PHONE_HOME_CITY_CODE, city_code);
265 imported_profile->SetInfo(PHONE_HOME_NUMBER, number);
266 } else if (group == AutofillType::PHONE_FAX) {
267 imported_profile->SetInfo(PHONE_FAX_COUNTRY_CODE, country_code);
268 imported_profile->SetInfo(PHONE_FAX_CITY_CODE, city_code);
269 imported_profile->SetInfo(PHONE_FAX_NUMBER, number);
270 }
271
272 continue;
273 }
274
275 // Phone and fax numbers can be split across multiple fields, so we 258 // Phone and fax numbers can be split across multiple fields, so we
276 // might have already stored the prefix, and now be at the suffix. 259 // might have already stored the prefix, and now be at the suffix.
277 // If so, combine them to form the full number. 260 // If so, combine them to form the full number.
278 if (group == AutofillType::PHONE_HOME || 261 switch (field_type) {
279 group == AutofillType::PHONE_FAX) { 262 case PHONE_HOME_CITY_CODE:
280 AutofillFieldType number_type = PHONE_HOME_NUMBER; 263 home_city_code = value;
281 if (group == AutofillType::PHONE_FAX) 264 break;
282 number_type = PHONE_FAX_NUMBER; 265 case PHONE_HOME_COUNTRY_CODE:
283 266 home_country_code = value;
284 string16 stored_number = imported_profile->GetInfo(number_type); 267 break;
285 if (stored_number.size() == 268 case PHONE_HOME_CITY_AND_NUMBER:
286 static_cast<size_t>(PhoneNumber::kPrefixLength) && 269 home_number = value;
287 value.size() == static_cast<size_t>(PhoneNumber::kSuffixLength)) { 270 break;
288 value = stored_number + value; 271 // Phone and fax numbers can be split across multiple fields, so we
289 } 272 // might have already stored the prefix, and now be at the suffix.
273 // If so, combine them to form the full number.
274 case PHONE_HOME_NUMBER:
275 home_number.append(value);
276 break;
277 case PHONE_FAX_CITY_CODE:
278 fax_city_code = value;
279 break;
280 case PHONE_FAX_COUNTRY_CODE:
281 fax_country_code = value;
282 break;
283 case PHONE_FAX_NUMBER:
284 fax_number.append(value);
285 break;
286 case PHONE_FAX_CITY_AND_NUMBER:
287 fax_number = value;
288 break;
289 default:
290 imported_profile->SetInfo(field_type, value);
291 break;
290 } 292 }
291 293
292 imported_profile->SetInfo(field_type, value);
293
294 // Reject profiles with invalid country information. 294 // Reject profiles with invalid country information.
295 if (field_type == ADDRESS_HOME_COUNTRY && 295 if (field_type == ADDRESS_HOME_COUNTRY &&
296 !value.empty() && imported_profile->CountryCode().empty()) { 296 !value.empty() && imported_profile->CountryCode().empty()) {
297 imported_profile.reset(); 297 imported_profile.reset();
298 break; 298 break;
299 } 299 }
300 } 300 }
301 } 301 }
302 302
303 // Build phone numbers if they are from parts.
304 if (imported_profile.get()) {
305 if (!home_number.empty()) {
306 string16 constructed_number;
307 if (!autofill_i18n::ConstructPhoneNumber(
308 home_country_code, home_city_code, home_number,
309 imported_profile->CountryCode(),
310 (home_country_code.empty() ?
311 autofill_i18n::NATIONAL : autofill_i18n::INTERNATIONAL),
312 &constructed_number)) {
313 imported_profile.reset();
314 } else {
315 imported_profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, constructed_number);
316 }
317 }
318 if (!fax_number.empty()) {
319 string16 constructed_number;
320 if (!autofill_i18n::ConstructPhoneNumber(
321 fax_country_code, fax_city_code, fax_number,
322 imported_profile->CountryCode(),
323 (fax_country_code.empty() ?
324 autofill_i18n::NATIONAL : autofill_i18n::INTERNATIONAL),
325 &constructed_number)) {
326 imported_profile.reset();
327 } else {
328 imported_profile->SetInfo(PHONE_FAX_WHOLE_NUMBER, constructed_number);
329 }
330 }
331 }
332 // Normalize phone numbers.
333 if (imported_profile.get()) {
334 // Reject profile if even one of the phones is invalid.
335 if (!imported_profile->NormalizePhones())
Ilya Sherman 2011/05/14 04:38:51 It looks like this is the only place where Normali
GeorgeY 2011/05/18 17:41:45 home_number_, fax_number_ are encapsulated in prof
336 imported_profile.reset();
337 }
338
303 // Reject the profile if minimum address and validation requirements are not 339 // Reject the profile if minimum address and validation requirements are not
304 // met. 340 // met.
305 if (imported_profile.get() && !IsValidLearnableProfile(*imported_profile)) 341 if (imported_profile.get() && !IsValidLearnableProfile(*imported_profile))
306 imported_profile.reset(); 342 imported_profile.reset();
307 343
308 // Reject the credit card if we did not detect enough filled credit card 344 // Reject the credit card if we did not detect enough filled credit card
309 // fields or if the credit card number does not seem to be valid. 345 // fields or if the credit card number does not seem to be valid.
310 if (local_imported_credit_card.get() && 346 if (local_imported_credit_card.get() &&
311 (importable_credit_card_fields < kMinCreditCardImportSize || 347 (importable_credit_card_fields < kMinCreditCardImportSize ||
312 !CreditCard::IsValidCreditCardNumber( 348 !CreditCard::IsValidCreditCardNumber(
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 } 973 }
938 974
939 const AutofillMetrics* PersonalDataManager::metric_logger() const { 975 const AutofillMetrics* PersonalDataManager::metric_logger() const {
940 return metric_logger_.get(); 976 return metric_logger_.get();
941 } 977 }
942 978
943 void PersonalDataManager::set_metric_logger( 979 void PersonalDataManager::set_metric_logger(
944 const AutofillMetrics* metric_logger) { 980 const AutofillMetrics* metric_logger) {
945 metric_logger_.reset(metric_logger); 981 metric_logger_.reset(metric_logger);
946 } 982 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698