| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 bool operator()(const string16* phone) { | 188 bool operator()(const string16* phone) { |
| 189 return autofill_i18n::PhoneNumbersMatch(*phone, phone_, country_code_); | 189 return autofill_i18n::PhoneNumbersMatch(*phone, phone_, country_code_); |
| 190 } | 190 } |
| 191 | 191 |
| 192 private: | 192 private: |
| 193 string16 phone_; | 193 string16 phone_; |
| 194 std::string country_code_; | 194 std::string country_code_; |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 // Functor used to check for case-insensitive equality of two strings. |
| 198 struct CaseInsensitiveStringEquals |
| 199 : public std::binary_function<string16, string16, bool> |
| 200 { |
| 201 bool operator()(const string16& x, const string16& y) const { |
| 202 return |
| 203 x.size() == y.size() && StringToLowerASCII(x) == StringToLowerASCII(y); |
| 204 } |
| 205 }; |
| 206 |
| 197 } // namespace | 207 } // namespace |
| 198 | 208 |
| 199 AutofillProfile::AutofillProfile(const std::string& guid) | 209 AutofillProfile::AutofillProfile(const std::string& guid) |
| 200 : guid_(guid), | 210 : guid_(guid), |
| 201 name_(1), | 211 name_(1), |
| 202 email_(1), | 212 email_(1), |
| 203 home_number_(1, PhoneNumber(this)) { | 213 home_number_(1, PhoneNumber(this)) { |
| 204 } | 214 } |
| 205 | 215 |
| 206 AutofillProfile::AutofillProfile() | 216 AutofillProfile::AutofillProfile() |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 516 |
| 507 bool AutofillProfile::operator!=(const AutofillProfile& profile) const { | 517 bool AutofillProfile::operator!=(const AutofillProfile& profile) const { |
| 508 return !operator==(profile); | 518 return !operator==(profile); |
| 509 } | 519 } |
| 510 | 520 |
| 511 const string16 AutofillProfile::PrimaryValue() const { | 521 const string16 AutofillProfile::PrimaryValue() const { |
| 512 return GetInfo(ADDRESS_HOME_LINE1) + | 522 return GetInfo(ADDRESS_HOME_LINE1) + |
| 513 GetInfo(ADDRESS_HOME_CITY); | 523 GetInfo(ADDRESS_HOME_CITY); |
| 514 } | 524 } |
| 515 | 525 |
| 516 // Functor used to check for case-insensitive equality of two strings. | 526 bool AutofillProfile::IsSubsetOf(const AutofillProfile& profile) const { |
| 517 struct CaseInsensitiveStringEquals | 527 FieldTypeSet types; |
| 518 : public std::binary_function<string16, string16, bool> | 528 GetNonEmptyTypes(&types); |
| 519 { | 529 |
| 520 bool operator()(const string16& x, const string16& y) const { | 530 for (FieldTypeSet::const_iterator iter = types.begin(); iter != types.end(); |
| 521 if (x.size() != y.size()) return false; | 531 ++iter) { |
| 522 return StringToLowerASCII(x) == StringToLowerASCII(y); | 532 if (StringToLowerASCII(GetInfo(*iter)) != |
| 533 StringToLowerASCII(profile.GetInfo(*iter))) |
| 534 return false; |
| 523 } | 535 } |
| 524 }; | 536 |
| 537 return true; |
| 538 } |
| 525 | 539 |
| 526 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile) { | 540 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile) { |
| 527 FieldTypeSet field_types; | 541 FieldTypeSet field_types; |
| 528 profile.GetNonEmptyTypes(&field_types); | 542 profile.GetNonEmptyTypes(&field_types); |
| 529 | 543 |
| 530 // Only transfer "full" types (e.g. full name) and not fragments (e.g. | 544 // Only transfer "full" types (e.g. full name) and not fragments (e.g. |
| 531 // first name, last name). | 545 // first name, last name). |
| 532 CollapseCompoundFieldTypes(&field_types); | 546 CollapseCompoundFieldTypes(&field_types); |
| 533 | 547 |
| 534 for (FieldTypeSet::const_iterator iter = field_types.begin(); | 548 for (FieldTypeSet::const_iterator iter = field_types.begin(); |
| 535 iter != field_types.end(); ++iter) { | 549 iter != field_types.end(); ++iter) { |
| 536 if (AutofillProfile::SupportsMultiValue(*iter)) { | 550 if (AutofillProfile::SupportsMultiValue(*iter)) { |
| 537 std::vector<string16> new_values; | 551 std::vector<string16> new_values; |
| 538 profile.GetMultiInfo(*iter, &new_values); | 552 profile.GetMultiInfo(*iter, &new_values); |
| 539 std::vector<string16> existing_values; | 553 std::vector<string16> existing_values; |
| 540 GetMultiInfo(*iter, &existing_values); | 554 GetMultiInfo(*iter, &existing_values); |
| 555 |
| 556 // GetMultiInfo always returns at least one element, even if the profile |
| 557 // has no data stored for this field type. |
| 558 if (existing_values.size() == 1 && existing_values.front().empty()) |
| 559 existing_values.clear(); |
| 560 |
| 541 FieldTypeGroup group = AutofillType(*iter).group(); | 561 FieldTypeGroup group = AutofillType(*iter).group(); |
| 542 for (std::vector<string16>::iterator value_iter = new_values.begin(); | 562 for (std::vector<string16>::iterator value_iter = new_values.begin(); |
| 543 value_iter != new_values.end(); ++value_iter) { | 563 value_iter != new_values.end(); ++value_iter) { |
| 544 // Don't add duplicates. | 564 // Don't add duplicates. |
| 545 if (group == AutofillType::PHONE_HOME) { | 565 if (group == AutofillType::PHONE_HOME) { |
| 546 AddPhoneIfUnique(*value_iter, &existing_values); | 566 AddPhoneIfUnique(*value_iter, &existing_values); |
| 547 } else { | 567 } else { |
| 548 std::vector<string16>::const_iterator existing_iter = std::find_if( | 568 std::vector<string16>::const_iterator existing_iter = std::find_if( |
| 549 existing_values.begin(), existing_values.end(), | 569 existing_values.begin(), existing_values.end(), |
| 550 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); | 570 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); |
| 551 if (existing_iter == existing_values.end()) | 571 if (existing_iter == existing_values.end()) |
| 552 existing_values.insert(existing_values.end(), *value_iter); | 572 existing_values.insert(existing_values.end(), *value_iter); |
| 553 } | 573 } |
| 554 } | 574 } |
| 555 SetMultiInfo(*iter, existing_values); | 575 SetMultiInfo(*iter, existing_values); |
| 556 } else { | 576 } else { |
| 557 SetInfo(*iter, profile.GetInfo(*iter)); | 577 string16 new_value = profile.GetInfo(*iter); |
| 578 if (StringToLowerASCII(GetInfo(*iter)) != StringToLowerASCII(new_value)) |
| 579 SetInfo(*iter, new_value); |
| 558 } | 580 } |
| 559 } | 581 } |
| 560 } | 582 } |
| 561 | 583 |
| 562 void AutofillProfile::AddPhoneIfUnique(const string16& phone, | 584 void AutofillProfile::AddPhoneIfUnique(const string16& phone, |
| 563 std::vector<string16>* existing_phones) { | 585 std::vector<string16>* existing_phones) { |
| 564 DCHECK(existing_phones); | 586 DCHECK(existing_phones); |
| 565 // Phones allow "fuzzy" matching, so "1-800-FLOWERS", "18003569377", | 587 // Phones allow "fuzzy" matching, so "1-800-FLOWERS", "18003569377", |
| 566 // "(800)356-9377" and "356-9377" are considered the same. | 588 // "(800)356-9377" and "356-9377" are considered the same. |
| 567 std::vector<string16>::const_iterator phone_iter; | 589 std::vector<string16>::const_iterator phone_iter; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_CITY)) | 759 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_CITY)) |
| 738 << " " | 760 << " " |
| 739 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_STATE)) | 761 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_STATE)) |
| 740 << " " | 762 << " " |
| 741 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_ZIP)) | 763 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_ZIP)) |
| 742 << " " | 764 << " " |
| 743 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_COUNTRY)) | 765 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_COUNTRY)) |
| 744 << " " | 766 << " " |
| 745 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 767 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
| 746 } | 768 } |
| OLD | NEW |