Add diagnostics_writer.cc to the list of files allowed to printf.
[chromium-blink-merge.git] / components / autofill / content / browser / wallet / gaia_account.cc
blob23323cef9b6c6745602e0f83fb90ab825c3d523c
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
3 // found in the LICENSE file.
5 #include "components/autofill/content/browser/wallet/gaia_account.h"
7 #include "base/logging.h"
8 #include "base/values.h"
10 namespace autofill {
12 namespace wallet {
14 GaiaAccount::~GaiaAccount() {}
16 // static
17 scoped_ptr<GaiaAccount> GaiaAccount::Create(
18 const base::DictionaryValue& dictionary) {
19 std::string email_address;
20 if (!dictionary.GetString("buyer_email", &email_address)) {
21 DLOG(ERROR) << "GAIA account: missing email address";
22 return scoped_ptr<GaiaAccount>();
25 std::string obfuscated_id;
26 if (!dictionary.GetString("gaia_id", &obfuscated_id)) {
27 DLOG(ERROR) << "GAIA account: missing GAIA id";
28 return scoped_ptr<GaiaAccount>();
31 int index = 0;
32 if (!dictionary.GetInteger("gaia_index", &index) ||
33 index < 0) {
34 DLOG(ERROR) << "GAIA account: missing or bad GAIA index";
35 return scoped_ptr<GaiaAccount>();
38 bool is_active = false;
39 if (!dictionary.GetBoolean("is_active", &is_active)) {
40 DLOG(ERROR) << "GAIA account: missing is_active";
41 return scoped_ptr<GaiaAccount>();
44 return scoped_ptr<GaiaAccount>(new GaiaAccount(email_address,
45 obfuscated_id,
46 index,
47 is_active));
50 // static
51 scoped_ptr<GaiaAccount> GaiaAccount::CreateForTesting(
52 const std::string& email_address,
53 const std::string& obfuscated_id,
54 size_t index,
55 bool is_active) {
56 scoped_ptr<GaiaAccount> account(new GaiaAccount(email_address,
57 obfuscated_id,
58 index,
59 is_active));
60 return account.Pass();
63 bool GaiaAccount::operator==(const GaiaAccount& other) const {
64 return email_address_ == other.email_address_ &&
65 obfuscated_id_ == other.obfuscated_id_ &&
66 index_ == other.index_ &&
67 is_active_ == other.is_active_;
70 bool GaiaAccount::operator!=(const GaiaAccount& other) const {
71 return !(*this == other);
74 GaiaAccount::GaiaAccount(const std::string& email_address,
75 const std::string& obfuscated_id,
76 size_t index,
77 bool is_active)
78 : email_address_(email_address),
79 obfuscated_id_(obfuscated_id),
80 index_(index),
81 is_active_(is_active) {}
83 } // namespace wallet
85 } // namespace autofill