Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/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" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 // Return true if the |field_type| and |value| are valid within the context | 97 // Return true if the |field_type| and |value| are valid within the context |
| 98 // of importing a form. | 98 // of importing a form. |
| 99 bool IsValidFieldTypeAndValue(const std::set<AutofillFieldType>& types_seen, | 99 bool IsValidFieldTypeAndValue(const std::set<AutofillFieldType>& types_seen, |
| 100 AutofillFieldType field_type, | 100 AutofillFieldType field_type, |
| 101 const string16& value) { | 101 const string16& value) { |
| 102 // Abandon the import if two fields of the same type are encountered. | 102 // Abandon the import if two fields of the same type are encountered. |
| 103 // This indicates ambiguous data or miscategorization of types. | 103 // This indicates ambiguous data or miscategorization of types. |
| 104 // Make an exception for PHONE_HOME_NUMBER however as both prefix and | 104 // Make an exception for PHONE_HOME_NUMBER however as both prefix and |
| 105 // suffix are stored against this type. | 105 // suffix are stored against this type. |
| 106 if (types_seen.count(field_type) && | 106 if (types_seen.count(field_type) && |
| 107 field_type != PHONE_HOME_NUMBER && | 107 field_type != PHONE_HOME_NUMBER) { |
|
Ilya Sherman
2011/09/15 03:47:08
nit: I think this can now all fit on one line.
James Hawkins
2011/09/16 03:23:28
Done.
| |
| 108 field_type != PHONE_FAX_NUMBER) { | |
| 109 return false; | 108 return false; |
| 110 } | 109 } |
| 111 | 110 |
| 112 // Abandon the import if an email address value shows up in a field that is | 111 // Abandon the import if an email address value shows up in a field that is |
| 113 // not an email address. | 112 // not an email address. |
| 114 if (field_type != EMAIL_ADDRESS && IsValidEmail(value)) | 113 if (field_type != EMAIL_ADDRESS && IsValidEmail(value)) |
| 115 return false; | 114 return false; |
| 116 | 115 |
| 117 return true; | 116 return true; |
| 118 } | 117 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 // possible to import. | 210 // possible to import. |
| 212 int importable_credit_card_fields = 0; | 211 int importable_credit_card_fields = 0; |
| 213 std::vector<const FormStructure*>::const_iterator iter; | 212 std::vector<const FormStructure*>::const_iterator iter; |
| 214 | 213 |
| 215 // Detect and discard forms with multiple fields of the same type. | 214 // Detect and discard forms with multiple fields of the same type. |
| 216 std::set<AutofillFieldType> types_seen; | 215 std::set<AutofillFieldType> types_seen; |
| 217 | 216 |
| 218 // We only set complete phone, so aggregate phone parts in these vars and set | 217 // We only set complete phone, so aggregate phone parts in these vars and set |
| 219 // complete at the end. | 218 // complete at the end. |
| 220 PhoneNumber::PhoneCombineHelper home(AutofillType::PHONE_HOME); | 219 PhoneNumber::PhoneCombineHelper home(AutofillType::PHONE_HOME); |
| 221 PhoneNumber::PhoneCombineHelper fax(AutofillType::PHONE_FAX); | |
| 222 | 220 |
| 223 for (size_t i = 0; i < form.field_count(); ++i) { | 221 for (size_t i = 0; i < form.field_count(); ++i) { |
| 224 const AutofillField* field = form.field(i); | 222 const AutofillField* field = form.field(i); |
| 225 string16 value = CollapseWhitespace(field->value, false); | 223 string16 value = CollapseWhitespace(field->value, false); |
| 226 | 224 |
| 227 // If we don't know the type of the field, or the user hasn't entered any | 225 // If we don't know the type of the field, or the user hasn't entered any |
| 228 // information into the field, then skip it. | 226 // information into the field, then skip it. |
| 229 if (!field->IsFieldFillable() || value.empty()) | 227 if (!field->IsFieldFillable() || value.empty()) |
| 230 continue; | 228 continue; |
| 231 | 229 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 246 if (LowerCaseEqualsASCII(field->form_control_type, "month")) { | 244 if (LowerCaseEqualsASCII(field->form_control_type, "month")) { |
| 247 DCHECK_EQ(CREDIT_CARD_EXP_MONTH, field_type); | 245 DCHECK_EQ(CREDIT_CARD_EXP_MONTH, field_type); |
| 248 local_imported_credit_card->SetInfoForMonthInputType(value); | 246 local_imported_credit_card->SetInfoForMonthInputType(value); |
| 249 } else { | 247 } else { |
| 250 local_imported_credit_card->SetCanonicalizedInfo(field_type, value); | 248 local_imported_credit_card->SetCanonicalizedInfo(field_type, value); |
| 251 } | 249 } |
| 252 ++importable_credit_card_fields; | 250 ++importable_credit_card_fields; |
| 253 } else { | 251 } else { |
| 254 // We need to store phone data in the variables, before building the whole | 252 // We need to store phone data in the variables, before building the whole |
| 255 // number at the end. The rest of the fields are set "as is". | 253 // number at the end. The rest of the fields are set "as is". |
| 256 // If the fields are not the phone fields in question both home.SetInfo() | 254 // If the fields are not the phone fields in question home.SetInfo() is |
| 257 // and fax.SetInfo() are going to return false. | 255 // going to return false. |
| 258 if (!home.SetInfo(field_type, value) && !fax.SetInfo(field_type, value)) | 256 if (!home.SetInfo(field_type, value)) |
| 259 imported_profile->SetCanonicalizedInfo(field_type, value); | 257 imported_profile->SetCanonicalizedInfo(field_type, value); |
| 260 | 258 |
| 261 // Reject profiles with invalid country information. | 259 // Reject profiles with invalid country information. |
| 262 if (field_type == ADDRESS_HOME_COUNTRY && | 260 if (field_type == ADDRESS_HOME_COUNTRY && |
| 263 !value.empty() && imported_profile->CountryCode().empty()) { | 261 !value.empty() && imported_profile->CountryCode().empty()) { |
| 264 imported_profile.reset(); | 262 imported_profile.reset(); |
| 265 break; | 263 break; |
| 266 } | 264 } |
| 267 } | 265 } |
| 268 } | 266 } |
| 269 | 267 |
| 270 // Construct the phone and fax numbers. Reject the profile if either number | 268 // Construct the phone number. Reject the profile if the number is invalid. |
| 271 // is invalid. | |
| 272 if (imported_profile.get() && !home.IsEmpty()) { | 269 if (imported_profile.get() && !home.IsEmpty()) { |
| 273 string16 constructed_number; | 270 string16 constructed_number; |
| 274 if (!home.ParseNumber(imported_profile->CountryCode(), | 271 if (!home.ParseNumber(imported_profile->CountryCode(), |
| 275 &constructed_number) || | 272 &constructed_number) || |
| 276 !imported_profile->SetCanonicalizedInfo(PHONE_HOME_WHOLE_NUMBER, | 273 !imported_profile->SetCanonicalizedInfo(PHONE_HOME_WHOLE_NUMBER, |
| 277 constructed_number)) { | 274 constructed_number)) { |
| 278 imported_profile.reset(); | 275 imported_profile.reset(); |
| 279 } | 276 } |
| 280 } | 277 } |
| 281 if (imported_profile.get() && !fax.IsEmpty()) { | |
| 282 string16 constructed_number; | |
| 283 if (!fax.ParseNumber(imported_profile->CountryCode(), | |
| 284 &constructed_number) || | |
| 285 !imported_profile->SetCanonicalizedInfo(PHONE_FAX_WHOLE_NUMBER, | |
| 286 constructed_number)) { | |
| 287 imported_profile.reset(); | |
| 288 } | |
| 289 } | |
| 290 | 278 |
| 291 // Reject the profile if minimum address and validation requirements are not | 279 // Reject the profile if minimum address and validation requirements are not |
| 292 // met. | 280 // met. |
| 293 if (imported_profile.get() && !IsValidLearnableProfile(*imported_profile)) | 281 if (imported_profile.get() && !IsValidLearnableProfile(*imported_profile)) |
| 294 imported_profile.reset(); | 282 imported_profile.reset(); |
| 295 | 283 |
| 296 // Reject the credit card if we did not detect enough filled credit card | 284 // Reject the credit card if we did not detect enough filled credit card |
| 297 // fields or if the credit card number does not seem to be valid. | 285 // fields or if the credit card number does not seem to be valid. |
| 298 if (local_imported_credit_card.get() && | 286 if (local_imported_credit_card.get() && |
| 299 !local_imported_credit_card->IsComplete()) { | 287 !local_imported_credit_card->IsComplete()) { |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 920 } | 908 } |
| 921 | 909 |
| 922 const AutofillMetrics* PersonalDataManager::metric_logger() const { | 910 const AutofillMetrics* PersonalDataManager::metric_logger() const { |
| 923 return metric_logger_.get(); | 911 return metric_logger_.get(); |
| 924 } | 912 } |
| 925 | 913 |
| 926 void PersonalDataManager::set_metric_logger( | 914 void PersonalDataManager::set_metric_logger( |
| 927 const AutofillMetrics* metric_logger) { | 915 const AutofillMetrics* metric_logger) { |
| 928 metric_logger_.reset(metric_logger); | 916 metric_logger_.reset(metric_logger); |
| 929 } | 917 } |
| OLD | NEW |