summaryrefslogtreecommitdiff
path: root/chromium/components/autofill/content/browser/wallet/gaia_account.cc
blob: 23323cef9b6c6745602e0f83fb90ab825c3d523c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill/content/browser/wallet/gaia_account.h"

#include "base/logging.h"
#include "base/values.h"

namespace autofill {

namespace wallet {

GaiaAccount::~GaiaAccount() {}

// static
scoped_ptr<GaiaAccount> GaiaAccount::Create(
    const base::DictionaryValue& dictionary) {
  std::string email_address;
  if (!dictionary.GetString("buyer_email", &email_address)) {
    DLOG(ERROR) << "GAIA account: missing email address";
    return scoped_ptr<GaiaAccount>();
  }

  std::string obfuscated_id;
  if (!dictionary.GetString("gaia_id", &obfuscated_id)) {
    DLOG(ERROR) << "GAIA account: missing GAIA id";
    return scoped_ptr<GaiaAccount>();
  }

  int index = 0;
  if (!dictionary.GetInteger("gaia_index", &index) ||
      index < 0) {
    DLOG(ERROR) << "GAIA account: missing or bad GAIA index";
    return scoped_ptr<GaiaAccount>();
  }

  bool is_active = false;
  if (!dictionary.GetBoolean("is_active", &is_active)) {
    DLOG(ERROR) << "GAIA account: missing is_active";
    return scoped_ptr<GaiaAccount>();
  }

  return scoped_ptr<GaiaAccount>(new GaiaAccount(email_address,
                                                 obfuscated_id,
                                                 index,
                                                 is_active));
}

// static
scoped_ptr<GaiaAccount> GaiaAccount::CreateForTesting(
    const std::string& email_address,
    const std::string& obfuscated_id,
    size_t index,
    bool is_active) {
  scoped_ptr<GaiaAccount> account(new GaiaAccount(email_address,
                                                  obfuscated_id,
                                                  index,
                                                  is_active));
  return account.Pass();
}

bool GaiaAccount::operator==(const GaiaAccount& other) const {
  return email_address_ == other.email_address_ &&
      obfuscated_id_ == other.obfuscated_id_ &&
      index_ == other.index_ &&
      is_active_ == other.is_active_;
}

bool GaiaAccount::operator!=(const GaiaAccount& other) const {
  return !(*this == other);
}

GaiaAccount::GaiaAccount(const std::string& email_address,
                         const std::string& obfuscated_id,
                         size_t index,
                         bool is_active)
    : email_address_(email_address),
      obfuscated_id_(obfuscated_id),
      index_(index),
      is_active_(is_active) {}

}  // namespace wallet

}  // namespace autofill