Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(771)

Side by Side Diff: components/autofill/content/browser/wallet/wallet_address.cc

Issue 107383002: Use base namespace for string16 in components and cloud_print. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/content/browser/wallet/wallet_address.h" 5 #include "components/autofill/content/browser/wallet/wallet_address.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 13 matching lines...) Expand all
24 24
25 Address* CreateAddressInternal(const base::DictionaryValue& dictionary, 25 Address* CreateAddressInternal(const base::DictionaryValue& dictionary,
26 const std::string& object_id) { 26 const std::string& object_id) {
27 std::string country_name_code; 27 std::string country_name_code;
28 if (!dictionary.GetString("postal_address.country_name_code", 28 if (!dictionary.GetString("postal_address.country_name_code",
29 &country_name_code)) { 29 &country_name_code)) {
30 DLOG(ERROR) << "Response from Google Wallet missing country name"; 30 DLOG(ERROR) << "Response from Google Wallet missing country name";
31 return NULL; 31 return NULL;
32 } 32 }
33 33
34 string16 recipient_name; 34 base::string16 recipient_name;
35 if (!dictionary.GetString("postal_address.recipient_name", 35 if (!dictionary.GetString("postal_address.recipient_name",
36 &recipient_name)) { 36 &recipient_name)) {
37 DLOG(ERROR) << "Response from Google Wallet missing recipient name"; 37 DLOG(ERROR) << "Response from Google Wallet missing recipient name";
38 return NULL; 38 return NULL;
39 } 39 }
40 40
41 string16 postal_code_number; 41 base::string16 postal_code_number;
42 if (!dictionary.GetString("postal_address.postal_code_number", 42 if (!dictionary.GetString("postal_address.postal_code_number",
43 &postal_code_number)) { 43 &postal_code_number)) {
44 DLOG(ERROR) << "Response from Google Wallet missing postal code number"; 44 DLOG(ERROR) << "Response from Google Wallet missing postal code number";
45 return NULL; 45 return NULL;
46 } 46 }
47 47
48 string16 phone_number; 48 base::string16 phone_number;
49 if (!dictionary.GetString("phone_number", &phone_number)) 49 if (!dictionary.GetString("phone_number", &phone_number))
50 DVLOG(1) << "Response from Google Wallet missing phone number"; 50 DVLOG(1) << "Response from Google Wallet missing phone number";
51 51
52 string16 address_line_1; 52 base::string16 address_line_1;
53 string16 address_line_2; 53 base::string16 address_line_2;
54 const ListValue* address_line_list; 54 const ListValue* address_line_list;
55 if (dictionary.GetList("postal_address.address_line", &address_line_list)) { 55 if (dictionary.GetList("postal_address.address_line", &address_line_list)) {
56 if (!address_line_list->GetString(0, &address_line_1)) 56 if (!address_line_list->GetString(0, &address_line_1))
57 DVLOG(1) << "Response from Google Wallet missing address line 1"; 57 DVLOG(1) << "Response from Google Wallet missing address line 1";
58 if (!address_line_list->GetString(1, &address_line_2)) 58 if (!address_line_list->GetString(1, &address_line_2))
59 DVLOG(1) << "Response from Google Wallet missing address line 2"; 59 DVLOG(1) << "Response from Google Wallet missing address line 2";
60 } else { 60 } else {
61 DVLOG(1) << "Response from Google Wallet missing address lines"; 61 DVLOG(1) << "Response from Google Wallet missing address lines";
62 } 62 }
63 63
64 string16 locality_name; 64 base::string16 locality_name;
65 if (!dictionary.GetString("postal_address.locality_name", 65 if (!dictionary.GetString("postal_address.locality_name",
66 &locality_name)) { 66 &locality_name)) {
67 DVLOG(1) << "Response from Google Wallet missing locality name"; 67 DVLOG(1) << "Response from Google Wallet missing locality name";
68 } 68 }
69 69
70 string16 administrative_area_name; 70 base::string16 administrative_area_name;
71 if (!dictionary.GetString("postal_address.administrative_area_name", 71 if (!dictionary.GetString("postal_address.administrative_area_name",
72 &administrative_area_name)) { 72 &administrative_area_name)) {
73 DVLOG(1) << "Response from Google Wallet missing administrative area name"; 73 DVLOG(1) << "Response from Google Wallet missing administrative area name";
74 } 74 }
75 75
76 Address* address = new Address(country_name_code, 76 Address* address = new Address(country_name_code,
77 recipient_name, 77 recipient_name,
78 address_line_1, 78 address_line_1,
79 address_line_2, 79 address_line_2,
80 locality_name, 80 locality_name,
(...skipping 28 matching lines...) Expand all
109 state_names::GetNameAndAbbreviation(profile.GetRawInfo(ADDRESS_HOME_STATE), 109 state_names::GetNameAndAbbreviation(profile.GetRawInfo(ADDRESS_HOME_STATE),
110 NULL, 110 NULL,
111 &administrative_area_name_); 111 &administrative_area_name_);
112 StringToUpperASCII(&administrative_area_name_); 112 StringToUpperASCII(&administrative_area_name_);
113 113
114 if (!country_name_code_.empty()) 114 if (!country_name_code_.empty())
115 phone_object_ = i18n::PhoneObject(phone_number_, country_name_code_); 115 phone_object_ = i18n::PhoneObject(phone_number_, country_name_code_);
116 } 116 }
117 117
118 Address::Address(const std::string& country_name_code, 118 Address::Address(const std::string& country_name_code,
119 const string16& recipient_name, 119 const base::string16& recipient_name,
120 const string16& address_line_1, 120 const base::string16& address_line_1,
121 const string16& address_line_2, 121 const base::string16& address_line_2,
122 const string16& locality_name, 122 const base::string16& locality_name,
123 const string16& administrative_area_name, 123 const base::string16& administrative_area_name,
124 const string16& postal_code_number, 124 const base::string16& postal_code_number,
125 const string16& phone_number, 125 const base::string16& phone_number,
126 const std::string& object_id) 126 const std::string& object_id)
127 : country_name_code_(country_name_code), 127 : country_name_code_(country_name_code),
128 recipient_name_(recipient_name), 128 recipient_name_(recipient_name),
129 address_line_1_(address_line_1), 129 address_line_1_(address_line_1),
130 address_line_2_(address_line_2), 130 address_line_2_(address_line_2),
131 locality_name_(locality_name), 131 locality_name_(locality_name),
132 administrative_area_name_(administrative_area_name), 132 administrative_area_name_(administrative_area_name),
133 postal_code_number_(postal_code_number), 133 postal_code_number_(postal_code_number),
134 phone_number_(phone_number), 134 phone_number_(phone_number),
135 phone_object_(phone_number, country_name_code), 135 phone_object_(phone_number, country_name_code),
(...skipping 23 matching lines...) Expand all
159 159
160 // static 160 // static
161 scoped_ptr<Address> Address::CreateDisplayAddress( 161 scoped_ptr<Address> Address::CreateDisplayAddress(
162 const base::DictionaryValue& dictionary) { 162 const base::DictionaryValue& dictionary) {
163 std::string country_code; 163 std::string country_code;
164 if (!dictionary.GetString("country_code", &country_code)) { 164 if (!dictionary.GetString("country_code", &country_code)) {
165 DLOG(ERROR) << "Reponse from Google Wallet missing country code"; 165 DLOG(ERROR) << "Reponse from Google Wallet missing country code";
166 return scoped_ptr<Address>(); 166 return scoped_ptr<Address>();
167 } 167 }
168 168
169 string16 name; 169 base::string16 name;
170 if (!dictionary.GetString("name", &name)) { 170 if (!dictionary.GetString("name", &name)) {
171 DLOG(ERROR) << "Reponse from Google Wallet missing name"; 171 DLOG(ERROR) << "Reponse from Google Wallet missing name";
172 return scoped_ptr<Address>(); 172 return scoped_ptr<Address>();
173 } 173 }
174 174
175 string16 postal_code; 175 base::string16 postal_code;
176 if (!dictionary.GetString("postal_code", &postal_code)) { 176 if (!dictionary.GetString("postal_code", &postal_code)) {
177 DLOG(ERROR) << "Reponse from Google Wallet missing postal code"; 177 DLOG(ERROR) << "Reponse from Google Wallet missing postal code";
178 return scoped_ptr<Address>(); 178 return scoped_ptr<Address>();
179 } 179 }
180 180
181 string16 address1; 181 base::string16 address1;
182 if (!dictionary.GetString("address1", &address1)) 182 if (!dictionary.GetString("address1", &address1))
183 DVLOG(1) << "Reponse from Google Wallet missing address1"; 183 DVLOG(1) << "Reponse from Google Wallet missing address1";
184 184
185 string16 address2; 185 base::string16 address2;
186 if (!dictionary.GetString("address2", &address2)) 186 if (!dictionary.GetString("address2", &address2))
187 DVLOG(1) << "Reponse from Google Wallet missing address2"; 187 DVLOG(1) << "Reponse from Google Wallet missing address2";
188 188
189 string16 city; 189 base::string16 city;
190 if (!dictionary.GetString("city", &city)) 190 if (!dictionary.GetString("city", &city))
191 DVLOG(1) << "Reponse from Google Wallet missing city"; 191 DVLOG(1) << "Reponse from Google Wallet missing city";
192 192
193 string16 state; 193 base::string16 state;
194 if (!dictionary.GetString("state", &state)) 194 if (!dictionary.GetString("state", &state))
195 DVLOG(1) << "Reponse from Google Wallet missing state"; 195 DVLOG(1) << "Reponse from Google Wallet missing state";
196 196
197 string16 phone_number; 197 base::string16 phone_number;
198 if (!dictionary.GetString("phone_number", &phone_number)) 198 if (!dictionary.GetString("phone_number", &phone_number))
199 DVLOG(1) << "Reponse from Google Wallet missing phone number"; 199 DVLOG(1) << "Reponse from Google Wallet missing phone number";
200 200
201 std::string address_state; 201 std::string address_state;
202 if (!dictionary.GetString("type", &address_state)) 202 if (!dictionary.GetString("type", &address_state))
203 DVLOG(1) << "Response from Google Wallet missing type/state of address"; 203 DVLOG(1) << "Response from Google Wallet missing type/state of address";
204 204
205 scoped_ptr<Address> address( 205 scoped_ptr<Address> address(
206 new Address(country_code, 206 new Address(country_code,
207 name, 207 name,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 dict->SetString("country_name_code", country_name_code_); 240 dict->SetString("country_name_code", country_name_code_);
241 dict->SetString("recipient_name", recipient_name_); 241 dict->SetString("recipient_name", recipient_name_);
242 dict->SetString("locality_name", locality_name_); 242 dict->SetString("locality_name", locality_name_);
243 dict->SetString("administrative_area_name", 243 dict->SetString("administrative_area_name",
244 administrative_area_name_); 244 administrative_area_name_);
245 dict->SetString("postal_code_number", postal_code_number_); 245 dict->SetString("postal_code_number", postal_code_number_);
246 246
247 return dict.Pass(); 247 return dict.Pass();
248 } 248 }
249 249
250 string16 Address::DisplayName() const { 250 base::string16 Address::DisplayName() const {
251 #if defined(OS_ANDROID) 251 #if defined(OS_ANDROID)
252 // TODO(aruslan): improve this stub implementation. 252 // TODO(aruslan): improve this stub implementation.
253 return recipient_name(); 253 return recipient_name();
254 #else 254 #else
255 // TODO(estade): improve this stub implementation + l10n. 255 // TODO(estade): improve this stub implementation + l10n.
256 return recipient_name() + ASCIIToUTF16(", ") + address_line_1(); 256 return recipient_name() + ASCIIToUTF16(", ") + address_line_1();
257 #endif 257 #endif
258 } 258 }
259 259
260 string16 Address::DisplayNameDetail() const { 260 base::string16 Address::DisplayNameDetail() const {
261 #if defined(OS_ANDROID) 261 #if defined(OS_ANDROID)
262 // TODO(aruslan): improve this stub implementation. 262 // TODO(aruslan): improve this stub implementation.
263 return address_line_1(); 263 return address_line_1();
264 #else 264 #else
265 return string16(); 265 return base::string16();
266 #endif 266 #endif
267 } 267 }
268 268
269 string16 Address::DisplayPhoneNumber() const { 269 base::string16 Address::DisplayPhoneNumber() const {
270 // Return a formatted phone number. Wallet doesn't store user formatting, so 270 // Return a formatted phone number. Wallet doesn't store user formatting, so
271 // impose our own. phone_number() always includes a country code, so using 271 // impose our own. phone_number() always includes a country code, so using
272 // PhoneObject to format it would result in an internationalized format. Since 272 // PhoneObject to format it would result in an internationalized format. Since
273 // Wallet only supports the US right now, stick to national formatting. 273 // Wallet only supports the US right now, stick to national formatting.
274 return i18n::PhoneObject(phone_number(), country_name_code()). 274 return i18n::PhoneObject(phone_number(), country_name_code()).
275 GetNationallyFormattedNumber(); 275 GetNationallyFormattedNumber();
276 } 276 }
277 277
278 string16 Address::GetInfo(const AutofillType& type, 278 base::string16 Address::GetInfo(const AutofillType& type,
279 const std::string& app_locale) const { 279 const std::string& app_locale) const {
280 if (type.html_type() == HTML_TYPE_COUNTRY_CODE) { 280 if (type.html_type() == HTML_TYPE_COUNTRY_CODE) {
281 DCHECK(IsStringASCII(country_name_code())); 281 DCHECK(IsStringASCII(country_name_code()));
282 return ASCIIToUTF16(country_name_code()); 282 return ASCIIToUTF16(country_name_code());
283 } else if (type.html_type() == HTML_TYPE_STREET_ADDRESS) { 283 } else if (type.html_type() == HTML_TYPE_STREET_ADDRESS) {
284 base::string16 address = address_line_1(); 284 base::string16 address = address_line_1();
285 if (!address_line_2().empty()) 285 if (!address_line_2().empty())
286 address += ASCIIToUTF16(", ") + address_line_2(); 286 address += ASCIIToUTF16(", ") + address_line_2();
287 return address; 287 return address;
288 } 288 }
289 289
(...skipping 29 matching lines...) Expand all
319 case ADDRESS_HOME_DEPENDENT_LOCALITY: 319 case ADDRESS_HOME_DEPENDENT_LOCALITY:
320 case ADDRESS_HOME_SORTING_CODE: 320 case ADDRESS_HOME_SORTING_CODE:
321 case COMPANY_NAME: 321 case COMPANY_NAME:
322 // Fields that some countries request but Wallet doesn't support. 322 // Fields that some countries request but Wallet doesn't support.
323 // TODO(dbeam): can these be supported by Wallet? 323 // TODO(dbeam): can these be supported by Wallet?
324 return base::string16(); 324 return base::string16();
325 325
326 // TODO(estade): implement more. 326 // TODO(estade): implement more.
327 default: 327 default:
328 NOTREACHED(); 328 NOTREACHED();
329 return string16(); 329 return base::string16();
330 } 330 }
331 } 331 }
332 332
333 void Address::SetPhoneNumber(const base::string16& phone_number) { 333 void Address::SetPhoneNumber(const base::string16& phone_number) {
334 phone_number_ = phone_number; 334 phone_number_ = phone_number;
335 phone_object_ = i18n::PhoneObject(phone_number_, country_name_code_); 335 phone_object_ = i18n::PhoneObject(phone_number_, country_name_code_);
336 } 336 }
337 337
338 bool Address::EqualsIgnoreID(const Address& other) const { 338 bool Address::EqualsIgnoreID(const Address& other) const {
339 return country_name_code_ == other.country_name_code_ && 339 return country_name_code_ == other.country_name_code_ &&
(...skipping 10 matching lines...) Expand all
350 bool Address::operator==(const Address& other) const { 350 bool Address::operator==(const Address& other) const {
351 return object_id_ == other.object_id_ && EqualsIgnoreID(other); 351 return object_id_ == other.object_id_ && EqualsIgnoreID(other);
352 } 352 }
353 353
354 bool Address::operator!=(const Address& other) const { 354 bool Address::operator!=(const Address& other) const {
355 return !(*this == other); 355 return !(*this == other);
356 } 356 }
357 357
358 } // namespace wallet 358 } // namespace wallet
359 } // namespace autofill 359 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698