| OLD | NEW |
| 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> |
| 11 #include <ostream> | 11 #include <ostream> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/guid.h" | 14 #include "base/guid.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "components/autofill/core/browser/autofill_data_util.h" | 25 #include "components/autofill/core/browser/autofill_data_util.h" |
| 26 #include "components/autofill/core/browser/autofill_field.h" | 26 #include "components/autofill/core/browser/autofill_field.h" |
| 27 #include "components/autofill/core/browser/autofill_type.h" | 27 #include "components/autofill/core/browser/autofill_type.h" |
| 28 #include "components/autofill/core/browser/validation.h" | 28 #include "components/autofill/core/browser/validation.h" |
| 29 #include "components/autofill/core/common/autofill_clock.h" |
| 29 #include "components/autofill/core/common/autofill_l10n_util.h" | 30 #include "components/autofill/core/common/autofill_l10n_util.h" |
| 30 #include "components/autofill/core/common/autofill_regexes.h" | 31 #include "components/autofill/core/common/autofill_regexes.h" |
| 31 #include "components/autofill/core/common/form_field_data.h" | 32 #include "components/autofill/core/common/form_field_data.h" |
| 32 #include "grit/components_scaled_resources.h" | 33 #include "grit/components_scaled_resources.h" |
| 33 #include "grit/components_strings.h" | 34 #include "grit/components_strings.h" |
| 34 #include "third_party/icu/source/common/unicode/uloc.h" | 35 #include "third_party/icu/source/common/unicode/uloc.h" |
| 35 #include "third_party/icu/source/i18n/unicode/dtfmtsym.h" | 36 #include "third_party/icu/source/i18n/unicode/dtfmtsym.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 37 | 38 |
| 38 using base::ASCIIToUTF16; | 39 using base::ASCIIToUTF16; |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 // If |expiration_year| is beyond this millenium, or more than 2 digits but | 467 // If |expiration_year| is beyond this millenium, or more than 2 digits but |
| 467 // before the current millenium (e.g. "545", "1995"), return. What is left are | 468 // before the current millenium (e.g. "545", "1995"), return. What is left are |
| 468 // values like "45" or "2018". | 469 // values like "45" or "2018". |
| 469 if (expiration_year > 2999 || | 470 if (expiration_year > 2999 || |
| 470 (expiration_year > 99 && expiration_year < 2000)) | 471 (expiration_year > 99 && expiration_year < 2000)) |
| 471 return; | 472 return; |
| 472 | 473 |
| 473 // Will normalize 2-digit years to the 4-digit version. | 474 // Will normalize 2-digit years to the 4-digit version. |
| 474 if (expiration_year > 0 && expiration_year < 100) { | 475 if (expiration_year > 0 && expiration_year < 100) { |
| 475 base::Time::Exploded now_exploded; | 476 base::Time::Exploded now_exploded; |
| 476 base::Time::Now().LocalExplode(&now_exploded); | 477 AutofillClock::Now().LocalExplode(&now_exploded); |
| 477 expiration_year += (now_exploded.year / 100) * 100; | 478 expiration_year += (now_exploded.year / 100) * 100; |
| 478 } | 479 } |
| 479 | 480 |
| 480 expiration_year_ = expiration_year; | 481 expiration_year_ = expiration_year; |
| 481 } | 482 } |
| 482 | 483 |
| 483 base::string16 CreditCard::LastFourDigits() const { | 484 base::string16 CreditCard::LastFourDigits() const { |
| 484 static const size_t kNumLastDigits = 4; | 485 static const size_t kNumLastDigits = 4; |
| 485 | 486 |
| 486 base::string16 number = StripSeparators(number_); | 487 base::string16 number = StripSeparators(number_); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 return false; | 544 return false; |
| 544 } | 545 } |
| 545 | 546 |
| 546 // Heuristically aggregated data should never overwrite verified data, with | 547 // Heuristically aggregated data should never overwrite verified data, with |
| 547 // the exception of expired verified cards. Instead, discard any heuristically | 548 // the exception of expired verified cards. Instead, discard any heuristically |
| 548 // aggregated credit cards that disagree with explicitly entered data, so that | 549 // aggregated credit cards that disagree with explicitly entered data, so that |
| 549 // the UI is not cluttered with duplicate cards. | 550 // the UI is not cluttered with duplicate cards. |
| 550 if (this->IsVerified() && !imported_card.IsVerified()) { | 551 if (this->IsVerified() && !imported_card.IsVerified()) { |
| 551 // If the original card is expired and the imported card is not, and the | 552 // If the original card is expired and the imported card is not, and the |
| 552 // name on the cards are identical, update the expiration date. | 553 // name on the cards are identical, update the expiration date. |
| 553 if (this->IsExpired(base::Time::Now()) && | 554 if (this->IsExpired(AutofillClock::Now()) && |
| 554 !imported_card.IsExpired(base::Time::Now()) && | 555 !imported_card.IsExpired(AutofillClock::Now()) && |
| 555 (name_on_card_ == imported_card.name_on_card_)) { | 556 (name_on_card_ == imported_card.name_on_card_)) { |
| 556 DCHECK(imported_card.expiration_month_ && imported_card.expiration_year_); | 557 DCHECK(imported_card.expiration_month_ && imported_card.expiration_year_); |
| 557 expiration_month_ = imported_card.expiration_month_; | 558 expiration_month_ = imported_card.expiration_month_; |
| 558 expiration_year_ = imported_card.expiration_year_; | 559 expiration_year_ = imported_card.expiration_year_; |
| 559 } | 560 } |
| 560 return true; | 561 return true; |
| 561 } | 562 } |
| 562 | 563 |
| 563 set_origin(imported_card.origin()); | 564 set_origin(imported_card.origin()); |
| 564 | 565 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 } | 653 } |
| 653 | 654 |
| 654 bool CreditCard::IsEmpty(const std::string& app_locale) const { | 655 bool CreditCard::IsEmpty(const std::string& app_locale) const { |
| 655 ServerFieldTypeSet types; | 656 ServerFieldTypeSet types; |
| 656 GetNonEmptyTypes(app_locale, &types); | 657 GetNonEmptyTypes(app_locale, &types); |
| 657 return types.empty(); | 658 return types.empty(); |
| 658 } | 659 } |
| 659 | 660 |
| 660 bool CreditCard::IsValid() const { | 661 bool CreditCard::IsValid() const { |
| 661 return IsValidCreditCardNumber(number_) && | 662 return IsValidCreditCardNumber(number_) && |
| 662 IsValidCreditCardExpirationDate( | 663 IsValidCreditCardExpirationDate(expiration_year_, expiration_month_, |
| 663 expiration_year_, expiration_month_, base::Time::Now()); | 664 AutofillClock::Now()); |
| 664 } | 665 } |
| 665 | 666 |
| 666 void CreditCard::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { | 667 void CreditCard::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { |
| 667 supported_types->insert(CREDIT_CARD_NAME_FULL); | 668 supported_types->insert(CREDIT_CARD_NAME_FULL); |
| 668 supported_types->insert(CREDIT_CARD_NAME_FIRST); | 669 supported_types->insert(CREDIT_CARD_NAME_FIRST); |
| 669 supported_types->insert(CREDIT_CARD_NAME_LAST); | 670 supported_types->insert(CREDIT_CARD_NAME_LAST); |
| 670 supported_types->insert(CREDIT_CARD_NUMBER); | 671 supported_types->insert(CREDIT_CARD_NUMBER); |
| 671 supported_types->insert(CREDIT_CARD_TYPE); | 672 supported_types->insert(CREDIT_CARD_TYPE); |
| 672 supported_types->insert(CREDIT_CARD_EXP_MONTH); | 673 supported_types->insert(CREDIT_CARD_EXP_MONTH); |
| 673 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); | 674 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 number_ = number; | 779 number_ = number; |
| 779 | 780 |
| 780 // Set the type based on the card number, but only for full numbers, not | 781 // Set the type based on the card number, but only for full numbers, not |
| 781 // when we have masked cards from the server (last 4 digits). | 782 // when we have masked cards from the server (last 4 digits). |
| 782 if (record_type_ != MASKED_SERVER_CARD) | 783 if (record_type_ != MASKED_SERVER_CARD) |
| 783 type_ = GetCreditCardType(StripSeparators(number_)); | 784 type_ = GetCreditCardType(StripSeparators(number_)); |
| 784 } | 785 } |
| 785 | 786 |
| 786 void CreditCard::RecordAndLogUse() { | 787 void CreditCard::RecordAndLogUse() { |
| 787 UMA_HISTOGRAM_COUNTS_1000("Autofill.DaysSinceLastUse.CreditCard", | 788 UMA_HISTOGRAM_COUNTS_1000("Autofill.DaysSinceLastUse.CreditCard", |
| 788 (base::Time::Now() - use_date()).InDays()); | 789 (AutofillClock::Now() - use_date()).InDays()); |
| 789 RecordUse(); | 790 RecordUse(); |
| 790 } | 791 } |
| 791 | 792 |
| 792 // static | 793 // static |
| 793 bool CreditCard::ConvertMonth(const base::string16& month, | 794 bool CreditCard::ConvertMonth(const base::string16& month, |
| 794 const std::string& app_locale, | 795 const std::string& app_locale, |
| 795 int* num) { | 796 int* num) { |
| 796 if (month.empty()) | 797 if (month.empty()) |
| 797 return false; | 798 return false; |
| 798 | 799 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 const char kDinersCard[] = "dinersCC"; | 873 const char kDinersCard[] = "dinersCC"; |
| 873 const char kDiscoverCard[] = "discoverCC"; | 874 const char kDiscoverCard[] = "discoverCC"; |
| 874 const char kGenericCard[] = "genericCC"; | 875 const char kGenericCard[] = "genericCC"; |
| 875 const char kJCBCard[] = "jcbCC"; | 876 const char kJCBCard[] = "jcbCC"; |
| 876 const char kMasterCard[] = "masterCardCC"; | 877 const char kMasterCard[] = "masterCardCC"; |
| 877 const char kMirCard[] = "mirCC"; | 878 const char kMirCard[] = "mirCC"; |
| 878 const char kUnionPay[] = "unionPayCC"; | 879 const char kUnionPay[] = "unionPayCC"; |
| 879 const char kVisaCard[] = "visaCC"; | 880 const char kVisaCard[] = "visaCC"; |
| 880 | 881 |
| 881 } // namespace autofill | 882 } // namespace autofill |
| OLD | NEW |