| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/autofill/wallet/wallet_address.h" | 5 #include "chrome/browser/autofill/wallet/wallet_address.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 | 10 |
| 11 namespace autofill { | 11 namespace autofill { |
| 12 namespace wallet { | 12 namespace wallet { |
| 13 | 13 |
| 14 namespace { |
| 15 |
| 16 Address* CreateAddressInternal(const base::DictionaryValue& dictionary, |
| 17 const std::string& object_id) { |
| 18 std::string country_name_code; |
| 19 if (!dictionary.GetString("postal_address.country_name_code", |
| 20 &country_name_code)) { |
| 21 DLOG(ERROR) << "Response from Google Wallet missing country name"; |
| 22 return NULL; |
| 23 } |
| 24 |
| 25 string16 recipient_name; |
| 26 if (!dictionary.GetString("postal_address.recipient_name", |
| 27 &recipient_name)) { |
| 28 DLOG(ERROR) << "Response from Google Wallet recipient name"; |
| 29 return NULL; |
| 30 } |
| 31 |
| 32 string16 postal_code_number; |
| 33 if (!dictionary.GetString("postal_address.postal_code_number", |
| 34 &postal_code_number)) { |
| 35 DLOG(ERROR) << "Response from Google Wallet missing postal code number"; |
| 36 return NULL; |
| 37 } |
| 38 |
| 39 string16 phone_number; |
| 40 if (!dictionary.GetString("phone_number", &phone_number)) |
| 41 DVLOG(1) << "Response from Google Wallet missing phone number"; |
| 42 |
| 43 string16 address_line_1; |
| 44 string16 address_line_2; |
| 45 const ListValue* address_line_list; |
| 46 if (dictionary.GetList("postal_address.address_line", &address_line_list)) { |
| 47 if (!address_line_list->GetString(0, &address_line_1)) |
| 48 DVLOG(1) << "Response from Google Wallet missing address line 1"; |
| 49 if (!address_line_list->GetString(1, &address_line_2)) |
| 50 DVLOG(1) << "Response from Google Wallet missing address line 2"; |
| 51 } else { |
| 52 DVLOG(1) << "Response from Google Wallet missing address lines"; |
| 53 } |
| 54 |
| 55 string16 locality_name; |
| 56 if (!dictionary.GetString("postal_address.locality_name", |
| 57 &locality_name)) { |
| 58 DVLOG(1) << "Response from Google Wallet missing locality name"; |
| 59 } |
| 60 |
| 61 string16 administrative_area_name; |
| 62 if (!dictionary.GetString("postal_address.administrative_area_name", |
| 63 &administrative_area_name)) { |
| 64 DVLOG(1) << "Response from Google Wallet missing administrative area name"; |
| 65 } |
| 66 |
| 67 return new Address(country_name_code, |
| 68 recipient_name , |
| 69 address_line_1, |
| 70 address_line_2, |
| 71 locality_name, |
| 72 administrative_area_name, |
| 73 postal_code_number, |
| 74 phone_number, |
| 75 object_id); |
| 76 } |
| 77 |
| 78 } // namespace |
| 79 |
| 14 Address::Address() {} | 80 Address::Address() {} |
| 15 | 81 |
| 16 Address::Address(const std::string& country_name_code, | 82 Address::Address(const std::string& country_name_code, |
| 17 const string16& recipient_name, | 83 const string16& recipient_name, |
| 18 const string16& address_line_1, | 84 const string16& address_line_1, |
| 19 const string16& address_line_2, | 85 const string16& address_line_2, |
| 20 const string16& locality_name, | 86 const string16& locality_name, |
| 21 const string16& administrative_area_name, | 87 const string16& administrative_area_name, |
| 22 const string16& postal_code_number, | 88 const string16& postal_code_number, |
| 23 const string16& phone_number, | 89 const string16& phone_number, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 case ADDRESS_HOME_ZIP: | 155 case ADDRESS_HOME_ZIP: |
| 90 return postal_code_number(); | 156 return postal_code_number(); |
| 91 | 157 |
| 92 // TODO(estade): implement more. | 158 // TODO(estade): implement more. |
| 93 default: | 159 default: |
| 94 NOTREACHED(); | 160 NOTREACHED(); |
| 95 return string16(); | 161 return string16(); |
| 96 } | 162 } |
| 97 } | 163 } |
| 98 | 164 |
| 99 scoped_ptr<Address> | 165 scoped_ptr<Address> Address::CreateAddressWithID( |
| 100 Address::CreateAddressWithID(const base::DictionaryValue& dictionary) { | 166 const base::DictionaryValue& dictionary) { |
| 101 std::string object_id; | 167 std::string object_id; |
| 102 if (!dictionary.GetString("id", &object_id)) { | 168 if (!dictionary.GetString("id", &object_id)) { |
| 103 DLOG(ERROR) << "Response from Google Wallet missing object id"; | 169 DLOG(ERROR) << "Response from Google Wallet missing object id"; |
| 104 return scoped_ptr<Address>(); | 170 return scoped_ptr<Address>(); |
| 105 } | 171 } |
| 106 | 172 return scoped_ptr<Address>(CreateAddressInternal(dictionary, object_id)); |
| 107 std::string country_name_code; | |
| 108 if (!dictionary.GetString("postal_address.country_name_code", | |
| 109 &country_name_code)) { | |
| 110 DLOG(ERROR) << "Response from Google Wallet missing country name"; | |
| 111 return scoped_ptr<Address>(); | |
| 112 } | |
| 113 | |
| 114 string16 recipient_name; | |
| 115 if (!dictionary.GetString("postal_address.recipient_name", | |
| 116 &recipient_name)) { | |
| 117 DLOG(ERROR) << "Response from Google Wallet recipient name"; | |
| 118 return scoped_ptr<Address>(); | |
| 119 } | |
| 120 | |
| 121 string16 postal_code_number; | |
| 122 if (!dictionary.GetString("postal_address.postal_code_number", | |
| 123 &postal_code_number)) { | |
| 124 DLOG(ERROR) << "Response from Google Wallet missing postal code number"; | |
| 125 return scoped_ptr<Address>(); | |
| 126 } | |
| 127 | |
| 128 string16 phone_number; | |
| 129 if (!dictionary.GetString("phone_number", &phone_number)) | |
| 130 DVLOG(1) << "Response from Google Wallet missing phone number"; | |
| 131 | |
| 132 string16 address_line_1; | |
| 133 string16 address_line_2; | |
| 134 const ListValue* address_line_list; | |
| 135 if (dictionary.GetList("postal_address.address_line", &address_line_list)) { | |
| 136 if (!address_line_list->GetString(0, &address_line_1)) | |
| 137 DVLOG(1) << "Response from Google Wallet missing address line 1"; | |
| 138 if (!address_line_list->GetString(1, &address_line_2)) | |
| 139 DVLOG(1) << "Response from Google Wallet missing address line 2"; | |
| 140 } else { | |
| 141 DVLOG(1) << "Response from Google Wallet missing address lines"; | |
| 142 } | |
| 143 | |
| 144 string16 locality_name; | |
| 145 if (!dictionary.GetString("postal_address.locality_name", | |
| 146 &locality_name)) { | |
| 147 DVLOG(1) << "Response from Google Wallet missing locality name"; | |
| 148 } | |
| 149 | |
| 150 string16 administrative_area_name; | |
| 151 if (!dictionary.GetString("postal_address.administrative_area_name", | |
| 152 &administrative_area_name)) { | |
| 153 DVLOG(1) << "Response from Google Wallet missing administrative area name"; | |
| 154 } | |
| 155 | |
| 156 return scoped_ptr<Address>(new Address(country_name_code, | |
| 157 recipient_name , | |
| 158 address_line_1, | |
| 159 address_line_2, | |
| 160 locality_name, | |
| 161 administrative_area_name, | |
| 162 postal_code_number, | |
| 163 phone_number, | |
| 164 object_id)); | |
| 165 } | 173 } |
| 166 | 174 |
| 167 scoped_ptr<Address> | 175 scoped_ptr<Address> Address::CreateAddress( |
| 168 Address::CreateDisplayAddress(const base::DictionaryValue& dictionary) { | 176 const base::DictionaryValue& dictionary) { |
| 177 std::string object_id; |
| 178 dictionary.GetString("id", &object_id); |
| 179 return scoped_ptr<Address>(CreateAddressInternal(dictionary, object_id)); |
| 180 } |
| 181 |
| 182 scoped_ptr<Address> Address::CreateDisplayAddress( |
| 183 const base::DictionaryValue& dictionary) { |
| 169 std::string country_code; | 184 std::string country_code; |
| 170 if (!dictionary.GetString("country_code", &country_code)) { | 185 if (!dictionary.GetString("country_code", &country_code)) { |
| 171 DLOG(ERROR) << "Reponse from Google Wallet missing country code"; | 186 DLOG(ERROR) << "Reponse from Google Wallet missing country code"; |
| 172 return scoped_ptr<Address>(); | 187 return scoped_ptr<Address>(); |
| 173 } | 188 } |
| 174 | 189 |
| 175 string16 name; | 190 string16 name; |
| 176 if (!dictionary.GetString("name", &name)) { | 191 if (!dictionary.GetString("name", &name)) { |
| 177 DLOG(ERROR) << "Reponse from Google Wallet missing name"; | 192 DLOG(ERROR) << "Reponse from Google Wallet missing name"; |
| 178 return scoped_ptr<Address>(); | 193 return scoped_ptr<Address>(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 phone_number_ == other.phone_number_ && | 241 phone_number_ == other.phone_number_ && |
| 227 object_id_ == other.object_id_; | 242 object_id_ == other.object_id_; |
| 228 } | 243 } |
| 229 | 244 |
| 230 bool Address::operator!=(const Address& other) const { | 245 bool Address::operator!=(const Address& other) const { |
| 231 return !(*this == other); | 246 return !(*this == other); |
| 232 } | 247 } |
| 233 | 248 |
| 234 } // namespace wallet | 249 } // namespace wallet |
| 235 } // namespace autofill | 250 } // namespace autofill |
| OLD | NEW |