OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/core/browser/autofill_profile.h" | 5 #include "components/autofill/core/browser/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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 } | 511 } |
512 } else if (StringToLowerASCII(GetRawInfo(*it)) != | 512 } else if (StringToLowerASCII(GetRawInfo(*it)) != |
513 StringToLowerASCII(profile.GetRawInfo(*it))) { | 513 StringToLowerASCII(profile.GetRawInfo(*it))) { |
514 return false; | 514 return false; |
515 } | 515 } |
516 } | 516 } |
517 | 517 |
518 return true; | 518 return true; |
519 } | 519 } |
520 | 520 |
| 521 void AutofillProfile::OverwriteOrAppendNames( |
| 522 const std::vector<NameInfo>& names) { |
| 523 std::vector<NameInfo> results(name_); |
| 524 for (std::vector<NameInfo>::const_iterator it = names.begin(); |
| 525 it != names.end(); |
| 526 ++it) { |
| 527 NameInfo imported_name = *it; |
| 528 bool should_append_imported_name = true; |
| 529 |
| 530 for (size_t index = 0; index < name_.size(); ++index) { |
| 531 NameInfo current_name = name_[index]; |
| 532 if (current_name == imported_name) { |
| 533 should_append_imported_name = false; |
| 534 break; |
| 535 } |
| 536 |
| 537 base::string16 full_name = current_name.GetRawInfo(NAME_FULL); |
| 538 if (full_name == imported_name.GetRawInfo(NAME_FULL)) { |
| 539 // The imported name has the same full name string as one of the |
| 540 // existing names for this profile. Because full names are |
| 541 // _heuristically_ parsed into {first, middle, last} name components, |
| 542 // it's possible that either the existing name or the imported name |
| 543 // was misparsed. Prefer to keep the name whose {first, middle, |
| 544 // last} components do not match those computed by the heuristic |
| 545 // parse, as this more likely represents the correct, user-input parse |
| 546 // of the name. |
| 547 NameInfo heuristically_parsed_name; |
| 548 heuristically_parsed_name.SetRawInfo(NAME_FULL, full_name); |
| 549 if (imported_name == heuristically_parsed_name) { |
| 550 should_append_imported_name = false; |
| 551 break; |
| 552 } |
| 553 |
| 554 if (current_name == heuristically_parsed_name) { |
| 555 results[index] = imported_name; |
| 556 should_append_imported_name = false; |
| 557 break; |
| 558 } |
| 559 } |
| 560 } |
| 561 |
| 562 // Append unique names to the list. |
| 563 if (should_append_imported_name) |
| 564 results.push_back(imported_name); |
| 565 } |
| 566 |
| 567 name_.swap(results); |
| 568 } |
| 569 |
521 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, | 570 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, |
522 const std::string& app_locale) { | 571 const std::string& app_locale) { |
523 // Verified profiles should never be overwritten with unverified data. | 572 // Verified profiles should never be overwritten with unverified data. |
524 DCHECK(!IsVerified() || profile.IsVerified()); | 573 DCHECK(!IsVerified() || profile.IsVerified()); |
525 set_origin(profile.origin()); | 574 set_origin(profile.origin()); |
526 set_language_code(profile.language_code()); | 575 set_language_code(profile.language_code()); |
527 | 576 |
528 ServerFieldTypeSet field_types; | 577 ServerFieldTypeSet field_types; |
529 profile.GetNonEmptyTypes(app_locale, &field_types); | 578 profile.GetNonEmptyTypes(app_locale, &field_types); |
530 | 579 |
(...skipping 29 matching lines...) Expand all Loading... |
560 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); | 609 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); |
561 } else { | 610 } else { |
562 std::vector<base::string16>::const_iterator existing_iter = | 611 std::vector<base::string16>::const_iterator existing_iter = |
563 std::find_if( | 612 std::find_if( |
564 existing_values.begin(), existing_values.end(), | 613 existing_values.begin(), existing_values.end(), |
565 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); | 614 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); |
566 if (existing_iter == existing_values.end()) | 615 if (existing_iter == existing_values.end()) |
567 existing_values.insert(existing_values.end(), *value_iter); | 616 existing_values.insert(existing_values.end(), *value_iter); |
568 } | 617 } |
569 } | 618 } |
570 SetRawMultiInfo(*iter, existing_values); | 619 if (group == NAME) |
| 620 OverwriteOrAppendNames(profile.name_); |
| 621 else |
| 622 SetRawMultiInfo(*iter, existing_values); |
571 } else { | 623 } else { |
572 base::string16 new_value = profile.GetRawInfo(*iter); | 624 base::string16 new_value = profile.GetRawInfo(*iter); |
573 if (StringToLowerASCII(GetRawInfo(*iter)) != | 625 if (StringToLowerASCII(GetRawInfo(*iter)) != |
574 StringToLowerASCII(new_value)) { | 626 StringToLowerASCII(new_value)) { |
575 SetRawInfo(*iter, new_value); | 627 SetRawInfo(*iter, new_value); |
576 } | 628 } |
577 } | 629 } |
578 } | 630 } |
579 } | 631 } |
580 | 632 |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) | 919 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
868 << " " | 920 << " " |
869 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 921 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
870 << " " | 922 << " " |
871 << profile.language_code() | 923 << profile.language_code() |
872 << " " | 924 << " " |
873 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 925 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
874 } | 926 } |
875 | 927 |
876 } // namespace autofill | 928 } // namespace autofill |
OLD | NEW |