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

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

Issue 2093363002: Autofill address editor in PaymentRequest UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@contact-editor
Patch Set: Fix try-bot Created 4 years, 5 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 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 (*labels)[profile_index] = label; 749 (*labels)[profile_index] = label;
750 } else { 750 } else {
751 // We have more than one profile with the same label, so add 751 // We have more than one profile with the same label, so add
752 // differentiating fields. 752 // differentiating fields.
753 CreateInferredLabelsHelper(profiles, it.second, fields_to_use, 753 CreateInferredLabelsHelper(profiles, it.second, fields_to_use,
754 minimal_fields_shown, app_locale, labels); 754 minimal_fields_shown, app_locale, labels);
755 } 755 }
756 } 756 }
757 } 757 }
758 758
759 void AutofillProfile::GenerateServerProfileIdentifier() {
760 DCHECK_EQ(SERVER_PROFILE, record_type());
761 base::string16 contents = GetRawInfo(NAME_FIRST);
762 contents.append(GetRawInfo(NAME_MIDDLE));
763 contents.append(GetRawInfo(NAME_LAST));
764 contents.append(GetRawInfo(EMAIL_ADDRESS));
765 contents.append(GetRawInfo(COMPANY_NAME));
766 contents.append(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
767 contents.append(GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY));
768 contents.append(GetRawInfo(ADDRESS_HOME_CITY));
769 contents.append(GetRawInfo(ADDRESS_HOME_STATE));
770 contents.append(GetRawInfo(ADDRESS_HOME_ZIP));
771 contents.append(GetRawInfo(ADDRESS_HOME_SORTING_CODE));
772 contents.append(GetRawInfo(ADDRESS_HOME_COUNTRY));
773 contents.append(GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
774 std::string contents_utf8 = UTF16ToUTF8(contents);
775 contents_utf8.append(language_code());
776 server_id_ = base::SHA1HashString(contents_utf8);
777 }
778
779 void AutofillProfile::RecordAndLogUse() {
780 UMA_HISTOGRAM_COUNTS_1000("Autofill.DaysSinceLastUse.Profile",
781 (base::Time::Now() - use_date()).InDays());
782 RecordUse();
783 }
784
785 // static
786 base::string16 AutofillProfile::CanonicalizeProfileString(
787 const base::string16& str) {
788 // The locale doesn't matter for general string canonicalization.
789 AutofillProfileComparator comparator("en-US");
790 return comparator.NormalizeForComparison(str);
791 }
792
793 void AutofillProfile::GetSupportedTypes(
794 ServerFieldTypeSet* supported_types) const {
795 FormGroupList info = FormGroups();
796 for (const auto& it : info) {
797 it->GetSupportedTypes(supported_types);
798 }
799 }
800
801 base::string16 AutofillProfile::ConstructInferredLabel( 759 base::string16 AutofillProfile::ConstructInferredLabel(
802 const std::vector<ServerFieldType>& included_fields, 760 const std::vector<ServerFieldType>& included_fields,
803 size_t num_fields_to_use, 761 size_t num_fields_to_use,
804 const std::string& app_locale) const { 762 const std::string& app_locale) const {
805 // TODO(estade): use libaddressinput? 763 // TODO(estade): use libaddressinput?
806 base::string16 separator = 764 base::string16 separator =
807 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); 765 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR);
808 766
809 AutofillType region_code_type(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE); 767 AutofillType region_code_type(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE);
810 const base::string16& profile_region_code = 768 const base::string16& profile_region_code =
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 } 827 }
870 828
871 // If country code is missing, libaddressinput won't be used to format the 829 // If country code is missing, libaddressinput won't be used to format the
872 // address. In this case the suggestion might include a multi-line street 830 // address. In this case the suggestion might include a multi-line street
873 // address which needs to be flattened. 831 // address which needs to be flattened.
874 base::ReplaceChars(label, base::ASCIIToUTF16("\n"), separator, &label); 832 base::ReplaceChars(label, base::ASCIIToUTF16("\n"), separator, &label);
875 833
876 return label; 834 return label;
877 } 835 }
878 836
837 void AutofillProfile::GenerateServerProfileIdentifier() {
838 DCHECK_EQ(SERVER_PROFILE, record_type());
839 base::string16 contents = GetRawInfo(NAME_FIRST);
840 contents.append(GetRawInfo(NAME_MIDDLE));
841 contents.append(GetRawInfo(NAME_LAST));
842 contents.append(GetRawInfo(EMAIL_ADDRESS));
843 contents.append(GetRawInfo(COMPANY_NAME));
844 contents.append(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
845 contents.append(GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY));
846 contents.append(GetRawInfo(ADDRESS_HOME_CITY));
847 contents.append(GetRawInfo(ADDRESS_HOME_STATE));
848 contents.append(GetRawInfo(ADDRESS_HOME_ZIP));
849 contents.append(GetRawInfo(ADDRESS_HOME_SORTING_CODE));
850 contents.append(GetRawInfo(ADDRESS_HOME_COUNTRY));
851 contents.append(GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
852 std::string contents_utf8 = UTF16ToUTF8(contents);
853 contents_utf8.append(language_code());
854 server_id_ = base::SHA1HashString(contents_utf8);
855 }
856
857 void AutofillProfile::RecordAndLogUse() {
858 UMA_HISTOGRAM_COUNTS_1000("Autofill.DaysSinceLastUse.Profile",
859 (base::Time::Now() - use_date()).InDays());
860 RecordUse();
861 }
862
863 // static
864 base::string16 AutofillProfile::CanonicalizeProfileString(
865 const base::string16& str) {
866 // The locale doesn't matter for general string canonicalization.
867 AutofillProfileComparator comparator("en-US");
868 return comparator.NormalizeForComparison(str);
869 }
870
871 void AutofillProfile::GetSupportedTypes(
872 ServerFieldTypeSet* supported_types) const {
873 FormGroupList info = FormGroups();
874 for (const auto& it : info) {
875 it->GetSupportedTypes(supported_types);
876 }
877 }
878
879 // static 879 // static
880 void AutofillProfile::CreateInferredLabelsHelper( 880 void AutofillProfile::CreateInferredLabelsHelper(
881 const std::vector<AutofillProfile*>& profiles, 881 const std::vector<AutofillProfile*>& profiles,
882 const std::list<size_t>& indices, 882 const std::list<size_t>& indices,
883 const std::vector<ServerFieldType>& fields, 883 const std::vector<ServerFieldType>& fields,
884 size_t num_fields_to_include, 884 size_t num_fields_to_include,
885 const std::string& app_locale, 885 const std::string& app_locale,
886 std::vector<base::string16>* labels) { 886 std::vector<base::string16>* labels) {
887 // For efficiency, we first construct a map of fields to their text values and 887 // For efficiency, we first construct a map of fields to their text values and
888 // each value's frequency. 888 // each value's frequency.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " 1019 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " "
1020 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " 1020 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " "
1021 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " 1021 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " "
1022 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " 1022 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " "
1023 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " 1023 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " "
1024 << profile.language_code() << " " 1024 << profile.language_code() << " "
1025 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 1025 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
1026 } 1026 }
1027 1027
1028 } // namespace autofill 1028 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_profile.h ('k') | third_party/libaddressinput/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698