OLD | NEW |
(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 Address* Address::CreateAddressWithID(const base::DictionaryValue& dictionary) { |
| 36 std::string object_id; |
| 37 if (!dictionary.GetString("id", &object_id)) { |
| 38 DLOG(ERROR) << "Response from Google Wallet missing object id"; |
| 39 return NULL; |
| 40 } |
| 41 |
| 42 std::string country_name_code; |
| 43 if (!dictionary.GetString("postal_address.country_name_code", |
| 44 &country_name_code)) { |
| 45 DLOG(ERROR) << "Response from Google Wallet missing country name"; |
| 46 return NULL; |
| 47 } |
| 48 |
| 49 std::string recipient_name; |
| 50 if (!dictionary.GetString("postal_address.recipient_name", |
| 51 &recipient_name)) { |
| 52 DLOG(ERROR) << "Response from Google Wallet recipient name"; |
| 53 return NULL; |
| 54 } |
| 55 |
| 56 std::string postal_code_number; |
| 57 if (!dictionary.GetString("postal_address.postal_code_number", |
| 58 &postal_code_number)) { |
| 59 DLOG(ERROR) << "Response from Google Wallet missing postal code number"; |
| 60 return NULL; |
| 61 } |
| 62 |
| 63 std::string phone_number; |
| 64 if (!dictionary.GetString("phone_number", &phone_number)) |
| 65 DVLOG(1) << "Response from Google Wallet missing phone number"; |
| 66 |
| 67 std::string address_line_1; |
| 68 std::string address_line_2; |
| 69 const ListValue* address_line_list; |
| 70 if (dictionary.GetList("postal_address.address_line", &address_line_list)) { |
| 71 if (!address_line_list->GetString(0, &address_line_1)) |
| 72 DVLOG(1) << "Response from Google Wallet missing address line 1"; |
| 73 if (!address_line_list->GetString(1, &address_line_2)) |
| 74 DVLOG(1) << "Response from Google Wallet missing address line 2"; |
| 75 } else { |
| 76 DVLOG(1) << "Response from Google Wallet missing address lines"; |
| 77 } |
| 78 |
| 79 std::string locality_name; |
| 80 if (!dictionary.GetString("postal_address.locality_name", |
| 81 &locality_name)) { |
| 82 DVLOG(1) << "Response from Google Wallet missing locality name"; |
| 83 } |
| 84 |
| 85 std::string administrative_area_name; |
| 86 if (!dictionary.GetString("postal_address.administrative_area_name", |
| 87 &administrative_area_name)) { |
| 88 DVLOG(1) << "Response from Google Wallet missing administrative area name"; |
| 89 } |
| 90 |
| 91 return new Address(country_name_code, |
| 92 recipient_name , |
| 93 address_line_1, |
| 94 address_line_2, |
| 95 locality_name, |
| 96 administrative_area_name, |
| 97 postal_code_number, |
| 98 phone_number, |
| 99 object_id); |
| 100 } |
| 101 |
| 102 |
| 103 Address* Address::CreateDisplayAddress( |
| 104 const base::DictionaryValue& dictionary) { |
| 105 std::string country_code; |
| 106 if (!dictionary.GetString("country_code", &country_code)) { |
| 107 DLOG(ERROR) << "Reponse from Google Wallet missing country code"; |
| 108 return NULL; |
| 109 } |
| 110 |
| 111 std::string name; |
| 112 if (!dictionary.GetString("name", &name)) { |
| 113 DLOG(ERROR) << "Reponse from Google Wallet missing name"; |
| 114 return NULL; |
| 115 } |
| 116 |
| 117 std::string postal_code; |
| 118 if (!dictionary.GetString("postal_code", &postal_code)) { |
| 119 DLOG(ERROR) << "Reponse from Google Wallet missing postal code"; |
| 120 return NULL; |
| 121 } |
| 122 |
| 123 std::string address1; |
| 124 if (!dictionary.GetString("address1", &address1)) |
| 125 DVLOG(1) << "Reponse from Google Wallet missing address1"; |
| 126 |
| 127 std::string address2; |
| 128 if (!dictionary.GetString("address2", &address2)) |
| 129 DVLOG(1) << "Reponse from Google Wallet missing address2"; |
| 130 |
| 131 std::string city; |
| 132 if (!dictionary.GetString("city", &city)) |
| 133 DVLOG(1) << "Reponse from Google Wallet missing city"; |
| 134 |
| 135 std::string state; |
| 136 if (!dictionary.GetString("state", &state)) |
| 137 DVLOG(1) << "Reponse from Google Wallet missing state"; |
| 138 |
| 139 std::string phone_number; |
| 140 if (!dictionary.GetString("phone_number", &phone_number)) |
| 141 DVLOG(1) << "Reponse from Google Wallet missing phone number"; |
| 142 |
| 143 return new Address(country_code, |
| 144 name, |
| 145 address1, |
| 146 address2, |
| 147 city, |
| 148 state, |
| 149 postal_code, |
| 150 phone_number, |
| 151 ""); |
| 152 } |
| 153 |
| 154 bool Address::operator==(const Address& other) const { |
| 155 return country_name_code_ == other.country_name_code_ && |
| 156 recipient_name_ == other.recipient_name_ && |
| 157 address_line_1_ == other.address_line_1_ && |
| 158 address_line_2_ == other.address_line_2_ && |
| 159 locality_name_ == other.locality_name_ && |
| 160 administrative_area_name_ == other.administrative_area_name_ && |
| 161 postal_code_number_ == other.postal_code_number_ && |
| 162 phone_number_ == other.phone_number_ && |
| 163 object_id_ == other.object_id_; |
| 164 } |
| 165 |
| 166 bool Address::operator!=(const Address& other) const { |
| 167 return !(*this == other); |
| 168 } |
| 169 |
| 170 } // end wallet namespace |
| 171 |
OLD | NEW |