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

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

Issue 6673079: Reduce boxing and unboxing of AutofillFieldType (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
« no previous file with comments | « chrome/browser/autofill/contact_info.h ('k') | chrome/browser/autofill/credit_card.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/contact_info.h" 5 #include "chrome/browser/autofill/contact_info.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/autofill/autofill_type.h" 10 #include "chrome/browser/autofill/autofill_type.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (!last().empty()) 74 if (!last().empty())
75 available_types->insert(NAME_LAST); 75 available_types->insert(NAME_LAST);
76 76
77 if (!MiddleInitial().empty()) 77 if (!MiddleInitial().empty())
78 available_types->insert(NAME_MIDDLE_INITIAL); 78 available_types->insert(NAME_MIDDLE_INITIAL);
79 79
80 if (!FullName().empty()) 80 if (!FullName().empty())
81 available_types->insert(NAME_FULL); 81 available_types->insert(NAME_FULL);
82 } 82 }
83 83
84 void NameInfo::FindInfoMatches(const AutofillType& type, 84 void NameInfo::FindInfoMatches(AutofillFieldType type,
85 const string16& info, 85 const string16& info,
86 std::vector<string16>* matched_text) const { 86 std::vector<string16>* matched_text) const {
87 DCHECK(matched_text); 87 DCHECK(matched_text);
88 88
89 string16 match; 89 string16 match;
90 if (type.field_type() == UNKNOWN_TYPE) { 90 if (type == UNKNOWN_TYPE) {
91 for (size_t i = 0; i < kAutoFillNameInfoLength; i++) { 91 for (size_t i = 0; i < kAutoFillNameInfoLength; i++) {
92 if (FindInfoMatchesHelper(kAutoFillNameInfoTypes[i], info, &match)) 92 if (FindInfoMatchesHelper(kAutoFillNameInfoTypes[i], info, &match))
93 matched_text->push_back(match); 93 matched_text->push_back(match);
94 } 94 }
95 } else if (FindInfoMatchesHelper(type.field_type(), info, &match)) { 95 } else if (FindInfoMatchesHelper(type, info, &match)) {
96 matched_text->push_back(match); 96 matched_text->push_back(match);
97 } 97 }
98 } 98 }
99 99
100 string16 NameInfo::GetFieldText(const AutofillType& type) const { 100 string16 NameInfo::GetFieldText(AutofillFieldType type) const {
101 AutofillFieldType field_type = type.field_type(); 101 if (type == NAME_FIRST)
102 if (field_type == NAME_FIRST)
103 return first(); 102 return first();
104 103
105 if (field_type == NAME_MIDDLE) 104 if (type == NAME_MIDDLE)
106 return middle(); 105 return middle();
107 106
108 if (field_type == NAME_LAST) 107 if (type == NAME_LAST)
109 return last(); 108 return last();
110 109
111 if (field_type == NAME_MIDDLE_INITIAL) 110 if (type == NAME_MIDDLE_INITIAL)
112 return MiddleInitial(); 111 return MiddleInitial();
113 112
114 if (field_type == NAME_FULL) 113 if (type == NAME_FULL)
115 return FullName(); 114 return FullName();
116 115
117 return string16(); 116 return string16();
118 } 117 }
119 118
120 void NameInfo::SetInfo(const AutofillType& type, const string16& value) { 119 void NameInfo::SetInfo(AutofillFieldType type, const string16& value) {
121 AutofillFieldType field_type = type.field_type(); 120 DCHECK_EQ(AutofillType::NAME, AutofillType(type).group());
122 DCHECK_EQ(AutofillType::NAME, type.group()); 121 if (type == NAME_FIRST)
123 if (field_type == NAME_FIRST)
124 SetFirst(value); 122 SetFirst(value);
125 else if (field_type == NAME_MIDDLE || field_type == NAME_MIDDLE_INITIAL) 123 else if (type == NAME_MIDDLE || type == NAME_MIDDLE_INITIAL)
126 SetMiddle(value); 124 SetMiddle(value);
127 else if (field_type == NAME_LAST) 125 else if (type == NAME_LAST)
128 SetLast(value); 126 SetLast(value);
129 else if (field_type == NAME_FULL) 127 else if (type == NAME_FULL)
130 SetFullName(value); 128 SetFullName(value);
131 else 129 else
132 NOTREACHED(); 130 NOTREACHED();
133 } 131 }
134 132
135 bool NameInfo::FindInfoMatchesHelper(const AutofillFieldType& field_type, 133 bool NameInfo::FindInfoMatchesHelper(AutofillFieldType field_type,
136 const string16& info, 134 const string16& info,
137 string16* match) const { 135 string16* match) const {
138 if (match == NULL) { 136 if (match == NULL) {
139 DLOG(ERROR) << "NULL match string passed in"; 137 DLOG(ERROR) << "NULL match string passed in";
140 return false; 138 return false;
141 } 139 }
142 140
143 match->clear(); 141 match->clear();
144 if (field_type == NAME_FIRST && 142 if (field_type == NAME_FIRST &&
145 StartsWith(first(), info, false)) { 143 StartsWith(first(), info, false)) {
146 *match = first(); 144 *match = first();
147 } else if (field_type == NAME_MIDDLE && 145 } else if (field_type == NAME_MIDDLE &&
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 if (email_ == text) 387 if (email_ == text)
390 possible_types->insert(EMAIL_ADDRESS); 388 possible_types->insert(EMAIL_ADDRESS);
391 } 389 }
392 390
393 void EmailInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const { 391 void EmailInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const {
394 DCHECK(available_types); 392 DCHECK(available_types);
395 if (!email_.empty()) 393 if (!email_.empty())
396 available_types->insert(EMAIL_ADDRESS); 394 available_types->insert(EMAIL_ADDRESS);
397 } 395 }
398 396
399 void EmailInfo::FindInfoMatches(const AutofillType& type, 397 void EmailInfo::FindInfoMatches(AutofillFieldType type,
400 const string16& info, 398 const string16& info,
401 std::vector<string16>* matched_text) const { 399 std::vector<string16>* matched_text) const {
402 DCHECK(matched_text); 400 DCHECK(matched_text);
403 401
404 string16 match; 402 string16 match;
405 if (type.field_type() == UNKNOWN_TYPE && StartsWith(email_, info, false)) { 403 if ((type == UNKNOWN_TYPE || type == EMAIL_ADDRESS) &&
404 StartsWith(email_, info, false)) {
406 matched_text->push_back(email_); 405 matched_text->push_back(email_);
407 } else if (type.field_type() == EMAIL_ADDRESS &&
408 StartsWith(email_, info, false)) {
409 matched_text->push_back(email_);
410 } 406 }
411 } 407 }
412 408
413 string16 EmailInfo::GetFieldText(const AutofillType& type) const { 409 string16 EmailInfo::GetFieldText(AutofillFieldType type) const {
414 AutofillFieldType field_type = type.field_type(); 410 if (type == EMAIL_ADDRESS)
415 if (field_type == EMAIL_ADDRESS)
416 return email_; 411 return email_;
417 412
418 return string16(); 413 return string16();
419 } 414 }
420 415
421 void EmailInfo::SetInfo(const AutofillType& type, const string16& value) { 416 void EmailInfo::SetInfo(AutofillFieldType type, const string16& value) {
422 DCHECK_EQ(AutofillType::EMAIL, type.group()); 417 DCHECK_EQ(EMAIL_ADDRESS, type);
423 email_ = value; 418 email_ = value;
424 } 419 }
425 420
426 CompanyInfo::CompanyInfo() {} 421 CompanyInfo::CompanyInfo() {}
427 422
428 CompanyInfo::CompanyInfo(const CompanyInfo& info) : FormGroup() { 423 CompanyInfo::CompanyInfo(const CompanyInfo& info) : FormGroup() {
429 *this = info; 424 *this = info;
430 } 425 }
431 426
432 CompanyInfo::~CompanyInfo() {} 427 CompanyInfo::~CompanyInfo() {}
(...skipping 14 matching lines...) Expand all
447 possible_types->insert(COMPANY_NAME); 442 possible_types->insert(COMPANY_NAME);
448 } 443 }
449 444
450 void CompanyInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const { 445 void CompanyInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const {
451 DCHECK(available_types); 446 DCHECK(available_types);
452 447
453 if (!company_name_.empty()) 448 if (!company_name_.empty())
454 available_types->insert(COMPANY_NAME); 449 available_types->insert(COMPANY_NAME);
455 } 450 }
456 451
457 void CompanyInfo::FindInfoMatches(const AutofillType& type, 452 void CompanyInfo::FindInfoMatches(AutofillFieldType type,
458 const string16& info, 453 const string16& info,
459 std::vector<string16>* matched_text) const { 454 std::vector<string16>* matched_text) const {
460 DCHECK(matched_text); 455 DCHECK(matched_text);
461 456
462 string16 match; 457 string16 match;
463 if (type.field_type() == UNKNOWN_TYPE && 458 if ((type == UNKNOWN_TYPE || type == COMPANY_NAME) &&
464 StartsWith(company_name_, info, false)) {
465 matched_text->push_back(company_name_);
466 } else if (type.field_type() == COMPANY_NAME &&
467 StartsWith(company_name_, info, false)) { 459 StartsWith(company_name_, info, false)) {
468 matched_text->push_back(company_name_); 460 matched_text->push_back(company_name_);
469 } 461 }
470 } 462 }
471 463
472 string16 CompanyInfo::GetFieldText(const AutofillType& type) const { 464 string16 CompanyInfo::GetFieldText(AutofillFieldType type) const {
473 AutofillFieldType field_type = type.field_type(); 465 if (type == COMPANY_NAME)
474
475 if (field_type == COMPANY_NAME)
476 return company_name_; 466 return company_name_;
477 467
478 return string16(); 468 return string16();
479 } 469 }
480 470
481 void CompanyInfo::SetInfo(const AutofillType& type, const string16& value) { 471 void CompanyInfo::SetInfo(AutofillFieldType type, const string16& value) {
482 DCHECK_EQ(AutofillType::COMPANY, type.group()); 472 DCHECK_EQ(COMPANY_NAME, type);
483 company_name_ = value; 473 company_name_ = value;
484 } 474 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/contact_info.h ('k') | chrome/browser/autofill/credit_card.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698