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