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> name_list(name_); | |
Ilya Sherman
2014/06/03 00:25:32
nit: Let's call this "result" or something. Other
Pritam Nikam
2014/06/03 15:37:34
Done.
name_list -> result
| |
524 for (std::vector<NameInfo>::const_iterator it = names.begin(); | |
525 it != names.end(); | |
526 ++it) { | |
527 NameInfo imported_profile_name = *it; | |
Ilya Sherman
2014/06/03 00:25:32
nit: Let's drop "profile", and call this |imported
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
528 NameInfo profile_name_with_parsed_tokens; | |
Ilya Sherman
2014/06/03 00:25:32
nit: Let's call this something more like |heuristi
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
529 bool prefer_imported_profile_name = false; | |
530 bool identical_full_names = false; | |
Ilya Sherman
2014/06/03 00:25:32
Let's simplify the logic a bit by replacing these
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
531 | |
532 for (size_t index = 0; index < name_.size(); ++index) { | |
533 NameInfo current_name = name_[index]; | |
534 base::string16 full_name = current_name.GetRawInfo(NAME_FULL); | |
535 if (full_name == imported_profile_name.GetRawInfo(NAME_FULL)) { | |
536 // Identical full names, we should always prefer to keep ones with more | |
537 // information, i.e. where parsing the full_name_ does not give the same | |
538 // results as are stored in first_, middle_, and last_. | |
Ilya Sherman
2014/06/03 00:25:32
Here's a suggested rewording of this comment. Of
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
539 identical_full_names = true; | |
540 profile_name_with_parsed_tokens.SetRawInfo(NAME_FULL, full_name); | |
541 prefer_imported_profile_name = | |
542 (current_name == profile_name_with_parsed_tokens) || | |
543 (current_name == imported_profile_name); | |
544 | |
545 if (prefer_imported_profile_name) { | |
546 name_list[index] = imported_profile_name; | |
547 break; | |
548 } | |
Ilya Sherman
2014/06/03 00:25:32
With the changes above, the body of this loop woul
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
549 } | |
550 } | |
551 | |
552 // Append unique names to the list | |
Ilya Sherman
2014/06/03 00:25:32
nit: Please end the sentence with a period.
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
553 if (!identical_full_names || | |
554 (!prefer_imported_profile_name && | |
555 imported_profile_name != profile_name_with_parsed_tokens)) { | |
Ilya Sherman
2014/06/03 00:25:32
With the changes above, this if-stmt's condition w
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
556 name_list.push_back(imported_profile_name); | |
557 } | |
558 } | |
Ilya Sherman
2014/06/03 00:25:32
Optional nit: I'd leave a blank line after this on
Pritam Nikam
2014/06/03 15:37:34
Done.
In my opinion,below check is still required
| |
559 name_.swap(name_list); | |
560 } | |
561 | |
521 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, | 562 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, |
522 const std::string& app_locale) { | 563 const std::string& app_locale) { |
523 // Verified profiles should never be overwritten with unverified data. | 564 // Verified profiles should never be overwritten with unverified data. |
524 DCHECK(!IsVerified() || profile.IsVerified()); | 565 DCHECK(!IsVerified() || profile.IsVerified()); |
525 set_origin(profile.origin()); | 566 set_origin(profile.origin()); |
526 set_language_code(profile.language_code()); | 567 set_language_code(profile.language_code()); |
527 | 568 |
528 ServerFieldTypeSet field_types; | 569 ServerFieldTypeSet field_types; |
529 profile.GetNonEmptyTypes(app_locale, &field_types); | 570 profile.GetNonEmptyTypes(app_locale, &field_types); |
530 | 571 |
(...skipping 29 matching lines...) Expand all Loading... | |
560 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); | 601 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); |
561 } else { | 602 } else { |
562 std::vector<base::string16>::const_iterator existing_iter = | 603 std::vector<base::string16>::const_iterator existing_iter = |
563 std::find_if( | 604 std::find_if( |
564 existing_values.begin(), existing_values.end(), | 605 existing_values.begin(), existing_values.end(), |
565 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); | 606 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); |
566 if (existing_iter == existing_values.end()) | 607 if (existing_iter == existing_values.end()) |
567 existing_values.insert(existing_values.end(), *value_iter); | 608 existing_values.insert(existing_values.end(), *value_iter); |
568 } | 609 } |
569 } | 610 } |
570 SetRawMultiInfo(*iter, existing_values); | 611 if (group == NAME) { |
612 OverwriteOrAppendNames(profile.name_); | |
613 } else { | |
614 SetRawMultiInfo(*iter, existing_values); | |
615 } | |
Ilya Sherman
2014/06/03 00:25:32
nit: No need for curly braces.
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
571 } else { | 616 } else { |
572 base::string16 new_value = profile.GetRawInfo(*iter); | 617 base::string16 new_value = profile.GetRawInfo(*iter); |
573 if (StringToLowerASCII(GetRawInfo(*iter)) != | 618 if (StringToLowerASCII(GetRawInfo(*iter)) != |
574 StringToLowerASCII(new_value)) { | 619 StringToLowerASCII(new_value)) { |
575 SetRawInfo(*iter, new_value); | 620 SetRawInfo(*iter, new_value); |
576 } | 621 } |
577 } | 622 } |
578 } | 623 } |
579 } | 624 } |
580 | 625 |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
867 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) | 912 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
868 << " " | 913 << " " |
869 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 914 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
870 << " " | 915 << " " |
871 << profile.language_code() | 916 << profile.language_code() |
872 << " " | 917 << " " |
873 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 918 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
874 } | 919 } |
875 | 920 |
876 } // namespace autofill | 921 } // namespace autofill |
OLD | NEW |