1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_items.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <limits>
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/logging.h"
10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/strings/string_number_conversions.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/values.h"
13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/autofill/content/browser/wallet/gaia_account.h"
14eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_type.h"
15eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/credit_card.h"
161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "grit/components_scaled_resources.h"
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "grit/components_strings.h"
18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/resource/resource_bundle.h"
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/image/image.h"
217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace autofill {
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace wallet {
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace {
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kLegalDocumentUrl[] =
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    "https://wallet.google.com/legaldocument?docId=";
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kPrivacyNoticeUrl[] = "https://wallet.google.com/files/privacy.html";
31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// TODO(estade): move to base/.
33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)template<class T>
34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool VectorsAreEqual(const std::vector<T*>& a, const std::vector<T*>& b) {
35c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (a.size() != b.size())
36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return false;
37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < a.size(); ++i) {
39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (*a[i] != *b[i])
40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      return false;
41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return true;
44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WalletItems::MaskedInstrument::Type
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    TypeFromString(const std::string& type_string) {
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (type_string == "VISA")
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::VISA;
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (type_string == "MASTER_CARD")
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::MASTER_CARD;
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (type_string == "AMEX")
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::AMEX;
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (type_string == "DISCOVER")
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::DISCOVER;
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (type_string == "SOLO")
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::SOLO;
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (type_string == "MAESTRO")
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::MAESTRO;
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (type_string == "SWITCH")
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::SWITCH;
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return WalletItems::MaskedInstrument::UNKNOWN;
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WalletItems::MaskedInstrument::Status
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    StatusFromString(const std::string& status_string) {
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status_string == "AMEX_NOT_SUPPORTED")
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::AMEX_NOT_SUPPORTED;
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status_string == "PENDING")
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::PENDING;
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status_string == "VALID")
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::VALID;
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status_string == "DECLINED")
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::DECLINED;
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status_string == "DISABLED_FOR_THIS_MERCHANT")
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::DISABLED_FOR_THIS_MERCHANT;
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status_string == "UNSUPPORTED_COUNTRY")
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::UNSUPPORTED_COUNTRY;
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status_string == "EXPIRED")
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::EXPIRED;
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status_string == "BILLING_INCOMPLETE")
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return WalletItems::MaskedInstrument::BILLING_INCOMPLETE;
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return WalletItems::MaskedInstrument::INAPPLICABLE;
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
86d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)base::string16 DisplayStringFromType(WalletItems::MaskedInstrument::Type type) {
87d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  switch (type) {
88d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    case WalletItems::MaskedInstrument::AMEX:
89d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      return CreditCard::TypeForDisplay(kAmericanExpressCard);
90d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    case WalletItems::MaskedInstrument::DISCOVER:
91d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      return CreditCard::TypeForDisplay(kDiscoverCard);
92d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    case WalletItems::MaskedInstrument::MASTER_CARD:
93d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      return CreditCard::TypeForDisplay(kMasterCard);
94d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    case WalletItems::MaskedInstrument::VISA:
95d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      return CreditCard::TypeForDisplay(kVisaCard);
96d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    default:
97d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      return CreditCard::TypeForDisplay(kGenericCard);
98d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
99d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
100d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // anonymous namespace
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WalletItems::MaskedInstrument::MaskedInstrument(
104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const base::string16& descriptive_name,
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const WalletItems::MaskedInstrument::Type& type,
106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const base::string16& last_four_digits,
1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int expiration_month,
1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int expiration_year,
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    scoped_ptr<Address> address,
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const WalletItems::MaskedInstrument::Status& status,
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const std::string& object_id)
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : descriptive_name_(descriptive_name),
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      type_(type),
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      last_four_digits_(last_four_digits),
1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      expiration_month_(expiration_month),
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      expiration_year_(expiration_year),
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      address_(address.Pass()),
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      status_(status),
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      object_id_(object_id) {
120a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DCHECK(address_);
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WalletItems::MaskedInstrument::~MaskedInstrument() {}
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)scoped_ptr<WalletItems::MaskedInstrument>
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    WalletItems::MaskedInstrument::CreateMaskedInstrument(
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const base::DictionaryValue& dictionary) {
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string type_string;
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Type type;
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (dictionary.GetString("type", &type_string)) {
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    type = TypeFromString(type_string);
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DLOG(ERROR) << "Response from Google Wallet missing card type";
1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return scoped_ptr<MaskedInstrument>();
1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::string16 last_four_digits;
1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!dictionary.GetString("last_four_digits", &last_four_digits)) {
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DLOG(ERROR) << "Response from Google Wallet missing last four digits";
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return scoped_ptr<MaskedInstrument>();
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string status_string;
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Status status;
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (dictionary.GetString("status", &status_string)) {
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    status = StatusFromString(status_string);
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DLOG(ERROR) << "Response from Google Wallet missing status";
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return scoped_ptr<MaskedInstrument>();
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string object_id;
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!dictionary.GetString("object_id", &object_id)) {
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DLOG(ERROR) << "Response from Google Wallet missing object id";
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return scoped_ptr<MaskedInstrument>();
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::DictionaryValue* address_dict;
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!dictionary.GetDictionary("billing_address", &address_dict)) {
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DLOG(ERROR) << "Response from Google wallet missing address";
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return scoped_ptr<MaskedInstrument>();
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<Address> address = Address::CreateDisplayAddress(*address_dict);
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
165a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!address) {
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DLOG(ERROR) << "Response from Google wallet contained malformed address";
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return scoped_ptr<MaskedInstrument>();
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int expiration_month;
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!dictionary.GetInteger("expiration_month", &expiration_month))
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DVLOG(1) << "Response from Google Wallet missing expiration month";
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int expiration_year;
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!dictionary.GetInteger("expiration_year", &expiration_year))
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DVLOG(1) << "Response from Google Wallet missing expiration year";
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::string16 descriptive_name;
1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!dictionary.GetString("descriptive_name", &descriptive_name))
1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DVLOG(1) << "Response from Google Wallet missing descriptive name";
1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return scoped_ptr<MaskedInstrument>(new MaskedInstrument(descriptive_name,
1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                           type,
1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                           last_four_digits,
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                           expiration_month,
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                           expiration_year,
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                           address.Pass(),
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                           status,
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                           object_id));
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool WalletItems::MaskedInstrument::operator==(
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const WalletItems::MaskedInstrument& other) const {
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (descriptive_name_ != other.descriptive_name_)
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (type_ != other.type_)
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (last_four_digits_ != other.last_four_digits_)
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (expiration_month_ != other.expiration_month_)
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (expiration_year_ != other.expiration_year_)
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
204a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (address_) {
205a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    if (other.address_) {
206a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      if (*address_ != *other.address_)
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        return false;
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    } else {
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return false;
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
211a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  } else if (other.address_) {
2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status_ != other.status_)
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (object_id_ != other.object_id_)
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return true;
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool WalletItems::MaskedInstrument::operator!=(
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const WalletItems::MaskedInstrument& other) const {
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return !(*this == other);
2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
226c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const WalletItems::MaskedInstrument* WalletItems::GetInstrumentById(
227c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const std::string& object_id) const {
228c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (object_id.empty())
229c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return NULL;
230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < instruments_.size(); ++i) {
232c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (instruments_[i]->object_id() == object_id)
233c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      return instruments_[i];
234c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
235c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
236c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return NULL;
237c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
238c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
23990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool WalletItems::HasRequiredAction(RequiredAction action) const {
24090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DCHECK(ActionAppliesToWalletItems(action));
24190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return std::find(required_actions_.begin(),
24290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                   required_actions_.end(),
24390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                   action) != required_actions_.end();
24490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
24590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)bool WalletItems::SupportsCard(const base::string16& card_number,
2471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                               base::string16* message) const {
248116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  const char* const card_type = CreditCard::GetCreditCardType(card_number);
2491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (card_type == kVisaCard ||
2511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      card_type == kMasterCard ||
2521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      card_type == kDiscoverCard) {
2531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return true;
2541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
2551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (card_type == kAmericanExpressCard) {
2571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (amex_permission_ == AMEX_ALLOWED)
2581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      return true;
2591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    *message = l10n_util::GetStringUTF16(
2611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        IDS_AUTOFILL_CREDIT_CARD_NOT_SUPPORTED_BY_WALLET_FOR_MERCHANT);
2621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return false;
2631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
2641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  *message = l10n_util::GetStringUTF16(
2661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      IDS_AUTOFILL_CREDIT_CARD_NOT_SUPPORTED_BY_WALLET);
2671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)   return false;
2681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
2691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
270a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)std::string WalletItems::ObfuscatedGaiaId() const {
271a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (active_account_index_ >= gaia_accounts_.size())
272a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return std::string();
273a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
274a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return gaia_accounts_[active_account_index_]->obfuscated_id();
275a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
276a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
277c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)base::string16 WalletItems::MaskedInstrument::DisplayName() const {
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_ANDROID)
2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TODO(aruslan): improve this stub implementation.
2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return descriptive_name();
2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return descriptive_name();
2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
286c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)base::string16 WalletItems::MaskedInstrument::DisplayNameDetail() const {
2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_ANDROID)
2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TODO(aruslan): improve this stub implementation.
2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return address().DisplayName();
2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else
291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return base::string16();
2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
295c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)base::string16 WalletItems::MaskedInstrument::TypeAndLastFourDigits() const {
296c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TODO(dbeam): i18n.
2975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return DisplayStringFromType(type_) + base::ASCIIToUTF16(" - ") +
298d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)         last_four_digits();
299c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
300c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const gfx::Image& WalletItems::MaskedInstrument::CardIcon() const {
3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int idr = 0;
3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  switch (type_) {
3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case AMEX:
3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      idr = IDR_AUTOFILL_CC_AMEX;
3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case DISCOVER:
3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      idr = IDR_AUTOFILL_CC_DISCOVER;
3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case MASTER_CARD:
3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      idr = IDR_AUTOFILL_CC_MASTERCARD;
3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case VISA:
3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      idr = IDR_AUTOFILL_CC_VISA;
3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
320eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    case SOLO:
3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case MAESTRO:
3222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case SWITCH:
3232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case UNKNOWN:
3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      idr = IDR_AUTOFILL_CC_GENERIC;
3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return ResourceBundle::GetSharedInstance().GetImageNamed(idr);
3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
331c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)base::string16 WalletItems::MaskedInstrument::GetInfo(
3323240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch    const AutofillType& type,
333c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const std::string& app_locale) const {
3343240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch  if (type.group() != CREDIT_CARD)
335c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return address().GetInfo(type, app_locale);
3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
337bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  switch (type.GetStorableType()) {
3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case CREDIT_CARD_NAME:
3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return address().recipient_name();
3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case CREDIT_CARD_NUMBER:
34290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      return DisplayName();
3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case CREDIT_CARD_EXP_4_DIGIT_YEAR:
3452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return base::IntToString16(expiration_year());
3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case CREDIT_CARD_VERIFICATION_CODE:
3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      break;
3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
350d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    case CREDIT_CARD_TYPE:
351d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      return DisplayStringFromType(type_);
352d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    default:
3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      NOTREACHED();
3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
357c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return base::string16();
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WalletItems::LegalDocument::~LegalDocument() {}
3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)scoped_ptr<WalletItems::LegalDocument>
3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    WalletItems::LegalDocument::CreateLegalDocument(
3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const base::DictionaryValue& dictionary) {
365c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  std::string id;
366c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!dictionary.GetString("legal_document_id", &id)) {
3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DLOG(ERROR) << "Response from Google Wallet missing legal document id";
3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return scoped_ptr<LegalDocument>();
3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
371c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::string16 display_name;
3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!dictionary.GetString("display_name", &display_name)) {
3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DLOG(ERROR) << "Response from Google Wallet missing display name";
3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return scoped_ptr<LegalDocument>();
3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
377c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return scoped_ptr<LegalDocument>(new LegalDocument(id, display_name));
3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
380c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)scoped_ptr<WalletItems::LegalDocument>
381c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    WalletItems::LegalDocument::CreatePrivacyPolicyDocument() {
382c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return scoped_ptr<LegalDocument>(new LegalDocument(
383c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      GURL(kPrivacyNoticeUrl),
384c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PRIVACY_POLICY_LINK)));
3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool WalletItems::LegalDocument::operator==(const LegalDocument& other) const {
388c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return id_ == other.id_ &&
389c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)         url_ == other.url_ &&
3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)         display_name_ == other.display_name_;
3912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool WalletItems::LegalDocument::operator!=(const LegalDocument& other) const {
3942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return !(*this == other);
3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
397c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)WalletItems::LegalDocument::LegalDocument(const std::string& id,
398c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                          const base::string16& display_name)
399c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    : id_(id),
400c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      url_(kLegalDocumentUrl + id),
401c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      display_name_(display_name) {}
402c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
403c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)WalletItems::LegalDocument::LegalDocument(const GURL& url,
404c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                          const base::string16& display_name)
405c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    : url_(url),
406c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      display_name_(display_name) {}
407c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WalletItems::WalletItems(const std::vector<RequiredAction>& required_actions,
4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                         const std::string& google_transaction_id,
4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                         const std::string& default_instrument_id,
4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                         const std::string& default_address_id,
412a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                         AmexPermission amex_permission)
4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : required_actions_(required_actions),
4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      google_transaction_id_(google_transaction_id),
4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      default_instrument_id_(default_instrument_id),
4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      default_address_id_(default_address_id),
417a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      active_account_index_(std::numeric_limits<size_t>::max()),
418a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      amex_permission_(amex_permission) {}
4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WalletItems::~WalletItems() {}
4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)scoped_ptr<WalletItems>
4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    WalletItems::CreateWalletItems(const base::DictionaryValue& dictionary) {
4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<RequiredAction> required_action;
4255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::ListValue* required_action_list;
4262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (dictionary.GetList("required_action", &required_action_list)) {
4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    for (size_t i = 0; i < required_action_list->GetSize(); ++i) {
4282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      std::string action_string;
4292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (required_action_list->GetString(i, &action_string)) {
4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        RequiredAction action = ParseRequiredActionFromString(action_string);
4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        if (!ActionAppliesToWalletItems(action)) {
4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          DLOG(ERROR) << "Response from Google wallet with bad required action:"
4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                         " \"" << action_string << "\"";
4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          return scoped_ptr<WalletItems>();
4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        }
4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        required_action.push_back(action);
4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      }
4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
4402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DVLOG(1) << "Response from Google wallet missing required actions";
4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string google_transaction_id;
4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!dictionary.GetString("google_transaction_id", &google_transaction_id) &&
4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      required_action.empty()) {
4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DLOG(ERROR) << "Response from Google wallet missing google transaction id";
4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return scoped_ptr<WalletItems>();
4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string default_instrument_id;
4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!dictionary.GetString("default_instrument_id", &default_instrument_id))
4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DVLOG(1) << "Response from Google wallet missing default instrument id";
4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string default_address_id;
4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!dictionary.GetString("default_address_id", &default_address_id))
4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DVLOG(1) << "Response from Google wallet missing default_address_id";
4572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
458a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // obfuscated_gaia_id is deprecated.
4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
46068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  bool amex_disallowed = true;
46168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  if (!dictionary.GetBoolean("amex_disallowed", &amex_disallowed))
46268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    DVLOG(1) << "Response from Google wallet missing the amex_disallowed field";
46368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  AmexPermission amex_permission =
46468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      amex_disallowed ? AMEX_DISALLOWED : AMEX_ALLOWED;
46568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
466a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  scoped_ptr<WalletItems> wallet_items(new WalletItems(required_action,
467a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                                       google_transaction_id,
468a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                                       default_instrument_id,
469a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                                       default_address_id,
470a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                                       amex_permission));
471f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  std::vector<std::string> gaia_accounts;
472f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  const base::ListValue* gaia_profiles;
473f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (dictionary.GetList("gaia_profile", &gaia_profiles)) {
474f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    for (size_t i = 0; i < gaia_profiles->GetSize(); ++i) {
475f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const base::DictionaryValue* account_dict;
476f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      std::string email;
477a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      if (!gaia_profiles->GetDictionary(i, &account_dict))
478a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        continue;
479a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
480a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      scoped_ptr<GaiaAccount> gaia_account(
481a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          GaiaAccount::Create(*account_dict));
482a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      if (gaia_account)
483a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        wallet_items->AddAccount(gaia_account.Pass());
484f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
485f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  } else {
486a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    DVLOG(1) << "Response from Google wallet missing GAIA accounts";
487f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
488f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
4895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::ListValue* legal_docs;
4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (dictionary.GetList("required_legal_document", &legal_docs)) {
4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    for (size_t i = 0; i < legal_docs->GetSize(); ++i) {
4925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const base::DictionaryValue* legal_doc_dict;
4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (legal_docs->GetDictionary(i, &legal_doc_dict)) {
4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        scoped_ptr<LegalDocument> legal_doc(
4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            LegalDocument::CreateLegalDocument(*legal_doc_dict));
496a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        if (legal_doc)
4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          wallet_items->AddLegalDocument(legal_doc.Pass());
498a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        else
4992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          return scoped_ptr<WalletItems>();
5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      }
5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
502c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
503c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (!legal_docs->empty()) {
504c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      // Always append the privacy policy link as well.
505c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      wallet_items->AddLegalDocument(
506c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          LegalDocument::CreatePrivacyPolicyDocument());
507c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DVLOG(1) << "Response from Google wallet missing legal docs";
5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::ListValue* instruments;
5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (dictionary.GetList("instrument", &instruments)) {
5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    for (size_t i = 0; i < instruments->GetSize(); ++i) {
5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const base::DictionaryValue* instrument_dict;
5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (instruments->GetDictionary(i, &instrument_dict)) {
5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        scoped_ptr<MaskedInstrument> instrument(
5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            MaskedInstrument::CreateMaskedInstrument(*instrument_dict));
519a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        if (instrument)
5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          wallet_items->AddInstrument(instrument.Pass());
5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      }
5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DVLOG(1) << "Response from Google wallet missing instruments";
5252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::ListValue* addresses;
5282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (dictionary.GetList("address", &addresses)) {
5292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    for (size_t i = 0; i < addresses->GetSize(); ++i) {
5305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const base::DictionaryValue* address_dict;
5312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (addresses->GetDictionary(i, &address_dict)) {
5322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        scoped_ptr<Address> address(
5332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            Address::CreateAddressWithID(*address_dict));
534a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        if (address)
5352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          wallet_items->AddAddress(address.Pass());
5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      }
5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DVLOG(1) << "Response from Google wallet missing addresses";
5402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
542116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  const base::ListValue* allowed_shipping_countries;
543116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (dictionary.GetList("allowed_shipping_spec_by_country",
544116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                         &allowed_shipping_countries)) {
545116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    for (size_t i = 0; i < allowed_shipping_countries->GetSize(); ++i) {
546116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const base::DictionaryValue* country_spec;
547116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      std::string country_code;
548116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      if (allowed_shipping_countries->GetDictionary(i, &country_spec) &&
549116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch          country_spec->GetString("country_code", &country_code)) {
550116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        wallet_items->AddAllowedShippingCountry(country_code);
551116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      }
552116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    }
553116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  } else {
554116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    DVLOG(1) << "Response from Google wallet missing allowed shipping"
555116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                " countries";
556116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
557116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
5582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return wallet_items.Pass();
5592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
561a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void WalletItems::AddAccount(scoped_ptr<GaiaAccount> account) {
562a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (account->index() != gaia_accounts_.size()) {
563a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    DVLOG(1) << "Tried to add account out of order";
564a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return;
565a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
566a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
567a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (account->is_active())
568a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    active_account_index_ = account->index();
569a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
570a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  gaia_accounts_.push_back(account.release());
571a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
572a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
5732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool WalletItems::operator==(const WalletItems& other) const {
5742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return google_transaction_id_ == other.google_transaction_id_ &&
5752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)         default_instrument_id_ == other.default_instrument_id_ &&
5762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)         default_address_id_ == other.default_address_id_ &&
5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)         required_actions_ == other.required_actions_ &&
578a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)         // This check is technically redundant, but is useful for tests.
579a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)         ObfuscatedGaiaId() == other.ObfuscatedGaiaId() &&
580f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)         active_account_index() == other.active_account_index() &&
581a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)         VectorsAreEqual<GaiaAccount>(gaia_accounts(),
582a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                      other.gaia_accounts()) &&
583c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)         VectorsAreEqual<MaskedInstrument>(instruments(),
584f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                            other.instruments()) &&
585c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)         VectorsAreEqual<Address>(addresses(), other.addresses()) &&
586c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)         VectorsAreEqual<LegalDocument>(legal_documents(),
587116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                         other.legal_documents()) &&
588116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch         allowed_shipping_countries() == other.allowed_shipping_countries();
5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool WalletItems::operator!=(const WalletItems& other) const {
5922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return !(*this == other);
5932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace wallet
5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace autofill
597