Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: components/autofill/browser/autofill_profile.h

Issue 17392006: In components/autofill, move browser/ to core/browser/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to fix conflicts Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_PROFILE_H_
6 #define COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_PROFILE_H_
7
8 #include <stddef.h>
9
10 #include <iosfwd>
11 #include <list>
12 #include <string>
13 #include <vector>
14
15 #include "base/compiler_specific.h"
16 #include "base/strings/string16.h"
17 #include "components/autofill/browser/address.h"
18 #include "components/autofill/browser/autofill_data_model.h"
19 #include "components/autofill/browser/autofill_type.h"
20 #include "components/autofill/browser/contact_info.h"
21 #include "components/autofill/browser/field_types.h"
22 #include "components/autofill/browser/phone_number.h"
23
24 namespace autofill {
25
26 struct FormFieldData;
27
28 // A collection of FormGroups stored in a profile. AutofillProfile also
29 // implements the FormGroup interface so that owners of this object can request
30 // form information from the profile, and the profile will delegate the request
31 // to the requested form group type.
32 class AutofillProfile : public AutofillDataModel {
33 public:
34 AutofillProfile(const std::string& guid, const std::string& origin);
35
36 // For use in STL containers.
37 AutofillProfile();
38 AutofillProfile(const AutofillProfile& profile);
39 virtual ~AutofillProfile();
40
41 AutofillProfile& operator=(const AutofillProfile& profile);
42
43 // FormGroup:
44 virtual void GetMatchingTypes(const base::string16& text,
45 const std::string& app_locale,
46 FieldTypeSet* matching_types) const OVERRIDE;
47 virtual base::string16 GetRawInfo(AutofillFieldType type) const OVERRIDE;
48 virtual void SetRawInfo(AutofillFieldType type,
49 const base::string16& value) OVERRIDE;
50 virtual base::string16 GetInfo(AutofillFieldType type,
51 const std::string& app_locale) const OVERRIDE;
52 virtual bool SetInfo(AutofillFieldType type,
53 const base::string16& value,
54 const std::string& app_locale) OVERRIDE;
55
56 // AutofillDataModel:
57 virtual void FillFormField(const AutofillField& field,
58 size_t variant,
59 const std::string& app_locale,
60 FormFieldData* field_data) const OVERRIDE;
61
62 // Multi-value equivalents to |GetInfo| and |SetInfo|.
63 void SetRawMultiInfo(AutofillFieldType type,
64 const std::vector<base::string16>& values);
65 void GetRawMultiInfo(AutofillFieldType type,
66 std::vector<base::string16>* values) const;
67 void GetMultiInfo(AutofillFieldType type,
68 const std::string& app_locale,
69 std::vector<base::string16>* values) const;
70
71 // Set |field_data|'s value for phone number based on contents of |this|.
72 // The |field| specifies the type of the phone and whether this is a
73 // phone prefix or suffix. The |variant| parameter specifies which value in a
74 // multi-valued profile.
75 void FillPhoneNumberField(const AutofillField& field,
76 size_t variant,
77 const std::string& app_locale,
78 FormFieldData* field_data) const;
79
80 // The user-visible label of the profile, generated in relation to other
81 // profiles. Shows at least 2 fields that differentiate profile from other
82 // profiles. See AdjustInferredLabels() further down for more description.
83 const base::string16 Label() const;
84
85 // Returns true if there are no values (field types) set.
86 bool IsEmpty(const std::string& app_locale) const;
87
88 // 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
90 // culling duplicates. The ordering is based on collation order of the
91 // textual contents of the fields.
92 // GUIDs and origins are not compared, only the values of the contents
93 // themselves. Full profile comparision, comparison includes multi-valued
94 // fields.
95 int Compare(const AutofillProfile& profile) const;
96
97 // Equality operators compare GUIDs, origins, and the contents in the
98 // comparison.
99 bool operator==(const AutofillProfile& profile) const;
100 virtual bool operator!=(const AutofillProfile& profile) const;
101
102 // Returns concatenation of full name and address line 1. This acts as the
103 // basis of comparison for new values that are submitted through forms to
104 // aid with correct aggregation of new data.
105 const base::string16 PrimaryValue() const;
106
107 // Returns true if the data in this AutofillProfile is a subset of the data in
108 // |profile|.
109 bool IsSubsetOf(const AutofillProfile& profile,
110 const std::string& app_locale) const;
111
112 // Overwrites the single-valued field data in |profile| with this
113 // Profile. Or, for multi-valued fields append the new values.
114 void OverwriteWithOrAddTo(const AutofillProfile& profile,
115 const std::string& app_locale);
116
117 // Returns |true| if |type| accepts multi-values.
118 static bool SupportsMultiValue(AutofillFieldType type);
119
120 // Adjusts the labels according to profile data.
121 // Labels contain minimal different combination of:
122 // 1. Full name.
123 // 2. Address.
124 // 3. E-mail.
125 // 4. Phone.
126 // 5. Company name.
127 // Profile labels are changed accordingly to these rules.
128 // Returns true if any of the profiles were updated.
129 // This function is useful if you want to adjust unique labels for all
130 // profiles. For non permanent situations (selection of profile, when user
131 // started typing in the field, for example) use CreateInferredLabels().
132 static bool AdjustInferredLabels(std::vector<AutofillProfile*>* profiles);
133
134 // Creates inferred labels for |profiles|, according to the rules above and
135 // stores them in |created_labels|. If |suggested_fields| is not NULL, the
136 // resulting label fields are drawn from |suggested_fields|, except excluding
137 // |excluded_field|. Otherwise, the label fields are drawn from a default set,
138 // and |excluded_field| is ignored; by convention, it should be of
139 // |UNKNOWN_TYPE| when |suggested_fields| is NULL. Each label includes at
140 // least |minimal_fields_shown| fields, if possible.
141 static void CreateInferredLabels(
142 const std::vector<AutofillProfile*>* profiles,
143 const std::vector<AutofillFieldType>* suggested_fields,
144 AutofillFieldType excluded_field,
145 size_t minimal_fields_shown,
146 std::vector<base::string16>* created_labels);
147
148 private:
149 typedef std::vector<const FormGroup*> FormGroupList;
150
151 // FormGroup:
152 virtual bool FillCountrySelectControl(const std::string& app_locale,
153 FormFieldData* field) const OVERRIDE;
154 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE;
155
156 // Shared implementation for GetRawMultiInfo() and GetMultiInfo(). Pass an
157 // empty |app_locale| to get the raw info; otherwise, the returned info is
158 // canonicalized according to the given |app_locale|, if appropriate.
159 void GetMultiInfoImpl(AutofillFieldType type,
160 const std::string& app_locale,
161 std::vector<base::string16>* values) const;
162
163 // Checks if the |phone| is in the |existing_phones| using fuzzy matching:
164 // for example, "1-800-FLOWERS", "18003569377", "(800)356-9377" and "356-9377"
165 // are considered the same.
166 // Adds the |phone| to the |existing_phones| if not already there.
167 void AddPhoneIfUnique(const base::string16& phone,
168 const std::string& app_locale,
169 std::vector<base::string16>* existing_phones);
170
171 // Builds inferred label from the first |num_fields_to_include| non-empty
172 // fields in |label_fields|. Uses as many fields as possible if there are not
173 // enough non-empty fields.
174 base::string16 ConstructInferredLabel(
175 const std::vector<AutofillFieldType>& label_fields,
176 size_t num_fields_to_include) const;
177
178 // Creates inferred labels for |profiles| at indices corresponding to
179 // |indices|, and stores the results to the corresponding elements of
180 // |created_labels|. These labels include enough fields to differentiate among
181 // the profiles, if possible; and also at least |num_fields_to_include|
182 // fields, if possible. The label fields are drawn from |fields|.
183 static void CreateDifferentiatingLabels(
184 const std::vector<AutofillProfile*>& profiles,
185 const std::list<size_t>& indices,
186 const std::vector<AutofillFieldType>& fields,
187 size_t num_fields_to_include,
188 std::vector<base::string16>* created_labels);
189
190 // Utilities for listing and lookup of the data members that constitute
191 // user-visible profile information.
192 FormGroupList FormGroups() const;
193 const FormGroup* FormGroupForType(AutofillFieldType type) const;
194 FormGroup* MutableFormGroupForType(AutofillFieldType type);
195
196 // The label presented to the user when selecting a profile.
197 base::string16 label_;
198
199 // Personal information for this profile.
200 std::vector<NameInfo> name_;
201 std::vector<EmailInfo> email_;
202 CompanyInfo company_;
203 std::vector<PhoneNumber> phone_number_;
204 Address address_;
205 };
206
207 // So we can compare AutofillProfiles with EXPECT_EQ().
208 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile);
209
210 } // namespace autofill
211
212 #endif // COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_PROFILE_H_
OLDNEW
« no previous file with comments | « components/autofill/browser/autofill_popup_delegate.h ('k') | components/autofill/browser/autofill_profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698