| 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/autofill_profile.h" | 5 #include "chrome/browser/autofill/autofill_profile.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 299 |
| 300 void AutofillProfile::SetMultiInfo(AutofillFieldType type, | 300 void AutofillProfile::SetMultiInfo(AutofillFieldType type, |
| 301 const std::vector<string16>& values) { | 301 const std::vector<string16>& values) { |
| 302 switch (AutofillType(type).group()) { | 302 switch (AutofillType(type).group()) { |
| 303 case AutofillType::NAME: | 303 case AutofillType::NAME: |
| 304 CopyValuesToItems(type, values, &name_, NameInfo()); | 304 CopyValuesToItems(type, values, &name_, NameInfo()); |
| 305 break; | 305 break; |
| 306 case AutofillType::EMAIL: | 306 case AutofillType::EMAIL: |
| 307 CopyValuesToItems(type, values, &email_, EmailInfo()); | 307 CopyValuesToItems(type, values, &email_, EmailInfo()); |
| 308 break; | 308 break; |
| 309 case AutofillType::PHONE_HOME: | 309 case AutofillType::PHONE: |
| 310 CopyValuesToItems(type, | 310 CopyValuesToItems(type, |
| 311 values, | 311 values, |
| 312 &home_number_, | 312 &home_number_, |
| 313 PhoneNumber(this)); | 313 PhoneNumber(this)); |
| 314 break; | 314 break; |
| 315 default: | 315 default: |
| 316 if (values.size() == 1) { | 316 if (values.size() == 1) { |
| 317 SetInfo(type, values[0]); | 317 SetInfo(type, values[0]); |
| 318 } else if (values.size() == 0) { | 318 } else if (values.size() == 0) { |
| 319 SetInfo(type, string16()); | 319 SetInfo(type, string16()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 338 void AutofillProfile::GetMultiInfoImpl(AutofillFieldType type, | 338 void AutofillProfile::GetMultiInfoImpl(AutofillFieldType type, |
| 339 bool canonicalize, | 339 bool canonicalize, |
| 340 std::vector<string16>* values) const { | 340 std::vector<string16>* values) const { |
| 341 switch (AutofillType(type).group()) { | 341 switch (AutofillType(type).group()) { |
| 342 case AutofillType::NAME: | 342 case AutofillType::NAME: |
| 343 CopyItemsToValues(type, name_, canonicalize, values); | 343 CopyItemsToValues(type, name_, canonicalize, values); |
| 344 break; | 344 break; |
| 345 case AutofillType::EMAIL: | 345 case AutofillType::EMAIL: |
| 346 CopyItemsToValues(type, email_, canonicalize, values); | 346 CopyItemsToValues(type, email_, canonicalize, values); |
| 347 break; | 347 break; |
| 348 case AutofillType::PHONE_HOME: | 348 case AutofillType::PHONE: |
| 349 CopyItemsToValues(type, home_number_, canonicalize, values); | 349 CopyItemsToValues(type, home_number_, canonicalize, values); |
| 350 break; | 350 break; |
| 351 default: | 351 default: |
| 352 values->resize(1); | 352 values->resize(1); |
| 353 (*values)[0] = GetInfo(type); | 353 (*values)[0] = GetInfo(type); |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 | 356 |
| 357 // static | 357 // static |
| 358 bool AutofillProfile::SupportsMultiValue(AutofillFieldType type) { | 358 bool AutofillProfile::SupportsMultiValue(AutofillFieldType type) { |
| 359 AutofillType::FieldTypeGroup group = AutofillType(type).group(); | 359 AutofillType::FieldTypeGroup group = AutofillType(type).group(); |
| 360 return group == AutofillType::NAME || | 360 return group == AutofillType::NAME || |
| 361 group == AutofillType::EMAIL || | 361 group == AutofillType::EMAIL || |
| 362 group == AutofillType::PHONE_HOME; | 362 group == AutofillType::PHONE; |
| 363 } | 363 } |
| 364 | 364 |
| 365 const string16 AutofillProfile::Label() const { | 365 const string16 AutofillProfile::Label() const { |
| 366 return label_; | 366 return label_; |
| 367 } | 367 } |
| 368 | 368 |
| 369 const std::string AutofillProfile::CountryCode() const { | 369 const std::string AutofillProfile::CountryCode() const { |
| 370 return address_.country_code(); | 370 return address_.country_code(); |
| 371 } | 371 } |
| 372 | 372 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 GetNonEmptyTypes(&types); | 528 GetNonEmptyTypes(&types); |
| 529 | 529 |
| 530 for (FieldTypeSet::const_iterator iter = types.begin(); iter != types.end(); | 530 for (FieldTypeSet::const_iterator iter = types.begin(); iter != types.end(); |
| 531 ++iter) { | 531 ++iter) { |
| 532 if (*iter == NAME_FULL) { | 532 if (*iter == NAME_FULL) { |
| 533 // Ignore the compound "full name" field type. We are only interested in | 533 // Ignore the compound "full name" field type. We are only interested in |
| 534 // comparing the constituent parts. For example, if |this| has a middle | 534 // comparing the constituent parts. For example, if |this| has a middle |
| 535 // name saved, but |profile| lacks one, |profile| could still be a subset | 535 // name saved, but |profile| lacks one, |profile| could still be a subset |
| 536 // of |this|. | 536 // of |this|. |
| 537 continue; | 537 continue; |
| 538 } else if (AutofillType(*iter).group() == AutofillType::PHONE_HOME) { | 538 } else if (AutofillType(*iter).group() == AutofillType::PHONE) { |
| 539 // Phone numbers should be canonicalized prior to being compared. | 539 // Phone numbers should be canonicalized prior to being compared. |
| 540 if (*iter != PHONE_HOME_WHOLE_NUMBER) { | 540 if (*iter != PHONE_HOME_WHOLE_NUMBER) { |
| 541 continue; | 541 continue; |
| 542 } else if (!autofill_i18n::PhoneNumbersMatch(GetInfo(*iter), | 542 } else if (!autofill_i18n::PhoneNumbersMatch(GetInfo(*iter), |
| 543 profile.GetInfo(*iter), | 543 profile.GetInfo(*iter), |
| 544 CountryCode())) { | 544 CountryCode())) { |
| 545 return false; | 545 return false; |
| 546 } | 546 } |
| 547 } else if (StringToLowerASCII(GetInfo(*iter)) != | 547 } else if (StringToLowerASCII(GetInfo(*iter)) != |
| 548 StringToLowerASCII(profile.GetInfo(*iter))) { | 548 StringToLowerASCII(profile.GetInfo(*iter))) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 571 | 571 |
| 572 // GetMultiInfo always returns at least one element, even if the profile | 572 // GetMultiInfo always returns at least one element, even if the profile |
| 573 // has no data stored for this field type. | 573 // has no data stored for this field type. |
| 574 if (existing_values.size() == 1 && existing_values.front().empty()) | 574 if (existing_values.size() == 1 && existing_values.front().empty()) |
| 575 existing_values.clear(); | 575 existing_values.clear(); |
| 576 | 576 |
| 577 FieldTypeGroup group = AutofillType(*iter).group(); | 577 FieldTypeGroup group = AutofillType(*iter).group(); |
| 578 for (std::vector<string16>::iterator value_iter = new_values.begin(); | 578 for (std::vector<string16>::iterator value_iter = new_values.begin(); |
| 579 value_iter != new_values.end(); ++value_iter) { | 579 value_iter != new_values.end(); ++value_iter) { |
| 580 // Don't add duplicates. | 580 // Don't add duplicates. |
| 581 if (group == AutofillType::PHONE_HOME) { | 581 if (group == AutofillType::PHONE) { |
| 582 AddPhoneIfUnique(*value_iter, &existing_values); | 582 AddPhoneIfUnique(*value_iter, &existing_values); |
| 583 } else { | 583 } else { |
| 584 std::vector<string16>::const_iterator existing_iter = std::find_if( | 584 std::vector<string16>::const_iterator existing_iter = std::find_if( |
| 585 existing_values.begin(), existing_values.end(), | 585 existing_values.begin(), existing_values.end(), |
| 586 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); | 586 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); |
| 587 if (existing_iter == existing_values.end()) | 587 if (existing_iter == existing_values.end()) |
| 588 existing_values.insert(existing_values.end(), *value_iter); | 588 existing_values.insert(existing_values.end(), *value_iter); |
| 589 } | 589 } |
| 590 } | 590 } |
| 591 SetMultiInfo(*iter, existing_values); | 591 SetMultiInfo(*iter, existing_values); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 switch (AutofillType(type).group()) { | 732 switch (AutofillType(type).group()) { |
| 733 case AutofillType::NAME: | 733 case AutofillType::NAME: |
| 734 form_group = &name_[0]; | 734 form_group = &name_[0]; |
| 735 break; | 735 break; |
| 736 case AutofillType::EMAIL: | 736 case AutofillType::EMAIL: |
| 737 form_group = &email_[0]; | 737 form_group = &email_[0]; |
| 738 break; | 738 break; |
| 739 case AutofillType::COMPANY: | 739 case AutofillType::COMPANY: |
| 740 form_group = &company_; | 740 form_group = &company_; |
| 741 break; | 741 break; |
| 742 case AutofillType::PHONE_HOME: | 742 case AutofillType::PHONE: |
| 743 form_group = &home_number_[0]; | 743 form_group = &home_number_[0]; |
| 744 break; | 744 break; |
| 745 case AutofillType::ADDRESS_HOME: | 745 case AutofillType::ADDRESS_HOME: |
| 746 form_group = &address_; | 746 form_group = &address_; |
| 747 break; | 747 break; |
| 748 default: | 748 default: |
| 749 break; | 749 break; |
| 750 } | 750 } |
| 751 return form_group; | 751 return form_group; |
| 752 } | 752 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 775 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_CITY)) | 775 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_CITY)) |
| 776 << " " | 776 << " " |
| 777 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_STATE)) | 777 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_STATE)) |
| 778 << " " | 778 << " " |
| 779 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_ZIP)) | 779 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_ZIP)) |
| 780 << " " | 780 << " " |
| 781 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_COUNTRY)) | 781 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_COUNTRY)) |
| 782 << " " | 782 << " " |
| 783 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 783 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
| 784 } | 784 } |
| OLD | NEW |