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

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

Issue 2884051: Merge 53276 - AutoFill Empty profiles should not be saved from AutoFillDialog... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/472/src/
Patch Set: Created 10 years, 4 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/personal_data_manager.cc » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 299 }
300 300
301 return true; 301 return true;
302 } 302 }
303 303
304 bool CreditCard::operator!=(const CreditCard& creditcard) const { 304 bool CreditCard::operator!=(const CreditCard& creditcard) const {
305 return !operator==(creditcard); 305 return !operator==(creditcard);
306 } 306 }
307 307
308 // Use the Luhn formula to validate the number. 308 // Use the Luhn formula to validate the number.
309 // static
309 bool CreditCard::IsCreditCardNumber(const string16& text) { 310 bool CreditCard::IsCreditCardNumber(const string16& text) {
310 string16 number; 311 string16 number;
311 RemoveChars(text, kCreditCardSeparators.c_str(), &number); 312 RemoveChars(text, kCreditCardSeparators.c_str(), &number);
312 313
313 int sum = 0; 314 int sum = 0;
314 bool odd = false; 315 bool odd = false;
315 string16::reverse_iterator iter; 316 string16::reverse_iterator iter;
316 for (iter = number.rbegin(); iter != number.rend(); ++iter) { 317 for (iter = number.rbegin(); iter != number.rend(); ++iter) {
317 if (!IsAsciiDigit(*iter)) 318 if (!IsAsciiDigit(*iter))
318 return false; 319 return false;
319 320
320 int digit = *iter - '0'; 321 int digit = *iter - '0';
321 if (odd) { 322 if (odd) {
322 digit *= 2; 323 digit *= 2;
323 sum += digit / 10 + digit % 10; 324 sum += digit / 10 + digit % 10;
324 } else { 325 } else {
325 sum += digit; 326 sum += digit;
326 } 327 }
327 odd = !odd; 328 odd = !odd;
328 } 329 }
329 330
330 return (sum % 10) == 0; 331 return (sum % 10) == 0;
331 } 332 }
332 333
334 bool CreditCard::IsEmpty() const {
335 FieldTypeSet types;
336 GetAvailableFieldTypes(&types);
337 return types.empty() && billing_address().empty();
338 }
339
340
333 string16 CreditCard::ExpirationMonthAsString() const { 341 string16 CreditCard::ExpirationMonthAsString() const {
334 if (expiration_month_ == 0) 342 if (expiration_month_ == 0)
335 return string16(); 343 return string16();
336 344
337 string16 month = IntToString16(expiration_month_); 345 string16 month = IntToString16(expiration_month_);
338 if (expiration_month_ >= 10) 346 if (expiration_month_ >= 10)
339 return month; 347 return month;
340 348
341 string16 zero = ASCIIToUTF16("0"); 349 string16 zero = ASCIIToUTF16("0");
342 zero.append(month); 350 zero.append(month);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_TYPE))) 518 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_TYPE)))
511 << " " 519 << " "
512 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER))) 520 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)))
513 << " " 521 << " "
514 << UTF16ToUTF8(creditcard.GetFieldText( 522 << UTF16ToUTF8(creditcard.GetFieldText(
515 AutoFillType(CREDIT_CARD_EXP_MONTH))) 523 AutoFillType(CREDIT_CARD_EXP_MONTH)))
516 << " " 524 << " "
517 << UTF16ToUTF8(creditcard.GetFieldText( 525 << UTF16ToUTF8(creditcard.GetFieldText(
518 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); 526 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)));
519 } 527 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/credit_card.h ('k') | chrome/browser/autofill/personal_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698