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 #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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 // Same as operator==, but ignores differences in guid and cares about | 92 // Same as operator==, but ignores differences in guid and cares about |
| 93 // differences in usage stats. | 93 // differences in usage stats. |
| 94 bool EqualsForSyncPurposes(const AutofillProfile& profile) const; | 94 bool EqualsForSyncPurposes(const AutofillProfile& profile) const; |
| 95 | 95 |
| 96 // Equality operators compare GUIDs, origins, language code, and the contents | 96 // Equality operators compare GUIDs, origins, language code, and the contents |
| 97 // in the comparison. Usage metadata (use count, use date, modification date) | 97 // in the comparison. Usage metadata (use count, use date, modification date) |
| 98 // are NOT compared. | 98 // are NOT compared. |
| 99 bool operator==(const AutofillProfile& profile) const; | 99 bool operator==(const AutofillProfile& profile) const; |
| 100 virtual bool operator!=(const AutofillProfile& profile) const; | 100 virtual bool operator!=(const AutofillProfile& profile) const; |
| 101 | 101 |
| 102 // Returns concatenation of first name, last name, address line 1 and city, | |
| 103 // with each part separated by a whitespace. This acts as the basis of | |
| 104 // comparison for new values that are submitted through forms to aid with | |
| 105 // correct aggregation of new data. | |
| 106 const base::string16 PrimaryValue(const std::string& app_locale) const; | |
| 107 | |
| 108 // Returns true if the data in this AutofillProfile is a subset of the data in | 102 // Returns true if the data in this AutofillProfile is a subset of the data in |
| 109 // |profile|. | 103 // |profile|. |
| 110 bool IsSubsetOf(const AutofillProfile& profile, | 104 bool IsSubsetOf(const AutofillProfile& profile, |
| 111 const std::string& app_locale) const; | 105 const std::string& app_locale) const; |
| 112 | 106 |
| 113 // Like IsSubsetOf, but only considers the types present in |types|. | 107 // Like IsSubsetOf, but only considers the types present in |types|. |
| 114 bool IsSubsetOfForFieldSet(const AutofillProfile& profile, | 108 bool IsSubsetOfForFieldSet(const AutofillProfile& profile, |
| 115 const std::string& app_locale, | 109 const std::string& app_locale, |
| 116 const ServerFieldTypeSet& types) const; | 110 const ServerFieldTypeSet& types) const; |
| 117 | 111 |
| 118 // Overwrites the field data in this Profile with the non-empty fields in | 112 // Merges the data from |this| profile and the given |profile| into |this| |
| 119 // |profile|. Returns |true| if at least one field was overwritten. | 113 // profile. Expects that |this| and |profile| have already been deemed |
| 120 // The usage stats, the origin and the language code are always updated and | 114 // mergeable by an AutofillProfileComparator. |
| 121 // have no effect on the return value. | 115 bool MergeDataFrom(const AutofillProfile& profile, |
| 122 bool OverwriteWith(const AutofillProfile& profile, | |
| 123 const std::string& app_locale); | 116 const std::string& app_locale); |
| 124 | 117 |
| 125 // Saves info from |profile| into |this|, provided |this| and |profile| do not | 118 // Saves info from |profile| into |this|, provided |this| and |profile| do not |
| 126 // have any direct conflicts (i.e. data is present but different). Will not | 119 // have any direct conflicts (i.e. data is present but different). Will not |
| 127 // make changes if |this| is verified and |profile| is not. Returns true if | 120 // make changes if |this| is verified and |profile| is not. Returns true if |
| 128 // |this| and |profile| are similar. | 121 // |this| and |profile| are similar. |
| 129 bool SaveAdditionalInfo(const AutofillProfile& profile, | 122 bool SaveAdditionalInfo(const AutofillProfile& profile, |
|
Roger McFarlane (Chromium)
2016/06/29 18:26:19
Maybe (in a follow-on CL?) rename MergeDataFrom()
sebsg
2016/06/29 19:04:50
I agree, let's do that.
| |
| 130 const std::string& app_locale); | 123 const std::string& app_locale); |
| 131 | 124 |
| 132 // Returns |true| if |type| accepts multi-values. | 125 // Returns |true| if |type| accepts multi-values. |
| 133 static bool SupportsMultiValue(ServerFieldType type); | 126 static bool SupportsMultiValue(ServerFieldType type); |
| 134 | 127 |
| 135 // Creates a differentiating label for each of the |profiles|. | 128 // Creates a differentiating label for each of the |profiles|. |
| 136 // Labels consist of the minimal differentiating combination of: | 129 // Labels consist of the minimal differentiating combination of: |
| 137 // 1. Full name. | 130 // 1. Full name. |
| 138 // 2. Address. | 131 // 2. Address. |
| 139 // 3. E-mail. | 132 // 3. E-mail. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 170 | 163 |
| 171 // Creates an identifier and saves it as |server_id_|. Only used for | 164 // Creates an identifier and saves it as |server_id_|. Only used for |
| 172 // server credit cards. The server doesn't attach an identifier so Chrome | 165 // server credit cards. The server doesn't attach an identifier so Chrome |
| 173 // creates its own. The ID is a hash of the data contained in the profile. | 166 // creates its own. The ID is a hash of the data contained in the profile. |
| 174 void GenerateServerProfileIdentifier(); | 167 void GenerateServerProfileIdentifier(); |
| 175 | 168 |
| 176 // Logs the number of days since the profile was last used and records its | 169 // Logs the number of days since the profile was last used and records its |
| 177 // use. | 170 // use. |
| 178 void RecordAndLogUse(); | 171 void RecordAndLogUse(); |
| 179 | 172 |
| 180 // TODO(crbug.com/574081): Move common profile methods to a utils file. | |
| 181 // Returns a standardized representation of the given string for comparison | |
| 182 // purposes. The resulting string will be lower-cased with all punctuation | |
| 183 // substituted by spaces. Whitespace will be converted to ASCII space, and | |
| 184 // multiple whitespace characters will be collapsed. | |
| 185 // | |
| 186 // This string is designed for comparison purposes only and isn't suitable | |
| 187 // for storing or displaying to the user. | |
| 188 static base::string16 CanonicalizeProfileString(const base::string16& str); | |
| 189 | |
| 190 private: | 173 private: |
| 191 typedef std::vector<const FormGroup*> FormGroupList; | 174 typedef std::vector<const FormGroup*> FormGroupList; |
| 192 | 175 |
| 193 // FormGroup: | 176 // FormGroup: |
| 194 void GetSupportedTypes(ServerFieldTypeSet* supported_types) const override; | 177 void GetSupportedTypes(ServerFieldTypeSet* supported_types) const override; |
| 195 | 178 |
| 196 // Builds inferred label from the first |num_fields_to_include| non-empty | 179 // Builds inferred label from the first |num_fields_to_include| non-empty |
| 197 // fields in |label_fields|. Uses as many fields as possible if there are not | 180 // fields in |label_fields|. Uses as many fields as possible if there are not |
| 198 // enough non-empty fields. | 181 // enough non-empty fields. |
| 199 base::string16 ConstructInferredLabel( | 182 base::string16 ConstructInferredLabel( |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 213 size_t num_fields_to_include, | 196 size_t num_fields_to_include, |
| 214 const std::string& app_locale, | 197 const std::string& app_locale, |
| 215 std::vector<base::string16>* labels); | 198 std::vector<base::string16>* labels); |
| 216 | 199 |
| 217 // Utilities for listing and lookup of the data members that constitute | 200 // Utilities for listing and lookup of the data members that constitute |
| 218 // user-visible profile information. | 201 // user-visible profile information. |
| 219 FormGroupList FormGroups() const; | 202 FormGroupList FormGroups() const; |
| 220 const FormGroup* FormGroupForType(const AutofillType& type) const; | 203 const FormGroup* FormGroupForType(const AutofillType& type) const; |
| 221 FormGroup* MutableFormGroupForType(const AutofillType& type); | 204 FormGroup* MutableFormGroupForType(const AutofillType& type); |
| 222 | 205 |
| 223 // If |name| has the same full name representation as |name_|, | |
| 224 // this will keep the one that has more information (i.e. | |
| 225 // is not reconstructible via a heuristic parse of the full name string). | |
| 226 // Returns |true| is |name_| was overwritten. | |
| 227 bool OverwriteName(const NameInfo& name, const std::string& app_locale); | |
| 228 | |
| 229 // Same as operator==, but ignores differences in GUID. | 206 // Same as operator==, but ignores differences in GUID. |
| 230 bool EqualsSansGuid(const AutofillProfile& profile) const; | 207 bool EqualsSansGuid(const AutofillProfile& profile) const; |
| 231 | 208 |
| 232 RecordType record_type_; | 209 RecordType record_type_; |
| 233 | 210 |
| 234 // Personal information for this profile. | 211 // Personal information for this profile. |
| 235 NameInfo name_; | 212 NameInfo name_; |
| 236 EmailInfo email_; | 213 EmailInfo email_; |
| 237 CompanyInfo company_; | 214 CompanyInfo company_; |
| 238 PhoneNumber phone_number_; | 215 PhoneNumber phone_number_; |
| 239 Address address_; | 216 Address address_; |
| 240 | 217 |
| 241 // The BCP 47 language code that can be used to format |address_| for display. | 218 // The BCP 47 language code that can be used to format |address_| for display. |
| 242 std::string language_code_; | 219 std::string language_code_; |
| 243 | 220 |
| 244 // ID used for identifying this profile. Only set for SERVER_PROFILEs. This is | 221 // ID used for identifying this profile. Only set for SERVER_PROFILEs. This is |
| 245 // a hash of the contents. | 222 // a hash of the contents. |
| 246 std::string server_id_; | 223 std::string server_id_; |
| 247 }; | 224 }; |
| 248 | 225 |
| 249 // So we can compare AutofillProfiles with EXPECT_EQ(). | 226 // So we can compare AutofillProfiles with EXPECT_EQ(). |
| 250 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile); | 227 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile); |
| 251 | 228 |
| 252 } // namespace autofill | 229 } // namespace autofill |
| 253 | 230 |
| 254 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_H_ | 231 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_PROFILE_H_ |
| OLD | NEW |