| 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 "components/autofill/browser/wallet/wallet_address.h" | 5 #include "components/autofill/browser/wallet/wallet_address.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "components/autofill/browser/autofill_country.h" | 11 #include "components/autofill/browser/autofill_country.h" |
| 12 #include "components/autofill/browser/autofill_profile.h" | 12 #include "components/autofill/browser/autofill_profile.h" |
| 13 | 13 |
| 14 namespace autofill { | 14 namespace autofill { |
| 15 namespace wallet { | 15 namespace wallet { |
| 16 | 16 |
| 17 // Server specified type for address with complete details. |
| 18 const char kFullAddress[] = "FULL"; |
| 19 const char kTrue[] = "true"; |
| 20 |
| 17 namespace { | 21 namespace { |
| 18 | 22 |
| 19 Address* CreateAddressInternal(const base::DictionaryValue& dictionary, | 23 Address* CreateAddressInternal(const base::DictionaryValue& dictionary, |
| 20 const std::string& object_id) { | 24 const std::string& object_id) { |
| 21 std::string country_name_code; | 25 std::string country_name_code; |
| 22 if (!dictionary.GetString("postal_address.country_name_code", | 26 if (!dictionary.GetString("postal_address.country_name_code", |
| 23 &country_name_code)) { | 27 &country_name_code)) { |
| 24 DLOG(ERROR) << "Response from Google Wallet missing country name"; | 28 DLOG(ERROR) << "Response from Google Wallet missing country name"; |
| 25 return NULL; | 29 return NULL; |
| 26 } | 30 } |
| 27 | 31 |
| 28 string16 recipient_name; | 32 string16 recipient_name; |
| 29 if (!dictionary.GetString("postal_address.recipient_name", | 33 if (!dictionary.GetString("postal_address.recipient_name", |
| 30 &recipient_name)) { | 34 &recipient_name)) { |
| 31 DLOG(ERROR) << "Response from Google Wallet recipient name"; | 35 DLOG(ERROR) << "Response from Google Wallet missing recipient name"; |
| 32 return NULL; | 36 return NULL; |
| 33 } | 37 } |
| 34 | 38 |
| 35 string16 postal_code_number; | 39 string16 postal_code_number; |
| 36 if (!dictionary.GetString("postal_address.postal_code_number", | 40 if (!dictionary.GetString("postal_address.postal_code_number", |
| 37 &postal_code_number)) { | 41 &postal_code_number)) { |
| 38 DLOG(ERROR) << "Response from Google Wallet missing postal code number"; | 42 DLOG(ERROR) << "Response from Google Wallet missing postal code number"; |
| 39 return NULL; | 43 return NULL; |
| 40 } | 44 } |
| 41 | 45 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 60 &locality_name)) { | 64 &locality_name)) { |
| 61 DVLOG(1) << "Response from Google Wallet missing locality name"; | 65 DVLOG(1) << "Response from Google Wallet missing locality name"; |
| 62 } | 66 } |
| 63 | 67 |
| 64 string16 administrative_area_name; | 68 string16 administrative_area_name; |
| 65 if (!dictionary.GetString("postal_address.administrative_area_name", | 69 if (!dictionary.GetString("postal_address.administrative_area_name", |
| 66 &administrative_area_name)) { | 70 &administrative_area_name)) { |
| 67 DVLOG(1) << "Response from Google Wallet missing administrative area name"; | 71 DVLOG(1) << "Response from Google Wallet missing administrative area name"; |
| 68 } | 72 } |
| 69 | 73 |
| 70 return new Address(country_name_code, | 74 std::string is_minimal_address; |
| 71 recipient_name , | 75 if (!dictionary.GetString("is_minimal_address", &is_minimal_address)) |
| 72 address_line_1, | 76 DVLOG(1) << "Response from Google Wallet missing is_minimal_address bit"; |
| 73 address_line_2, | 77 |
| 74 locality_name, | 78 Address* address = new Address(country_name_code, |
| 75 administrative_area_name, | 79 recipient_name, |
| 76 postal_code_number, | 80 address_line_1, |
| 77 phone_number, | 81 address_line_2, |
| 78 object_id); | 82 locality_name, |
| 83 administrative_area_name, |
| 84 postal_code_number, |
| 85 phone_number, |
| 86 object_id); |
| 87 address->set_is_complete_address(is_minimal_address != kTrue); |
| 88 |
| 89 return address; |
| 79 } | 90 } |
| 80 | 91 |
| 81 } // namespace | 92 } // namespace |
| 82 | 93 |
| 83 Address::Address() {} | 94 Address::Address() {} |
| 84 | 95 |
| 85 Address::Address(const AutofillProfile& profile) | 96 Address::Address(const AutofillProfile& profile) |
| 86 : country_name_code_( | 97 : country_name_code_( |
| 87 UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))), | 98 UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))), |
| 88 recipient_name_(profile.GetRawInfo(NAME_FULL)), | 99 recipient_name_(profile.GetRawInfo(NAME_FULL)), |
| 89 address_line_1_(profile.GetRawInfo(ADDRESS_HOME_LINE1)), | 100 address_line_1_(profile.GetRawInfo(ADDRESS_HOME_LINE1)), |
| 90 address_line_2_(profile.GetRawInfo(ADDRESS_HOME_LINE2)), | 101 address_line_2_(profile.GetRawInfo(ADDRESS_HOME_LINE2)), |
| 91 locality_name_(profile.GetRawInfo(ADDRESS_HOME_CITY)), | 102 locality_name_(profile.GetRawInfo(ADDRESS_HOME_CITY)), |
| 92 administrative_area_name_(profile.GetRawInfo(ADDRESS_HOME_STATE)), | 103 administrative_area_name_(profile.GetRawInfo(ADDRESS_HOME_STATE)), |
| 93 postal_code_number_(profile.GetRawInfo(ADDRESS_HOME_ZIP)), | 104 postal_code_number_(profile.GetRawInfo(ADDRESS_HOME_ZIP)), |
| 94 phone_number_(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)) {} | 105 phone_number_(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)), |
| 106 is_complete_address_(true) {} |
| 95 | 107 |
| 96 Address::Address(const std::string& country_name_code, | 108 Address::Address(const std::string& country_name_code, |
| 97 const string16& recipient_name, | 109 const string16& recipient_name, |
| 98 const string16& address_line_1, | 110 const string16& address_line_1, |
| 99 const string16& address_line_2, | 111 const string16& address_line_2, |
| 100 const string16& locality_name, | 112 const string16& locality_name, |
| 101 const string16& administrative_area_name, | 113 const string16& administrative_area_name, |
| 102 const string16& postal_code_number, | 114 const string16& postal_code_number, |
| 103 const string16& phone_number, | 115 const string16& phone_number, |
| 104 const std::string& object_id) | 116 const std::string& object_id) |
| 105 : country_name_code_(country_name_code), | 117 : country_name_code_(country_name_code), |
| 106 recipient_name_(recipient_name), | 118 recipient_name_(recipient_name), |
| 107 address_line_1_(address_line_1), | 119 address_line_1_(address_line_1), |
| 108 address_line_2_(address_line_2), | 120 address_line_2_(address_line_2), |
| 109 locality_name_(locality_name), | 121 locality_name_(locality_name), |
| 110 administrative_area_name_(administrative_area_name), | 122 administrative_area_name_(administrative_area_name), |
| 111 postal_code_number_(postal_code_number), | 123 postal_code_number_(postal_code_number), |
| 112 phone_number_(phone_number), | 124 phone_number_(phone_number), |
| 113 object_id_(object_id) {} | 125 object_id_(object_id), |
| 126 is_complete_address_(true) {} |
| 114 | 127 |
| 115 Address::~Address() {} | 128 Address::~Address() {} |
| 116 | 129 |
| 117 // static | 130 // static |
| 118 scoped_ptr<Address> Address::CreateAddressWithID( | 131 scoped_ptr<Address> Address::CreateAddressWithID( |
| 119 const base::DictionaryValue& dictionary) { | 132 const base::DictionaryValue& dictionary) { |
| 120 std::string object_id; | 133 std::string object_id; |
| 121 if (!dictionary.GetString("id", &object_id)) { | 134 if (!dictionary.GetString("id", &object_id)) { |
| 122 DLOG(ERROR) << "Response from Google Wallet missing object id"; | 135 DLOG(ERROR) << "Response from Google Wallet missing object id"; |
| 123 return scoped_ptr<Address>(); | 136 return scoped_ptr<Address>(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 DVLOG(1) << "Reponse from Google Wallet missing city"; | 180 DVLOG(1) << "Reponse from Google Wallet missing city"; |
| 168 | 181 |
| 169 string16 state; | 182 string16 state; |
| 170 if (!dictionary.GetString("state", &state)) | 183 if (!dictionary.GetString("state", &state)) |
| 171 DVLOG(1) << "Reponse from Google Wallet missing state"; | 184 DVLOG(1) << "Reponse from Google Wallet missing state"; |
| 172 | 185 |
| 173 string16 phone_number; | 186 string16 phone_number; |
| 174 if (!dictionary.GetString("phone_number", &phone_number)) | 187 if (!dictionary.GetString("phone_number", &phone_number)) |
| 175 DVLOG(1) << "Reponse from Google Wallet missing phone number"; | 188 DVLOG(1) << "Reponse from Google Wallet missing phone number"; |
| 176 | 189 |
| 177 return scoped_ptr<Address>(new Address(country_code, | 190 std::string address_state; |
| 178 name, | 191 if (!dictionary.GetString("type", &address_state)) |
| 179 address1, | 192 DVLOG(1) << "Response from Google Wallet missing type/state of address"; |
| 180 address2, | 193 |
| 181 city, | 194 scoped_ptr<Address> address( |
| 182 state, | 195 new Address(country_code, |
| 183 postal_code, | 196 name, |
| 184 phone_number, | 197 address1, |
| 185 std::string())); | 198 address2, |
| 199 city, |
| 200 state, |
| 201 postal_code, |
| 202 phone_number, |
| 203 std::string())); |
| 204 address->set_is_complete_address(address_state == kFullAddress); |
| 205 |
| 206 return address.Pass(); |
| 186 } | 207 } |
| 187 | 208 |
| 188 scoped_ptr<base::DictionaryValue> Address::ToDictionaryWithID() const { | 209 scoped_ptr<base::DictionaryValue> Address::ToDictionaryWithID() const { |
| 189 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 210 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 190 | 211 |
| 191 if (!object_id_.empty()) | 212 if (!object_id_.empty()) |
| 192 dict->SetString("id", object_id_); | 213 dict->SetString("id", object_id_); |
| 193 dict->SetString("phone_number", phone_number_); | 214 dict->SetString("phone_number", phone_number_); |
| 194 dict->Set("postal_address", ToDictionaryWithoutID().release()); | 215 dict->Set("postal_address", ToDictionaryWithoutID().release()); |
| 195 | 216 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 293 |
| 273 bool Address::operator==(const Address& other) const { | 294 bool Address::operator==(const Address& other) const { |
| 274 return country_name_code_ == other.country_name_code_ && | 295 return country_name_code_ == other.country_name_code_ && |
| 275 recipient_name_ == other.recipient_name_ && | 296 recipient_name_ == other.recipient_name_ && |
| 276 address_line_1_ == other.address_line_1_ && | 297 address_line_1_ == other.address_line_1_ && |
| 277 address_line_2_ == other.address_line_2_ && | 298 address_line_2_ == other.address_line_2_ && |
| 278 locality_name_ == other.locality_name_ && | 299 locality_name_ == other.locality_name_ && |
| 279 administrative_area_name_ == other.administrative_area_name_ && | 300 administrative_area_name_ == other.administrative_area_name_ && |
| 280 postal_code_number_ == other.postal_code_number_ && | 301 postal_code_number_ == other.postal_code_number_ && |
| 281 phone_number_ == other.phone_number_ && | 302 phone_number_ == other.phone_number_ && |
| 282 object_id_ == other.object_id_; | 303 object_id_ == other.object_id_ && |
| 304 is_complete_address_ == other.is_complete_address_; |
| 283 } | 305 } |
| 284 | 306 |
| 285 bool Address::operator!=(const Address& other) const { | 307 bool Address::operator!=(const Address& other) const { |
| 286 return !(*this == other); | 308 return !(*this == other); |
| 287 } | 309 } |
| 288 | 310 |
| 289 } // namespace wallet | 311 } // namespace wallet |
| 290 } // namespace autofill | 312 } // namespace autofill |
| OLD | NEW |