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 <map> | 9 #include <map> |
9 #include <set> | 10 #include <set> |
10 | 11 |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/autofill/address.h" | 16 #include "chrome/browser/autofill/address.h" |
16 #include "chrome/browser/autofill/autofill_type.h" | 17 #include "chrome/browser/autofill/autofill_type.h" |
17 #include "chrome/browser/autofill/contact_info.h" | 18 #include "chrome/browser/autofill/contact_info.h" |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 531 |
531 bool AutofillProfile::operator!=(const AutofillProfile& profile) const { | 532 bool AutofillProfile::operator!=(const AutofillProfile& profile) const { |
532 return !operator==(profile); | 533 return !operator==(profile); |
533 } | 534 } |
534 | 535 |
535 const string16 AutofillProfile::PrimaryValue() const { | 536 const string16 AutofillProfile::PrimaryValue() const { |
536 return GetInfo(ADDRESS_HOME_LINE1) + | 537 return GetInfo(ADDRESS_HOME_LINE1) + |
537 GetInfo(ADDRESS_HOME_CITY); | 538 GetInfo(ADDRESS_HOME_CITY); |
538 } | 539 } |
539 | 540 |
| 541 // Functor used to check for case-insensitive equality of two strings. |
| 542 struct CaseInsensitiveStringEquals |
| 543 : public std::binary_function<string16, string16, bool> |
| 544 { |
| 545 bool operator()(const string16& x, const string16& y) const { |
| 546 return std::equal(x.begin(), x.end(), y.begin(), |
| 547 base::CaseInsensitiveCompare<string16::value_type>()); |
| 548 } |
| 549 }; |
| 550 |
540 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile) { | 551 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile) { |
541 FieldTypeSet field_types; | 552 FieldTypeSet field_types; |
542 profile.GetNonEmptyTypes(&field_types); | 553 profile.GetNonEmptyTypes(&field_types); |
543 | 554 |
544 // Only transfer "full" types (e.g. full name) and not fragments (e.g. | 555 // Only transfer "full" types (e.g. full name) and not fragments (e.g. |
545 // first name, last name). | 556 // first name, last name). |
546 CollapseCompoundFieldTypes(&field_types); | 557 CollapseCompoundFieldTypes(&field_types); |
547 | 558 |
548 for (FieldTypeSet::const_iterator iter = field_types.begin(); | 559 for (FieldTypeSet::const_iterator iter = field_types.begin(); |
549 iter != field_types.end(); ++iter) { | 560 iter != field_types.end(); ++iter) { |
550 if (AutofillProfile::SupportsMultiValue(*iter)) { | 561 if (AutofillProfile::SupportsMultiValue(*iter)) { |
551 std::vector<string16> new_values; | 562 std::vector<string16> new_values; |
552 profile.GetMultiInfo(*iter, &new_values); | 563 profile.GetMultiInfo(*iter, &new_values); |
553 std::vector<string16> existing_values; | 564 std::vector<string16> existing_values; |
554 GetMultiInfo(*iter, &existing_values); | 565 GetMultiInfo(*iter, &existing_values); |
555 FieldTypeGroup group = AutofillType(*iter).group(); | 566 FieldTypeGroup group = AutofillType(*iter).group(); |
556 for (std::vector<string16>::iterator value_iter = new_values.begin(); | 567 for (std::vector<string16>::iterator value_iter = new_values.begin(); |
557 value_iter != new_values.end(); ++value_iter) { | 568 value_iter != new_values.end(); ++value_iter) { |
558 // Don't add duplicates. | 569 // Don't add duplicates. |
559 if (group == AutofillType::PHONE_HOME || | 570 if (group == AutofillType::PHONE_HOME || |
560 group == AutofillType::PHONE_FAX) { | 571 group == AutofillType::PHONE_FAX) { |
561 AddPhoneIfUnique(*value_iter, &existing_values); | 572 AddPhoneIfUnique(*value_iter, &existing_values); |
562 } else { | 573 } else { |
563 if (std::find(existing_values.begin(), existing_values.end(), | 574 std::vector<string16>::const_iterator existing_iter = std::find_if( |
564 *value_iter) == existing_values.end()) { | 575 existing_values.begin(), existing_values.end(), |
| 576 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); |
| 577 if (existing_iter == existing_values.end()) |
565 existing_values.insert(existing_values.end(), *value_iter); | 578 existing_values.insert(existing_values.end(), *value_iter); |
566 } | |
567 } | 579 } |
568 } | 580 } |
569 SetMultiInfo(*iter, existing_values); | 581 SetMultiInfo(*iter, existing_values); |
570 } else { | 582 } else { |
571 SetInfo(*iter, profile.GetInfo(*iter)); | 583 SetInfo(*iter, profile.GetInfo(*iter)); |
572 } | 584 } |
573 } | 585 } |
574 } | 586 } |
575 | 587 |
576 void AutofillProfile::AddPhoneIfUnique(const string16& phone, | 588 void AutofillProfile::AddPhoneIfUnique(const string16& phone, |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_STATE)) | 774 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_STATE)) |
763 << " " | 775 << " " |
764 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_ZIP)) | 776 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_ZIP)) |
765 << " " | 777 << " " |
766 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_COUNTRY)) | 778 << UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_COUNTRY)) |
767 << " " | 779 << " " |
768 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)) | 780 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)) |
769 << " " | 781 << " " |
770 << UTF16ToUTF8(MultiString(profile, PHONE_FAX_WHOLE_NUMBER)); | 782 << UTF16ToUTF8(MultiString(profile, PHONE_FAX_WHOLE_NUMBER)); |
771 } | 783 } |
OLD | NEW |