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