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> |
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/string16.h" | 16 #include "base/string16.h" |
16 #include "components/autofill/browser/address.h" | 17 #include "components/autofill/browser/address.h" |
| 18 #include "components/autofill/browser/autofill_data_model.h" |
17 #include "components/autofill/browser/autofill_type.h" | 19 #include "components/autofill/browser/autofill_type.h" |
18 #include "components/autofill/browser/contact_info.h" | 20 #include "components/autofill/browser/contact_info.h" |
19 #include "components/autofill/browser/field_types.h" | 21 #include "components/autofill/browser/field_types.h" |
20 #include "components/autofill/browser/form_group.h" | |
21 #include "components/autofill/browser/phone_number.h" | 22 #include "components/autofill/browser/phone_number.h" |
22 | 23 |
23 namespace autofill { | 24 namespace autofill { |
24 | 25 |
25 struct FormFieldData; | 26 struct FormFieldData; |
26 | 27 |
27 // A collection of FormGroups stored in a profile. AutofillProfile also | 28 // A collection of FormGroups stored in a profile. AutofillProfile also |
28 // implements the FormGroup interface so that owners of this object can request | 29 // implements the FormGroup interface so that owners of this object can request |
29 // form information from the profile, and the profile will delegate the request | 30 // form information from the profile, and the profile will delegate the request |
30 // to the requested form group type. | 31 // to the requested form group type. |
31 class AutofillProfile : public FormGroup { | 32 class AutofillProfile : public AutofillDataModel { |
32 public: | 33 public: |
33 explicit AutofillProfile(const std::string& guid); | 34 explicit AutofillProfile(const std::string& guid); |
34 | 35 |
35 // For use in STL containers. | 36 // For use in STL containers. |
36 AutofillProfile(); | 37 AutofillProfile(); |
37 AutofillProfile(const AutofillProfile& profile); | 38 AutofillProfile(const AutofillProfile& profile); |
38 virtual ~AutofillProfile(); | 39 virtual ~AutofillProfile(); |
39 | 40 |
40 AutofillProfile& operator=(const AutofillProfile& profile); | 41 AutofillProfile& operator=(const AutofillProfile& profile); |
41 | 42 |
42 // FormGroup: | 43 // FormGroup: |
43 virtual std::string GetGUID() const OVERRIDE; | |
44 virtual void GetMatchingTypes(const base::string16& text, | 44 virtual void GetMatchingTypes(const base::string16& text, |
45 const std::string& app_locale, | 45 const std::string& app_locale, |
46 FieldTypeSet* matching_types) const OVERRIDE; | 46 FieldTypeSet* matching_types) const OVERRIDE; |
47 virtual base::string16 GetRawInfo(AutofillFieldType type) const OVERRIDE; | 47 virtual base::string16 GetRawInfo(AutofillFieldType type) const OVERRIDE; |
48 virtual void SetRawInfo(AutofillFieldType type, | 48 virtual void SetRawInfo(AutofillFieldType 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(AutofillFieldType 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(AutofillFieldType 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 |
| 56 // AutofillDataModel: |
55 virtual void FillFormField(const AutofillField& field, | 57 virtual void FillFormField(const AutofillField& field, |
56 size_t variant, | 58 size_t variant, |
57 const std::string& app_locale, | 59 const std::string& app_locale, |
58 FormFieldData* field_data) const OVERRIDE; | 60 FormFieldData* field_data) const OVERRIDE; |
59 | 61 |
60 // Multi-value equivalents to |GetInfo| and |SetInfo|. | 62 // Multi-value equivalents to |GetInfo| and |SetInfo|. |
61 void SetRawMultiInfo(AutofillFieldType type, | 63 void SetRawMultiInfo(AutofillFieldType type, |
62 const std::vector<base::string16>& values); | 64 const std::vector<base::string16>& values); |
63 void GetRawMultiInfo(AutofillFieldType type, | 65 void GetRawMultiInfo(AutofillFieldType type, |
64 std::vector<base::string16>* values) const; | 66 std::vector<base::string16>* values) const; |
65 void GetMultiInfo(AutofillFieldType type, | 67 void GetMultiInfo(AutofillFieldType type, |
66 const std::string& app_locale, | 68 const std::string& app_locale, |
67 std::vector<base::string16>* values) const; | 69 std::vector<base::string16>* values) const; |
68 | 70 |
69 // 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|. |
70 // 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 |
71 // 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 |
72 // multi-valued profile. | 74 // multi-valued profile. |
73 void FillPhoneNumberField(const AutofillField& field, | 75 void FillPhoneNumberField(const AutofillField& field, |
74 size_t variant, | 76 size_t variant, |
75 const std::string& app_locale, | 77 const std::string& app_locale, |
76 FormFieldData* field_data) const; | 78 FormFieldData* field_data) const; |
77 | 79 |
78 // 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 |
79 // profiles. Shows at least 2 fields that differentiate profile from other | 81 // profiles. Shows at least 2 fields that differentiate profile from other |
80 // profiles. See AdjustInferredLabels() further down for more description. | 82 // profiles. See AdjustInferredLabels() further down for more description. |
81 const base::string16 Label() const; | 83 const base::string16 Label() const; |
82 | 84 |
83 // This guid is the primary identifier for |AutofillProfile| objects. | |
84 // TODO(estade): remove this and just use GetGUID(). |guid_| can probably | |
85 // be moved to FormGroup. | |
86 const std::string guid() const { return guid_; } | |
87 void set_guid(const std::string& guid) { guid_ = guid; } | |
88 | |
89 // Returns true if there are no values (field types) set. | 85 // Returns true if there are no values (field types) set. |
90 bool IsEmpty(const std::string& app_locale) const; | 86 bool IsEmpty(const std::string& app_locale) const; |
91 | 87 |
92 // Comparison for Sync. Returns 0 if the profile is the same as |this|, | 88 // 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 | 89 // 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 | 90 // culling duplicates. The ordering is based on collation order of the |
95 // textual contents of the fields. | 91 // textual contents of the fields. |
96 // GUIDs are not compared, only the values of the contents themselves. | 92 // GUIDs are not compared, only the values of the contents themselves. |
97 // Full profile comparision, comparison includes multi-valued fields. | 93 // Full profile comparision, comparison includes multi-valued fields. |
98 int Compare(const AutofillProfile& profile) const; | 94 int Compare(const AutofillProfile& profile) const; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 187 |
192 // Utilities for listing and lookup of the data members that constitute | 188 // Utilities for listing and lookup of the data members that constitute |
193 // user-visible profile information. | 189 // user-visible profile information. |
194 FormGroupList FormGroups() const; | 190 FormGroupList FormGroups() const; |
195 const FormGroup* FormGroupForType(AutofillFieldType type) const; | 191 const FormGroup* FormGroupForType(AutofillFieldType type) const; |
196 FormGroup* MutableFormGroupForType(AutofillFieldType type); | 192 FormGroup* MutableFormGroupForType(AutofillFieldType type); |
197 | 193 |
198 // The label presented to the user when selecting a profile. | 194 // The label presented to the user when selecting a profile. |
199 base::string16 label_; | 195 base::string16 label_; |
200 | 196 |
201 // The guid of this profile. | |
202 std::string guid_; | |
203 | |
204 // Personal information for this profile. | 197 // Personal information for this profile. |
205 std::vector<NameInfo> name_; | 198 std::vector<NameInfo> name_; |
206 std::vector<EmailInfo> email_; | 199 std::vector<EmailInfo> email_; |
207 CompanyInfo company_; | 200 CompanyInfo company_; |
208 std::vector<PhoneNumber> home_number_; | 201 std::vector<PhoneNumber> home_number_; |
209 Address address_; | 202 Address address_; |
210 }; | 203 }; |
211 | 204 |
212 // So we can compare AutofillProfiles with EXPECT_EQ(). | 205 // So we can compare AutofillProfiles with EXPECT_EQ(). |
213 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile); | 206 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile); |
214 | 207 |
215 } // namespace autofill | 208 } // namespace autofill |
216 | 209 |
217 #endif // COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_PROFILE_H_ | 210 #endif // COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_PROFILE_H_ |
OLD | NEW |