Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: components/autofill/core/browser/autofill_profile.cc

Issue 1973873002: [Autofill] Improve the merging of two profiles' names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_profile_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 10 #include <memory>
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 !imported_name.GetRawInfo(NAME_FULL).empty()) { 492 !imported_name.GetRawInfo(NAME_FULL).empty()) {
493 name_.SetRawInfo(NAME_FULL, imported_name.GetRawInfo(NAME_FULL)); 493 name_.SetRawInfo(NAME_FULL, imported_name.GetRawInfo(NAME_FULL));
494 return true; 494 return true;
495 } 495 }
496 return false; 496 return false;
497 } 497 }
498 498
499 l10n::CaseInsensitiveCompare compare; 499 l10n::CaseInsensitiveCompare compare;
500 AutofillType type = AutofillType(NAME_FULL); 500 AutofillType type = AutofillType(NAME_FULL);
501 base::string16 full_name = name_.GetInfo(type, app_locale); 501 base::string16 full_name = name_.GetInfo(type, app_locale);
502 if (compare.StringsEqual(full_name, 502 // Always overwrite if the name parts are empty.
503 if (!name_.NamePartsAreEmpty() &&
504 compare.StringsEqual(full_name,
503 imported_name.GetInfo(type, app_locale))) { 505 imported_name.GetInfo(type, app_locale))) {
504 // The imported name has the same full name string as the name for this 506 // The imported name has the same full name string as the name for this
505 // profile. Because full names are _heuristically_ parsed into 507 // profile. Because full names are _heuristically_ parsed into
506 // {first, middle, last} name components, it's possible that either the 508 // {first, middle, last} name components, it's possible that either the
507 // existing name or the imported name was misparsed. Prefer to keep the 509 // existing name or the imported name was misparsed. Prefer to keep the
508 // name whose {first, middle, last} components do not match those computed 510 // name whose {first, middle, last} components do not match those computed
509 // by the heuristic parse, as this more likely represents the correct, 511 // by the heuristic parse, as this more likely represents the correct,
510 // user-input parse of the name. 512 // user-input parse of the name.
511 NameInfo heuristically_parsed_name; 513 NameInfo heuristically_parsed_name;
512 heuristically_parsed_name.SetInfo(type, full_name, app_locale); 514 heuristically_parsed_name.SetInfo(type, full_name, app_locale);
513 if (imported_name.ParsedNamesAreEqual(heuristically_parsed_name)) 515 if (imported_name.ParsedNamesAreEqual(heuristically_parsed_name))
514 return false; 516 return false;
515 } 517 }
516 518
517 name_ = imported_name; 519 name_.OverwriteName(imported_name);
518 return true; 520 return true;
519 } 521 }
520 522
521 bool AutofillProfile::OverwriteWith(const AutofillProfile& profile, 523 bool AutofillProfile::OverwriteWith(const AutofillProfile& profile,
522 const std::string& app_locale) { 524 const std::string& app_locale) {
523 // Verified profiles should never be overwritten with unverified data. 525 // Verified profiles should never be overwritten with unverified data.
524 DCHECK(!IsVerified() || profile.IsVerified()); 526 DCHECK(!IsVerified() || profile.IsVerified());
525 set_origin(profile.origin()); 527 set_origin(profile.origin());
526 set_language_code(profile.language_code()); 528 set_language_code(profile.language_code());
527 set_use_count(profile.use_count() + use_count()); 529 set_use_count(profile.use_count() + use_count());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 } 580 }
579 581
580 return did_overwrite; 582 return did_overwrite;
581 } 583 }
582 584
583 bool AutofillProfile::SaveAdditionalInfo(const AutofillProfile& profile, 585 bool AutofillProfile::SaveAdditionalInfo(const AutofillProfile& profile,
584 const std::string& app_locale) { 586 const std::string& app_locale) {
585 ServerFieldTypeSet field_types, other_field_types; 587 ServerFieldTypeSet field_types, other_field_types;
586 GetNonEmptyTypes(app_locale, &field_types); 588 GetNonEmptyTypes(app_locale, &field_types);
587 profile.GetNonEmptyTypes(app_locale, &other_field_types); 589 profile.GetNonEmptyTypes(app_locale, &other_field_types);
590
588 // The address needs to be compared line by line to take into account the 591 // The address needs to be compared line by line to take into account the
589 // logic for empty fields implemented in the loop. 592 // logic for empty fields implemented in the loop.
590 field_types.erase(ADDRESS_HOME_STREET_ADDRESS); 593 field_types.erase(ADDRESS_HOME_STREET_ADDRESS);
591 l10n::CaseInsensitiveCompare compare; 594 l10n::CaseInsensitiveCompare compare;
592 for (ServerFieldType field_type : field_types) { 595 for (ServerFieldType field_type : field_types) {
593 if (other_field_types.count(field_type)) { 596 if (other_field_types.count(field_type)) {
594 AutofillType type = AutofillType(field_type); 597 AutofillType type = AutofillType(field_type);
595 // Special cases for name and phone. If the whole/full value matches, skip 598 // Special cases for name and phone. If the whole/full value matches, skip
596 // the individual fields comparison. 599 // the individual fields comparison.
597 if (type.group() == NAME && 600 if (type.group() == NAME &&
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 CanonicalizeProfileString(profile.GetRawInfo(field_type)), 637 CanonicalizeProfileString(profile.GetRawInfo(field_type)),
635 CanonicalizeProfileString(GetRawInfo(field_type))) && 638 CanonicalizeProfileString(GetRawInfo(field_type))) &&
636 !compare.StringsEqual(CanonicalizeProfileString(profile.GetRawInfo( 639 !compare.StringsEqual(CanonicalizeProfileString(profile.GetRawInfo(
637 ADDRESS_HOME_STREET_ADDRESS)), 640 ADDRESS_HOME_STREET_ADDRESS)),
638 CanonicalizeProfileString(GetRawInfo( 641 CanonicalizeProfileString(GetRawInfo(
639 ADDRESS_HOME_STREET_ADDRESS)))) { 642 ADDRESS_HOME_STREET_ADDRESS)))) {
640 return false; 643 return false;
641 } 644 }
642 continue; 645 continue;
643 } 646 }
647
644 // Special case for the state to support abbreviations. Currently only the 648 // Special case for the state to support abbreviations. Currently only the
645 // US states are supported. 649 // US states are supported.
646 if (field_type == ADDRESS_HOME_STATE) { 650 if (field_type == ADDRESS_HOME_STATE) {
647 base::string16 full; 651 base::string16 full;
648 base::string16 abbreviation; 652 base::string16 abbreviation;
649 state_names::GetNameAndAbbreviation(GetRawInfo(ADDRESS_HOME_STATE), 653 state_names::GetNameAndAbbreviation(GetRawInfo(ADDRESS_HOME_STATE),
650 &full, &abbreviation); 654 &full, &abbreviation);
651 if (compare.StringsEqual(profile.GetRawInfo(ADDRESS_HOME_STATE), 655 if (compare.StringsEqual(profile.GetRawInfo(ADDRESS_HOME_STATE),
652 full) || 656 full) ||
653 compare.StringsEqual(profile.GetRawInfo(ADDRESS_HOME_STATE), 657 compare.StringsEqual(profile.GetRawInfo(ADDRESS_HOME_STATE),
654 abbreviation)) 658 abbreviation))
655 continue; 659 continue;
656 } 660 }
657 661
658 // Special case for company names to support cannonicalized variations. 662 // Special case for company names to support cannonicalized variations.
659 if (field_type == COMPANY_NAME) { 663 if (field_type == COMPANY_NAME) {
660 if (compare.StringsEqual( 664 if (compare.StringsEqual(
661 CanonicalizeProfileString(profile.GetRawInfo(field_type)), 665 CanonicalizeProfileString(profile.GetRawInfo(field_type)),
662 CanonicalizeProfileString(GetRawInfo(field_type)))) { 666 CanonicalizeProfileString(GetRawInfo(field_type)))) {
663 continue; 667 continue;
664 } 668 }
665 } 669 }
666 670
671 // Special case for middle name to support initials.
672 if (field_type == NAME_MIDDLE) {
673 base::string16 middle_name = GetRawInfo(NAME_MIDDLE);
674 base::string16 profile_middle_name = profile.GetRawInfo(NAME_MIDDLE);
675 DCHECK(!middle_name.empty());
676 DCHECK(!profile_middle_name.empty());
677 // If one of the two middle names is an initial that matches the first
678 // letter of the other middle name, they are considered equivalent.
679 if ((middle_name.size() == 1 || profile_middle_name.size() == 1) &&
680 middle_name[0] == profile_middle_name[0]) {
681 continue;
682 }
683 }
684
667 if (!compare.StringsEqual(profile.GetRawInfo(field_type), 685 if (!compare.StringsEqual(profile.GetRawInfo(field_type),
668 GetRawInfo(field_type))) { 686 GetRawInfo(field_type))) {
669 return false; 687 return false;
670 } 688 }
671 } 689 }
672 } 690 }
673 691
674 if (!IsVerified() || profile.IsVerified()) { 692 if (!IsVerified() || profile.IsVerified()) {
675 if (OverwriteWith(profile, app_locale)) { 693 if (OverwriteWith(profile, app_locale)) {
676 AutofillMetrics::LogProfileActionOnFormSubmitted( 694 AutofillMetrics::LogProfileActionOnFormSubmitted(
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " 1084 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " "
1067 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " 1085 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " "
1068 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " 1086 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " "
1069 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " 1087 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " "
1070 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " 1088 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " "
1071 << profile.language_code() << " " 1089 << profile.language_code() << " "
1072 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 1090 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
1073 } 1091 }
1074 1092
1075 } // namespace autofill 1093 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_profile_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698