OLD | NEW |
---|---|
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/personal_data_manager.h" | 5 #include "components/autofill/browser/personal_data_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <iterator> | 9 #include <iterator> |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 // Returns true if minimum requirements for import of a given |profile| have | 80 // Returns true if minimum requirements for import of a given |profile| have |
81 // been met. An address submitted via a form must have at least the fields | 81 // been met. An address submitted via a form must have at least the fields |
82 // required as determined by its country code. | 82 // required as determined by its country code. |
83 // No verification of validity of the contents is preformed. This is an | 83 // No verification of validity of the contents is preformed. This is an |
84 // existence check only. | 84 // existence check only. |
85 bool IsMinimumAddress(const AutofillProfile& profile) { | 85 bool IsMinimumAddress(const AutofillProfile& profile) { |
86 // All countries require at least one address line. | 86 // All countries require at least one address line. |
87 if (profile.GetRawInfo(ADDRESS_HOME_LINE1).empty()) | 87 if (profile.GetRawInfo(ADDRESS_HOME_LINE1).empty()) |
88 return false; | 88 return false; |
89 std::string app_locale = AutofillCountry::ApplicationLocale(); | 89 std::string app_locale = AutofillCountry::ApplicationLocale(); |
90 std::string country_code = profile.CountryCode(); | 90 std::string country_code = |
91 UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)); | |
91 | 92 |
92 if (country_code.empty()) | 93 if (country_code.empty()) |
93 country_code = AutofillCountry::CountryCodeForLocale(app_locale); | 94 country_code = AutofillCountry::CountryCodeForLocale(app_locale); |
94 | 95 |
95 AutofillCountry country(country_code, app_locale); | 96 AutofillCountry country(country_code, app_locale); |
96 | 97 |
97 if (country.requires_city() && profile.GetRawInfo(ADDRESS_HOME_CITY).empty()) | 98 if (country.requires_city() && profile.GetRawInfo(ADDRESS_HOME_CITY).empty()) |
98 return false; | 99 return false; |
99 | 100 |
100 if (country.requires_state() && | 101 if (country.requires_state() && |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 } else { | 272 } else { |
272 // We need to store phone data in the variables, before building the whole | 273 // We need to store phone data in the variables, before building the whole |
273 // number at the end. The rest of the fields are set "as is". | 274 // number at the end. The rest of the fields are set "as is". |
274 // If the fields are not the phone fields in question home.SetInfo() is | 275 // If the fields are not the phone fields in question home.SetInfo() is |
275 // going to return false. | 276 // going to return false. |
276 if (!home.SetInfo(field_type, value)) | 277 if (!home.SetInfo(field_type, value)) |
277 imported_profile->SetInfo(field_type, value, app_locale); | 278 imported_profile->SetInfo(field_type, value, app_locale); |
278 | 279 |
279 // Reject profiles with invalid country information. | 280 // Reject profiles with invalid country information. |
280 if (field_type == ADDRESS_HOME_COUNTRY && | 281 if (field_type == ADDRESS_HOME_COUNTRY && |
281 !value.empty() && imported_profile->CountryCode().empty()) { | 282 !value.empty() && |
283 imported_profile->GetRawInfo(ADDRESS_HOME_COUNTRY).empty()) { | |
282 imported_profile.reset(); | 284 imported_profile.reset(); |
283 break; | 285 break; |
284 } | 286 } |
285 } | 287 } |
286 } | 288 } |
287 | 289 |
288 // Construct the phone number. Reject the profile if the number is invalid. | 290 // Construct the phone number. Reject the profile if the number is invalid. |
289 if (imported_profile.get() && !home.IsEmpty()) { | 291 if (imported_profile.get() && !home.IsEmpty()) { |
290 string16 constructed_number; | 292 string16 constructed_number; |
291 if (!home.ParseNumber(*imported_profile, app_locale, &constructed_number) || | 293 if (!home.ParseNumber(*imported_profile, app_locale, &constructed_number) || |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 const AutofillProfile& profile) { | 662 const AutofillProfile& profile) { |
661 if (!IsMinimumAddress(profile)) | 663 if (!IsMinimumAddress(profile)) |
662 return false; | 664 return false; |
663 | 665 |
664 string16 email = profile.GetRawInfo(EMAIL_ADDRESS); | 666 string16 email = profile.GetRawInfo(EMAIL_ADDRESS); |
665 if (!email.empty() && !autofill::IsValidEmailAddress(email)) | 667 if (!email.empty() && !autofill::IsValidEmailAddress(email)) |
666 return false; | 668 return false; |
667 | 669 |
668 // Reject profiles with invalid US state information. | 670 // Reject profiles with invalid US state information. |
669 string16 state = profile.GetRawInfo(ADDRESS_HOME_STATE); | 671 string16 state = profile.GetRawInfo(ADDRESS_HOME_STATE); |
670 if (profile.CountryCode() == "US" && | 672 if (UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) == "US" && |
Ilya Sherman
2013/04/05 05:18:01
nit: It's more typical to convert the "US" constan
jam
2013/04/05 06:45:54
Done.
| |
671 !state.empty() && !FormGroup::IsValidState(state)) { | 673 !state.empty() && !FormGroup::IsValidState(state)) { |
672 return false; | 674 return false; |
673 } | 675 } |
674 | 676 |
675 // Reject profiles with invalid US zip information. | 677 // Reject profiles with invalid US zip information. |
676 string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); | 678 string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); |
677 if (profile.CountryCode() == "US" && !zip.empty() && | 679 if (UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) == "US" && |
Ilya Sherman
2013/04/05 05:18:01
Ditto.
jam
2013/04/05 06:45:54
Done.
| |
678 !autofill::IsValidZip(zip)) | 680 !zip.empty() && !autofill::IsValidZip(zip)) |
679 return false; | 681 return false; |
680 | 682 |
681 return true; | 683 return true; |
682 } | 684 } |
683 | 685 |
684 // static | 686 // static |
685 bool PersonalDataManager::MergeProfile( | 687 bool PersonalDataManager::MergeProfile( |
686 const AutofillProfile& profile, | 688 const AutofillProfile& profile, |
687 const std::vector<AutofillProfile*>& existing_profiles, | 689 const std::vector<AutofillProfile*>& existing_profiles, |
688 std::vector<AutofillProfile>* merged_profiles) { | 690 std::vector<AutofillProfile>* merged_profiles) { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
976 | 978 |
977 void PersonalDataManager::set_metric_logger( | 979 void PersonalDataManager::set_metric_logger( |
978 const AutofillMetrics* metric_logger) { | 980 const AutofillMetrics* metric_logger) { |
979 metric_logger_.reset(metric_logger); | 981 metric_logger_.reset(metric_logger); |
980 } | 982 } |
981 | 983 |
982 void PersonalDataManager::set_browser_context( | 984 void PersonalDataManager::set_browser_context( |
983 content::BrowserContext* context) { | 985 content::BrowserContext* context) { |
984 browser_context_ = context; | 986 browser_context_ = context; |
985 } | 987 } |
OLD | NEW |