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

Side by Side Diff: components/autofill/core/browser/credit_card.cc

Issue 1867523003: [Autofill] Suggest expired credit cards last. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactored CC suggestions to use IsExpired Created 4 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/core/browser/credit_card.h" 5 #include "components/autofill/core/browser/credit_card.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 expiration_month_ != 0 && 640 expiration_month_ != 0 &&
641 expiration_year_ != 0; 641 expiration_year_ != 0;
642 } 642 }
643 643
644 bool CreditCard::IsValid() const { 644 bool CreditCard::IsValid() const {
645 return IsValidCreditCardNumber(number_) && 645 return IsValidCreditCardNumber(number_) &&
646 IsValidCreditCardExpirationDate( 646 IsValidCreditCardExpirationDate(
647 expiration_year_, expiration_month_, base::Time::Now()); 647 expiration_year_, expiration_month_, base::Time::Now());
648 } 648 }
649 649
650 bool CreditCard::IsExpired(base::Time::Exploded time) const {
651 // Credit cards with no saved expiration are never considered expired.
652 if (expiration_month_ == 0 && expiration_year_ == 0)
653 return false;
654
655 // Credit cards expire at the end of the specified month.
656 return expiration_year_ < time.year ||
657 (expiration_year_ == time.year && expiration_month_ < time.month);
658 }
659
650 void CreditCard::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { 660 void CreditCard::GetSupportedTypes(ServerFieldTypeSet* supported_types) const {
651 supported_types->insert(CREDIT_CARD_NAME_FULL); 661 supported_types->insert(CREDIT_CARD_NAME_FULL);
652 supported_types->insert(CREDIT_CARD_NAME_FIRST); 662 supported_types->insert(CREDIT_CARD_NAME_FIRST);
653 supported_types->insert(CREDIT_CARD_NAME_LAST); 663 supported_types->insert(CREDIT_CARD_NAME_LAST);
654 supported_types->insert(CREDIT_CARD_NUMBER); 664 supported_types->insert(CREDIT_CARD_NUMBER);
655 supported_types->insert(CREDIT_CARD_TYPE); 665 supported_types->insert(CREDIT_CARD_TYPE);
656 supported_types->insert(CREDIT_CARD_EXP_MONTH); 666 supported_types->insert(CREDIT_CARD_EXP_MONTH);
657 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); 667 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR);
658 supported_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR); 668 supported_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR);
659 supported_types->insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR); 669 supported_types->insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 const char kAmericanExpressCard[] = "americanExpressCC"; 808 const char kAmericanExpressCard[] = "americanExpressCC";
799 const char kDinersCard[] = "dinersCC"; 809 const char kDinersCard[] = "dinersCC";
800 const char kDiscoverCard[] = "discoverCC"; 810 const char kDiscoverCard[] = "discoverCC";
801 const char kGenericCard[] = "genericCC"; 811 const char kGenericCard[] = "genericCC";
802 const char kJCBCard[] = "jcbCC"; 812 const char kJCBCard[] = "jcbCC";
803 const char kMasterCard[] = "masterCardCC"; 813 const char kMasterCard[] = "masterCardCC";
804 const char kUnionPay[] = "unionPayCC"; 814 const char kUnionPay[] = "unionPayCC";
805 const char kVisaCard[] = "visaCC"; 815 const char kVisaCard[] = "visaCC";
806 816
807 } // namespace autofill 817 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698