Chromium Code Reviews| 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 NameInfo heuristically_parsed_name; | |
| 529 bool should_append_imported_name = true; | |
| 530 | |
| 531 for (size_t index = 0; index < name_.size(); ++index) { | |
| 532 NameInfo current_name = name_[index]; | |
| 533 if (current_name == imported_name) { | |
| 534 should_append_imported_name = false; | |
| 535 break; | |
| 536 } | |
| 537 | |
| 538 base::string16 full_name = current_name.GetRawInfo(NAME_FULL); | |
| 539 if (full_name == imported_name.GetRawInfo(NAME_FULL)) { | |
| 540 // The imported name has the same full name string as one of the | |
| 541 // existing names for this profile. Because full names are | |
| 542 // _heuristically_ parsed into {first, middle, last} name components, | |
| 543 // it's possible that either the existing name or the imported name | |
| 544 // was misparsed. Prefer to keep the name whose {first, middle, | |
| 545 // last} components do not match those computed by the heuristic | |
| 546 // parse, as this more likely represents the correct, user-input parse | |
| 547 // of the name. | |
| 548 heuristically_parsed_name.SetRawInfo(NAME_FULL, full_name); | |
| 549 if (current_name == heuristically_parsed_name) { | |
| 550 results[index] = imported_name; | |
| 551 should_append_imported_name = false; | |
| 552 break; | |
| 553 } | |
| 554 } | |
| 555 } | |
| 556 | |
| 557 // Append unique names to the list. | |
| 558 if (should_append_imported_name && | |
| 559 (imported_name != heuristically_parsed_name)) | |
|
Ilya Sherman
2014/06/03 22:09:52
What is the test case that would fail if this line
Pritam Nikam
2014/06/04 06:54:44
If this (imported_name != heuristically_parsed_nam
Ilya Sherman
2014/06/04 22:38:27
Sorry, you are of course correct that this check i
Pritam Nikam
2014/06/07 06:25:12
Done.
| |
| 560 results.push_back(imported_name); | |
| 561 } | |
| 562 | |
| 563 name_.swap(results); | |
| 564 } | |
| 565 | |
| 521 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, | 566 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, |
| 522 const std::string& app_locale) { | 567 const std::string& app_locale) { |
| 523 // Verified profiles should never be overwritten with unverified data. | 568 // Verified profiles should never be overwritten with unverified data. |
| 524 DCHECK(!IsVerified() || profile.IsVerified()); | 569 DCHECK(!IsVerified() || profile.IsVerified()); |
| 525 set_origin(profile.origin()); | 570 set_origin(profile.origin()); |
| 526 set_language_code(profile.language_code()); | 571 set_language_code(profile.language_code()); |
| 527 | 572 |
| 528 ServerFieldTypeSet field_types; | 573 ServerFieldTypeSet field_types; |
| 529 profile.GetNonEmptyTypes(app_locale, &field_types); | 574 profile.GetNonEmptyTypes(app_locale, &field_types); |
| 530 | 575 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 560 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); | 605 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); |
| 561 } else { | 606 } else { |
| 562 std::vector<base::string16>::const_iterator existing_iter = | 607 std::vector<base::string16>::const_iterator existing_iter = |
| 563 std::find_if( | 608 std::find_if( |
| 564 existing_values.begin(), existing_values.end(), | 609 existing_values.begin(), existing_values.end(), |
| 565 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); | 610 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); |
| 566 if (existing_iter == existing_values.end()) | 611 if (existing_iter == existing_values.end()) |
| 567 existing_values.insert(existing_values.end(), *value_iter); | 612 existing_values.insert(existing_values.end(), *value_iter); |
| 568 } | 613 } |
| 569 } | 614 } |
| 570 SetRawMultiInfo(*iter, existing_values); | 615 if (group == NAME) |
| 616 OverwriteOrAppendNames(profile.name_); | |
| 617 else | |
| 618 SetRawMultiInfo(*iter, existing_values); | |
| 571 } else { | 619 } else { |
| 572 base::string16 new_value = profile.GetRawInfo(*iter); | 620 base::string16 new_value = profile.GetRawInfo(*iter); |
| 573 if (StringToLowerASCII(GetRawInfo(*iter)) != | 621 if (StringToLowerASCII(GetRawInfo(*iter)) != |
| 574 StringToLowerASCII(new_value)) { | 622 StringToLowerASCII(new_value)) { |
| 575 SetRawInfo(*iter, new_value); | 623 SetRawInfo(*iter, new_value); |
| 576 } | 624 } |
| 577 } | 625 } |
| 578 } | 626 } |
| 579 } | 627 } |
| 580 | 628 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) | 915 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
| 868 << " " | 916 << " " |
| 869 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 917 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
| 870 << " " | 918 << " " |
| 871 << profile.language_code() | 919 << profile.language_code() |
| 872 << " " | 920 << " " |
| 873 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 921 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
| 874 } | 922 } |
| 875 | 923 |
| 876 } // namespace autofill | 924 } // namespace autofill |
| OLD | NEW |