| 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/webkit_resources.h" | 14 #include "grit/webkit_resources.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
| 15 | 17 |
| 16 namespace autofill { | 18 namespace autofill { |
| 17 namespace wallet { | 19 namespace wallet { |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 return !(*this == other); | 205 return !(*this == other); |
| 204 } | 206 } |
| 205 | 207 |
| 206 bool WalletItems::HasRequiredAction(RequiredAction action) const { | 208 bool WalletItems::HasRequiredAction(RequiredAction action) const { |
| 207 DCHECK(ActionAppliesToWalletItems(action)); | 209 DCHECK(ActionAppliesToWalletItems(action)); |
| 208 return std::find(required_actions_.begin(), | 210 return std::find(required_actions_.begin(), |
| 209 required_actions_.end(), | 211 required_actions_.end(), |
| 210 action) != required_actions_.end(); | 212 action) != required_actions_.end(); |
| 211 } | 213 } |
| 212 | 214 |
| 215 const WalletItems::MaskedInstrument* WalletItems::GetInstrumentById( |
| 216 const std::string& object_id) const { |
| 217 if (object_id.empty()) |
| 218 return NULL; |
| 219 |
| 220 for (size_t i = 0; i < instruments_.size(); ++i) { |
| 221 if (instruments_[i]->object_id() == object_id) |
| 222 return instruments_[i]; |
| 223 } |
| 224 |
| 225 return NULL; |
| 226 } |
| 227 |
| 213 string16 WalletItems::MaskedInstrument::DisplayName() const { | 228 string16 WalletItems::MaskedInstrument::DisplayName() const { |
| 214 #if defined(OS_ANDROID) | 229 #if defined(OS_ANDROID) |
| 215 // TODO(aruslan): improve this stub implementation. | 230 // TODO(aruslan): improve this stub implementation. |
| 216 return descriptive_name(); | 231 return descriptive_name(); |
| 217 #else | 232 #else |
| 218 return descriptive_name(); | 233 return descriptive_name(); |
| 219 #endif | 234 #endif |
| 220 } | 235 } |
| 221 | 236 |
| 222 string16 WalletItems::MaskedInstrument::DisplayNameDetail() const { | 237 string16 WalletItems::MaskedInstrument::DisplayNameDetail() const { |
| 223 #if defined(OS_ANDROID) | 238 #if defined(OS_ANDROID) |
| 224 // TODO(aruslan): improve this stub implementation. | 239 // TODO(aruslan): improve this stub implementation. |
| 225 return address().DisplayName(); | 240 return address().DisplayName(); |
| 226 #else | 241 #else |
| 227 return string16(); | 242 return string16(); |
| 228 #endif | 243 #endif |
| 229 } | 244 } |
| 230 | 245 |
| 246 string16 WalletItems::MaskedInstrument::TypeAndLastFourDigits() const { |
| 247 string16 display_type = CreditCard::TypeForDisplay(kGenericCard); |
| 248 |
| 249 if (type_ == AMEX) |
| 250 display_type = CreditCard::TypeForDisplay(kAmericanExpressCard); |
| 251 else if (type_ == DISCOVER) |
| 252 display_type = CreditCard::TypeForDisplay(kDiscoverCard); |
| 253 else if (type_ == MASTER_CARD) |
| 254 display_type = CreditCard::TypeForDisplay(kMasterCard); |
| 255 else if (type_ == SOLO) |
| 256 display_type = CreditCard::TypeForDisplay(kSoloCard); |
| 257 else if (type_ == VISA) |
| 258 display_type = CreditCard::TypeForDisplay(kVisaCard); |
| 259 |
| 260 // TODO(dbeam): i18n. |
| 261 return display_type + ASCIIToUTF16(" - ") + last_four_digits(); |
| 262 } |
| 263 |
| 231 const gfx::Image& WalletItems::MaskedInstrument::CardIcon() const { | 264 const gfx::Image& WalletItems::MaskedInstrument::CardIcon() const { |
| 232 int idr = 0; | 265 int idr = 0; |
| 233 switch (type_) { | 266 switch (type_) { |
| 234 case AMEX: | 267 case AMEX: |
| 235 idr = IDR_AUTOFILL_CC_AMEX; | 268 idr = IDR_AUTOFILL_CC_AMEX; |
| 236 break; | 269 break; |
| 237 | 270 |
| 238 case DISCOVER: | 271 case DISCOVER: |
| 239 idr = IDR_AUTOFILL_CC_DISCOVER; | 272 idr = IDR_AUTOFILL_CC_DISCOVER; |
| 240 break; | 273 break; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 required_actions_ == other.required_actions_ && | 482 required_actions_ == other.required_actions_ && |
| 450 obfuscated_gaia_id_ == other.obfuscated_gaia_id_; | 483 obfuscated_gaia_id_ == other.obfuscated_gaia_id_; |
| 451 } | 484 } |
| 452 | 485 |
| 453 bool WalletItems::operator!=(const WalletItems& other) const { | 486 bool WalletItems::operator!=(const WalletItems& other) const { |
| 454 return !(*this == other); | 487 return !(*this == other); |
| 455 } | 488 } |
| 456 | 489 |
| 457 } // namespace wallet | 490 } // namespace wallet |
| 458 } // namespace autofill | 491 } // namespace autofill |
| OLD | NEW |