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 // a valid autofill profile can't have more than one nameInfo | |
524 DCHECK(names.size() == 1); | |
Ilya Sherman
2014/05/31 00:34:41
Thanks for listing the cases from which this metho
Pritam Nikam
2014/05/31 10:30:41
Done.
| |
525 | |
526 NameInfo imported_profile_name = names[0]; | |
527 NameInfo profile_name_with_parsed_tokens; | |
528 bool prefer_imported_profile_name = false; | |
529 bool identical_full_names = false; | |
530 | |
531 for (size_t index = 0; index < name_.size(); ++index) { | |
532 NameInfo current_name = name_[index]; | |
533 base::string16 full_name = current_name.GetRawInfo(NAME_FULL); | |
534 if (full_name == imported_profile_name.GetRawInfo(NAME_FULL)) { | |
535 // Identical full names, we should always prefer to keep ones with more | |
536 // information, i.e. where parsing the full_name_ does not give the same | |
537 // results as are stored in first_, middle_, and last_. | |
538 identical_full_names = true; | |
539 profile_name_with_parsed_tokens.SetRawInfo(NAME_FULL, full_name); | |
540 prefer_imported_profile_name = | |
541 (current_name == profile_name_with_parsed_tokens) || | |
542 (current_name == imported_profile_name); | |
543 | |
544 if (prefer_imported_profile_name) { | |
545 name_[index] = imported_profile_name; | |
546 break; | |
547 } | |
548 } | |
549 } | |
550 | |
551 // Append unique names to the list | |
552 if (!identical_full_names || | |
553 (!prefer_imported_profile_name && | |
554 imported_profile_name != profile_name_with_parsed_tokens)) { | |
555 name_.push_back(imported_profile_name); | |
556 } | |
557 } | |
558 | |
521 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, | 559 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, |
522 const std::string& app_locale) { | 560 const std::string& app_locale) { |
523 // Verified profiles should never be overwritten with unverified data. | 561 // Verified profiles should never be overwritten with unverified data. |
524 DCHECK(!IsVerified() || profile.IsVerified()); | 562 DCHECK(!IsVerified() || profile.IsVerified()); |
525 set_origin(profile.origin()); | 563 set_origin(profile.origin()); |
526 set_language_code(profile.language_code()); | 564 set_language_code(profile.language_code()); |
527 | 565 |
528 ServerFieldTypeSet field_types; | 566 ServerFieldTypeSet field_types; |
529 profile.GetNonEmptyTypes(app_locale, &field_types); | 567 profile.GetNonEmptyTypes(app_locale, &field_types); |
530 | 568 |
(...skipping 29 matching lines...) Expand all Loading... | |
560 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); | 598 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); |
561 } else { | 599 } else { |
562 std::vector<base::string16>::const_iterator existing_iter = | 600 std::vector<base::string16>::const_iterator existing_iter = |
563 std::find_if( | 601 std::find_if( |
564 existing_values.begin(), existing_values.end(), | 602 existing_values.begin(), existing_values.end(), |
565 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); | 603 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); |
566 if (existing_iter == existing_values.end()) | 604 if (existing_iter == existing_values.end()) |
567 existing_values.insert(existing_values.end(), *value_iter); | 605 existing_values.insert(existing_values.end(), *value_iter); |
568 } | 606 } |
569 } | 607 } |
570 SetRawMultiInfo(*iter, existing_values); | 608 if (group == NAME) { |
609 OverwriteOrAppendNames(profile.name_); | |
610 } else { | |
611 SetRawMultiInfo(*iter, existing_values); | |
612 } | |
571 } else { | 613 } else { |
572 base::string16 new_value = profile.GetRawInfo(*iter); | 614 base::string16 new_value = profile.GetRawInfo(*iter); |
573 if (StringToLowerASCII(GetRawInfo(*iter)) != | 615 if (StringToLowerASCII(GetRawInfo(*iter)) != |
574 StringToLowerASCII(new_value)) { | 616 StringToLowerASCII(new_value)) { |
575 SetRawInfo(*iter, new_value); | 617 SetRawInfo(*iter, new_value); |
576 } | 618 } |
577 } | 619 } |
578 } | 620 } |
579 } | 621 } |
580 | 622 |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) | 910 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
869 << " " | 911 << " " |
870 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 912 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
871 << " " | 913 << " " |
872 << profile.language_code() | 914 << profile.language_code() |
873 << " " | 915 << " " |
874 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 916 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
875 } | 917 } |
876 | 918 |
877 } // namespace autofill | 919 } // namespace autofill |
OLD | NEW |