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

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

Issue 2607043002: [Autofill] Credit Card Autofill Last Used Date Experiment (Closed)
Patch Set: Addressed comments 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 // Time format pattern for short month name (3 digits) and day in month (2
55 // digits), e.g. in en-US locale, it can be used to generate "Feb 02".
56 const char kTimeFormatPatternNoYearShortMonthDate[] = "MMMdd";
52 57
53 bool ConvertYear(const base::string16& year, int* num) { 58 bool ConvertYear(const base::string16& year, int* num) {
54 // If the |year| is empty, clear the stored value. 59 // If the |year| is empty, clear the stored value.
55 if (year.empty()) { 60 if (year.empty()) {
56 *num = 0; 61 *num = 0;
57 return true; 62 return true;
58 } 63 }
59 64
60 // Try parsing the |year| as a number. 65 // Try parsing the |year| as a number.
61 if (base::StringToInt(year, num)) 66 if (base::StringToInt(year, num))
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 expiration_month_ = credit_card.expiration_month_; 535 expiration_month_ = credit_card.expiration_month_;
531 expiration_year_ = credit_card.expiration_year_; 536 expiration_year_ = credit_card.expiration_year_;
532 server_id_ = credit_card.server_id_; 537 server_id_ = credit_card.server_id_;
533 server_status_ = credit_card.server_status_; 538 server_status_ = credit_card.server_status_;
534 billing_address_id_ = credit_card.billing_address_id_; 539 billing_address_id_ = credit_card.billing_address_id_;
535 540
536 set_guid(credit_card.guid()); 541 set_guid(credit_card.guid());
537 set_origin(credit_card.origin()); 542 set_origin(credit_card.origin());
538 } 543 }
539 544
545 base::string16 CreditCard::GetLastUsedDateForDisplay(
546 const std::string& app_locale) const {
547 bool show_expiration_date =
548 ShowExpirationDateInAutofillCreditCardLastUsedDate();
549
550 DCHECK(use_count() > 0);
551 // use_count() is initialized as 1 when the card is just added.
552 if (use_count() == 1) {
553 return show_expiration_date
554 ? l10n_util::GetStringFUTF16(
555 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_ADDED_DATE,
556 GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR),
557 app_locale),
558 base::TimeFormatWithPattern(
559 use_date(), kTimeFormatPatternNoYearShortMonthDate))
560 : l10n_util::GetStringFUTF16(
561 IDS_AUTOFILL_CREDIT_CARD_ADDED_DATE,
562 base::TimeFormatWithPattern(
563 use_date(), kTimeFormatPatternNoYearShortMonthDate));
564 }
565
566 // use_count() > 1 when the card has been used in autofill.
567
568 // If the card was last used in autofill more than a year ago,
569 // display "last used > 1 year ago" without showing date detail.
570 if ((AutofillClock::Now() - use_date()).InDays() > 365) {
571 return show_expiration_date
572 ? l10n_util::GetStringFUTF16(
573 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_YEAR_AGO,
574 GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR),
575 app_locale))
576 : l10n_util::GetStringUTF16(
577 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_YEAR_AGO);
578 }
579
580 // If the card was last used in autofill within a year, show date information.
581 return show_expiration_date
582 ? l10n_util::GetStringFUTF16(
583 IDS_AUTOFILL_CREDIT_CARD_EXP_AND_LAST_USED_DATE,
584 GetInfo(AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR),
585 app_locale),
586 base::TimeFormatWithPattern(
587 use_date(), kTimeFormatPatternNoYearShortMonthDate))
588 : l10n_util::GetStringFUTF16(
589 IDS_AUTOFILL_CREDIT_CARD_LAST_USED_DATE,
590 base::TimeFormatWithPattern(
591 use_date(), kTimeFormatPatternNoYearShortMonthDate));
592 }
593
540 bool CreditCard::UpdateFromImportedCard(const CreditCard& imported_card, 594 bool CreditCard::UpdateFromImportedCard(const CreditCard& imported_card,
541 const std::string& app_locale) { 595 const std::string& app_locale) {
542 if (this->GetInfo(AutofillType(CREDIT_CARD_NUMBER), app_locale) != 596 if (this->GetInfo(AutofillType(CREDIT_CARD_NUMBER), app_locale) !=
543 imported_card.GetInfo(AutofillType(CREDIT_CARD_NUMBER), app_locale)) { 597 imported_card.GetInfo(AutofillType(CREDIT_CARD_NUMBER), app_locale)) {
544 return false; 598 return false;
545 } 599 }
546 600
547 // Heuristically aggregated data should never overwrite verified data, with 601 // Heuristically aggregated data should never overwrite verified data, with
548 // the exception of expired verified cards. Instead, discard any heuristically 602 // the exception of expired verified cards. Instead, discard any heuristically
549 // aggregated credit cards that disagree with explicitly entered data, so that 603 // 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"; 927 const char kDinersCard[] = "dinersCC";
874 const char kDiscoverCard[] = "discoverCC"; 928 const char kDiscoverCard[] = "discoverCC";
875 const char kGenericCard[] = "genericCC"; 929 const char kGenericCard[] = "genericCC";
876 const char kJCBCard[] = "jcbCC"; 930 const char kJCBCard[] = "jcbCC";
877 const char kMasterCard[] = "masterCardCC"; 931 const char kMasterCard[] = "masterCardCC";
878 const char kMirCard[] = "mirCC"; 932 const char kMirCard[] = "mirCC";
879 const char kUnionPay[] = "unionPayCC"; 933 const char kUnionPay[] = "unionPayCC";
880 const char kVisaCard[] = "visaCC"; 934 const char kVisaCard[] = "visaCC";
881 935
882 } // namespace autofill 936 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/credit_card.h ('k') | components/autofill/core/browser/credit_card_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698