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

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

Issue 1931123002: [Autofill] Make PersonalDataManager::OverwriteWith case sensitive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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
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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 if (!compare->StringsEqual(value, profile.GetRawInfo(type))) 477 if (!compare->StringsEqual(value, profile.GetRawInfo(type)))
478 return false; 478 return false;
479 } 479 }
480 } 480 }
481 481
482 return true; 482 return true;
483 } 483 }
484 484
485 bool AutofillProfile::OverwriteName(const NameInfo& imported_name, 485 bool AutofillProfile::OverwriteName(const NameInfo& imported_name,
486 const std::string& app_locale) { 486 const std::string& app_locale) {
487 // Check if the names parts are equal.
487 if (name_.ParsedNamesAreEqual(imported_name)) { 488 if (name_.ParsedNamesAreEqual(imported_name)) {
489 // If the current |name_| has an empty NAME_FULL but the the |imported_name|
490 // has not, overwrite only NAME_FULL.
488 if (name_.GetRawInfo(NAME_FULL).empty() && 491 if (name_.GetRawInfo(NAME_FULL).empty() &&
489 !imported_name.GetRawInfo(NAME_FULL).empty()) { 492 !imported_name.GetRawInfo(NAME_FULL).empty()) {
490 name_.SetRawInfo(NAME_FULL, imported_name.GetRawInfo(NAME_FULL)); 493 name_.SetRawInfo(NAME_FULL, imported_name.GetRawInfo(NAME_FULL));
491 return true; 494 return true;
492 } 495 }
493 return false; 496 return false;
494 } 497 }
495 498
496 l10n::CaseInsensitiveCompare compare; 499 l10n::CaseInsensitiveCompare compare;
497 AutofillType type = AutofillType(NAME_FULL); 500 AutofillType type = AutofillType(NAME_FULL);
(...skipping 20 matching lines...) Expand all
518 bool AutofillProfile::OverwriteWith(const AutofillProfile& profile, 521 bool AutofillProfile::OverwriteWith(const AutofillProfile& profile,
519 const std::string& app_locale) { 522 const std::string& app_locale) {
520 // Verified profiles should never be overwritten with unverified data. 523 // Verified profiles should never be overwritten with unverified data.
521 DCHECK(!IsVerified() || profile.IsVerified()); 524 DCHECK(!IsVerified() || profile.IsVerified());
522 set_origin(profile.origin()); 525 set_origin(profile.origin());
523 set_language_code(profile.language_code()); 526 set_language_code(profile.language_code());
524 set_use_count(profile.use_count() + use_count()); 527 set_use_count(profile.use_count() + use_count());
525 if (profile.use_date() > use_date()) 528 if (profile.use_date() > use_date())
526 set_use_date(profile.use_date()); 529 set_use_date(profile.use_date());
527 530
528 ServerFieldTypeSet field_types; 531 // |types_to_overwrite| is initially populated with all types that have
529 profile.GetNonEmptyTypes(app_locale, &field_types); 532 // non-empty data in the incoming |profile|. After adjustment, all data from
533 // |profile| corresponding to types in |types_to_overwrite| is overwritten in
534 // |this| profile.
535 ServerFieldTypeSet types_to_overwrite;
536 profile.GetNonEmptyTypes(app_locale, &types_to_overwrite);
530 537
531 // Only transfer "full" types (e.g. full name) and not fragments (e.g. 538 // Only transfer "full" types (e.g. full name) and not fragments (e.g.
532 // first name, last name). 539 // first name, last name).
533 CollapseCompoundFieldTypes(&field_types); 540 CollapseCompoundFieldTypes(&types_to_overwrite);
534 541
535 // Remove ADDRESS_HOME_STREET_ADDRESS to ensure a merge of the address line by 542 // Remove ADDRESS_HOME_STREET_ADDRESS to ensure a merge of the address line by
536 // line. See comment below. 543 // line. See comment below.
537 field_types.erase(ADDRESS_HOME_STREET_ADDRESS); 544 types_to_overwrite.erase(ADDRESS_HOME_STREET_ADDRESS);
538 545
539 l10n::CaseInsensitiveCompare compare; 546 l10n::CaseInsensitiveCompare compare;
540 547
541 // Special case for addresses. With the whole address comparison, it is now 548 // Special case for addresses. With the whole address comparison, it is now
542 // necessary to make sure to keep the best address format: both lines used. 549 // necessary to make sure to keep the best address format: both lines used.
543 // This is because some sites might not have an address line 2 and the 550 // This is because some sites might not have an address line 2 and the
544 // previous value should not be replaced with an empty string in that case. 551 // previous value should not be replaced with an empty string in that case.
545 if (compare.StringsEqual( 552 if (compare.StringsEqual(
546 CanonicalizeProfileString( 553 CanonicalizeProfileString(
547 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)), 554 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)),
548 CanonicalizeProfileString(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS))) && 555 CanonicalizeProfileString(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS))) &&
549 !GetRawInfo(ADDRESS_HOME_LINE2).empty() && 556 !GetRawInfo(ADDRESS_HOME_LINE2).empty() &&
550 profile.GetRawInfo(ADDRESS_HOME_LINE2).empty()) { 557 profile.GetRawInfo(ADDRESS_HOME_LINE2).empty()) {
551 field_types.erase(ADDRESS_HOME_LINE1); 558 types_to_overwrite.erase(ADDRESS_HOME_LINE1);
552 field_types.erase(ADDRESS_HOME_LINE2); 559 types_to_overwrite.erase(ADDRESS_HOME_LINE2);
553 } 560 }
554 561
555 bool did_overwrite = false; 562 bool did_overwrite = false;
556 563
557 for (ServerFieldTypeSet::const_iterator iter = field_types.begin(); 564 for (const ServerFieldType field_type : types_to_overwrite) {
558 iter != field_types.end(); ++iter) { 565 // Special case for names.
559 FieldTypeGroup group = AutofillType(*iter).group(); 566 if (AutofillType(field_type).group() == NAME) {
560 567 did_overwrite |= OverwriteName(profile.name_, app_locale);
561 // Special case names.
562 if (group == NAME) {
563 did_overwrite = OverwriteName(profile.name_, app_locale) || did_overwrite;
564 continue; 568 continue;
565 } 569 }
566 570
567 base::string16 new_value = profile.GetRawInfo(*iter); 571 base::string16 new_value = profile.GetRawInfo(field_type);
568 if (!compare.StringsEqual(GetRawInfo(*iter), new_value)) { 572 // Overwrite the data in |this| profile for the field type and set
569 SetRawInfo(*iter, new_value); 573 // |did_overwrite| if the previous data was different than the |new_value|.
574 if (GetRawInfo(field_type) != new_value) {
575 SetRawInfo(field_type, new_value);
570 did_overwrite = true; 576 did_overwrite = true;
571 } 577 }
572 } 578 }
573 579
574 return did_overwrite; 580 return did_overwrite;
575 } 581 }
576 582
577 bool AutofillProfile::SaveAdditionalInfo(const AutofillProfile& profile, 583 bool AutofillProfile::SaveAdditionalInfo(const AutofillProfile& profile,
578 const std::string& app_locale) { 584 const std::string& app_locale) {
579 ServerFieldTypeSet field_types, other_field_types; 585 ServerFieldTypeSet field_types, other_field_types;
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " 1056 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " "
1051 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " 1057 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " "
1052 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " 1058 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " "
1053 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " 1059 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " "
1054 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " 1060 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " "
1055 << profile.language_code() << " " 1061 << profile.language_code() << " "
1056 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 1062 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
1057 } 1063 }
1058 1064
1059 } // namespace autofill 1065 } // 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