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