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

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

Issue 12434004: Move remaining Autofill code to //components/autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix long lines Created 7 years, 9 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 CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILE_H_
6 #define CHROME_BROWSER_AUTOFILL_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/string16.h"
16 #include "chrome/browser/autofill/address.h"
17 #include "chrome/browser/autofill/autofill_type.h"
18 #include "chrome/browser/autofill/contact_info.h"
19 #include "chrome/browser/autofill/field_types.h"
20 #include "chrome/browser/autofill/form_group.h"
21 #include "chrome/browser/autofill/phone_number.h"
22
23 struct FormFieldData;
24
25 // A collection of FormGroups stored in a profile. AutofillProfile also
26 // implements the FormGroup interface so that owners of this object can request
27 // form information from the profile, and the profile will delegate the request
28 // to the requested form group type.
29 class AutofillProfile : public FormGroup {
30 public:
31 explicit AutofillProfile(const std::string& guid);
32
33 // For use in STL containers.
34 AutofillProfile();
35 AutofillProfile(const AutofillProfile& profile);
36 virtual ~AutofillProfile();
37
38 AutofillProfile& operator=(const AutofillProfile& profile);
39
40 // FormGroup:
41 virtual std::string GetGUID() const OVERRIDE;
42 virtual void GetMatchingTypes(const string16& text,
43 const std::string& app_locale,
44 FieldTypeSet* matching_types) const OVERRIDE;
45 virtual string16 GetRawInfo(AutofillFieldType type) const OVERRIDE;
46 virtual void SetRawInfo(AutofillFieldType type,
47 const string16& value) OVERRIDE;
48 virtual string16 GetInfo(AutofillFieldType type,
49 const std::string& app_locale) const OVERRIDE;
50 virtual bool SetInfo(AutofillFieldType type,
51 const string16& value,
52 const std::string& app_locale) OVERRIDE;
53 virtual void FillFormField(const AutofillField& field,
54 size_t variant,
55 FormFieldData* field_data) const OVERRIDE;
56
57 // Multi-value equivalents to |GetInfo| and |SetInfo|.
58 void SetRawMultiInfo(AutofillFieldType type,
59 const std::vector<string16>& values);
60 void GetRawMultiInfo(AutofillFieldType type,
61 std::vector<string16>* values) const;
62 void GetMultiInfo(AutofillFieldType type,
63 const std::string& app_locale,
64 std::vector<string16>* values) const;
65
66 // 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 // phone prefix or suffix. The |variant| parameter specifies which value in a
69 // multi-valued profile.
70 void FillPhoneNumberField(const AutofillField& field,
71 size_t variant,
72 FormFieldData* field_data) const;
73
74 // The user-visible label of the profile, generated in relation to other
75 // profiles. Shows at least 2 fields that differentiate profile from other
76 // profiles. See AdjustInferredLabels() further down for more description.
77 const string16 Label() const;
78
79 // This guid is the primary identifier for |AutofillProfile| objects.
80 // TODO(estade): remove this and just use GetGUID(). |guid_| can probably
81 // be moved to FormGroup.
82 const std::string guid() const { return guid_; }
83 void set_guid(const std::string& guid) { guid_ = guid; }
84
85 // Accessors for the stored address's country code.
86 const std::string CountryCode() const;
87 void SetCountryCode(const std::string& country_code);
88
89 // Returns true if there are no values (field types) set.
90 bool IsEmpty() const;
91
92 // 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 // culling duplicates. The ordering is based on collation order of the
95 // textual contents of the fields.
96 // GUIDs are not compared, only the values of the contents themselves.
97 // Full profile comparision, comparison includes multi-valued fields.
98 int Compare(const AutofillProfile& profile) const;
99
100 // Equality operators compare GUIDs and the contents in the comparison.
101 bool operator==(const AutofillProfile& profile) const;
102 virtual bool operator!=(const AutofillProfile& profile) const;
103
104 // Returns concatenation of full name and address line 1. This acts as the
105 // basis of comparison for new values that are submitted through forms to
106 // aid with correct aggregation of new data.
107 const string16 PrimaryValue() const;
108
109 // Returns true if the data in this AutofillProfile is a subset of the data in
110 // |profile|.
111 bool IsSubsetOf(const AutofillProfile& profile) const;
112
113 // Overwrites the single-valued field data in |profile| with this
114 // Profile. Or, for multi-valued fields append the new values.
115 void OverwriteWithOrAddTo(const AutofillProfile& profile);
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<string16>* created_labels);
147
148 private:
149 typedef std::vector<const FormGroup*> FormGroupList;
150
151 // FormGroup:
152 virtual bool FillCountrySelectControl(FormFieldData* field) const OVERRIDE;
153 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE;
154
155 // Shared implementation for GetRawMultiInfo() and GetMultiInfo(). Pass an
156 // empty |app_locale| to get the raw info; otherwise, the returned info is
157 // canonicalized according to the given |app_locale|, if appropriate.
158 void GetMultiInfoImpl(AutofillFieldType type,
159 const std::string& app_locale,
160 std::vector<string16>* values) const;
161
162 // Checks if the |phone| is in the |existing_phones| using fuzzy matching:
163 // for example, "1-800-FLOWERS", "18003569377", "(800)356-9377" and "356-9377"
164 // are considered the same.
165 // Adds the |phone| to the |existing_phones| if not already there.
166 void AddPhoneIfUnique(const string16& phone,
167 std::vector<string16>* existing_phones);
168
169 // Builds inferred label from the first |num_fields_to_include| non-empty
170 // fields in |label_fields|. Uses as many fields as possible if there are not
171 // enough non-empty fields.
172 string16 ConstructInferredLabel(
173 const std::vector<AutofillFieldType>& label_fields,
174 size_t num_fields_to_include) const;
175
176 // Creates inferred labels for |profiles| at indices corresponding to
177 // |indices|, and stores the results to the corresponding elements of
178 // |created_labels|. These labels include enough fields to differentiate among
179 // the profiles, if possible; and also at least |num_fields_to_include|
180 // fields, if possible. The label fields are drawn from |fields|.
181 static void CreateDifferentiatingLabels(
182 const std::vector<AutofillProfile*>& profiles,
183 const std::list<size_t>& indices,
184 const std::vector<AutofillFieldType>& fields,
185 size_t num_fields_to_include,
186 std::vector<string16>* created_labels);
187
188 // Utilities for listing and lookup of the data members that constitute
189 // user-visible profile information.
190 FormGroupList FormGroups() const;
191 const FormGroup* FormGroupForType(AutofillFieldType type) const;
192 FormGroup* MutableFormGroupForType(AutofillFieldType type);
193
194 // The label presented to the user when selecting a profile.
195 string16 label_;
196
197 // The guid of this profile.
198 std::string guid_;
199
200 // Personal information for this profile.
201 std::vector<NameInfo> name_;
202 std::vector<EmailInfo> email_;
203 CompanyInfo company_;
204 std::vector<PhoneNumber> home_number_;
205 Address address_;
206 };
207
208 // So we can compare AutofillProfiles with EXPECT_EQ().
209 std::ostream& operator<<(std::ostream& os, const AutofillProfile& profile);
210
211 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILE_H_
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_popup_delegate.h ('k') | chrome/browser/autofill/autofill_profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698