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

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

Issue 1926553002: Prompt for expiration date for local cards. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_UNION_PAY); 74 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_UNION_PAY);
75 if (type == kVisaCard) 75 if (type == kVisaCard)
76 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); 76 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA);
77 77
78 // If you hit this DCHECK, the above list of cases needs to be updated to 78 // If you hit this DCHECK, the above list of cases needs to be updated to
79 // include a new card. 79 // include a new card.
80 DCHECK_EQ(kGenericCard, type); 80 DCHECK_EQ(kGenericCard, type);
81 return base::string16(); 81 return base::string16();
82 } 82 }
83 83
84 bool IsInThePast(int month, int year) {
Mathieu 2016/04/27 12:09:24 Could you use CreditCard::IsExpired? https://code.
please use gerrit instead 2016/04/27 18:05:44 Done.
85 base::Time::Exploded today;
86 base::Time::Now().LocalExplode(&today);
87 return today.year > year || (today.year == year && today.month > month);
88 }
89
84 } // namespace 90 } // namespace
85 91
86 CreditCard::CreditCard(const std::string& guid, const std::string& origin) 92 CreditCard::CreditCard(const std::string& guid, const std::string& origin)
87 : AutofillDataModel(guid, origin), 93 : AutofillDataModel(guid, origin),
88 record_type_(LOCAL_CARD), 94 record_type_(LOCAL_CARD),
89 type_(kGenericCard), 95 type_(kGenericCard),
90 expiration_month_(0), 96 expiration_month_(0),
91 expiration_year_(0), 97 expiration_year_(0),
92 server_status_(OK) {} 98 server_status_(OK) {}
93 99
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 void CreditCard::SetServerStatus(ServerStatus status) { 264 void CreditCard::SetServerStatus(ServerStatus status) {
259 DCHECK_NE(LOCAL_CARD, record_type()); 265 DCHECK_NE(LOCAL_CARD, record_type());
260 server_status_ = status; 266 server_status_ = status;
261 } 267 }
262 268
263 CreditCard::ServerStatus CreditCard::GetServerStatus() const { 269 CreditCard::ServerStatus CreditCard::GetServerStatus() const {
264 DCHECK_NE(LOCAL_CARD, record_type()); 270 DCHECK_NE(LOCAL_CARD, record_type());
265 return server_status_; 271 return server_status_;
266 } 272 }
267 273
274 bool CreditCard::ShouldUpdateExpiration() const {
275 switch (record_type()) {
276 case LOCAL_CARD:
277 return IsInThePast(expiration_month(), expiration_year());
278 case MASKED_SERVER_CARD:
279 case FULL_SERVER_CARD:
280 return server_status_ == EXPIRED ||
281 IsInThePast(expiration_month(), expiration_year());
282 }
283 NOTREACHED();
284 return false;
285 }
286
268 base::string16 CreditCard::GetRawInfo(ServerFieldType type) const { 287 base::string16 CreditCard::GetRawInfo(ServerFieldType type) const {
269 DCHECK_EQ(CREDIT_CARD, AutofillType(type).group()); 288 DCHECK_EQ(CREDIT_CARD, AutofillType(type).group());
270 switch (type) { 289 switch (type) {
271 case CREDIT_CARD_NAME_FULL: 290 case CREDIT_CARD_NAME_FULL:
272 return name_on_card_; 291 return name_on_card_;
273 292
274 case CREDIT_CARD_NAME_FIRST: 293 case CREDIT_CARD_NAME_FIRST:
275 return data_util::SplitName(name_on_card_).given; 294 return data_util::SplitName(name_on_card_).given;
276 295
277 case CREDIT_CARD_NAME_LAST: 296 case CREDIT_CARD_NAME_LAST:
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 const char kAmericanExpressCard[] = "americanExpressCC"; 826 const char kAmericanExpressCard[] = "americanExpressCC";
808 const char kDinersCard[] = "dinersCC"; 827 const char kDinersCard[] = "dinersCC";
809 const char kDiscoverCard[] = "discoverCC"; 828 const char kDiscoverCard[] = "discoverCC";
810 const char kGenericCard[] = "genericCC"; 829 const char kGenericCard[] = "genericCC";
811 const char kJCBCard[] = "jcbCC"; 830 const char kJCBCard[] = "jcbCC";
812 const char kMasterCard[] = "masterCardCC"; 831 const char kMasterCard[] = "masterCardCC";
813 const char kUnionPay[] = "unionPayCC"; 832 const char kUnionPay[] = "unionPayCC";
814 const char kVisaCard[] = "visaCC"; 833 const char kVisaCard[] = "visaCC";
815 834
816 } // namespace autofill 835 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698