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

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

Issue 2844463004: Rename card 'type' into 'issuer network.' (Closed)
Patch Set: read -> use Created 3 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 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_CREDIT_CARD_H_ 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_CREDIT_CARD_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_CREDIT_CARD_H_ 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_CREDIT_CARD_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "base/strings/string_piece_forward.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "components/autofill/core/browser/autofill_data_model.h" 18 #include "components/autofill/core/browser/autofill_data_model.h"
18 19
19 namespace autofill { 20 namespace autofill {
20 21
21 // A midline horizontal ellipsis (U+22EF). 22 // A midline horizontal ellipsis (U+22EF).
22 extern const base::char16 kMidlineEllipsis[]; 23 extern const base::char16 kMidlineEllipsis[];
23 24
24 // A form group that stores credit card information. 25 // A form group that stores card information.
25 class CreditCard : public AutofillDataModel { 26 class CreditCard : public AutofillDataModel {
26 public: 27 public:
27 enum RecordType { 28 enum RecordType {
28 // A card with a complete number managed by Chrome (and not representing 29 // A card with a complete number managed by Chrome (and not representing
29 // something on the server). 30 // something on the server).
30 LOCAL_CARD, 31 LOCAL_CARD,
31 32
32 // A card from Wallet with masked information. Such cards will only have 33 // A card from Wallet with masked information. Such cards will only have
33 // the last 4 digits of the card number, and require an extra download to 34 // the last 4 digits of the card number, and require an extra download to
34 // convert to a FULL_SERVER_CARD. 35 // convert to a FULL_SERVER_CARD.
35 MASKED_SERVER_CARD, 36 MASKED_SERVER_CARD,
36 37
37 // A card from the Wallet server with full information. This card is not 38 // A card from the Wallet server with full information. This card is not
38 // locally editable. 39 // locally editable.
39 FULL_SERVER_CARD, 40 FULL_SERVER_CARD,
40 }; 41 };
41 42
42 // The status of this credit card. Only used for server cards. 43 // The status of this card. Only used for server cards.
43 enum ServerStatus { 44 enum ServerStatus {
44 EXPIRED, 45 EXPIRED,
45 OK, 46 OK,
46 }; 47 };
47 48
48 CreditCard(const std::string& guid, const std::string& origin); 49 CreditCard(const std::string& guid, const std::string& origin);
49 50
50 // Creates a server card. The type must be MASKED_SERVER_CARD or 51 // Creates a server card. The type must be MASKED_SERVER_CARD or
51 // FULL_SERVER_CARD. 52 // FULL_SERVER_CARD.
52 CreditCard(RecordType type, const std::string& server_id); 53 CreditCard(RecordType type, const std::string& server_id);
53 54
54 // For use in STL containers. 55 // For use in STL containers.
55 CreditCard(); 56 CreditCard();
56 CreditCard(const CreditCard& credit_card); 57 CreditCard(const CreditCard& credit_card);
57 ~CreditCard() override; 58 ~CreditCard() override;
58 59
59 // Returns a version of |number| that has any separator characters removed. 60 // Returns a version of |number| that has any separator characters removed.
60 static const base::string16 StripSeparators(const base::string16& number); 61 static const base::string16 StripSeparators(const base::string16& number);
61 62
62 // The user-visible type of the card, e.g. 'Mastercard'. 63 // The user-visible issuer network of the card, e.g. 'Mastercard'.
63 static base::string16 TypeForDisplay(const std::string& type); 64 static base::string16 NetworkForDisplay(const std::string& network);
64 65
65 // The ResourceBundle ID for the appropriate credit card image. 66 // The ResourceBundle ID for the appropriate card issuer network image.
66 static int IconResourceId(const std::string& type); 67 static int IconResourceId(const std::string& network);
67 68
68 // Returns the internal representation of credit card type corresponding to 69 // Returns the internal representation of card issuer network corresponding to
69 // the given |number|. The credit card type is determined purely according to 70 // the given |number|. The card issuer network is determined purely according
70 // the Issuer Identification Number (IIN), a.k.a. the "Bank Identification 71 // to the Issuer Identification Number (IIN), a.k.a. the "Bank Identification
71 // Number (BIN)", which is parsed from the relevant prefix of the |number|. 72 // Number (BIN)", which is parsed from the relevant prefix of the |number|.
72 // This function performs no additional validation checks on the |number|. 73 // This function performs no additional validation checks on the |number|.
73 // Hence, the returned type for both the valid card "4111-1111-1111-1111" and 74 // Hence, the returned issuer network for both the valid card
74 // the invalid card "4garbage" will be Visa, which has an IIN of 4. 75 // "4111-1111-1111-1111" and the invalid card "4garbage" will be Visa, which
75 static const char* GetCreditCardType(const base::string16& number); 76 // has an IIN of 4.
77 static const char* GetCardNetwork(const base::string16& number);
76 78
77 // Type strings are defined at the bottom of this file, e.g. kVisaCard. 79 // Network issuer strings are defined at the bottom of this file, e.g.
78 void SetTypeForMaskedCard(const char* type); 80 // kVisaCard.
81 void SetNetworkForMaskedCard(base::StringPiece network);
79 82
80 // Sets/gets the status of a server card. 83 // Sets/gets the status of a server card.
81 void SetServerStatus(ServerStatus status); 84 void SetServerStatus(ServerStatus status);
82 ServerStatus GetServerStatus() const; 85 ServerStatus GetServerStatus() const;
83 86
84 // FormGroup: 87 // FormGroup:
85 void GetMatchingTypes(const base::string16& text, 88 void GetMatchingTypes(const base::string16& text,
86 const std::string& app_locale, 89 const std::string& app_locale,
87 ServerFieldTypeSet* matching_types) const override; 90 ServerFieldTypeSet* matching_types) const override;
88 base::string16 GetRawInfo(ServerFieldType type) const override; 91 base::string16 GetRawInfo(ServerFieldType type) const override;
89 void SetRawInfo(ServerFieldType type, const base::string16& value) override; 92 void SetRawInfo(ServerFieldType type, const base::string16& value) override;
90 base::string16 GetInfo(const AutofillType& type, 93 base::string16 GetInfo(const AutofillType& type,
91 const std::string& app_locale) const override; 94 const std::string& app_locale) const override;
92 bool SetInfo(const AutofillType& type, 95 bool SetInfo(const AutofillType& type,
93 const base::string16& value, 96 const base::string16& value,
94 const std::string& app_locale) override; 97 const std::string& app_locale) override;
95 98
96 // Credit card preview summary, for example: "Visa - 1234", ", 01/2020". 99 // Card preview summary, for example: "Visa - 1234", ", 01/2020".
97 const std::pair<base::string16, base::string16> LabelPieces() const; 100 const std::pair<base::string16, base::string16> LabelPieces() const;
98 101
99 // Like LabelPieces, but appends the two pieces together. 102 // Like LabelPieces, but appends the two pieces together.
100 const base::string16 Label() const; 103 const base::string16 Label() const;
101 104
102 // Special method to set value for HTML5 month input type. 105 // Special method to set value for HTML5 month input type.
103 void SetInfoForMonthInputType(const base::string16& value); 106 void SetInfoForMonthInputType(const base::string16& value);
104 107
105 // The last four digits of the credit card number (or possibly less if there 108 // The last four digits of the card number (or possibly less if there aren't
106 // aren't enough characters). 109 // enough characters).
107 base::string16 LastFourDigits() const; 110 base::string16 LastFourDigits() const;
108 // The user-visible type of the card, e.g. 'Mastercard'. 111 // The user-visible issuer network of the card, e.g. 'Mastercard'.
109 base::string16 TypeForDisplay() const; 112 base::string16 NetworkForDisplay() const;
110 // A label for this credit card formatted as 'Cardname - 2345'. 113 // A label for this card formatted as 'IssuerNetwork - 2345'.
111 base::string16 TypeAndLastFourDigits() const; 114 base::string16 NetworkAndLastFourDigits() const;
112 115
113 // Localized expiration for this credit card formatted as 'Exp: 06/17'. 116 // Localized expiration for this card formatted as 'Exp: 06/17'.
114 base::string16 AbbreviatedExpirationDateForDisplay() const; 117 base::string16 AbbreviatedExpirationDateForDisplay() const;
115 118
116 const std::string& type() const { return type_; } 119 const std::string& network() const { return network_; }
117 120
118 int expiration_month() const { return expiration_month_; } 121 int expiration_month() const { return expiration_month_; }
119 int expiration_year() const { return expiration_year_; } 122 int expiration_year() const { return expiration_year_; }
120 123
121 // These setters verify that the month and year are within appropriate 124 // These setters verify that the month and year are within appropriate
122 // ranges, or 0. They take integers as an alternative to setting the inputs 125 // ranges, or 0. They take integers as an alternative to setting the inputs
123 // from strings via SetInfo(). 126 // from strings via SetInfo().
124 void SetExpirationMonth(int expiration_month); 127 void SetExpirationMonth(int expiration_month);
125 void SetExpirationYear(int expiration_year); 128 void SetExpirationYear(int expiration_year);
126 129
127 const std::string& server_id() const { return server_id_; } 130 const std::string& server_id() const { return server_id_; }
128 void set_server_id(const std::string& server_id) { server_id_ = server_id; } 131 void set_server_id(const std::string& server_id) { server_id_ = server_id; }
129 132
130 // For use in STL containers. 133 // For use in STL containers.
131 void operator=(const CreditCard& credit_card); 134 void operator=(const CreditCard& credit_card);
132 135
133 // If the card numbers for |this| and |imported_card| match, and merging the 136 // If the card numbers for |this| and |imported_card| match, and merging the
134 // two wouldn't result in unverified data overwriting verified data, 137 // two wouldn't result in unverified data overwriting verified data,
135 // overwrites |this| card's data with the data in |credit_card|. 138 // overwrites |this| card's data with the data in |imported_card|. Returns
136 // Returns true if the card numbers match, false otherwise. 139 // true if the card numbers match, false otherwise.
137 bool UpdateFromImportedCard(const CreditCard& imported_card, 140 bool UpdateFromImportedCard(const CreditCard& imported_card,
138 const std::string& app_locale) WARN_UNUSED_RESULT; 141 const std::string& app_locale) WARN_UNUSED_RESULT;
139 142
140 // Comparison for Sync. Returns 0 if the credit card is the same as |this|, 143 // Comparison for Sync. Returns 0 if the card is the same as |this|, or < 0,
141 // or < 0, or > 0 if it is different. The implied ordering can be used for 144 // or > 0 if it is different. The implied ordering can be used for culling
142 // culling duplicates. The ordering is based on collation order of the 145 // duplicates. The ordering is based on collation order of the textual
143 // textual contents of the fields. 146 // contents of the fields.
144 // GUIDs, origins, labels, and unique IDs are not compared, only the values of 147 // GUIDs, origins, labels, and unique IDs are not compared, only the values of
145 // the credit cards themselves. 148 // the cards themselves.
146 int Compare(const CreditCard& credit_card) const; 149 int Compare(const CreditCard& credit_card) const;
147 150
148 // Determines if |this| is a local version of the server card |other|. 151 // Determines if |this| is a local version of the server card |other|.
149 bool IsLocalDuplicateOfServerCard(const CreditCard& other) const; 152 bool IsLocalDuplicateOfServerCard(const CreditCard& other) const;
150 153
151 // Determines if |this| has the same number as |other|. If either is a masked 154 // Determines if |this| has the same number as |other|. If either is a masked
152 // server card, compares the last four digits only. 155 // server card, compares the last four digits only.
153 bool HasSameNumberAs(const CreditCard& other) const; 156 bool HasSameNumberAs(const CreditCard& other) const;
154 157
155 // Equality operators compare GUIDs, origins, and the contents. 158 // Equality operators compare GUIDs, origins, and the contents.
156 // Usage metadata (use count, use date, modification date) are NOT compared. 159 // Usage metadata (use count, use date, modification date) are NOT compared.
157 bool operator==(const CreditCard& credit_card) const; 160 bool operator==(const CreditCard& credit_card) const;
158 bool operator!=(const CreditCard& credit_card) const; 161 bool operator!=(const CreditCard& credit_card) const;
159 162
160 // How this card is stored. 163 // How this card is stored.
161 RecordType record_type() const { return record_type_; } 164 RecordType record_type() const { return record_type_; }
162 void set_record_type(RecordType rt) { record_type_ = rt; } 165 void set_record_type(RecordType rt) { record_type_ = rt; }
163 166
164 // Returns true if there are no values (field types) set. 167 // Returns true if there are no values (field types) set.
165 bool IsEmpty(const std::string& app_locale) const; 168 bool IsEmpty(const std::string& app_locale) const;
166 169
167 // Returns true if all field types have valid values set and the card is not 170 // Returns true if all field types have valid values set and the card is not
168 // expired. MASKED_SERVER_CARDs will never be valid because the number is 171 // expired. MASKED_SERVER_CARDs will never be valid because the number is
169 // not complete. 172 // not complete.
170 bool IsValid() const; 173 bool IsValid() const;
171 174
172 // Returns the credit card number. 175 // Returns the card number.
173 const base::string16& number() const { return number_; } 176 const base::string16& number() const { return number_; }
174 // Sets |number_| to |number| and computes the appropriate card |type_|. 177 // Sets |number_| to |number| and computes the appropriate card issuer
178 // |network_|.
175 void SetNumber(const base::string16& number); 179 void SetNumber(const base::string16& number);
176 180
177 // Returns the date when the credit card was last used in autofill. 181 // Returns the date when the card was last used in autofill.
178 base::string16 GetLastUsedDateForDisplay(const std::string& app_locale) const; 182 base::string16 GetLastUsedDateForDisplay(const std::string& app_locale) const;
179 183
180 // Logs the number of days since the credit card was last used and records its 184 // Logs the number of days since the card was last used and records its use.
181 // use.
182 void RecordAndLogUse(); 185 void RecordAndLogUse();
183 186
184 // Converts a string representation of a month (such as "February" or "feb." 187 // Converts a string representation of a month (such as "February" or "feb."
185 // or "2") into a numeric value in [1, 12]. Returns true on successful 188 // or "2") into a numeric value in [1, 12]. Returns true on successful
186 // conversion or false if a month was not recognized. 189 // conversion or false if a month was not recognized.
187 static bool ConvertMonth(const base::string16& month, 190 static bool ConvertMonth(const base::string16& month,
188 const std::string& app_locale, 191 const std::string& app_locale,
189 int* num); 192 int* num);
190 193
191 // Returns whether the credit card is expired based on |current_time|. 194 // Returns whether the card is expired based on |current_time|.
192 bool IsExpired(const base::Time& current_time) const; 195 bool IsExpired(const base::Time& current_time) const;
193 196
194 // Whether the card expiration date should be updated. 197 // Whether the card expiration date should be updated.
195 bool ShouldUpdateExpiration(const base::Time& current_time) const; 198 bool ShouldUpdateExpiration(const base::Time& current_time) const;
196 199
197 const std::string& billing_address_id() const { return billing_address_id_; } 200 const std::string& billing_address_id() const { return billing_address_id_; }
198 void set_billing_address_id(const std::string& id) { 201 void set_billing_address_id(const std::string& id) {
199 billing_address_id_ = id; 202 billing_address_id_ = id;
200 } 203 }
201 204
(...skipping 11 matching lines...) Expand all
213 // digit months, with various separators. 216 // digit months, with various separators.
214 void SetExpirationDateFromString(const base::string16& text); 217 void SetExpirationDateFromString(const base::string16& text);
215 218
216 private: 219 private:
217 FRIEND_TEST_ALL_PREFIXES(CreditCardTest, SetExpirationDateFromString); 220 FRIEND_TEST_ALL_PREFIXES(CreditCardTest, SetExpirationDateFromString);
218 FRIEND_TEST_ALL_PREFIXES(CreditCardTest, SetExpirationYearFromString); 221 FRIEND_TEST_ALL_PREFIXES(CreditCardTest, SetExpirationYearFromString);
219 222
220 // FormGroup: 223 // FormGroup:
221 void GetSupportedTypes(ServerFieldTypeSet* supported_types) const override; 224 void GetSupportedTypes(ServerFieldTypeSet* supported_types) const override;
222 225
223 // The type of the card to fill in to the page, e.g. 'Mastercard'. 226 // The issuer network of the card to fill in to the page, e.g. 'Mastercard'.
224 base::string16 TypeForFill() const; 227 base::string16 NetworkForFill() const;
225 228
226 // The month and year are zero if not present. 229 // The month and year are zero if not present.
227 int Expiration4DigitYear() const { return expiration_year_; } 230 int Expiration4DigitYear() const { return expiration_year_; }
228 int Expiration2DigitYear() const { return expiration_year_ % 100; } 231 int Expiration2DigitYear() const { return expiration_year_ % 100; }
229 base::string16 ExpirationMonthAsString() const; 232 base::string16 ExpirationMonthAsString() const;
230 base::string16 Expiration4DigitYearAsString() const; 233 base::string16 Expiration4DigitYearAsString() const;
231 base::string16 Expiration2DigitYearAsString() const; 234 base::string16 Expiration2DigitYearAsString() const;
232 235
233 // See enum definition above. 236 // See enum definition above.
234 RecordType record_type_; 237 RecordType record_type_;
235 238
236 // The credit card number. For MASKED_SERVER_CARDs, this number will 239 // The card number. For MASKED_SERVER_CARDs, this number will just contain the
237 // just contain the last four digits of the card number. 240 // last four digits of the card number.
238 base::string16 number_; 241 base::string16 number_;
239 242
240 // The cardholder's name. May be empty. 243 // The cardholder's name. May be empty.
241 base::string16 name_on_card_; 244 base::string16 name_on_card_;
242 245
243 // The type of the card. This is one of the k...Card constants below. 246 // The network issuer of the card. This is one of the k...Card constants
244 std::string type_; 247 // below.
248 std::string network_;
245 249
246 // These members are zero if not present. 250 // These members are zero if not present.
247 int expiration_month_; 251 int expiration_month_;
248 int expiration_year_; 252 int expiration_year_;
249 253
250 // For server cards (both MASKED and UNMASKED) this is the ID assigned by the 254 // For server cards (both MASKED and UNMASKED) this is the ID assigned by the
251 // server to uniquely identify this card. 255 // server to uniquely identify this card.
252 std::string server_id_; 256 std::string server_id_;
253 257
254 // The status of the card, as reported by the server. Not valid for local 258 // The status of the card, as reported by the server. Not valid for local
(...skipping 14 matching lines...) Expand all
269 extern const char kGenericCard[]; 273 extern const char kGenericCard[];
270 extern const char kJCBCard[]; 274 extern const char kJCBCard[];
271 extern const char kMasterCard[]; 275 extern const char kMasterCard[];
272 extern const char kMirCard[]; 276 extern const char kMirCard[];
273 extern const char kUnionPay[]; 277 extern const char kUnionPay[];
274 extern const char kVisaCard[]; 278 extern const char kVisaCard[];
275 279
276 } // namespace autofill 280 } // namespace autofill
277 281
278 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_CREDIT_CARD_H_ 282 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_CREDIT_CARD_H_
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_test_utils.cc ('k') | components/autofill/core/browser/credit_card.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698