Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/autofill/wallet/wallet_address.cc

Issue 11293078: Integrating Online Wallet into Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing HexStringToInt Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/autofill/wallet/wallet_address.h"
6
7 #include "base/logging.h"
8 #include "base/values.h"
9
10 namespace wallet {
11
12 Address::Address() {}
13
14 Address::Address(const std::string& country_name_code,
15 const std::string& recipient_name,
16 const std::string& address_line_1,
17 const std::string& address_line_2,
18 const std::string& locality_name,
19 const std::string& administrative_area_name,
20 const std::string& postal_code_number,
21 const std::string& phone_number,
22 const std::string& object_id)
23 : country_name_code_(country_name_code),
24 recipient_name_(recipient_name),
25 address_line_1_(address_line_1),
26 address_line_2_(address_line_2),
27 locality_name_(locality_name),
28 administrative_area_name_(administrative_area_name),
29 postal_code_number_(postal_code_number),
30 phone_number_(phone_number),
31 object_id_(object_id) {}
32
33 Address::~Address() {}
34
35 scoped_ptr<Address>
36 Address::CreateAddressWithID(const base::DictionaryValue& dictionary) {
37 std::string object_id;
38 if (!dictionary.GetString("id", &object_id)) {
39 DLOG(ERROR) << "Response from Google Wallet missing object id";
40 return scoped_ptr<Address>();
41 }
42
43 std::string country_name_code;
44 if (!dictionary.GetString("postal_address.country_name_code",
45 &country_name_code)) {
46 DLOG(ERROR) << "Response from Google Wallet missing country name";
47 return scoped_ptr<Address>();
48 }
49
50 std::string recipient_name;
51 if (!dictionary.GetString("postal_address.recipient_name",
52 &recipient_name)) {
53 DLOG(ERROR) << "Response from Google Wallet recipient name";
54 return scoped_ptr<Address>();
55 }
56
57 std::string postal_code_number;
58 if (!dictionary.GetString("postal_address.postal_code_number",
59 &postal_code_number)) {
60 DLOG(ERROR) << "Response from Google Wallet missing postal code number";
61 return scoped_ptr<Address>();
62 }
63
64 std::string phone_number;
65 if (!dictionary.GetString("phone_number", &phone_number))
66 DVLOG(1) << "Response from Google Wallet missing phone number";
67
68 std::string address_line_1;
69 std::string address_line_2;
70 const ListValue* address_line_list;
71 if (dictionary.GetList("postal_address.address_line", &address_line_list)) {
72 if (!address_line_list->GetString(0, &address_line_1))
73 DVLOG(1) << "Response from Google Wallet missing address line 1";
74 if (!address_line_list->GetString(1, &address_line_2))
75 DVLOG(1) << "Response from Google Wallet missing address line 2";
76 } else {
77 DVLOG(1) << "Response from Google Wallet missing address lines";
78 }
79
80 std::string locality_name;
81 if (!dictionary.GetString("postal_address.locality_name",
82 &locality_name)) {
83 DVLOG(1) << "Response from Google Wallet missing locality name";
84 }
85
86 std::string administrative_area_name;
87 if (!dictionary.GetString("postal_address.administrative_area_name",
88 &administrative_area_name)) {
89 DVLOG(1) << "Response from Google Wallet missing administrative area name";
90 }
91
92 return scoped_ptr<Address>(new Address(country_name_code,
93 recipient_name ,
94 address_line_1,
95 address_line_2,
96 locality_name,
97 administrative_area_name,
98 postal_code_number,
99 phone_number,
100 object_id));
101 }
102
103
104 scoped_ptr<Address>
105 Address::CreateDisplayAddress(const base::DictionaryValue& dictionary) {
106 std::string country_code;
107 if (!dictionary.GetString("country_code", &country_code)) {
108 DLOG(ERROR) << "Reponse from Google Wallet missing country code";
109 return scoped_ptr<Address>();
110 }
111
112 std::string name;
113 if (!dictionary.GetString("name", &name)) {
114 DLOG(ERROR) << "Reponse from Google Wallet missing name";
115 return scoped_ptr<Address>();
116 }
117
118 std::string postal_code;
119 if (!dictionary.GetString("postal_code", &postal_code)) {
120 DLOG(ERROR) << "Reponse from Google Wallet missing postal code";
121 return scoped_ptr<Address>();
122 }
123
124 std::string address1;
125 if (!dictionary.GetString("address1", &address1))
126 DVLOG(1) << "Reponse from Google Wallet missing address1";
127
128 std::string address2;
129 if (!dictionary.GetString("address2", &address2))
130 DVLOG(1) << "Reponse from Google Wallet missing address2";
131
132 std::string city;
133 if (!dictionary.GetString("city", &city))
134 DVLOG(1) << "Reponse from Google Wallet missing city";
135
136 std::string state;
137 if (!dictionary.GetString("state", &state))
138 DVLOG(1) << "Reponse from Google Wallet missing state";
139
140 std::string phone_number;
141 if (!dictionary.GetString("phone_number", &phone_number))
142 DVLOG(1) << "Reponse from Google Wallet missing phone number";
143
144 return scoped_ptr<Address>(new Address(country_code,
145 name,
146 address1,
147 address2,
148 city,
149 state,
150 postal_code,
151 phone_number,
152 ""));
153 }
154
155 bool Address::operator==(const Address& other) const {
156 return country_name_code_ == other.country_name_code_ &&
157 recipient_name_ == other.recipient_name_ &&
158 address_line_1_ == other.address_line_1_ &&
159 address_line_2_ == other.address_line_2_ &&
160 locality_name_ == other.locality_name_ &&
161 administrative_area_name_ == other.administrative_area_name_ &&
162 postal_code_number_ == other.postal_code_number_ &&
163 phone_number_ == other.phone_number_ &&
164 object_id_ == other.object_id_;
165 }
166
167 bool Address::operator!=(const Address& other) const {
168 return !(*this == other);
169 }
170
171 } // namespace wallet
172
OLDNEW
« no previous file with comments | « chrome/browser/autofill/wallet/wallet_address.h ('k') | chrome/browser/autofill/wallet/wallet_address_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698