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_CONTACT_INFO_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_ |
6 #define CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_ | 6 #define CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | |
11 #include "base/string16.h" | 12 #include "base/string16.h" |
12 #include "chrome/browser/autofill/form_group.h" | 13 #include "chrome/browser/autofill/form_group.h" |
13 | 14 |
14 typedef std::vector<string16> NameTokens; | 15 // A form group that stores name information. |
16 class NameInfo : public FormGroup { | |
17 public: | |
18 NameInfo(); | |
19 explicit NameInfo(const NameInfo& info); | |
20 virtual ~NameInfo(); | |
15 | 21 |
16 // A form group that stores contact information. | 22 NameInfo& operator=(const NameInfo& info); |
17 class ContactInfo : public FormGroup { | |
18 public: | |
19 ContactInfo(); | |
20 virtual ~ContactInfo(); | |
21 | 23 |
22 // FormGroup implementation: | 24 // FormGroup implementation: |
23 virtual FormGroup* Clone() const; | |
24 virtual void GetPossibleFieldTypes(const string16& text, | 25 virtual void GetPossibleFieldTypes(const string16& text, |
25 FieldTypeSet* possible_types) const; | 26 FieldTypeSet* possible_types) const; |
26 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; | 27 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; |
27 virtual void FindInfoMatches(const AutofillType& type, | 28 virtual void FindInfoMatches(const AutofillType& type, |
28 const string16& info, | 29 const string16& info, |
29 std::vector<string16>* matched_text) const; | 30 std::vector<string16>* matched_text) const; |
30 virtual string16 GetFieldText(const AutofillType& type) const; | 31 virtual string16 GetFieldText(const AutofillType& type) const; |
31 virtual void SetInfo(const AutofillType& type, const string16& value); | 32 virtual void SetInfo(const AutofillType& type, const string16& value); |
32 | 33 |
33 private: | 34 private: |
34 friend class ContactInfoTest; | 35 typedef std::vector<string16> NameTokens; |
Ilya Sherman
2011/03/09 00:50:50
I don't think this typedef helps readability at al
dhollowa
2011/03/09 01:55:47
Done.
| |
35 explicit ContactInfo(const ContactInfo& contact_info); | 36 |
36 void operator=(const ContactInfo& info); | 37 FRIEND_TEST_ALL_PREFIXES(NameInfoTest, TestSetFullName); |
37 | 38 |
38 // Returns the full name, which can include up to the first, middle, middle | 39 // Returns the full name, which can include up to the first, middle, middle |
39 // initial, last name, and suffix. | 40 // initial, and last name. |
Ilya Sherman
2011/03/09 00:50:50
What does "middle, middle initial" mean? Presumab
dhollowa
2011/03/09 01:55:47
Done.
| |
40 string16 FullName() const; | 41 string16 FullName() const; |
41 | 42 |
42 // Returns the middle initial if |middle_| is non-empty. Returns an empty | 43 // Returns the middle initial if |middle_| is non-empty. Returns an empty |
43 // string otherwise. | 44 // string otherwise. |
44 string16 MiddleInitial() const; | 45 string16 MiddleInitial() const; |
45 | 46 |
46 const string16& first() const { return first_; } | 47 const string16& first() const { return first_; } |
47 const string16& middle() const { return middle_; } | 48 const string16& middle() const { return middle_; } |
48 const string16& last() const { return last_; } | 49 const string16& last() const { return last_; } |
49 const string16& suffix() const { return suffix_; } | |
50 const string16& email() const { return email_; } | |
51 const string16& company_name() const { return company_name_; } | |
52 | 50 |
53 // A helper function for FindInfoMatches that only handles matching the info | 51 // A helper function for FindInfoMatches that only handles matching the info |
54 // with the requested field type. | 52 // with the requested field type. |
55 bool FindInfoMatchesHelper(const AutofillFieldType& field_type, | 53 bool FindInfoMatchesHelper(const AutofillFieldType& field_type, |
56 const string16& info, | 54 const string16& info, |
57 string16* matched_text) const; | 55 string16* matched_text) const; |
58 | 56 |
59 // Returns true if |text| is the first name. | 57 // Returns true if |text| is the first name. |
60 bool IsFirstName(const string16& text) const; | 58 bool IsFirstName(const string16& text) const; |
61 | 59 |
62 // Returns true if |text| is the middle name. | 60 // Returns true if |text| is the middle name. |
63 bool IsMiddleName(const string16& text) const; | 61 bool IsMiddleName(const string16& text) const; |
64 | 62 |
65 // Returns true if |text| is the last name. | 63 // Returns true if |text| is the last name. |
66 bool IsLastName(const string16& text) const; | 64 bool IsLastName(const string16& text) const; |
67 | 65 |
68 // Returns true if |text| is the suffix. | |
69 bool IsSuffix(const string16& text) const; | |
70 | |
71 // Returns true if |text| is the middle initial. | 66 // Returns true if |text| is the middle initial. |
72 bool IsMiddleInitial(const string16& text) const; | 67 bool IsMiddleInitial(const string16& text) const; |
73 | 68 |
74 // Returns true if |text| is the last name. | 69 // Returns true if |text| is the last name. |
75 bool IsFullName(const string16& text) const; | 70 bool IsFullName(const string16& text) const; |
76 | 71 |
77 // Returns true if all of the tokens in |text| match the tokens in | 72 // Returns true if all of the tokens in |text| match the tokens in |
78 // |name_tokens|. | 73 // |name_tokens|. |
79 bool IsNameMatch(const string16& text, const NameTokens& name_tokens) const; | 74 bool IsNameMatch(const string16& text, const NameTokens& name_tokens) const; |
80 | 75 |
81 // Returns true if |word| is one of the tokens in |name_tokens|. | 76 // Returns true if |word| is one of the tokens in |name_tokens|. |
82 bool IsWordInName(const string16& word, const NameTokens& name_tokens) const; | 77 bool IsWordInName(const string16& word, const NameTokens& name_tokens) const; |
83 | 78 |
84 // Sets |first_| to |first| and |first_tokens_| to the set of tokens in | 79 // Sets |first_| to |first| and |first_tokens_| to the set of tokens in |
85 // |first|, made lowercase. | 80 // |first|, made lowercase. |
86 void SetFirst(const string16& first); | 81 void SetFirst(const string16& first); |
87 | 82 |
88 // Sets |middle_| to |middle| and |middle_tokens_| to the set of tokens in | 83 // Sets |middle_| to |middle| and |middle_tokens_| to the set of tokens in |
89 // |middle|, made lowercase. | 84 // |middle|, made lowercase. |
90 void SetMiddle(const string16& middle); | 85 void SetMiddle(const string16& middle); |
91 | 86 |
92 // Sets |last_| to |last| and |last_tokens_| to the set of tokens in |last|, | 87 // Sets |last_| to |last| and |last_tokens_| to the set of tokens in |last|, |
93 // made lowercase. | 88 // made lowercase. |
94 void SetLast(const string16& last); | 89 void SetLast(const string16& last); |
95 | 90 |
96 // Sets |first_|, |middle_|, |last_| and |*_tokens_| to the tokenized | 91 // Sets |first_|, |middle_|, |last_| and |*_tokens_| to the tokenized |
97 // |full|. It is tokenized on a space only. | 92 // |full|. It is tokenized on a space only. |
98 void SetFullName(const string16& full); | 93 void SetFullName(const string16& full); |
99 | 94 |
100 void set_suffix(const string16& suffix) { suffix_ = suffix; } | |
101 | |
102 // List of tokens in each part of the name. | 95 // List of tokens in each part of the name. |
103 NameTokens first_tokens_; | 96 NameTokens first_tokens_; |
104 NameTokens middle_tokens_; | 97 NameTokens middle_tokens_; |
105 NameTokens last_tokens_; | 98 NameTokens last_tokens_; |
106 | 99 |
107 // Contact information data. | |
108 string16 first_; | 100 string16 first_; |
109 string16 middle_; | 101 string16 middle_; |
110 string16 last_; | 102 string16 last_; |
111 string16 suffix_; | 103 }; |
104 | |
105 class EmailInfo : public FormGroup { | |
106 public: | |
107 EmailInfo(); | |
108 explicit EmailInfo(const EmailInfo& info); | |
109 virtual ~EmailInfo(); | |
110 | |
111 EmailInfo& operator=(const EmailInfo& info); | |
112 | |
113 // FormGroup implementation: | |
114 virtual void GetPossibleFieldTypes(const string16& text, | |
115 FieldTypeSet* possible_types) const; | |
116 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; | |
117 virtual void FindInfoMatches(const AutofillType& type, | |
118 const string16& info, | |
119 std::vector<string16>* matched_text) const; | |
120 virtual string16 GetFieldText(const AutofillType& type) const; | |
121 virtual void SetInfo(const AutofillType& type, const string16& value); | |
122 | |
123 private: | |
124 const string16& email() const { return email_; } | |
125 | |
126 // A helper function for FindInfoMatches that only handles matching the info | |
127 // with the requested field type. | |
128 bool FindInfoMatchesHelper(const AutofillFieldType& field_type, | |
129 const string16& info, | |
130 string16* matched_text) const; | |
131 | |
112 string16 email_; | 132 string16 email_; |
133 }; | |
134 | |
135 class CompanyInfo : public FormGroup { | |
136 public: | |
137 CompanyInfo(); | |
138 explicit CompanyInfo(const CompanyInfo& info); | |
139 virtual ~CompanyInfo(); | |
140 | |
141 CompanyInfo& operator=(const CompanyInfo& info); | |
142 | |
143 // FormGroup implementation: | |
Ilya Sherman
2011/03/09 00:50:50
nit: I thought we were dropping the " implementati
dhollowa
2011/03/09 01:55:47
Done. Here and in AutoFillProfile.
| |
144 virtual void GetPossibleFieldTypes(const string16& text, | |
145 FieldTypeSet* possible_types) const; | |
146 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; | |
147 virtual void FindInfoMatches(const AutofillType& type, | |
148 const string16& info, | |
149 std::vector<string16>* matched_text) const; | |
150 virtual string16 GetFieldText(const AutofillType& type) const; | |
151 virtual void SetInfo(const AutofillType& type, const string16& value); | |
152 | |
153 private: | |
154 const string16& company_name() const { return company_name_; } | |
155 | |
156 // A helper function for FindInfoMatches that only handles matching the info | |
157 // with the requested field type. | |
158 bool FindInfoMatchesHelper(const AutofillFieldType& field_type, | |
159 const string16& info, | |
160 string16* matched_text) const; | |
113 string16 company_name_; | 161 string16 company_name_; |
114 }; | 162 }; |
115 | 163 |
116 #endif // CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_ | 164 #endif // CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_ |
OLD | NEW |