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

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: Addressed comments 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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (name_.ParsedNamesAreEqual(imported_name)) { 487 if (name_.ParsedNamesAreEqual(imported_name)) {
488 if (name_.GetRawInfo(NAME_FULL).empty() && 488 if (name_.GetRawInfo(NAME_FULL).empty() &&
489 !imported_name.GetRawInfo(NAME_FULL).empty()) { 489 !imported_name.GetRawInfo(NAME_FULL).empty()) {
490 name_.SetRawInfo(NAME_FULL, imported_name.GetRawInfo(NAME_FULL)); 490 name_.SetRawInfo(NAME_FULL, imported_name.GetRawInfo(NAME_FULL));
Mathieu 2016/04/29 15:52:06 let's make sure that if name_'s NAME_FULL is empty
sebsg 2016/05/03 20:02:17 Done.
491 return true; 491 return true;
492 } 492 }
493 return false; 493 return false;
494 } 494 }
495 495
496 l10n::CaseInsensitiveCompare compare; 496 l10n::CaseInsensitiveCompare compare;
497 AutofillType type = AutofillType(NAME_FULL); 497 AutofillType type = AutofillType(NAME_FULL);
498 base::string16 full_name = name_.GetInfo(type, app_locale); 498 base::string16 full_name = name_.GetInfo(type, app_locale);
499 if (compare.StringsEqual(full_name, 499 if (compare.StringsEqual(full_name,
500 imported_name.GetInfo(type, app_locale))) { 500 imported_name.GetInfo(type, app_locale))) {
(...skipping 17 matching lines...) Expand all
518 bool AutofillProfile::OverwriteWith(const AutofillProfile& profile, 518 bool AutofillProfile::OverwriteWith(const AutofillProfile& profile,
519 const std::string& app_locale) { 519 const std::string& app_locale) {
520 // Verified profiles should never be overwritten with unverified data. 520 // Verified profiles should never be overwritten with unverified data.
521 DCHECK(!IsVerified() || profile.IsVerified()); 521 DCHECK(!IsVerified() || profile.IsVerified());
522 set_origin(profile.origin()); 522 set_origin(profile.origin());
523 set_language_code(profile.language_code()); 523 set_language_code(profile.language_code());
524 set_use_count(profile.use_count() + use_count()); 524 set_use_count(profile.use_count() + use_count());
525 if (profile.use_date() > use_date()) 525 if (profile.use_date() > use_date())
526 set_use_date(profile.use_date()); 526 set_use_date(profile.use_date());
527 527
528 ServerFieldTypeSet field_types; 528 // |types_to_overwrite| is initially populated with all types that have
529 profile.GetNonEmptyTypes(app_locale, &field_types); 529 // non-empty data in the incoming |profile|. After adjustment, all data from
530 // |profile| corresponding to types in |types_to_overwrite| is overwritten in
531 // |this| profile.
532 ServerFieldTypeSet types_to_overwrite;
533 profile.GetNonEmptyTypes(app_locale, &types_to_overwrite);
530 534
531 // Only transfer "full" types (e.g. full name) and not fragments (e.g. 535 // Only transfer "full" types (e.g. full name) and not fragments (e.g.
532 // first name, last name). 536 // first name, last name).
533 CollapseCompoundFieldTypes(&field_types); 537 CollapseCompoundFieldTypes(&types_to_overwrite);
534 538
535 // Remove ADDRESS_HOME_STREET_ADDRESS to ensure a merge of the address line by 539 // Remove ADDRESS_HOME_STREET_ADDRESS to ensure a merge of the address line by
536 // line. See comment below. 540 // line. See comment below.
537 field_types.erase(ADDRESS_HOME_STREET_ADDRESS); 541 types_to_overwrite.erase(ADDRESS_HOME_STREET_ADDRESS);
538 542
539 l10n::CaseInsensitiveCompare compare; 543 l10n::CaseInsensitiveCompare compare;
540 544
541 // Special case for addresses. With the whole address comparison, it is now 545 // 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. 546 // 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 547 // 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. 548 // previous value should not be replaced with an empty string in that case.
545 if (compare.StringsEqual( 549 if (compare.StringsEqual(
546 CanonicalizeProfileString( 550 CanonicalizeProfileString(
547 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)), 551 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)),
548 CanonicalizeProfileString(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS))) && 552 CanonicalizeProfileString(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS))) &&
549 !GetRawInfo(ADDRESS_HOME_LINE2).empty() && 553 !GetRawInfo(ADDRESS_HOME_LINE2).empty() &&
550 profile.GetRawInfo(ADDRESS_HOME_LINE2).empty()) { 554 profile.GetRawInfo(ADDRESS_HOME_LINE2).empty()) {
551 field_types.erase(ADDRESS_HOME_LINE1); 555 types_to_overwrite.erase(ADDRESS_HOME_LINE1);
552 field_types.erase(ADDRESS_HOME_LINE2); 556 types_to_overwrite.erase(ADDRESS_HOME_LINE2);
553 } 557 }
554 558
555 bool did_overwrite = false; 559 bool did_overwrite = false;
556 560
557 for (ServerFieldTypeSet::const_iterator iter = field_types.begin(); 561 for (ServerFieldTypeSet::const_iterator iter = types_to_overwrite.begin();
Mathieu 2016/04/29 15:52:06 nit: can we use a range for loop? for (const Serv
sebsg 2016/05/03 20:02:17 Done.
558 iter != field_types.end(); ++iter) { 562 iter != types_to_overwrite.end(); ++iter) {
559 FieldTypeGroup group = AutofillType(*iter).group(); 563 // Special case for names.
560 564 if (AutofillType(*iter).group() == NAME) {
561 // Special case names. 565 did_overwrite |= OverwriteName(profile.name_, app_locale);
562 if (group == NAME) {
563 did_overwrite = OverwriteName(profile.name_, app_locale) || did_overwrite;
564 continue; 566 continue;
565 } 567 }
566 568
567 base::string16 new_value = profile.GetRawInfo(*iter); 569 base::string16 new_value = profile.GetRawInfo(*iter);
568 if (!compare.StringsEqual(GetRawInfo(*iter), new_value)) { 570 // Overwrite the data in |this| profile for the field type and set
571 // |did_overwrite| if the previous data was different than the |new_value|.
572 if (GetRawInfo(*iter) != new_value) {
569 SetRawInfo(*iter, new_value); 573 SetRawInfo(*iter, new_value);
570 did_overwrite = true; 574 did_overwrite = true;
571 } 575 }
572 } 576 }
573 577
574 return did_overwrite; 578 return did_overwrite;
575 } 579 }
576 580
577 bool AutofillProfile::SaveAdditionalInfo(const AutofillProfile& profile, 581 bool AutofillProfile::SaveAdditionalInfo(const AutofillProfile& profile,
578 const std::string& app_locale) { 582 const std::string& app_locale) {
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " 1054 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " "
1051 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " 1055 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " "
1052 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " 1056 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " "
1053 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " 1057 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " "
1054 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " 1058 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " "
1055 << profile.language_code() << " " 1059 << profile.language_code() << " "
1056 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 1060 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
1057 } 1061 }
1058 1062
1059 } // namespace autofill 1063 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_profile.h ('k') | components/autofill/core/browser/contact_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698