| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/autofill/autofill_country.h" | 5 #include "chrome/browser/autofill/autofill_country.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 UErrorCode error_ignored = U_ZERO_ERROR; | 380 UErrorCode error_ignored = U_ZERO_ERROR; |
| 381 uloc_addLikelySubtags(locale.c_str(), | 381 uloc_addLikelySubtags(locale.c_str(), |
| 382 WriteInto(&likely_locale, kLocaleCapacity), | 382 WriteInto(&likely_locale, kLocaleCapacity), |
| 383 kLocaleCapacity, | 383 kLocaleCapacity, |
| 384 &error_ignored); | 384 &error_ignored); |
| 385 | 385 |
| 386 // Extract the country code. | 386 // Extract the country code. |
| 387 std::string country_code = icu::Locale(likely_locale.c_str()).getCountry(); | 387 std::string country_code = icu::Locale(likely_locale.c_str()).getCountry(); |
| 388 | 388 |
| 389 // Default to the United States if we have no better guess. | 389 // Default to the United States if we have no better guess. |
| 390 return !country_code.empty() ? country_code : "US"; | 390 if (!AutofillCountries::countries().count(country_code)) |
| 391 return "US"; |
| 392 return country_code; |
| 391 } | 393 } |
| 392 | 394 |
| 393 // static | 395 // static |
| 394 const std::string AutofillCountry::GetCountryCode( | 396 const std::string AutofillCountry::GetCountryCode( |
| 395 const string16& country, const std::string& locale) { | 397 const string16& country, const std::string& locale) { |
| 396 // First, check for a few common synonyms. | 398 // First, check for a few common synonyms. |
| 397 if (country == ASCIIToUTF16("United States of America")) | 399 if (country == ASCIIToUTF16("United States of America")) |
| 398 return "US"; | 400 return "US"; |
| 399 if (country == ASCIIToUTF16("Great Britain") || | 401 if (country == ASCIIToUTF16("Great Britain") || |
| 400 country == ASCIIToUTF16("UK")) | 402 country == ASCIIToUTF16("UK")) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 | 455 |
| 454 AutofillCountry::AutofillCountry(const std::string& country_code, | 456 AutofillCountry::AutofillCountry(const std::string& country_code, |
| 455 const string16& name, | 457 const string16& name, |
| 456 const string16& postal_code_label, | 458 const string16& postal_code_label, |
| 457 const string16& state_label) | 459 const string16& state_label) |
| 458 : country_code_(country_code), | 460 : country_code_(country_code), |
| 459 name_(name), | 461 name_(name), |
| 460 postal_code_label_(postal_code_label), | 462 postal_code_label_(postal_code_label), |
| 461 state_label_(state_label) { | 463 state_label_(state_label) { |
| 462 } | 464 } |
| OLD | NEW |