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

Side by Side Diff: chrome/browser/autofill/credit_card.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/credit_card.h ('k') | chrome/browser/autofill/form_group.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/credit_card.h" 5 #include "chrome/browser/autofill/credit_card.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 if (!Expiration2DigitYearAsString().empty()) 178 if (!Expiration2DigitYearAsString().empty())
179 available_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); 179 available_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR);
180 180
181 if (!Expiration4DigitYearAsString().empty()) 181 if (!Expiration4DigitYearAsString().empty())
182 available_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR); 182 available_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR);
183 183
184 if (!number().empty()) 184 if (!number().empty())
185 available_types->insert(CREDIT_CARD_NUMBER); 185 available_types->insert(CREDIT_CARD_NUMBER);
186 } 186 }
187 187
188 void CreditCard::FindInfoMatches(const AutofillType& type, 188 void CreditCard::FindInfoMatches(AutofillFieldType type,
189 const string16& info, 189 const string16& info,
190 std::vector<string16>* matched_text) const { 190 std::vector<string16>* matched_text) const {
191 DCHECK(matched_text); 191 DCHECK(matched_text);
192 192
193 string16 match; 193 string16 match;
194 switch (type.field_type()) { 194 switch (type) {
195 case CREDIT_CARD_NUMBER: { 195 case CREDIT_CARD_NUMBER: {
196 // Because the credit card number is encrypted and we are not able to do 196 // Because the credit card number is encrypted and we are not able to do
197 // comparisons with it we will say that any field that is known to be a 197 // comparisons with it we will say that any field that is known to be a
198 // credit card number field will match all credit card numbers. 198 // credit card number field will match all credit card numbers.
199 string16 text = GetPreviewText(AutofillType(CREDIT_CARD_NUMBER)); 199 string16 text = GetPreviewText(CREDIT_CARD_NUMBER);
200 if (!text.empty()) 200 if (!text.empty())
201 matched_text->push_back(text); 201 matched_text->push_back(text);
202 break; 202 break;
203 } 203 }
204 204
205 case CREDIT_CARD_VERIFICATION_CODE: 205 case CREDIT_CARD_VERIFICATION_CODE:
206 NOTREACHED(); 206 NOTREACHED();
207 break; 207 break;
208 208
209 case UNKNOWN_TYPE: 209 case UNKNOWN_TYPE:
210 for (int i = 0; i < kAutoFillCreditCardLength; ++i) { 210 for (int i = 0; i < kAutoFillCreditCardLength; ++i) {
211 if (FindInfoMatchesHelper(kAutoFillCreditCardTypes[i], info, &match)) 211 if (FindInfoMatchesHelper(kAutoFillCreditCardTypes[i], info, &match))
212 matched_text->push_back(match); 212 matched_text->push_back(match);
213 } 213 }
214 break; 214 break;
215 215
216 default: 216 default:
217 if (FindInfoMatchesHelper(type.field_type(), info, &match)) 217 if (FindInfoMatchesHelper(type, info, &match))
218 matched_text->push_back(match); 218 matched_text->push_back(match);
219 break; 219 break;
220 } 220 }
221 } 221 }
222 222
223 string16 CreditCard::GetFieldText(const AutofillType& type) const { 223 string16 CreditCard::GetFieldText(AutofillFieldType type) const {
224 switch (type.field_type()) { 224 switch (type) {
225 case CREDIT_CARD_NAME: 225 case CREDIT_CARD_NAME:
226 return name_on_card(); 226 return name_on_card();
227 227
228 case CREDIT_CARD_EXP_MONTH: 228 case CREDIT_CARD_EXP_MONTH:
229 return ExpirationMonthAsString(); 229 return ExpirationMonthAsString();
230 230
231 case CREDIT_CARD_EXP_2_DIGIT_YEAR: 231 case CREDIT_CARD_EXP_2_DIGIT_YEAR:
232 return Expiration2DigitYearAsString(); 232 return Expiration2DigitYearAsString();
233 233
234 case CREDIT_CARD_EXP_4_DIGIT_YEAR: 234 case CREDIT_CARD_EXP_4_DIGIT_YEAR:
(...skipping 25 matching lines...) Expand all
260 case CREDIT_CARD_VERIFICATION_CODE: 260 case CREDIT_CARD_VERIFICATION_CODE:
261 NOTREACHED(); 261 NOTREACHED();
262 return string16(); 262 return string16();
263 263
264 default: 264 default:
265 // ComputeDataPresentForArray will hit this repeatedly. 265 // ComputeDataPresentForArray will hit this repeatedly.
266 return string16(); 266 return string16();
267 } 267 }
268 } 268 }
269 269
270 string16 CreditCard::GetPreviewText(const AutofillType& type) const { 270 string16 CreditCard::GetPreviewText(AutofillFieldType type) const {
271 switch (type.field_type()) { 271 switch (type) {
272 case CREDIT_CARD_NUMBER: 272 case CREDIT_CARD_NUMBER:
273 return last_four_digits(); 273 return last_four_digits();
274 274
275 case CREDIT_CARD_VERIFICATION_CODE: 275 case CREDIT_CARD_VERIFICATION_CODE:
276 NOTREACHED(); 276 NOTREACHED();
277 return string16(); 277 return string16();
278 278
279 default: 279 default:
280 return GetFieldText(type); 280 return GetFieldText(type);
281 } 281 }
282 } 282 }
283 283
284 void CreditCard::SetInfo(const AutofillType& type, const string16& value) { 284 void CreditCard::SetInfo(AutofillFieldType type, const string16& value) {
285 switch (type.field_type()) { 285 switch (type) {
286 case CREDIT_CARD_NAME: 286 case CREDIT_CARD_NAME:
287 set_name_on_card(value); 287 set_name_on_card(value);
288 break; 288 break;
289 289
290 case CREDIT_CARD_EXP_MONTH: 290 case CREDIT_CARD_EXP_MONTH:
291 SetExpirationMonthFromString(value); 291 SetExpirationMonthFromString(value);
292 break; 292 break;
293 293
294 case CREDIT_CARD_EXP_2_DIGIT_YEAR: 294 case CREDIT_CARD_EXP_2_DIGIT_YEAR:
295 // This is a read-only attribute. 295 // This is a read-only attribute.
(...skipping 19 matching lines...) Expand all
315 set_last_four_digits(value.substr(value.length() - 4)); 315 set_last_four_digits(value.substr(value.length() - 4));
316 else 316 else
317 set_last_four_digits(string16()); 317 set_last_four_digits(string16());
318 } break; 318 } break;
319 319
320 case CREDIT_CARD_VERIFICATION_CODE: 320 case CREDIT_CARD_VERIFICATION_CODE:
321 NOTREACHED(); 321 NOTREACHED();
322 break; 322 break;
323 323
324 default: 324 default:
325 DLOG(ERROR) << "Attempting to set unknown info-type " 325 DLOG(ERROR) << "Attempting to set unknown info-type " << type;
326 << type.field_type();
327 break; 326 break;
328 } 327 }
329 } 328 }
330 329
331 const string16 CreditCard::Label() const { 330 const string16 CreditCard::Label() const {
332 return label_; 331 return label_;
333 } 332 }
334 333
335 void CreditCard::SetInfoForMonthInputType(const string16& value) { 334 void CreditCard::SetInfoForMonthInputType(const string16& value) {
336 // Check if |text| is "yyyy-mm" format first, and check normal month format. 335 // Check if |text| is "yyyy-mm" format first, and check normal month format.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 404
406 int CreditCard::Compare(const CreditCard& credit_card) const { 405 int CreditCard::Compare(const CreditCard& credit_card) const {
407 // The following CreditCard field types are the only types we store in the 406 // The following CreditCard field types are the only types we store in the
408 // WebDB so far, so we're only concerned with matching these types in the 407 // WebDB so far, so we're only concerned with matching these types in the
409 // credit card. 408 // credit card.
410 const AutofillFieldType types[] = { CREDIT_CARD_NAME, 409 const AutofillFieldType types[] = { CREDIT_CARD_NAME,
411 CREDIT_CARD_NUMBER, 410 CREDIT_CARD_NUMBER,
412 CREDIT_CARD_EXP_MONTH, 411 CREDIT_CARD_EXP_MONTH,
413 CREDIT_CARD_EXP_4_DIGIT_YEAR }; 412 CREDIT_CARD_EXP_4_DIGIT_YEAR };
414 for (size_t index = 0; index < arraysize(types); ++index) { 413 for (size_t index = 0; index < arraysize(types); ++index) {
415 int comparison = GetFieldText(AutofillType(types[index])).compare( 414 int comparison = GetFieldText(types[index]).compare(
416 credit_card.GetFieldText(AutofillType(types[index]))); 415 credit_card.GetFieldText(types[index]));
417 if (comparison != 0) 416 if (comparison != 0)
418 return comparison; 417 return comparison;
419 } 418 }
420 419
421 return 0; 420 return 0;
422 } 421 }
423 422
424 bool CreditCard::operator==(const CreditCard& credit_card) const { 423 bool CreditCard::operator==(const CreditCard& credit_card) const {
425 if (label_ != credit_card.label_ || guid_ != credit_card.guid_) 424 if (label_ != credit_card.label_ || guid_ != credit_card.guid_)
426 return false; 425 return false;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 521
523 void CreditCard::set_expiration_year(int expiration_year) { 522 void CreditCard::set_expiration_year(int expiration_year) {
524 if (expiration_year != 0 && 523 if (expiration_year != 0 &&
525 (expiration_year < 2006 || expiration_year > 10000)) { 524 (expiration_year < 2006 || expiration_year > 10000)) {
526 return; 525 return;
527 } 526 }
528 527
529 expiration_year_ = expiration_year; 528 expiration_year_ = expiration_year;
530 } 529 }
531 530
532 bool CreditCard::FindInfoMatchesHelper(const AutofillFieldType& field_type, 531 bool CreditCard::FindInfoMatchesHelper(AutofillFieldType field_type,
533 const string16& info, 532 const string16& info,
534 string16* match) const { 533 string16* match) const {
535 DCHECK(match); 534 DCHECK(match);
536 535
537 match->clear(); 536 match->clear();
538 switch (field_type) { 537 switch (field_type) {
539 case CREDIT_CARD_NAME: { 538 case CREDIT_CARD_NAME: {
540 if (StartsWith(name_on_card(), info, false)) 539 if (StartsWith(name_on_card(), info, false))
541 *match = name_on_card(); 540 *match = name_on_card();
542 break; 541 break;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 return true; 634 return true;
636 } 635 }
637 636
638 // So we can compare CreditCards with EXPECT_EQ(). 637 // So we can compare CreditCards with EXPECT_EQ().
639 std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) { 638 std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) {
640 return os 639 return os
641 << UTF16ToUTF8(credit_card.Label()) 640 << UTF16ToUTF8(credit_card.Label())
642 << " " 641 << " "
643 << credit_card.guid() 642 << credit_card.guid()
644 << " " 643 << " "
645 << UTF16ToUTF8(credit_card.GetFieldText(AutofillType(CREDIT_CARD_NAME))) 644 << UTF16ToUTF8(credit_card.GetFieldText(CREDIT_CARD_NAME))
646 << " " 645 << " "
647 << UTF16ToUTF8(credit_card.GetFieldText(AutofillType(CREDIT_CARD_TYPE))) 646 << UTF16ToUTF8(credit_card.GetFieldText(CREDIT_CARD_TYPE))
648 << " " 647 << " "
649 << UTF16ToUTF8(credit_card.GetFieldText(AutofillType(CREDIT_CARD_NUMBER))) 648 << UTF16ToUTF8(credit_card.GetFieldText(CREDIT_CARD_NUMBER))
650 << " " 649 << " "
651 << UTF16ToUTF8(credit_card.GetFieldText( 650 << UTF16ToUTF8(credit_card.GetFieldText(CREDIT_CARD_EXP_MONTH))
652 AutofillType(CREDIT_CARD_EXP_MONTH)))
653 << " " 651 << " "
654 << UTF16ToUTF8(credit_card.GetFieldText( 652 << UTF16ToUTF8(credit_card.GetFieldText(CREDIT_CARD_EXP_4_DIGIT_YEAR));
655 AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)));
656 } 653 }
657 654
658 // These values must match the values in WebKitClientImpl in webkit/glue. We 655 // These values must match the values in WebKitClientImpl in webkit/glue. We
659 // send these strings to WK, which then asks WebKitClientImpl to load the image 656 // send these strings to WK, which then asks WebKitClientImpl to load the image
660 // data. 657 // data.
661 const char* const kAmericanExpressCard = "americanExpressCC"; 658 const char* const kAmericanExpressCard = "americanExpressCC";
662 const char* const kDinersCard = "dinersCC"; 659 const char* const kDinersCard = "dinersCC";
663 const char* const kDiscoverCard = "discoverCC"; 660 const char* const kDiscoverCard = "discoverCC";
664 const char* const kGenericCard = "genericCC"; 661 const char* const kGenericCard = "genericCC";
665 const char* const kJCBCard = "jcbCC"; 662 const char* const kJCBCard = "jcbCC";
666 const char* const kMasterCard = "masterCardCC"; 663 const char* const kMasterCard = "masterCardCC";
667 const char* const kSoloCard = "soloCC"; 664 const char* const kSoloCard = "soloCC";
668 const char* const kVisaCard = "visaCC"; 665 const char* const kVisaCard = "visaCC";
OLDNEW
« no previous file with comments | « chrome/browser/autofill/credit_card.h ('k') | chrome/browser/autofill/form_group.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698