OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BROWSER_AUTOFILL_PROFILE_H_ | 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_PROFILE_H_ |
6 #define COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_PROFILE_H_ | 6 #define COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_PROFILE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <iosfwd> | 10 #include <iosfwd> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 virtual string16 GetRawInfo(AutofillFieldType type) const OVERRIDE; | 45 virtual string16 GetRawInfo(AutofillFieldType type) const OVERRIDE; |
46 virtual void SetRawInfo(AutofillFieldType type, | 46 virtual void SetRawInfo(AutofillFieldType type, |
47 const string16& value) OVERRIDE; | 47 const string16& value) OVERRIDE; |
48 virtual string16 GetInfo(AutofillFieldType type, | 48 virtual string16 GetInfo(AutofillFieldType type, |
49 const std::string& app_locale) const OVERRIDE; | 49 const std::string& app_locale) const OVERRIDE; |
50 virtual bool SetInfo(AutofillFieldType type, | 50 virtual bool SetInfo(AutofillFieldType type, |
51 const string16& value, | 51 const string16& value, |
52 const std::string& app_locale) OVERRIDE; | 52 const std::string& app_locale) OVERRIDE; |
53 virtual void FillFormField(const AutofillField& field, | 53 virtual void FillFormField(const AutofillField& field, |
54 size_t variant, | 54 size_t variant, |
| 55 const std::string& app_locale, |
55 FormFieldData* field_data) const OVERRIDE; | 56 FormFieldData* field_data) const OVERRIDE; |
56 | 57 |
57 // Multi-value equivalents to |GetInfo| and |SetInfo|. | 58 // Multi-value equivalents to |GetInfo| and |SetInfo|. |
58 void SetRawMultiInfo(AutofillFieldType type, | 59 void SetRawMultiInfo(AutofillFieldType type, |
59 const std::vector<string16>& values); | 60 const std::vector<string16>& values); |
60 void GetRawMultiInfo(AutofillFieldType type, | 61 void GetRawMultiInfo(AutofillFieldType type, |
61 std::vector<string16>* values) const; | 62 std::vector<string16>* values) const; |
62 void GetMultiInfo(AutofillFieldType type, | 63 void GetMultiInfo(AutofillFieldType type, |
63 const std::string& app_locale, | 64 const std::string& app_locale, |
64 std::vector<string16>* values) const; | 65 std::vector<string16>* values) const; |
65 | 66 |
66 // Set |field_data|'s value for phone number based on contents of |this|. | 67 // Set |field_data|'s value for phone number based on contents of |this|. |
67 // The |field| specifies the type of the phone and whether this is a | 68 // The |field| specifies the type of the phone and whether this is a |
68 // phone prefix or suffix. The |variant| parameter specifies which value in a | 69 // phone prefix or suffix. The |variant| parameter specifies which value in a |
69 // multi-valued profile. | 70 // multi-valued profile. |
70 void FillPhoneNumberField(const AutofillField& field, | 71 void FillPhoneNumberField(const AutofillField& field, |
71 size_t variant, | 72 size_t variant, |
| 73 const std::string& app_locale, |
72 FormFieldData* field_data) const; | 74 FormFieldData* field_data) const; |
73 | 75 |
74 // The user-visible label of the profile, generated in relation to other | 76 // The user-visible label of the profile, generated in relation to other |
75 // profiles. Shows at least 2 fields that differentiate profile from other | 77 // profiles. Shows at least 2 fields that differentiate profile from other |
76 // profiles. See AdjustInferredLabels() further down for more description. | 78 // profiles. See AdjustInferredLabels() further down for more description. |
77 const string16 Label() const; | 79 const string16 Label() const; |
78 | 80 |
79 // This guid is the primary identifier for |AutofillProfile| objects. | 81 // This guid is the primary identifier for |AutofillProfile| objects. |
80 // TODO(estade): remove this and just use GetGUID(). |guid_| can probably | 82 // TODO(estade): remove this and just use GetGUID(). |guid_| can probably |
81 // be moved to FormGroup. | 83 // be moved to FormGroup. |
82 const std::string guid() const { return guid_; } | 84 const std::string guid() const { return guid_; } |
83 void set_guid(const std::string& guid) { guid_ = guid; } | 85 void set_guid(const std::string& guid) { guid_ = guid; } |
84 | 86 |
85 // Returns true if there are no values (field types) set. | 87 // Returns true if there are no values (field types) set. |
86 bool IsEmpty() const; | 88 bool IsEmpty(const std::string& app_locale) const; |
87 | 89 |
88 // Comparison for Sync. Returns 0 if the profile is the same as |this|, | 90 // Comparison for Sync. Returns 0 if the profile is the same as |this|, |
89 // or < 0, or > 0 if it is different. The implied ordering can be used for | 91 // or < 0, or > 0 if it is different. The implied ordering can be used for |
90 // culling duplicates. The ordering is based on collation order of the | 92 // culling duplicates. The ordering is based on collation order of the |
91 // textual contents of the fields. | 93 // textual contents of the fields. |
92 // GUIDs are not compared, only the values of the contents themselves. | 94 // GUIDs are not compared, only the values of the contents themselves. |
93 // Full profile comparision, comparison includes multi-valued fields. | 95 // Full profile comparision, comparison includes multi-valued fields. |
94 int Compare(const AutofillProfile& profile) const; | 96 int Compare(const AutofillProfile& profile) const; |
95 | 97 |
96 // Equality operators compare GUIDs and the contents in the comparison. | 98 // Equality operators compare GUIDs and the contents in the comparison. |
97 bool operator==(const AutofillProfile& profile) const; | 99 bool operator==(const AutofillProfile& profile) const; |
98 virtual bool operator!=(const AutofillProfile& profile) const; | 100 virtual bool operator!=(const AutofillProfile& profile) const; |
99 | 101 |
100 // Returns concatenation of full name and address line 1. This acts as the | 102 // Returns concatenation of full name and address line 1. This acts as the |
101 // basis of comparison for new values that are submitted through forms to | 103 // basis of comparison for new values that are submitted through forms to |
102 // aid with correct aggregation of new data. | 104 // aid with correct aggregation of new data. |
103 const string16 PrimaryValue() const; | 105 const string16 PrimaryValue() const; |
104 | 106 |
105 // Returns true if the data in this AutofillProfile is a subset of the data in | 107 // Returns true if the data in this AutofillProfile is a subset of the data in |
106 // |profile|. | 108 // |profile|. |
107 bool IsSubsetOf(const AutofillProfile& profile) const; | 109 bool IsSubsetOf(const AutofillProfile& profile, |
| 110 const std::string& app_locale) const; |
108 | 111 |
109 // Overwrites the single-valued field data in |profile| with this | 112 // Overwrites the single-valued field data in |profile| with this |
110 // Profile. Or, for multi-valued fields append the new values. | 113 // Profile. Or, for multi-valued fields append the new values. |
111 void OverwriteWithOrAddTo(const AutofillProfile& profile); | 114 void OverwriteWithOrAddTo(const AutofillProfile& profile, |
| 115 const std::string& app_locale); |
112 | 116 |
113 // Returns |true| if |type| accepts multi-values. | 117 // Returns |true| if |type| accepts multi-values. |
114 static bool SupportsMultiValue(AutofillFieldType type); | 118 static bool SupportsMultiValue(AutofillFieldType type); |
115 | 119 |
116 // Adjusts the labels according to profile data. | 120 // Adjusts the labels according to profile data. |
117 // Labels contain minimal different combination of: | 121 // Labels contain minimal different combination of: |
118 // 1. Full name. | 122 // 1. Full name. |
119 // 2. Address. | 123 // 2. Address. |
120 // 3. E-mail. | 124 // 3. E-mail. |
121 // 4. Phone. | 125 // 4. Phone. |
(...skipping 16 matching lines...) Expand all Loading... |
138 const std::vector<AutofillProfile*>* profiles, | 142 const std::vector<AutofillProfile*>* profiles, |
139 const std::vector<AutofillFieldType>* suggested_fields, | 143 const std::vector<AutofillFieldType>* suggested_fields, |
140 AutofillFieldType excluded_field, | 144 AutofillFieldType excluded_field, |
141 size_t minimal_fields_shown, | 145 size_t minimal_fields_shown, |
142 std::vector<string16>* created_labels); | 146 std::vector<string16>* created_labels); |
143 | 147 |
144 private: | 148 private: |
145 typedef std::vector<const FormGroup*> FormGroupList; | 149 typedef std::vector<const FormGroup*> FormGroupList; |
146 | 150 |
147 // FormGroup: | 151 // FormGroup: |
148 virtual bool FillCountrySelectControl(FormFieldData* field) const OVERRIDE; | 152 virtual bool FillCountrySelectControl(const std::string& app_locale, |
| 153 FormFieldData* field) const OVERRIDE; |
149 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE; | 154 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE; |
150 | 155 |
151 // Shared implementation for GetRawMultiInfo() and GetMultiInfo(). Pass an | 156 // Shared implementation for GetRawMultiInfo() and GetMultiInfo(). Pass an |
152 // 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 |
153 // canonicalized according to the given |app_locale|, if appropriate. | 158 // canonicalized according to the given |app_locale|, if appropriate. |
154 void GetMultiInfoImpl(AutofillFieldType type, | 159 void GetMultiInfoImpl(AutofillFieldType type, |
155 const std::string& app_locale, | 160 const std::string& app_locale, |
156 std::vector<string16>* values) const; | 161 std::vector<string16>* values) const; |
157 | 162 |
158 // Checks if the |phone| is in the |existing_phones| using fuzzy matching: | 163 // Checks if the |phone| is in the |existing_phones| using fuzzy matching: |
159 // for example, "1-800-FLOWERS", "18003569377", "(800)356-9377" and "356-9377" | 164 // for example, "1-800-FLOWERS", "18003569377", "(800)356-9377" and "356-9377" |
160 // are considered the same. | 165 // are considered the same. |
161 // Adds the |phone| to the |existing_phones| if not already there. | 166 // Adds the |phone| to the |existing_phones| if not already there. |
162 void AddPhoneIfUnique(const string16& phone, | 167 void AddPhoneIfUnique(const string16& phone, |
| 168 const std::string& app_locale, |
163 std::vector<string16>* existing_phones); | 169 std::vector<string16>* existing_phones); |
164 | 170 |
165 // Builds inferred label from the first |num_fields_to_include| non-empty | 171 // Builds inferred label from the first |num_fields_to_include| non-empty |
166 // fields in |label_fields|. Uses as many fields as possible if there are not | 172 // fields in |label_fields|. Uses as many fields as possible if there are not |
167 // enough non-empty fields. | 173 // enough non-empty fields. |
168 string16 ConstructInferredLabel( | 174 string16 ConstructInferredLabel( |
169 const std::vector<AutofillFieldType>& label_fields, | 175 const std::vector<AutofillFieldType>& label_fields, |
170 size_t num_fields_to_include) const; | 176 size_t num_fields_to_include) const; |
171 | 177 |
172 // Creates inferred labels for |profiles| at indices corresponding to | 178 // Creates inferred labels for |profiles| at indices corresponding to |
(...skipping 25 matching lines...) Expand all Loading... |
198 std::vector<EmailInfo> email_; | 204 std::vector<EmailInfo> email_; |
199 CompanyInfo company_; | 205 CompanyInfo company_; |
200 std::vector<PhoneNumber> home_number_; | 206 std::vector<PhoneNumber> home_number_; |
201 Address address_; | 207 Address address_; |
202 }; | 208 }; |
203 | 209 |
204 // So we can compare AutofillProfiles with EXPECT_EQ(). | 210 // So we can compare AutofillProfiles with EXPECT_EQ(). |
205 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile); | 211 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile); |
206 | 212 |
207 #endif // COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_PROFILE_H_ | 213 #endif // COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_PROFILE_H_ |
OLD | NEW |