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::SetPreferredNameInfo( | |
|
Ilya Sherman
2014/05/29 07:38:03
nit: Please name this something more like "Overwri
Pritam Nikam
2014/05/30 11:12:40
Done.
| |
| 522 const std::vector<NameInfo>& profiles) { | |
|
Ilya Sherman
2014/05/29 07:38:03
nit: "profiles" -> "names"
Pritam Nikam
2014/05/30 11:12:40
Done.
| |
| 523 std::vector<NameInfo> append_list; | |
|
Ilya Sherman
2014/05/29 07:38:03
nit: Please name this something more like "names_t
Pritam Nikam
2014/05/30 11:12:40
Function restructured, hence not needed.
| |
| 524 std::vector<NameInfo> name_list(name_); | |
| 525 std::vector<NameInfo>::const_iterator itr = profiles.begin(); | |
|
Ilya Sherman
2014/05/29 07:38:03
nit: Please declare this within the scope of the f
Ilya Sherman
2014/05/29 07:38:03
nit: Please name this "it", as that is the common
Pritam Nikam
2014/05/30 11:12:40
Function restructured, hence not needed.
Pritam Nikam
2014/05/30 11:12:40
Done.
| |
| 526 | |
| 527 for (; itr != profiles.end(); ++itr) { | |
|
Ilya Sherman
2014/05/29 07:38:03
Is it ever possible for the imported profile to co
Pritam Nikam
2014/05/30 11:12:40
Done.
1. HTML Form submission can have maximum 1
| |
| 528 NameInfo imported_profile = *itr; | |
| 529 bool prefer_imported_profile = false; | |
| 530 bool identical_full_names = false; | |
| 531 | |
| 532 for (size_t index = 0; index < name_.size(); index++) { | |
|
Ilya Sherman
2014/05/29 07:38:03
nit: "index++" -> "++index"
Pritam Nikam
2014/05/30 11:12:40
Done.
| |
| 533 NameInfo prof = name_[index]; | |
|
Ilya Sherman
2014/05/29 07:38:03
nit: Please avoid using abbreviations when naming
Pritam Nikam
2014/05/30 11:12:40
Function restructured, hence not needed.
| |
| 534 base::string16 full_name = prof.GetRawInfo(NAME_FULL); | |
| 535 if (full_name == imported_profile.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_. | |
| 539 identical_full_names = true; | |
| 540 NameInfo profile_with_paresed_tokens; | |
| 541 profile_with_paresed_tokens.SetRawInfo(NAME_FULL, full_name); | |
| 542 if (prof == profile_with_paresed_tokens) | |
| 543 prefer_imported_profile = true; | |
| 544 | |
| 545 if (prefer_imported_profile) { | |
| 546 name_list[index] = imported_profile; | |
| 547 } else { | |
| 548 if ((imported_profile != prof) && | |
| 549 (imported_profile != profile_with_paresed_tokens)) | |
| 550 append_list.push_back(imported_profile); | |
|
Ilya Sherman
2014/05/29 07:38:03
This isn't quite right, as this variant of the nam
Pritam Nikam
2014/05/30 11:12:40
Done.
Added test-cases to cover identical full na
| |
| 551 } | |
| 552 } | |
| 553 } | |
| 554 | |
| 555 if (!identical_full_names) | |
| 556 append_list.push_back(imported_profile); | |
| 557 } | |
| 558 | |
| 559 if (!append_list.empty()) | |
| 560 name_list.insert(name_list.end(), append_list.begin(), append_list.end()); | |
| 561 | |
| 562 name_.swap(name_list); | |
| 563 } | |
| 564 | |
| 521 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, | 565 void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile, |
| 522 const std::string& app_locale) { | 566 const std::string& app_locale) { |
| 523 // Verified profiles should never be overwritten with unverified data. | 567 // Verified profiles should never be overwritten with unverified data. |
| 524 DCHECK(!IsVerified() || profile.IsVerified()); | 568 DCHECK(!IsVerified() || profile.IsVerified()); |
| 525 set_origin(profile.origin()); | 569 set_origin(profile.origin()); |
| 526 set_language_code(profile.language_code()); | 570 set_language_code(profile.language_code()); |
| 527 | 571 |
| 528 ServerFieldTypeSet field_types; | 572 ServerFieldTypeSet field_types; |
| 529 profile.GetNonEmptyTypes(app_locale, &field_types); | 573 profile.GetNonEmptyTypes(app_locale, &field_types); |
| 530 | 574 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 560 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); | 604 AddPhoneIfUnique(*value_iter, app_locale, &existing_values); |
| 561 } else { | 605 } else { |
| 562 std::vector<base::string16>::const_iterator existing_iter = | 606 std::vector<base::string16>::const_iterator existing_iter = |
| 563 std::find_if( | 607 std::find_if( |
| 564 existing_values.begin(), existing_values.end(), | 608 existing_values.begin(), existing_values.end(), |
| 565 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); | 609 std::bind1st(CaseInsensitiveStringEquals(), *value_iter)); |
| 566 if (existing_iter == existing_values.end()) | 610 if (existing_iter == existing_values.end()) |
| 567 existing_values.insert(existing_values.end(), *value_iter); | 611 existing_values.insert(existing_values.end(), *value_iter); |
| 568 } | 612 } |
| 569 } | 613 } |
| 570 SetRawMultiInfo(*iter, existing_values); | 614 if (group == NAME) |
| 615 SetPreferredNameInfo(profile.name_); | |
| 616 else | |
| 617 SetRawMultiInfo(*iter, existing_values); | |
| 571 } else { | 618 } else { |
| 572 base::string16 new_value = profile.GetRawInfo(*iter); | 619 base::string16 new_value = profile.GetRawInfo(*iter); |
| 573 if (StringToLowerASCII(GetRawInfo(*iter)) != | 620 if (StringToLowerASCII(GetRawInfo(*iter)) != |
| 574 StringToLowerASCII(new_value)) { | 621 StringToLowerASCII(new_value)) { |
| 575 SetRawInfo(*iter, new_value); | 622 SetRawInfo(*iter, new_value); |
| 576 } | 623 } |
| 577 } | 624 } |
| 578 } | 625 } |
| 579 } | 626 } |
| 580 | 627 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) | 915 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
| 869 << " " | 916 << " " |
| 870 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 917 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
| 871 << " " | 918 << " " |
| 872 << profile.language_code() | 919 << profile.language_code() |
| 873 << " " | 920 << " " |
| 874 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 921 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
| 875 } | 922 } |
| 876 | 923 |
| 877 } // namespace autofill | 924 } // namespace autofill |
| OLD | NEW |