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

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

Issue 261993006: Modified to allow to preserve two-word string in first-name and last-name in autofill profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated review comments and modified unit tests. Created 6 years, 6 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
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 <ostream> 10 #include <ostream>
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.EqualsIgnoreCase(imported_name)) {
533 should_append_imported_name = false;
534 break;
535 }
536
537 base::string16 full_name = current_name.GetRawInfo(NAME_FULL);
538 if (StringToLowerASCII(full_name) ==
539 StringToLowerASCII(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 NameInfo heuristically_parsed_name;
549 heuristically_parsed_name.SetRawInfo(NAME_FULL, full_name);
550 if (imported_name.EqualsIgnoreCase(heuristically_parsed_name)) {
551 should_append_imported_name = false;
552 break;
553 }
554
555 if (current_name.EqualsIgnoreCase(heuristically_parsed_name)) {
556 results[index] = imported_name;
557 should_append_imported_name = false;
558 break;
559 }
560 }
561 }
562
563 // Append unique names to the list.
564 if (should_append_imported_name)
565 results.push_back(imported_name);
566 }
567
568 name_.swap(results);
569 }
570
521 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, 571 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile,
522 const std::string& app_locale) { 572 const std::string& app_locale) {
523 // Verified profiles should never be overwritten with unverified data. 573 // Verified profiles should never be overwritten with unverified data.
524 DCHECK(!IsVerified() || profile.IsVerified()); 574 DCHECK(!IsVerified() || profile.IsVerified());
525 set_origin(profile.origin()); 575 set_origin(profile.origin());
526 set_language_code(profile.language_code()); 576 set_language_code(profile.language_code());
527 577
528 ServerFieldTypeSet field_types; 578 ServerFieldTypeSet field_types;
529 profile.GetNonEmptyTypes(app_locale, &field_types); 579 profile.GetNonEmptyTypes(app_locale, &field_types);
530 580
(...skipping 29 matching lines...) Expand all
560 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); 610 AddPhoneIfUnique(*value_iter, app_locale, &existing_values);
561 } else { 611 } else {
562 std::vector<base::string16>::const_iterator existing_iter = 612 std::vector<base::string16>::const_iterator existing_iter =
563 std::find_if( 613 std::find_if(
564 existing_values.begin(), existing_values.end(), 614 existing_values.begin(), existing_values.end(),
565 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); 615 std::bind1st(CaseInsensitiveStringEquals(), *value_iter));
566 if (existing_iter == existing_values.end()) 616 if (existing_iter == existing_values.end())
567 existing_values.insert(existing_values.end(), *value_iter); 617 existing_values.insert(existing_values.end(), *value_iter);
568 } 618 }
569 } 619 }
570 SetRawMultiInfo(*iter, existing_values); 620 if (group == NAME)
621 OverwriteOrAppendNames(profile.name_);
622 else
623 SetRawMultiInfo(*iter, existing_values);
571 } else { 624 } else {
572 base::string16 new_value = profile.GetRawInfo(*iter); 625 base::string16 new_value = profile.GetRawInfo(*iter);
573 if (StringToLowerASCII(GetRawInfo(*iter)) != 626 if (StringToLowerASCII(GetRawInfo(*iter)) !=
574 StringToLowerASCII(new_value)) { 627 StringToLowerASCII(new_value)) {
575 SetRawInfo(*iter, new_value); 628 SetRawInfo(*iter, new_value);
576 } 629 }
577 } 630 }
578 } 631 }
579 } 632 }
580 633
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) 920 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE))
868 << " " 921 << " "
869 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) 922 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))
870 << " " 923 << " "
871 << profile.language_code() 924 << profile.language_code()
872 << " " 925 << " "
873 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); 926 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER));
874 } 927 }
875 928
876 } // namespace autofill 929 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_profile.h ('k') | components/autofill/core/browser/autofill_profile_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698