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