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

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

Issue 2607043002: [Autofill] Credit Card Autofill Last Used Date Experiment (Closed)
Patch Set: Resolved patch conflicts Created 3 years, 10 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>
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/i18n/time_formatting.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
18 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_split.h" 21 #include "base/strings/string_split.h"
21 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
23 #include "base/time/time.h" 24 #include "base/time/time.h"
24 #include "build/build_config.h" 25 #include "build/build_config.h"
25 #include "components/autofill/core/browser/autofill_data_util.h" 26 #include "components/autofill/core/browser/autofill_data_util.h"
27 #include "components/autofill/core/browser/autofill_experiments.h"
26 #include "components/autofill/core/browser/autofill_field.h" 28 #include "components/autofill/core/browser/autofill_field.h"
27 #include "components/autofill/core/browser/autofill_type.h" 29 #include "components/autofill/core/browser/autofill_type.h"
28 #include "components/autofill/core/browser/validation.h" 30 #include "components/autofill/core/browser/validation.h"
29 #include "components/autofill/core/common/autofill_clock.h" 31 #include "components/autofill/core/common/autofill_clock.h"
30 #include "components/autofill/core/common/autofill_l10n_util.h" 32 #include "components/autofill/core/common/autofill_l10n_util.h"
31 #include "components/autofill/core/common/autofill_regexes.h" 33 #include "components/autofill/core/common/autofill_regexes.h"
32 #include "components/autofill/core/common/form_field_data.h" 34 #include "components/autofill/core/common/form_field_data.h"
33 #include "grit/components_scaled_resources.h" 35 #include "grit/components_scaled_resources.h"
34 #include "grit/components_strings.h" 36 #include "grit/components_strings.h"
35 #include "third_party/icu/source/common/unicode/uloc.h" 37 #include "third_party/icu/source/common/unicode/uloc.h"
36 #include "third_party/icu/source/i18n/unicode/dtfmtsym.h" 38 #include "third_party/icu/source/i18n/unicode/dtfmtsym.h"
37 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
38 40
39 using base::ASCIIToUTF16; 41 using base::ASCIIToUTF16;
40 42
41 namespace autofill { 43 namespace autofill {
42 44
43 const base::char16 kMidlineEllipsis[] = { 0x0020, 0x0020, 45 const base::char16 kMidlineEllipsis[] = { 0x0020, 0x0020,
44 0x2022, 0x2006, 46 0x2022, 0x2006,
45 0x2022, 0x2006, 47 0x2022, 0x2006,
46 0x2022, 0x2006, 48 0x2022, 0x2006,
47 0x2022, 0x2006, 0 }; 49 0x2022, 0x2006, 0 };
48 50
49 namespace { 51 namespace {
50 52
51 const base::char16 kCreditCardObfuscationSymbol = '*'; 53 const base::char16 kCreditCardObfuscationSymbol = '*';
54 const char kTimeFormatPatternNoYearShortMonthDate[] = "MMMdd";
Mathieu 2017/02/12 20:42:05 Can you add a comment giving an example date produ
jiahuiguo 2017/02/13 21:04:10 Done.
52 55
53 bool ConvertYear(const base::string16& year, int* num) { 56 bool ConvertYear(const base::string16& year, int* num) {
54 // If the |year| is empty, clear the stored value. 57 // If the |year| is empty, clear the stored value.
55 if (year.empty()) { 58 if (year.empty()) {
56 *num = 0; 59 *num = 0;
57 return true; 60 return true;
58 } 61 }
59 62
60 // Try parsing the |year| as a number. 63 // Try parsing the |year| as a number.
61 if (base::StringToInt(year, num)) 64 if (base::StringToInt(year, num))
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 expiration_month_ = credit_card.expiration_month_; 533 expiration_month_ = credit_card.expiration_month_;
531 expiration_year_ = credit_card.expiration_year_; 534 expiration_year_ = credit_card.expiration_year_;
532 server_id_ = credit_card.server_id_; 535 server_id_ = credit_card.server_id_;
533 server_status_ = credit_card.server_status_; 536 server_status_ = credit_card.server_status_;
534 billing_address_id_ = credit_card.billing_address_id_; 537 billing_address_id_ = credit_card.billing_address_id_;
535 538
536 set_guid(credit_card.guid()); 539 set_guid(credit_card.guid());
537 set_origin(credit_card.origin()); 540 set_origin(credit_card.origin());
538 } 541 }
539 542
543 base::string16 CreditCard::GetLastUsedDateForDisplay(
544 const std::string& app_locale) const {
545 bool show_expiration_date =
546 ShowExpirationDateInAutofillCreditCardLastUsedDate();
547
548 DCHECK(use_count() > 0);
549 // use_count() is initialized as 1 when the card is just added.
550 if (use_count() == 1) {
551 return show_expiration_date
552 ? l10n_util::GetStringFUTF16(
553 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_ADDED_DATE,
554 GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR),
555 app_locale),
556 base::TimeFormatWithPattern(
557 use_date(), kTimeFormatPatternNoYearShortMonthDate))
558 : l10n_util::GetStringFUTF16(
559 IDS_AUTOFILL_CREDIT_CARD_ADDED_DATE,
560 base::TimeFormatWithPattern(
561 use_date(), kTimeFormatPatternNoYearShortMonthDate));
562 }
563
564 // use_count() > 1 when the card has been used in autofill.
565
566 // If the card was last used in autofill more than a year ago,
567 // display "last used > 1 year ago" without showing date detail.
568 if ((AutofillClock::Now() - use_date()).InDays() > 365) {
569 return show_expiration_date
570 ? l10n_util::GetStringFUTF16(
571 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_YEAR_AGO,
572 GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR),
573 app_locale))
574 : l10n_util::GetStringUTF16(
575 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_YEAR_AGO);
576 }
577
578 // If the card was last used in autofill within a year, show date information.
579 return show_expiration_date
580 ? l10n_util::GetStringFUTF16(
581 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE,
582 GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR),
583 app_locale),
584 base::TimeFormatWithPattern(
585 use_date(), kTimeFormatPatternNoYearShortMonthDate))
586 : l10n_util::GetStringFUTF16(
587 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE,
588 base::TimeFormatWithPattern(
589 use_date(), kTimeFormatPatternNoYearShortMonthDate));
590 }
591
540 bool CreditCard::UpdateFromImportedCard(const CreditCard& imported_card, 592 bool CreditCard::UpdateFromImportedCard(const CreditCard& imported_card,
541 const std::string& app_locale) { 593 const std::string& app_locale) {
542 if (this->GetInfo(AutofillType(CREDIT_CARD_NUMBER), app_locale) != 594 if (this->GetInfo(AutofillType(CREDIT_CARD_NUMBER), app_locale) !=
543 imported_card.GetInfo(AutofillType(CREDIT_CARD_NUMBER), app_locale)) { 595 imported_card.GetInfo(AutofillType(CREDIT_CARD_NUMBER), app_locale)) {
544 return false; 596 return false;
545 } 597 }
546 598
547 // Heuristically aggregated data should never overwrite verified data, with 599 // Heuristically aggregated data should never overwrite verified data, with
548 // the exception of expired verified cards. Instead, discard any heuristically 600 // the exception of expired verified cards. Instead, discard any heuristically
549 // aggregated credit cards that disagree with explicitly entered data, so that 601 // aggregated credit cards that disagree with explicitly entered data, so that
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 const char kDinersCard[] = "dinersCC"; 925 const char kDinersCard[] = "dinersCC";
874 const char kDiscoverCard[] = "discoverCC"; 926 const char kDiscoverCard[] = "discoverCC";
875 const char kGenericCard[] = "genericCC"; 927 const char kGenericCard[] = "genericCC";
876 const char kJCBCard[] = "jcbCC"; 928 const char kJCBCard[] = "jcbCC";
877 const char kMasterCard[] = "masterCardCC"; 929 const char kMasterCard[] = "masterCardCC";
878 const char kMirCard[] = "mirCC"; 930 const char kMirCard[] = "mirCC";
879 const char kUnionPay[] = "unionPayCC"; 931 const char kUnionPay[] = "unionPayCC";
880 const char kVisaCard[] = "visaCC"; 932 const char kVisaCard[] = "visaCC";
881 933
882 } // namespace autofill 934 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698