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