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

Side by Side Diff: chrome/browser/autofill/personal_data_manager.cc

Issue 6673079: Reduce boxing and unboxing of AutofillFieldType (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compile on Windows. Created 9 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
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 #include "chrome/browser/autofill/personal_data_manager.h" 5 #include "chrome/browser/autofill/personal_data_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 WebKit::WebRegularExpression re(WebKit::WebString(kEmailPattern), 80 WebKit::WebRegularExpression re(WebKit::WebString(kEmailPattern),
81 WebKit::WebTextCaseInsensitive); 81 WebKit::WebTextCaseInsensitive);
82 return re.match(WebKit::WebString(StringToLowerASCII(value))) != -1; 82 return re.match(WebKit::WebString(StringToLowerASCII(value))) != -1;
83 } 83 }
84 84
85 // Returns true if minimum requirements for import of a given |profile| have 85 // Returns true if minimum requirements for import of a given |profile| have
86 // been met. An address submitted via a form must have at least these fields 86 // been met. An address submitted via a form must have at least these fields
87 // filled. No verification of validity of the contents is preformed. This is 87 // filled. No verification of validity of the contents is preformed. This is
88 // and existence check only. 88 // and existence check only.
89 bool IsMinimumAddress(const AutofillProfile& profile) { 89 bool IsMinimumAddress(const AutofillProfile& profile) {
90 return !profile.GetFieldText(AutofillType(ADDRESS_HOME_LINE1)).empty() && 90 return !profile.GetFieldText(ADDRESS_HOME_LINE1).empty() &&
91 !profile.GetFieldText(AutofillType(ADDRESS_HOME_CITY)).empty() && 91 !profile.GetFieldText(ADDRESS_HOME_CITY).empty() &&
92 !profile.GetFieldText(AutofillType(ADDRESS_HOME_STATE)).empty() && 92 !profile.GetFieldText(ADDRESS_HOME_STATE).empty() &&
93 !profile.GetFieldText(AutofillType(ADDRESS_HOME_ZIP)).empty(); 93 !profile.GetFieldText(ADDRESS_HOME_ZIP).empty();
94 } 94 }
95 95
96 // Whether we have already logged the number of profiles this session. 96 // Whether we have already logged the number of profiles this session.
97 bool g_has_logged_profile_count = false; 97 bool g_has_logged_profile_count = false;
98 98
99 } // namespace 99 } // namespace
100 100
101 PersonalDataManager::~PersonalDataManager() { 101 PersonalDataManager::~PersonalDataManager() {
102 CancelPendingQuery(&pending_profiles_query_); 102 CancelPendingQuery(&pending_profiles_query_);
103 CancelPendingQuery(&pending_creditcards_query_); 103 CancelPendingQuery(&pending_creditcards_query_);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 const FormStructure* form = *iter; 182 const FormStructure* form = *iter;
183 for (size_t i = 0; i < form->field_count(); ++i) { 183 for (size_t i = 0; i < form->field_count(); ++i) {
184 const AutofillField* field = form->field(i); 184 const AutofillField* field = form->field(i);
185 string16 value = CollapseWhitespace(field->value, false); 185 string16 value = CollapseWhitespace(field->value, false);
186 186
187 // If we don't know the type of the field, or the user hasn't entered any 187 // If we don't know the type of the field, or the user hasn't entered any
188 // information into the field, then skip it. 188 // information into the field, then skip it.
189 if (!field->IsFieldFillable() || value.empty()) 189 if (!field->IsFieldFillable() || value.empty())
190 continue; 190 continue;
191 191
192 AutofillType field_type(field->type()); 192 AutofillFieldType field_type = field->type();
193 FieldTypeGroup group(field_type.group()); 193 FieldTypeGroup group(AutofillType(field_type).group());
194 194
195 if (group == AutofillType::CREDIT_CARD) { 195 if (group == AutofillType::CREDIT_CARD) {
196 // If the user has a password set, we have no way of setting credit 196 // If the user has a password set, we have no way of setting credit
197 // card numbers. 197 // card numbers.
198 if (!HasPassword()) { 198 if (!HasPassword()) {
199 if (LowerCaseEqualsASCII(field->form_control_type, "month")) { 199 if (LowerCaseEqualsASCII(field->form_control_type, "month")) {
200 DCHECK_EQ(CREDIT_CARD_EXP_MONTH, field_type.field_type()); 200 DCHECK_EQ(CREDIT_CARD_EXP_MONTH, field_type);
201 local_imported_credit_card->SetInfoForMonthInputType(value); 201 local_imported_credit_card->SetInfoForMonthInputType(value);
202 } else { 202 } else {
203 local_imported_credit_card->SetInfo( 203 local_imported_credit_card->SetInfo(field_type, value);
204 AutofillType(field_type.field_type()), value);
205 } 204 }
206 ++importable_credit_card_fields; 205 ++importable_credit_card_fields;
207 } 206 }
208 } else { 207 } else {
209 // In the case of a phone number, if the whole phone number was entered 208 // In the case of a phone number, if the whole phone number was entered
210 // into a single field, then parse it and set the sub components. 209 // into a single field, then parse it and set the sub components.
211 if (field_type.subgroup() == AutofillType::PHONE_WHOLE_NUMBER) { 210 if (AutofillType(field_type).subgroup() ==
dhollowa 2011/03/16 17:07:11 nit: indent, or single line maybe?
Ilya Sherman 2011/03/17 03:42:29 Doesn't fit on a single line :(
211 AutofillType::PHONE_WHOLE_NUMBER) {
212 string16 number; 212 string16 number;
213 string16 city_code; 213 string16 city_code;
214 string16 country_code; 214 string16 country_code;
215 PhoneNumber::ParsePhoneNumber(value, 215 PhoneNumber::ParsePhoneNumber(value,
216 &number, 216 &number,
217 &city_code, 217 &city_code,
218 &country_code); 218 &country_code);
219 if (number.empty()) 219 if (number.empty())
220 continue; 220 continue;
221 221
222 if (group == AutofillType::PHONE_HOME) { 222 if (group == AutofillType::PHONE_HOME) {
223 imported_profile->SetInfo(AutofillType(PHONE_HOME_COUNTRY_CODE), 223 imported_profile->SetInfo(PHONE_HOME_COUNTRY_CODE, country_code);
224 country_code); 224 imported_profile->SetInfo(PHONE_HOME_CITY_CODE, city_code);
225 imported_profile->SetInfo(AutofillType(PHONE_HOME_CITY_CODE), 225 imported_profile->SetInfo(PHONE_HOME_NUMBER, number);
226 city_code);
227 imported_profile->SetInfo(AutofillType(PHONE_HOME_NUMBER), number);
228 } else if (group == AutofillType::PHONE_FAX) { 226 } else if (group == AutofillType::PHONE_FAX) {
229 imported_profile->SetInfo(AutofillType(PHONE_FAX_COUNTRY_CODE), 227 imported_profile->SetInfo(PHONE_FAX_COUNTRY_CODE, country_code);
230 country_code); 228 imported_profile->SetInfo(PHONE_FAX_CITY_CODE, city_code);
231 imported_profile->SetInfo(AutofillType(PHONE_FAX_CITY_CODE), 229 imported_profile->SetInfo(PHONE_FAX_NUMBER, number);
232 city_code);
233 imported_profile->SetInfo(AutofillType(PHONE_FAX_NUMBER), number);
234 } 230 }
235 231
236 continue; 232 continue;
237 } 233 }
238 234
239 // Phone and fax numbers can be split across multiple fields, so we 235 // Phone and fax numbers can be split across multiple fields, so we
240 // might have already stored the prefix, and now be at the suffix. 236 // might have already stored the prefix, and now be at the suffix.
241 // If so, combine them to form the full number. 237 // If so, combine them to form the full number.
242 if (group == AutofillType::PHONE_HOME || 238 if (group == AutofillType::PHONE_HOME ||
243 group == AutofillType::PHONE_FAX) { 239 group == AutofillType::PHONE_FAX) {
244 AutofillType number_type(PHONE_HOME_NUMBER); 240 AutofillFieldType number_type = PHONE_HOME_NUMBER;
245 if (group == AutofillType::PHONE_FAX) 241 if (group == AutofillType::PHONE_FAX)
246 number_type = AutofillType(PHONE_FAX_NUMBER); 242 number_type = PHONE_FAX_NUMBER;
247 243
248 string16 stored_number = imported_profile->GetFieldText(number_type); 244 string16 stored_number = imported_profile->GetFieldText(number_type);
249 if (stored_number.size() == 245 if (stored_number.size() ==
250 static_cast<size_t>(PhoneNumber::kPrefixLength) && 246 static_cast<size_t>(PhoneNumber::kPrefixLength) &&
251 value.size() == static_cast<size_t>(PhoneNumber::kSuffixLength)) { 247 value.size() == static_cast<size_t>(PhoneNumber::kSuffixLength)) {
252 value = stored_number + value; 248 value = stored_number + value;
253 } 249 }
254 } 250 }
255 251
256 if (field_type.field_type() == EMAIL_ADDRESS && !IsValidEmail(value)) 252 if (field_type == EMAIL_ADDRESS && !IsValidEmail(value))
257 continue; 253 continue;
258 254
259 imported_profile->SetInfo(AutofillType(field_type.field_type()), 255 imported_profile->SetInfo(field_type, value);
260 value);
261 ++importable_fields; 256 ++importable_fields;
262 } 257 }
263 } 258 }
264 } 259 }
265 260
266 // If the user did not enter enough information on the page then don't bother 261 // If the user did not enter enough information on the page then don't bother
267 // importing the data. 262 // importing the data.
268 if (importable_fields < kMinProfileImportSize) 263 if (importable_fields < kMinProfileImportSize)
269 imported_profile.reset(); 264 imported_profile.reset();
270 if (importable_credit_card_fields < kMinCreditCardImportSize) 265 if (importable_credit_card_fields < kMinCreditCardImportSize)
271 local_imported_credit_card.reset(); 266 local_imported_credit_card.reset();
272 267
273 if (imported_profile.get() && !IsMinimumAddress(*imported_profile.get())) 268 if (imported_profile.get() && !IsMinimumAddress(*imported_profile.get()))
274 imported_profile.reset(); 269 imported_profile.reset();
275 270
276 if (local_imported_credit_card.get() && 271 if (local_imported_credit_card.get() &&
277 !CreditCard::IsCreditCardNumber(local_imported_credit_card->GetFieldText( 272 !CreditCard::IsCreditCardNumber(local_imported_credit_card->GetFieldText(
278 AutofillType(CREDIT_CARD_NUMBER)))) { 273 CREDIT_CARD_NUMBER))) {
279 local_imported_credit_card.reset(); 274 local_imported_credit_card.reset();
280 } 275 }
281 276
282 // Don't import if we already have this info. 277 // Don't import if we already have this info.
283 if (local_imported_credit_card.get()) { 278 if (local_imported_credit_card.get()) {
284 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); 279 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin();
285 iter != credit_cards_.end(); 280 iter != credit_cards_.end();
286 ++iter) { 281 ++iter) {
287 if (local_imported_credit_card->IsSubsetOf(**iter)) { 282 if (local_imported_credit_card->IsSubsetOf(**iter)) {
288 local_imported_credit_card.reset(); 283 local_imported_credit_card.reset();
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 } 818 }
824 819
825 const AutofillMetrics* PersonalDataManager::metric_logger() const { 820 const AutofillMetrics* PersonalDataManager::metric_logger() const {
826 return metric_logger_.get(); 821 return metric_logger_.get();
827 } 822 }
828 823
829 void PersonalDataManager::set_metric_logger( 824 void PersonalDataManager::set_metric_logger(
830 const AutofillMetrics* metric_logger) { 825 const AutofillMetrics* metric_logger) {
831 metric_logger_.reset(metric_logger); 826 metric_logger_.reset(metric_logger);
832 } 827 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698