OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILE_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILE_H_ |
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILE_H_ | 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "chrome/browser/autofill/address.h" |
| 15 #include "chrome/browser/autofill/contact_info.h" |
| 16 #include "chrome/browser/autofill/fax_number.h" |
14 #include "chrome/browser/autofill/form_group.h" | 17 #include "chrome/browser/autofill/form_group.h" |
| 18 #include "chrome/browser/autofill/home_phone_number.h" |
15 | 19 |
16 // A collection of FormGroups stored in a profile. AutoFillProfile also | 20 // A collection of FormGroups stored in a profile. AutoFillProfile also |
17 // implements the FormGroup interface so that owners of this object can request | 21 // implements the FormGroup interface so that owners of this object can request |
18 // form information from the profile, and the profile will delegate the request | 22 // form information from the profile, and the profile will delegate the request |
19 // to the requested form group type. | 23 // to the requested form group type. |
20 class AutoFillProfile : public FormGroup { | 24 class AutoFillProfile : public FormGroup { |
21 public: | 25 public: |
22 explicit AutoFillProfile(const std::string& guid); | 26 explicit AutoFillProfile(const std::string& guid); |
23 | 27 |
24 // For use in STL containers. | 28 // For use in STL containers. |
25 AutoFillProfile(); | 29 AutoFillProfile(); |
26 AutoFillProfile(const AutoFillProfile&); | 30 AutoFillProfile(const AutoFillProfile&); |
27 virtual ~AutoFillProfile(); | 31 virtual ~AutoFillProfile(); |
28 | 32 |
29 // FormGroup implementation: | 33 AutoFillProfile& operator=(const AutoFillProfile& profile); |
| 34 |
| 35 // FormGroup: |
30 virtual void GetPossibleFieldTypes(const string16& text, | 36 virtual void GetPossibleFieldTypes(const string16& text, |
31 FieldTypeSet* possible_types) const; | 37 FieldTypeSet* possible_types) const; |
32 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; | 38 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; |
33 virtual string16 GetFieldText(const AutofillType& type) const; | 39 virtual string16 GetFieldText(const AutofillType& type) const; |
34 // Returns true if the info matches the profile data corresponding to type. | 40 // Returns true if the |value| matches the profile data corresponding to type. |
35 // If the type is UNKNOWN_TYPE then info will be matched against all of the | 41 // If the type is UNKNOWN_TYPE then |value| will be matched against all of the |
36 // profile data. | 42 // profile data. |
37 virtual void FindInfoMatches(const AutofillType& type, | 43 virtual void FindInfoMatches(const AutofillType& type, |
38 const string16& info, | 44 const string16& value, |
39 std::vector<string16>* matched_text) const; | 45 std::vector<string16>* matched_text) const; |
40 virtual void SetInfo(const AutofillType& type, const string16& value); | 46 virtual void SetInfo(const AutofillType& type, const string16& value); |
41 // Returns a copy of the profile it is called on. The caller is responsible | 47 |
42 // for deleting profile when they are done with it. | |
43 virtual FormGroup* Clone() const; | |
44 // The user-visible label of the profile, generated in relation to other | 48 // The user-visible label of the profile, generated in relation to other |
45 // profiles. Shows at least 2 fields that differentiate profile from other | 49 // profiles. Shows at least 2 fields that differentiate profile from other |
46 // profiles. See AdjustInferredLabels() further down for more description. | 50 // profiles. See AdjustInferredLabels() further down for more description. |
47 virtual const string16 Label() const; | 51 virtual const string16 Label() const; |
48 | 52 |
49 // This guid is the primary identifier for |AutoFillProfile| objects. | 53 // This guid is the primary identifier for |AutoFillProfile| objects. |
50 const std::string guid() const { return guid_; } | 54 const std::string guid() const { return guid_; } |
51 void set_guid(const std::string& guid) { guid_ = guid; } | 55 void set_guid(const std::string& guid) { guid_ = guid; } |
52 | 56 |
53 // Accessors for the stored address's country code. | 57 // Accessors for the stored address's country code. |
(...skipping 25 matching lines...) Expand all Loading... |
79 static void CreateInferredLabels( | 83 static void CreateInferredLabels( |
80 const std::vector<AutoFillProfile*>* profiles, | 84 const std::vector<AutoFillProfile*>* profiles, |
81 const std::vector<AutofillFieldType>* suggested_fields, | 85 const std::vector<AutofillFieldType>* suggested_fields, |
82 AutofillFieldType excluded_field, | 86 AutofillFieldType excluded_field, |
83 size_t minimal_fields_shown, | 87 size_t minimal_fields_shown, |
84 std::vector<string16>* created_labels); | 88 std::vector<string16>* created_labels); |
85 | 89 |
86 // Returns true if there are no values (field types) set. | 90 // Returns true if there are no values (field types) set. |
87 bool IsEmpty() const; | 91 bool IsEmpty() const; |
88 | 92 |
89 // For use in STL containers. | |
90 void operator=(const AutoFillProfile&); | |
91 | |
92 // Comparison for Sync. Returns 0 if the profile is the same as |this|, | 93 // 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 | 94 // 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 | 95 // culling duplicates. The ordering is based on collation order of the |
95 // textual contents of the fields. | 96 // textual contents of the fields. |
96 // GUIDs are not compared, only the values of the contents themselves. | 97 // GUIDs are not compared, only the values of the contents themselves. |
97 int Compare(const AutoFillProfile& profile) const; | 98 int Compare(const AutoFillProfile& profile) const; |
98 | 99 |
99 // Equality operators compare GUIDs and the contents in the comparison. | 100 // Equality operators compare GUIDs and the contents in the comparison. |
100 bool operator==(const AutoFillProfile& profile) const; | 101 bool operator==(const AutoFillProfile& profile) const; |
101 virtual bool operator!=(const AutoFillProfile& profile) const; | 102 virtual bool operator!=(const AutoFillProfile& profile) const; |
102 | 103 |
103 // Returns concatenation of full name and address line 1. This acts as the | 104 // Returns concatenation of full name and address line 1. This acts as the |
104 // basis of comparison for new values that are submitted through forms to | 105 // basis of comparison for new values that are submitted through forms to |
105 // aid with correct aggregation of new data. | 106 // aid with correct aggregation of new data. |
106 const string16 PrimaryValue() const; | 107 const string16 PrimaryValue() const; |
107 | 108 |
108 private: | 109 private: |
109 typedef std::map<FieldTypeGroup, FormGroup*> FormGroupMap; | 110 typedef std::vector<const FormGroup*> FormGroupList; |
| 111 typedef std::map<FieldTypeGroup, const FormGroup*> FormGroupMap; |
| 112 typedef std::map<FieldTypeGroup, FormGroup*> MutableFormGroupMap; |
110 | 113 |
111 // Builds inferred label from the first |num_fields_to_include| non-empty | 114 // Builds inferred label from the first |num_fields_to_include| non-empty |
112 // fields in |label_fields|. Uses as many fields as possible if there are not | 115 // fields in |label_fields|. Uses as many fields as possible if there are not |
113 // enough non-empty fields. | 116 // enough non-empty fields. |
114 string16 ConstructInferredLabel( | 117 string16 ConstructInferredLabel( |
115 const std::vector<AutofillFieldType>& label_fields, | 118 const std::vector<AutofillFieldType>& label_fields, |
116 size_t num_fields_to_include) const; | 119 size_t num_fields_to_include) const; |
117 | 120 |
118 // Creates inferred labels for |profiles| at indices corresponding to | 121 // Creates inferred labels for |profiles| at indices corresponding to |
119 // |indices|, and stores the results to the corresponding elements of | 122 // |indices|, and stores the results to the corresponding elements of |
120 // |created_labels|. These labels include enough fields to differentiate among | 123 // |created_labels|. These labels include enough fields to differentiate among |
121 // the profiles, if possible; and also at least |num_fields_to_include| | 124 // the profiles, if possible; and also at least |num_fields_to_include| |
122 // fields, if possible. The label fields are drawn from |fields|. | 125 // fields, if possible. The label fields are drawn from |fields|. |
123 static void CreateDifferentiatingLabels( | 126 static void CreateDifferentiatingLabels( |
124 const std::vector<AutoFillProfile*>& profiles, | 127 const std::vector<AutoFillProfile*>& profiles, |
125 const std::list<size_t>& indices, | 128 const std::list<size_t>& indices, |
126 const std::vector<AutofillFieldType>& fields, | 129 const std::vector<AutofillFieldType>& fields, |
127 size_t num_fields_to_include, | 130 size_t num_fields_to_include, |
128 std::vector<string16>* created_labels); | 131 std::vector<string16>* created_labels); |
129 | 132 |
130 // Utility to initialize a |FormGroupMap|. | 133 // Utilities for listing and lookup of the data members that constitute |
131 static void InitPersonalInfo(FormGroupMap* personal_info); | 134 // user-visible profile information. |
| 135 FormGroupList info_list() const; |
| 136 FormGroupMap info_map() const; |
| 137 MutableFormGroupMap mutable_info_map(); |
132 | 138 |
133 // The label presented to the user when selecting a profile. | 139 // The label presented to the user when selecting a profile. |
134 string16 label_; | 140 string16 label_; |
135 | 141 |
136 // The guid of this profile. | 142 // The guid of this profile. |
137 std::string guid_; | 143 std::string guid_; |
138 | 144 |
139 // Personal information for this profile. | 145 // Personal information for this profile. |
140 FormGroupMap personal_info_; | 146 NameInfo name_; |
| 147 EmailInfo email_; |
| 148 CompanyInfo company_; |
| 149 HomePhoneNumber home_number_; |
| 150 FaxNumber fax_number_; |
| 151 Address address_; |
141 }; | 152 }; |
142 | 153 |
143 // So we can compare AutoFillProfiles with EXPECT_EQ(). | 154 // So we can compare AutoFillProfiles with EXPECT_EQ(). |
144 std::ostream& operator<<(std::ostream& os, const AutoFillProfile& profile); | 155 std::ostream& operator<<(std::ostream& os, const AutoFillProfile& profile); |
145 | 156 |
146 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILE_H_ | 157 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILE_H_ |
OLD | NEW |