OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/wallet/wallet_items.h" | 5 #include "components/autofill/browser/wallet/wallet_items.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "components/autofill/browser/autofill_type.h" | 11 #include "components/autofill/browser/autofill_type.h" |
12 #include "components/autofill/browser/credit_card.h" | |
11 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
12 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
13 #include "grit/webkit_resources.h" | 15 #include "grit/webkit_resources.h" |
14 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
17 | 19 |
18 namespace autofill { | 20 namespace autofill { |
19 namespace wallet { | 21 namespace wallet { |
20 | 22 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 return !(*this == other); | 222 return !(*this == other); |
221 } | 223 } |
222 | 224 |
223 bool WalletItems::HasRequiredAction(RequiredAction action) const { | 225 bool WalletItems::HasRequiredAction(RequiredAction action) const { |
224 DCHECK(ActionAppliesToWalletItems(action)); | 226 DCHECK(ActionAppliesToWalletItems(action)); |
225 return std::find(required_actions_.begin(), | 227 return std::find(required_actions_.begin(), |
226 required_actions_.end(), | 228 required_actions_.end(), |
227 action) != required_actions_.end(); | 229 action) != required_actions_.end(); |
228 } | 230 } |
229 | 231 |
232 const WalletItems::MaskedInstrument* WalletItems::GetInstrumentById( | |
233 const std::string& object_id) const { | |
234 if (object_id.empty()) | |
235 return NULL; | |
236 | |
237 for (size_t i = 0; i < instruments_.size(); ++i) { | |
238 if (instruments_[i]->object_id() == object_id) | |
239 return instruments_[i]; | |
240 } | |
241 | |
242 return NULL; | |
243 } | |
244 | |
230 string16 WalletItems::MaskedInstrument::DisplayName() const { | 245 string16 WalletItems::MaskedInstrument::DisplayName() const { |
231 #if defined(OS_ANDROID) | 246 #if defined(OS_ANDROID) |
232 // TODO(aruslan): improve this stub implementation. | 247 // TODO(aruslan): improve this stub implementation. |
233 return descriptive_name(); | 248 return descriptive_name(); |
234 #else | 249 #else |
235 return descriptive_name(); | 250 return descriptive_name(); |
236 #endif | 251 #endif |
237 } | 252 } |
238 | 253 |
239 string16 WalletItems::MaskedInstrument::DisplayNameDetail() const { | 254 string16 WalletItems::MaskedInstrument::DisplayNameDetail() const { |
240 #if defined(OS_ANDROID) | 255 #if defined(OS_ANDROID) |
241 // TODO(aruslan): improve this stub implementation. | 256 // TODO(aruslan): improve this stub implementation. |
242 return address().DisplayName(); | 257 return address().DisplayName(); |
243 #else | 258 #else |
244 return string16(); | 259 return string16(); |
245 #endif | 260 #endif |
246 } | 261 } |
247 | 262 |
263 string16 WalletItems::MaskedInstrument::TypeAndLastFourDigits() const { | |
264 string16 display_type = CreditCard::TypeForDisplay(kGenericCard); | |
Ilya Sherman
2013/03/27 23:59:23
Optional nit: Consider initing to an empty string,
Dan Beam
2013/03/28 03:38:12
well, don't we disagree, lol. anyways, Done.
| |
265 | |
266 if (type_ == AMEX) | |
267 display_type = CreditCard::TypeForDisplay(kAmericanExpressCard); | |
268 else if (type_ == DISCOVER) | |
269 display_type = CreditCard::TypeForDisplay(kDiscoverCard); | |
270 else if (type_ == MASTER_CARD) | |
271 display_type = CreditCard::TypeForDisplay(kMasterCard); | |
272 else if (type_ == SOLO) | |
273 display_type = CreditCard::TypeForDisplay(kSoloCard); | |
274 else if (type_ == VISA) | |
275 display_type = CreditCard::TypeForDisplay(kVisaCard); | |
276 | |
277 // TODO(dbeam): i18n. | |
278 return display_type + ASCIIToUTF16(" - ") + last_four_digits(); | |
279 } | |
280 | |
248 const gfx::Image& WalletItems::MaskedInstrument::CardIcon() const { | 281 const gfx::Image& WalletItems::MaskedInstrument::CardIcon() const { |
249 int idr = 0; | 282 int idr = 0; |
250 switch (type_) { | 283 switch (type_) { |
251 case AMEX: | 284 case AMEX: |
252 idr = IDR_AUTOFILL_CC_AMEX; | 285 idr = IDR_AUTOFILL_CC_AMEX; |
253 break; | 286 break; |
254 | 287 |
255 case DISCOVER: | 288 case DISCOVER: |
256 idr = IDR_AUTOFILL_CC_DISCOVER; | 289 idr = IDR_AUTOFILL_CC_DISCOVER; |
257 break; | 290 break; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 VectorsAreEqual<LegalDocument>(legal_documents(), | 518 VectorsAreEqual<LegalDocument>(legal_documents(), |
486 other.legal_documents()); | 519 other.legal_documents()); |
487 } | 520 } |
488 | 521 |
489 bool WalletItems::operator!=(const WalletItems& other) const { | 522 bool WalletItems::operator!=(const WalletItems& other) const { |
490 return !(*this == other); | 523 return !(*this == other); |
491 } | 524 } |
492 | 525 |
493 } // namespace wallet | 526 } // namespace wallet |
494 } // namespace autofill | 527 } // namespace autofill |
OLD | NEW |