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> |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 // Creates a differentiating label for each of the |profiles|. | 117 // Creates a differentiating label for each of the |profiles|. |
118 // Labels consist of the minimal differentiating combination of: | 118 // Labels consist of the minimal differentiating combination of: |
119 // 1. Full name. | 119 // 1. Full name. |
120 // 2. Address. | 120 // 2. Address. |
121 // 3. E-mail. | 121 // 3. E-mail. |
122 // 4. Phone. | 122 // 4. Phone. |
123 // 5. Company name. | 123 // 5. Company name. |
124 static void CreateDifferentiatingLabels( | 124 static void CreateDifferentiatingLabels( |
125 const std::vector<AutofillProfile*>& profiles, | 125 const std::vector<AutofillProfile*>& profiles, |
| 126 const std::string& app_locale, |
126 std::vector<base::string16>* labels); | 127 std::vector<base::string16>* labels); |
127 | 128 |
128 // Creates inferred labels for |profiles|, according to the rules above and | 129 // Creates inferred labels for |profiles|, according to the rules above and |
129 // stores them in |created_labels|. If |suggested_fields| is not NULL, the | 130 // stores them in |created_labels|. If |suggested_fields| is not NULL, the |
130 // resulting label fields are drawn from |suggested_fields|, except excluding | 131 // resulting label fields are drawn from |suggested_fields|, except excluding |
131 // |excluded_field|. Otherwise, the label fields are drawn from a default set, | 132 // |excluded_field|. Otherwise, the label fields are drawn from a default set, |
132 // and |excluded_field| is ignored; by convention, it should be of | 133 // and |excluded_field| is ignored; by convention, it should be of |
133 // |UNKNOWN_TYPE| when |suggested_fields| is NULL. Each label includes at | 134 // |UNKNOWN_TYPE| when |suggested_fields| is NULL. Each label includes at |
134 // least |minimal_fields_shown| fields, if possible. | 135 // least |minimal_fields_shown| fields, if possible. |
135 static void CreateInferredLabels( | 136 static void CreateInferredLabels( |
136 const std::vector<AutofillProfile*>& profiles, | 137 const std::vector<AutofillProfile*>& profiles, |
137 const std::vector<ServerFieldType>* suggested_fields, | 138 const std::vector<ServerFieldType>* suggested_fields, |
138 ServerFieldType excluded_field, | 139 ServerFieldType excluded_field, |
139 size_t minimal_fields_shown, | 140 size_t minimal_fields_shown, |
| 141 const std::string& app_locale, |
140 std::vector<base::string16>* labels); | 142 std::vector<base::string16>* labels); |
141 | 143 |
142 const std::string& language_code() const { return language_code_; } | 144 const std::string& language_code() const { return language_code_; } |
143 void set_language_code(const std::string& language_code) { | 145 void set_language_code(const std::string& language_code) { |
144 language_code_ = language_code; | 146 language_code_ = language_code; |
145 } | 147 } |
146 | 148 |
147 private: | 149 private: |
148 typedef std::vector<const FormGroup*> FormGroupList; | 150 typedef std::vector<const FormGroup*> FormGroupList; |
149 | 151 |
150 // FormGroup: | 152 // FormGroup: |
151 virtual void GetSupportedTypes( | 153 virtual void GetSupportedTypes( |
152 ServerFieldTypeSet* supported_types) const OVERRIDE; | 154 ServerFieldTypeSet* supported_types) const OVERRIDE; |
153 | 155 |
154 // Shared implementation for GetRawMultiInfo() and GetMultiInfo(). Pass an | 156 // Shared implementation for GetRawMultiInfo() and GetMultiInfo(). Pass an |
155 // empty |app_locale| to get the raw info; otherwise, the returned info is | 157 // empty |app_locale| to get the raw info; otherwise, the returned info is |
156 // canonicalized according to the given |app_locale|, if appropriate. | 158 // canonicalized according to the given |app_locale|, if appropriate. |
157 void GetMultiInfoImpl(const AutofillType& type, | 159 void GetMultiInfoImpl(const AutofillType& type, |
158 const std::string& app_locale, | 160 const std::string& app_locale, |
159 std::vector<base::string16>* values) const; | 161 std::vector<base::string16>* values) const; |
160 | 162 |
161 // Checks if the |phone| is in the |existing_phones| using fuzzy matching: | |
162 // for example, "1-800-FLOWERS", "18003569377", "(800)356-9377" and "356-9377" | |
163 // are considered the same. | |
164 // Adds the |phone| to the |existing_phones| if not already there. | |
165 void AddPhoneIfUnique(const base::string16& phone, | |
166 const std::string& app_locale, | |
167 std::vector<base::string16>* existing_phones); | |
168 | |
169 // Builds inferred label from the first |num_fields_to_include| non-empty | 163 // Builds inferred label from the first |num_fields_to_include| non-empty |
170 // fields in |label_fields|. Uses as many fields as possible if there are not | 164 // fields in |label_fields|. Uses as many fields as possible if there are not |
171 // enough non-empty fields. | 165 // enough non-empty fields. |
172 base::string16 ConstructInferredLabel( | 166 base::string16 ConstructInferredLabel( |
173 const std::vector<ServerFieldType>& label_fields, | 167 const std::vector<ServerFieldType>& label_fields, |
174 size_t num_fields_to_include) const; | 168 size_t num_fields_to_include, |
| 169 const std::string& app_locale) const; |
175 | 170 |
176 // Creates inferred labels for |profiles| at indices corresponding to | 171 // Creates inferred labels for |profiles| at indices corresponding to |
177 // |indices|, and stores the results to the corresponding elements of | 172 // |indices|, and stores the results to the corresponding elements of |
178 // |labels|. These labels include enough fields to differentiate among the | 173 // |labels|. These labels include enough fields to differentiate among the |
179 // profiles, if possible; and also at least |num_fields_to_include| fields, if | 174 // profiles, if possible; and also at least |num_fields_to_include| fields, if |
180 // possible. The label fields are drawn from |fields|. | 175 // possible. The label fields are drawn from |fields|. |
181 static void CreateInferredLabelsHelper( | 176 static void CreateInferredLabelsHelper( |
182 const std::vector<AutofillProfile*>& profiles, | 177 const std::vector<AutofillProfile*>& profiles, |
183 const std::list<size_t>& indices, | 178 const std::list<size_t>& indices, |
184 const std::vector<ServerFieldType>& fields, | 179 const std::vector<ServerFieldType>& fields, |
185 size_t num_fields_to_include, | 180 size_t num_fields_to_include, |
| 181 const std::string& app_locale, |
186 std::vector<base::string16>* labels); | 182 std::vector<base::string16>* labels); |
187 | 183 |
188 // Utilities for listing and lookup of the data members that constitute | 184 // Utilities for listing and lookup of the data members that constitute |
189 // user-visible profile information. | 185 // user-visible profile information. |
190 FormGroupList FormGroups() const; | 186 FormGroupList FormGroups() const; |
191 const FormGroup* FormGroupForType(const AutofillType& type) const; | 187 const FormGroup* FormGroupForType(const AutofillType& type) const; |
192 FormGroup* MutableFormGroupForType(const AutofillType& type); | 188 FormGroup* MutableFormGroupForType(const AutofillType& type); |
193 | 189 |
194 // Appends unique names from |names| onto the |name_| list, dropping | 190 // Appends unique names from |names| onto the |name_| list, dropping |
195 // duplicates. If a name in |names| has the same full name representation | 191 // duplicates. If a name in |names| has the same full name representation |
196 // as a name in |name_|, keeps the variant that has more information (i.e. | 192 // as a name in |name_|, keeps the variant that has more information (i.e. |
197 // is not reconstructible via a heuristic parse of the full name string). | 193 // is not reconstructible via a heuristic parse of the full name string). |
198 void OverwriteOrAppendNames(const std::vector<NameInfo>& names); | 194 void OverwriteOrAppendNames(const std::vector<NameInfo>& names, |
| 195 const std::string& app_locale); |
199 | 196 |
200 // Personal information for this profile. | 197 // Personal information for this profile. |
201 std::vector<NameInfo> name_; | 198 std::vector<NameInfo> name_; |
202 std::vector<EmailInfo> email_; | 199 std::vector<EmailInfo> email_; |
203 CompanyInfo company_; | 200 CompanyInfo company_; |
204 std::vector<PhoneNumber> phone_number_; | 201 std::vector<PhoneNumber> phone_number_; |
205 Address address_; | 202 Address address_; |
206 | 203 |
207 // The BCP 47 language code that can be used to format |address_| for display. | 204 // The BCP 47 language code that can be used to format |address_| for display. |
208 std::string language_code_; | 205 std::string language_code_; |
209 }; | 206 }; |
210 | 207 |
211 // So we can compare AutofillProfiles with EXPECT_EQ(). | 208 // So we can compare AutofillProfiles with EXPECT_EQ(). |
212 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile); | 209 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile); |
213 | 210 |
214 } // namespace autofill | 211 } // namespace autofill |
215 | 212 |
216 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_H_ | 213 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_H_ |
OLD | NEW |