| 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 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_H_ |
| 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <iosfwd> | 10 #include <iosfwd> |
| 11 #include <list> | 11 #include <list> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "components/autofill/core/browser/address.h" | 17 #include "components/autofill/core/browser/address.h" |
| 18 #include "components/autofill/core/browser/autofill_data_model.h" | 18 #include "components/autofill/core/browser/autofill_data_model.h" |
| 19 #include "components/autofill/core/browser/autofill_type.h" | 19 #include "components/autofill/core/browser/autofill_type.h" |
| 20 #include "components/autofill/core/browser/contact_info.h" | 20 #include "components/autofill/core/browser/contact_info.h" |
| 21 #include "components/autofill/core/browser/field_types.h" | |
| 22 #include "components/autofill/core/browser/phone_number.h" | 21 #include "components/autofill/core/browser/phone_number.h" |
| 23 | 22 |
| 24 namespace autofill { | 23 namespace autofill { |
| 25 | 24 |
| 26 struct FormFieldData; | 25 struct FormFieldData; |
| 27 | 26 |
| 28 // A collection of FormGroups stored in a profile. AutofillProfile also | 27 // A collection of FormGroups stored in a profile. AutofillProfile also |
| 29 // implements the FormGroup interface so that owners of this object can request | 28 // implements the FormGroup interface so that owners of this object can request |
| 30 // form information from the profile, and the profile will delegate the request | 29 // form information from the profile, and the profile will delegate the request |
| 31 // to the requested form group type. | 30 // to the requested form group type. |
| 32 class AutofillProfile : public AutofillDataModel { | 31 class AutofillProfile : public AutofillDataModel { |
| 33 public: | 32 public: |
| 34 AutofillProfile(const std::string& guid, const std::string& origin); | 33 AutofillProfile(const std::string& guid, const std::string& origin); |
| 35 | 34 |
| 36 // For use in STL containers. | 35 // For use in STL containers. |
| 37 AutofillProfile(); | 36 AutofillProfile(); |
| 38 AutofillProfile(const AutofillProfile& profile); | 37 AutofillProfile(const AutofillProfile& profile); |
| 39 virtual ~AutofillProfile(); | 38 virtual ~AutofillProfile(); |
| 40 | 39 |
| 41 AutofillProfile& operator=(const AutofillProfile& profile); | 40 AutofillProfile& operator=(const AutofillProfile& profile); |
| 42 | 41 |
| 43 // FormGroup: | 42 // FormGroup: |
| 44 virtual void GetMatchingTypes(const base::string16& text, | 43 virtual void GetMatchingTypes( |
| 45 const std::string& app_locale, | 44 const base::string16& text, |
| 46 FieldTypeSet* matching_types) const OVERRIDE; | 45 const std::string& app_locale, |
| 47 virtual base::string16 GetRawInfo(AutofillFieldType type) const OVERRIDE; | 46 ServerFieldTypeSet* matching_types) const OVERRIDE; |
| 48 virtual void SetRawInfo(AutofillFieldType type, | 47 virtual base::string16 GetRawInfo(ServerFieldType type) const OVERRIDE; |
| 48 virtual void SetRawInfo(ServerFieldType type, |
| 49 const base::string16& value) OVERRIDE; | 49 const base::string16& value) OVERRIDE; |
| 50 virtual base::string16 GetInfo(AutofillFieldType type, | 50 virtual base::string16 GetInfo(const AutofillType& type, |
| 51 const std::string& app_locale) const OVERRIDE; | 51 const std::string& app_locale) const OVERRIDE; |
| 52 virtual bool SetInfo(AutofillFieldType type, | 52 virtual bool SetInfo(const AutofillType& type, |
| 53 const base::string16& value, | 53 const base::string16& value, |
| 54 const std::string& app_locale) OVERRIDE; | 54 const std::string& app_locale) OVERRIDE; |
| 55 | 55 |
| 56 // AutofillDataModel: | 56 // AutofillDataModel: |
| 57 virtual void FillFormField(const AutofillField& field, | 57 virtual void FillFormField(const AutofillField& field, |
| 58 size_t variant, | 58 size_t variant, |
| 59 const std::string& app_locale, | 59 const std::string& app_locale, |
| 60 FormFieldData* field_data) const OVERRIDE; | 60 FormFieldData* field_data) const OVERRIDE; |
| 61 | 61 |
| 62 // Multi-value equivalents to |GetInfo| and |SetInfo|. | 62 // Multi-value equivalents to |GetInfo| and |SetInfo|. |
| 63 void SetRawMultiInfo(AutofillFieldType type, | 63 void SetRawMultiInfo(ServerFieldType type, |
| 64 const std::vector<base::string16>& values); | 64 const std::vector<base::string16>& values); |
| 65 void GetRawMultiInfo(AutofillFieldType type, | 65 void GetRawMultiInfo(ServerFieldType type, |
| 66 std::vector<base::string16>* values) const; | 66 std::vector<base::string16>* values) const; |
| 67 void GetMultiInfo(AutofillFieldType type, | 67 void GetMultiInfo(const AutofillType& type, |
| 68 const std::string& app_locale, | 68 const std::string& app_locale, |
| 69 std::vector<base::string16>* values) const; | 69 std::vector<base::string16>* values) const; |
| 70 | 70 |
| 71 // Set |field_data|'s value for phone number based on contents of |this|. | 71 // Set |field_data|'s value for phone number based on contents of |this|. |
| 72 // The |field| specifies the type of the phone and whether this is a | 72 // The |field| specifies the type of the phone and whether this is a |
| 73 // phone prefix or suffix. The |variant| parameter specifies which value in a | 73 // phone prefix or suffix. The |variant| parameter specifies which value in a |
| 74 // multi-valued profile. | 74 // multi-valued profile. |
| 75 void FillPhoneNumberField(const AutofillField& field, | 75 void FillPhoneNumberField(const AutofillField& field, |
| 76 size_t variant, | 76 size_t variant, |
| 77 const std::string& app_locale, | 77 const std::string& app_locale, |
| 78 FormFieldData* field_data) const; | 78 FormFieldData* field_data) const; |
| 79 | 79 |
| 80 // The user-visible label of the profile, generated in relation to other | 80 // The user-visible label of the profile, generated in relation to other |
| 81 // profiles. Shows at least 2 fields that differentiate profile from other | 81 // profiles. Shows at least 2 fields that differentiate profile from other |
| 82 // profiles. See AdjustInferredLabels() further down for more description. | 82 // profiles. See AdjustInferredLabels() further down for more description. |
| 83 const base::string16 Label() const; | 83 const base::string16 Label() const; |
| 84 | 84 |
| 85 // Returns true if there are no values (field types) set. | 85 // Returns true if there are no values (field types) set. |
| 86 bool IsEmpty(const std::string& app_locale) const; | 86 bool IsEmpty(const std::string& app_locale) const; |
| 87 | 87 |
| 88 // Returns true if the |type| of data in this profile is present, but invalid. | 88 // Returns true if the |type| of data in this profile is present, but invalid. |
| 89 // Otherwise returns false. | 89 // Otherwise returns false. |
| 90 bool IsPresentButInvalid(AutofillFieldType type) const; | 90 bool IsPresentButInvalid(ServerFieldType type) const; |
| 91 | 91 |
| 92 // Comparison for Sync. Returns 0 if the profile is the same as |this|, | 92 // Comparison for Sync. Returns 0 if the profile is the same as |this|, |
| 93 // or < 0, or > 0 if it is different. The implied ordering can be used for | 93 // or < 0, or > 0 if it is different. The implied ordering can be used for |
| 94 // culling duplicates. The ordering is based on collation order of the | 94 // culling duplicates. The ordering is based on collation order of the |
| 95 // textual contents of the fields. | 95 // textual contents of the fields. |
| 96 // GUIDs and origins are not compared, only the values of the contents | 96 // GUIDs and origins are not compared, only the values of the contents |
| 97 // themselves. Full profile comparision, comparison includes multi-valued | 97 // themselves. Full profile comparision, comparison includes multi-valued |
| 98 // fields. | 98 // fields. |
| 99 int Compare(const AutofillProfile& profile) const; | 99 int Compare(const AutofillProfile& profile) const; |
| 100 | 100 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 112 // |profile|. | 112 // |profile|. |
| 113 bool IsSubsetOf(const AutofillProfile& profile, | 113 bool IsSubsetOf(const AutofillProfile& profile, |
| 114 const std::string& app_locale) const; | 114 const std::string& app_locale) const; |
| 115 | 115 |
| 116 // Overwrites the single-valued field data in |profile| with this | 116 // Overwrites the single-valued field data in |profile| with this |
| 117 // Profile. Or, for multi-valued fields append the new values. | 117 // Profile. Or, for multi-valued fields append the new values. |
| 118 void OverwriteWithOrAddTo(const AutofillProfile& profile, | 118 void OverwriteWithOrAddTo(const AutofillProfile& profile, |
| 119 const std::string& app_locale); | 119 const std::string& app_locale); |
| 120 | 120 |
| 121 // Returns |true| if |type| accepts multi-values. | 121 // Returns |true| if |type| accepts multi-values. |
| 122 static bool SupportsMultiValue(AutofillFieldType type); | 122 static bool SupportsMultiValue(ServerFieldType type); |
| 123 | 123 |
| 124 // Adjusts the labels according to profile data. | 124 // Adjusts the labels according to profile data. |
| 125 // Labels contain minimal different combination of: | 125 // Labels contain minimal different combination of: |
| 126 // 1. Full name. | 126 // 1. Full name. |
| 127 // 2. Address. | 127 // 2. Address. |
| 128 // 3. E-mail. | 128 // 3. E-mail. |
| 129 // 4. Phone. | 129 // 4. Phone. |
| 130 // 5. Company name. | 130 // 5. Company name. |
| 131 // Profile labels are changed accordingly to these rules. | 131 // Profile labels are changed accordingly to these rules. |
| 132 // Returns true if any of the profiles were updated. | 132 // Returns true if any of the profiles were updated. |
| 133 // This function is useful if you want to adjust unique labels for all | 133 // This function is useful if you want to adjust unique labels for all |
| 134 // profiles. For non permanent situations (selection of profile, when user | 134 // profiles. For non permanent situations (selection of profile, when user |
| 135 // started typing in the field, for example) use CreateInferredLabels(). | 135 // started typing in the field, for example) use CreateInferredLabels(). |
| 136 static bool AdjustInferredLabels(std::vector<AutofillProfile*>* profiles); | 136 static bool AdjustInferredLabels(std::vector<AutofillProfile*>* profiles); |
| 137 | 137 |
| 138 // Creates inferred labels for |profiles|, according to the rules above and | 138 // Creates inferred labels for |profiles|, according to the rules above and |
| 139 // stores them in |created_labels|. If |suggested_fields| is not NULL, the | 139 // stores them in |created_labels|. If |suggested_fields| is not NULL, the |
| 140 // resulting label fields are drawn from |suggested_fields|, except excluding | 140 // resulting label fields are drawn from |suggested_fields|, except excluding |
| 141 // |excluded_field|. Otherwise, the label fields are drawn from a default set, | 141 // |excluded_field|. Otherwise, the label fields are drawn from a default set, |
| 142 // and |excluded_field| is ignored; by convention, it should be of | 142 // and |excluded_field| is ignored; by convention, it should be of |
| 143 // |UNKNOWN_TYPE| when |suggested_fields| is NULL. Each label includes at | 143 // |UNKNOWN_TYPE| when |suggested_fields| is NULL. Each label includes at |
| 144 // least |minimal_fields_shown| fields, if possible. | 144 // least |minimal_fields_shown| fields, if possible. |
| 145 static void CreateInferredLabels( | 145 static void CreateInferredLabels( |
| 146 const std::vector<AutofillProfile*>* profiles, | 146 const std::vector<AutofillProfile*>* profiles, |
| 147 const std::vector<AutofillFieldType>* suggested_fields, | 147 const std::vector<ServerFieldType>* suggested_fields, |
| 148 AutofillFieldType excluded_field, | 148 ServerFieldType excluded_field, |
| 149 size_t minimal_fields_shown, | 149 size_t minimal_fields_shown, |
| 150 std::vector<base::string16>* created_labels); | 150 std::vector<base::string16>* created_labels); |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 typedef std::vector<const FormGroup*> FormGroupList; | 153 typedef std::vector<const FormGroup*> FormGroupList; |
| 154 | 154 |
| 155 // FormGroup: | 155 // FormGroup: |
| 156 virtual bool FillCountrySelectControl(const std::string& app_locale, | 156 virtual bool FillCountrySelectControl(const std::string& app_locale, |
| 157 FormFieldData* field) const OVERRIDE; | 157 FormFieldData* field) const OVERRIDE; |
| 158 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE; | 158 virtual void GetSupportedTypes( |
| 159 ServerFieldTypeSet* supported_types) const OVERRIDE; |
| 159 | 160 |
| 160 // Shared implementation for GetRawMultiInfo() and GetMultiInfo(). Pass an | 161 // Shared implementation for GetRawMultiInfo() and GetMultiInfo(). Pass an |
| 161 // empty |app_locale| to get the raw info; otherwise, the returned info is | 162 // empty |app_locale| to get the raw info; otherwise, the returned info is |
| 162 // canonicalized according to the given |app_locale|, if appropriate. | 163 // canonicalized according to the given |app_locale|, if appropriate. |
| 163 void GetMultiInfoImpl(AutofillFieldType type, | 164 void GetMultiInfoImpl(const AutofillType& type, |
| 164 const std::string& app_locale, | 165 const std::string& app_locale, |
| 165 std::vector<base::string16>* values) const; | 166 std::vector<base::string16>* values) const; |
| 166 | 167 |
| 167 // Checks if the |phone| is in the |existing_phones| using fuzzy matching: | 168 // Checks if the |phone| is in the |existing_phones| using fuzzy matching: |
| 168 // for example, "1-800-FLOWERS", "18003569377", "(800)356-9377" and "356-9377" | 169 // for example, "1-800-FLOWERS", "18003569377", "(800)356-9377" and "356-9377" |
| 169 // are considered the same. | 170 // are considered the same. |
| 170 // Adds the |phone| to the |existing_phones| if not already there. | 171 // Adds the |phone| to the |existing_phones| if not already there. |
| 171 void AddPhoneIfUnique(const base::string16& phone, | 172 void AddPhoneIfUnique(const base::string16& phone, |
| 172 const std::string& app_locale, | 173 const std::string& app_locale, |
| 173 std::vector<base::string16>* existing_phones); | 174 std::vector<base::string16>* existing_phones); |
| 174 | 175 |
| 175 // Builds inferred label from the first |num_fields_to_include| non-empty | 176 // Builds inferred label from the first |num_fields_to_include| non-empty |
| 176 // fields in |label_fields|. Uses as many fields as possible if there are not | 177 // fields in |label_fields|. Uses as many fields as possible if there are not |
| 177 // enough non-empty fields. | 178 // enough non-empty fields. |
| 178 base::string16 ConstructInferredLabel( | 179 base::string16 ConstructInferredLabel( |
| 179 const std::vector<AutofillFieldType>& label_fields, | 180 const std::vector<ServerFieldType>& label_fields, |
| 180 size_t num_fields_to_include) const; | 181 size_t num_fields_to_include) const; |
| 181 | 182 |
| 182 // Creates inferred labels for |profiles| at indices corresponding to | 183 // Creates inferred labels for |profiles| at indices corresponding to |
| 183 // |indices|, and stores the results to the corresponding elements of | 184 // |indices|, and stores the results to the corresponding elements of |
| 184 // |created_labels|. These labels include enough fields to differentiate among | 185 // |created_labels|. These labels include enough fields to differentiate among |
| 185 // the profiles, if possible; and also at least |num_fields_to_include| | 186 // the profiles, if possible; and also at least |num_fields_to_include| |
| 186 // fields, if possible. The label fields are drawn from |fields|. | 187 // fields, if possible. The label fields are drawn from |fields|. |
| 187 static void CreateDifferentiatingLabels( | 188 static void CreateDifferentiatingLabels( |
| 188 const std::vector<AutofillProfile*>& profiles, | 189 const std::vector<AutofillProfile*>& profiles, |
| 189 const std::list<size_t>& indices, | 190 const std::list<size_t>& indices, |
| 190 const std::vector<AutofillFieldType>& fields, | 191 const std::vector<ServerFieldType>& fields, |
| 191 size_t num_fields_to_include, | 192 size_t num_fields_to_include, |
| 192 std::vector<base::string16>* created_labels); | 193 std::vector<base::string16>* created_labels); |
| 193 | 194 |
| 194 // Utilities for listing and lookup of the data members that constitute | 195 // Utilities for listing and lookup of the data members that constitute |
| 195 // user-visible profile information. | 196 // user-visible profile information. |
| 196 FormGroupList FormGroups() const; | 197 FormGroupList FormGroups() const; |
| 197 const FormGroup* FormGroupForType(AutofillFieldType type) const; | 198 const FormGroup* FormGroupForType(const AutofillType& type) const; |
| 198 FormGroup* MutableFormGroupForType(AutofillFieldType type); | 199 FormGroup* MutableFormGroupForType(const AutofillType& type); |
| 199 | 200 |
| 200 // The label presented to the user when selecting a profile. | 201 // The label presented to the user when selecting a profile. |
| 201 base::string16 label_; | 202 base::string16 label_; |
| 202 | 203 |
| 203 // Personal information for this profile. | 204 // Personal information for this profile. |
| 204 std::vector<NameInfo> name_; | 205 std::vector<NameInfo> name_; |
| 205 std::vector<EmailInfo> email_; | 206 std::vector<EmailInfo> email_; |
| 206 CompanyInfo company_; | 207 CompanyInfo company_; |
| 207 std::vector<PhoneNumber> phone_number_; | 208 std::vector<PhoneNumber> phone_number_; |
| 208 Address address_; | 209 Address address_; |
| 209 }; | 210 }; |
| 210 | 211 |
| 211 // So we can compare AutofillProfiles with EXPECT_EQ(). | 212 // So we can compare AutofillProfiles with EXPECT_EQ(). |
| 212 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile); | 213 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile); |
| 213 | 214 |
| 214 } // namespace autofill | 215 } // namespace autofill |
| 215 | 216 |
| 216 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_H_ | 217 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_H_ |
| OLD | NEW |