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> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/guid.h" | 14 #include "base/guid.h" |
| 15 #include "base/i18n/case_conversion.h" | 15 #include "base/i18n/case_conversion.h" |
| 16 #include "base/i18n/char_iterator.h" | 16 #include "base/i18n/char_iterator.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/sha1.h" | 18 #include "base/sha1.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/utf_string_conversion_utils.h" | 20 #include "base/strings/utf_string_conversion_utils.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "components/autofill/core/browser/address.h" | 22 #include "components/autofill/core/browser/address.h" |
| 23 #include "components/autofill/core/browser/address_i18n.h" | 23 #include "components/autofill/core/browser/address_i18n.h" |
| 24 #include "components/autofill/core/browser/autofill_country.h" | 24 #include "components/autofill/core/browser/autofill_country.h" |
| 25 #include "components/autofill/core/browser/autofill_field.h" | 25 #include "components/autofill/core/browser/autofill_field.h" |
| 26 #include "components/autofill/core/browser/autofill_metrics.h" | |
| 26 #include "components/autofill/core/browser/autofill_type.h" | 27 #include "components/autofill/core/browser/autofill_type.h" |
| 27 #include "components/autofill/core/browser/contact_info.h" | 28 #include "components/autofill/core/browser/contact_info.h" |
| 28 #include "components/autofill/core/browser/phone_number.h" | 29 #include "components/autofill/core/browser/phone_number.h" |
| 29 #include "components/autofill/core/browser/phone_number_i18n.h" | 30 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 30 #include "components/autofill/core/browser/validation.h" | 31 #include "components/autofill/core/browser/validation.h" |
| 31 #include "components/autofill/core/common/autofill_l10n_util.h" | 32 #include "components/autofill/core/common/autofill_l10n_util.h" |
| 32 #include "components/autofill/core/common/form_field_data.h" | 33 #include "components/autofill/core/common/form_field_data.h" |
| 33 #include "grit/components_strings.h" | 34 #include "grit/components_strings.h" |
| 34 #include "third_party/icu/source/common/unicode/uchar.h" | 35 #include "third_party/icu/source/common/unicode/uchar.h" |
| 35 #include "third_party/libaddressinput/chromium/addressinput_util.h" | 36 #include "third_party/libaddressinput/chromium/addressinput_util.h" |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 if (!compare) | 474 if (!compare) |
| 474 compare.reset(new l10n::CaseInsensitiveCompare()); | 475 compare.reset(new l10n::CaseInsensitiveCompare()); |
| 475 if (!compare->StringsEqual(value, profile.GetRawInfo(type))) | 476 if (!compare->StringsEqual(value, profile.GetRawInfo(type))) |
| 476 return false; | 477 return false; |
| 477 } | 478 } |
| 478 } | 479 } |
| 479 | 480 |
| 480 return true; | 481 return true; |
| 481 } | 482 } |
| 482 | 483 |
| 483 void AutofillProfile::OverwriteName(const NameInfo& imported_name, | 484 bool AutofillProfile::OverwriteName(const NameInfo& imported_name, |
| 484 const std::string& app_locale) { | 485 const std::string& app_locale) { |
| 485 if (name_.ParsedNamesAreEqual(imported_name)) { | 486 if (name_.ParsedNamesAreEqual(imported_name)) { |
| 486 if (name_.GetRawInfo(NAME_FULL).empty()) | 487 if (name_.GetRawInfo(NAME_FULL).empty() && |
| 488 !imported_name.GetRawInfo(NAME_FULL).empty()) { | |
| 487 name_.SetRawInfo(NAME_FULL, imported_name.GetRawInfo(NAME_FULL)); | 489 name_.SetRawInfo(NAME_FULL, imported_name.GetRawInfo(NAME_FULL)); |
| 488 return; | 490 return true; |
| 491 } | |
| 492 return false; | |
| 489 } | 493 } |
| 490 | 494 |
| 491 l10n::CaseInsensitiveCompare compare; | 495 l10n::CaseInsensitiveCompare compare; |
| 492 AutofillType type = AutofillType(NAME_FULL); | 496 AutofillType type = AutofillType(NAME_FULL); |
| 493 base::string16 full_name = name_.GetInfo(type, app_locale); | 497 base::string16 full_name = name_.GetInfo(type, app_locale); |
| 494 if (compare.StringsEqual(full_name, | 498 if (compare.StringsEqual(full_name, |
| 495 imported_name.GetInfo(type, app_locale))) { | 499 imported_name.GetInfo(type, app_locale))) { |
| 496 // The imported name has the same full name string as the name for this | 500 // The imported name has the same full name string as the name for this |
| 497 // profile. Because full names are _heuristically_ parsed into | 501 // profile. Because full names are _heuristically_ parsed into |
| 498 // {first, middle, last} name components, it's possible that either the | 502 // {first, middle, last} name components, it's possible that either the |
| 499 // existing name or the imported name was misparsed. Prefer to keep the | 503 // existing name or the imported name was misparsed. Prefer to keep the |
| 500 // name whose {first, middle, last} components do not match those computed | 504 // name whose {first, middle, last} components do not match those computed |
| 501 // by the heuristic parse, as this more likely represents the correct, | 505 // by the heuristic parse, as this more likely represents the correct, |
| 502 // user-input parse of the name. | 506 // user-input parse of the name. |
| 503 NameInfo heuristically_parsed_name; | 507 NameInfo heuristically_parsed_name; |
| 504 heuristically_parsed_name.SetInfo(type, full_name, app_locale); | 508 heuristically_parsed_name.SetInfo(type, full_name, app_locale); |
| 505 if (imported_name.ParsedNamesAreEqual(heuristically_parsed_name)) | 509 if (imported_name.ParsedNamesAreEqual(heuristically_parsed_name)) |
| 506 return; | 510 return false; |
| 507 } | 511 } |
| 508 | 512 |
| 509 name_ = imported_name; | 513 name_ = imported_name; |
| 514 return true; | |
| 510 } | 515 } |
| 511 | 516 |
| 512 void AutofillProfile::OverwriteWith(const AutofillProfile& profile, | 517 bool AutofillProfile::OverwriteWith(const AutofillProfile& profile, |
| 513 const std::string& app_locale) { | 518 const std::string& app_locale) { |
| 514 // Verified profiles should never be overwritten with unverified data. | 519 // Verified profiles should never be overwritten with unverified data. |
| 515 DCHECK(!IsVerified() || profile.IsVerified()); | 520 DCHECK(!IsVerified() || profile.IsVerified()); |
| 516 set_origin(profile.origin()); | 521 set_origin(profile.origin()); |
| 517 set_language_code(profile.language_code()); | 522 set_language_code(profile.language_code()); |
| 518 set_use_count(profile.use_count() + use_count()); | 523 set_use_count(profile.use_count() + use_count()); |
| 519 if (profile.use_date() > use_date()) | 524 if (profile.use_date() > use_date()) |
| 520 set_use_date(profile.use_date()); | 525 set_use_date(profile.use_date()); |
| 521 | 526 |
| 522 ServerFieldTypeSet field_types; | 527 ServerFieldTypeSet field_types; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 538 // previous value should not be replaced with an empty string in that case. | 543 // previous value should not be replaced with an empty string in that case. |
| 539 if (compare.StringsEqual( | 544 if (compare.StringsEqual( |
| 540 CanonicalizeProfileString( | 545 CanonicalizeProfileString( |
| 541 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)), | 546 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)), |
| 542 CanonicalizeProfileString(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS))) && | 547 CanonicalizeProfileString(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS))) && |
| 543 profile.GetRawInfo(ADDRESS_HOME_LINE2) == base::UTF8ToUTF16("")) { | 548 profile.GetRawInfo(ADDRESS_HOME_LINE2) == base::UTF8ToUTF16("")) { |
| 544 field_types.erase(ADDRESS_HOME_LINE1); | 549 field_types.erase(ADDRESS_HOME_LINE1); |
| 545 field_types.erase(ADDRESS_HOME_LINE2); | 550 field_types.erase(ADDRESS_HOME_LINE2); |
| 546 } | 551 } |
| 547 | 552 |
| 553 bool did_overwrite = false; | |
| 554 | |
| 548 for (ServerFieldTypeSet::const_iterator iter = field_types.begin(); | 555 for (ServerFieldTypeSet::const_iterator iter = field_types.begin(); |
| 549 iter != field_types.end(); ++iter) { | 556 iter != field_types.end(); ++iter) { |
| 550 FieldTypeGroup group = AutofillType(*iter).group(); | 557 FieldTypeGroup group = AutofillType(*iter).group(); |
| 551 // Special case names. | 558 // Special case names. |
| 552 if (group == NAME) { | 559 if (group == NAME) { |
| 553 OverwriteName(profile.name_, app_locale); | 560 if (OverwriteName(profile.name_, app_locale)) { |
| 561 did_overwrite = true; | |
|
Evan Stade
2015/10/14 20:42:01
nit: did_overwrite = OverwriteName() || did_overwr
sebsg
2015/10/21 17:35:26
Done.
| |
| 562 } | |
| 554 continue; | 563 continue; |
| 555 } | 564 } |
| 556 | 565 |
| 557 base::string16 new_value = profile.GetRawInfo(*iter); | 566 base::string16 new_value = profile.GetRawInfo(*iter); |
| 558 if (!compare.StringsEqual(GetRawInfo(*iter), new_value)) | 567 if (!compare.StringsEqual(GetRawInfo(*iter), new_value)) { |
| 559 SetRawInfo(*iter, new_value); | 568 SetRawInfo(*iter, new_value); |
| 569 did_overwrite = true; | |
| 570 } | |
| 560 } | 571 } |
| 572 | |
| 573 return did_overwrite; | |
| 561 } | 574 } |
| 562 | 575 |
| 563 bool AutofillProfile::SaveAdditionalInfo(const AutofillProfile& profile, | 576 bool AutofillProfile::SaveAdditionalInfo(const AutofillProfile& profile, |
| 564 const std::string& app_locale) { | 577 const std::string& app_locale) { |
| 565 ServerFieldTypeSet field_types, other_field_types; | 578 ServerFieldTypeSet field_types, other_field_types; |
| 566 GetNonEmptyTypes(app_locale, &field_types); | 579 GetNonEmptyTypes(app_locale, &field_types); |
| 567 profile.GetNonEmptyTypes(app_locale, &other_field_types); | 580 profile.GetNonEmptyTypes(app_locale, &other_field_types); |
| 568 // The address needs to be compared line by line to take into account the | 581 // The address needs to be compared line by line to take into account the |
| 569 // logic for empty fields implemented in the loop. | 582 // logic for empty fields implemented in the loop. |
| 570 field_types.erase(ADDRESS_HOME_STREET_ADDRESS); | 583 field_types.erase(ADDRESS_HOME_STREET_ADDRESS); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 } | 619 } |
| 607 continue; | 620 continue; |
| 608 } | 621 } |
| 609 if (!compare.StringsEqual(profile.GetRawInfo(field_type), | 622 if (!compare.StringsEqual(profile.GetRawInfo(field_type), |
| 610 GetRawInfo(field_type))) { | 623 GetRawInfo(field_type))) { |
| 611 return false; | 624 return false; |
| 612 } | 625 } |
| 613 } | 626 } |
| 614 } | 627 } |
| 615 | 628 |
| 616 if (!IsVerified() || profile.IsVerified()) | 629 if (!IsVerified() || profile.IsVerified()) { |
| 617 OverwriteWith(profile, app_locale); | 630 if (OverwriteWith(profile, app_locale)) { |
| 631 AutofillMetrics::LogProfileActionOnFormSubmitted( | |
| 632 AutofillMetrics::EXISTING_PROFILE_UPDATED); | |
| 633 } else { | |
| 634 AutofillMetrics::LogProfileActionOnFormSubmitted( | |
| 635 AutofillMetrics::EXISTING_PROFILE_USED); | |
| 636 } | |
| 637 } | |
| 618 return true; | 638 return true; |
| 619 } | 639 } |
| 620 | 640 |
| 621 // static | 641 // static |
| 622 bool AutofillProfile::SupportsMultiValue(ServerFieldType type) { | 642 bool AutofillProfile::SupportsMultiValue(ServerFieldType type) { |
| 623 FieldTypeGroup group = AutofillType(type).group(); | 643 FieldTypeGroup group = AutofillType(type).group(); |
| 624 return group == NAME || | 644 return group == NAME || |
| 625 group == NAME_BILLING || | 645 group == NAME_BILLING || |
| 626 group == EMAIL || | 646 group == EMAIL || |
| 627 group == PHONE_HOME || | 647 group == PHONE_HOME || |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 993 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " | 1013 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " |
| 994 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " | 1014 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " |
| 995 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " | 1015 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " |
| 996 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " | 1016 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " |
| 997 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " | 1017 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " |
| 998 << profile.language_code() << " " | 1018 << profile.language_code() << " " |
| 999 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | 1019 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
| 1000 } | 1020 } |
| 1001 | 1021 |
| 1002 } // namespace autofill | 1022 } // namespace autofill |
| OLD | NEW |