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 "chrome/browser/search_engines/template_url_prepopulate_data.h" | 5 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
6 | 6 |
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 7 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
8 #include <locale.h> | 8 #include <locale.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 | 519 |
520 | 520 |
521 // Geographic mappings ///////////////////////////////////////////////////////// | 521 // Geographic mappings ///////////////////////////////////////////////////////// |
522 | 522 |
523 // Please refer to ISO 3166-1 for information about the two-character country | 523 // Please refer to ISO 3166-1 for information about the two-character country |
524 // codes; http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 is useful. In the | 524 // codes; http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 is useful. In the |
525 // following (C++) code, we pack the two letters of the country code into an int | 525 // following (C++) code, we pack the two letters of the country code into an int |
526 // value we call the CountryID. | 526 // value we call the CountryID. |
527 | 527 |
528 const int kCountryIDUnknown = -1; | 528 const int kCountryIDUnknown = -1; |
529 const int kCountryIDNotSet = 0; | |
530 | 529 |
531 inline int CountryCharsToCountryID(char c1, char c2) { | 530 inline int CountryCharsToCountryID(char c1, char c2) { |
532 return c1 << 8 | c2; | 531 return c1 << 8 | c2; |
533 } | 532 } |
534 | 533 |
535 int CountryCharsToCountryIDWithUpdate(char c1, char c2) { | 534 int CountryCharsToCountryIDWithUpdate(char c1, char c2) { |
536 // SPECIAL CASE: In 2003, Yugoslavia renamed itself to Serbia and Montenegro. | 535 // SPECIAL CASE: In 2003, Yugoslavia renamed itself to Serbia and Montenegro. |
537 // Serbia and Montenegro dissolved their union in June 2006. Yugoslavia was | 536 // Serbia and Montenegro dissolved their union in June 2006. Yugoslavia was |
538 // ISO 'YU' and Serbia and Montenegro were ISO 'CS'. Serbia was subsequently | 537 // ISO 'YU' and Serbia and Montenegro were ISO 'CS'. Serbia was subsequently |
539 // issued 'RS' and Montenegro 'ME'. Windows XP and Mac OS X Leopard still use | 538 // issued 'RS' and Montenegro 'ME'. Windows XP and Mac OS X Leopard still use |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 CFRange char_range = CFRangeMake(0, 2); | 627 CFRange char_range = CFRangeMake(0, 2); |
629 CFStringGetCharacters(country, char_range, isobuf); | 628 CFStringGetCharacters(country, char_range, isobuf); |
630 | 629 |
631 return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]), | 630 return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]), |
632 static_cast<char>(isobuf[1])); | 631 static_cast<char>(isobuf[1])); |
633 } | 632 } |
634 | 633 |
635 #elif defined(OS_ANDROID) | 634 #elif defined(OS_ANDROID) |
636 | 635 |
637 // Initialized by InitCountryCode(). | 636 // Initialized by InitCountryCode(). |
638 int g_country_code_at_install = kCountryIDNotSet; | 637 int g_country_code_at_install = kCountryIDUnknown; |
639 | 638 |
640 int GetCurrentCountryID() { | 639 int GetCurrentCountryID() { |
641 DCHECK(g_country_code_at_install != kCountryIDNotSet); | |
642 return g_country_code_at_install; | 640 return g_country_code_at_install; |
643 } | 641 } |
644 | 642 |
| 643 void InitCountryCode(const std::string& country_code) { |
| 644 if (country_code.size() != 2) { |
| 645 DLOG(ERROR) << "Invalid country code: " << country_code; |
| 646 g_country_code_at_install = kCountryIDUnknown; |
| 647 } else { |
| 648 g_country_code_at_install = |
| 649 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); |
| 650 } |
| 651 } |
| 652 |
645 #elif defined(OS_POSIX) | 653 #elif defined(OS_POSIX) |
646 | 654 |
647 int GetCurrentCountryID() { | 655 int GetCurrentCountryID() { |
648 const char* locale = setlocale(LC_MESSAGES, NULL); | 656 const char* locale = setlocale(LC_MESSAGES, NULL); |
649 | 657 |
650 if (!locale) | 658 if (!locale) |
651 return kCountryIDUnknown; | 659 return kCountryIDUnknown; |
652 | 660 |
653 // The format of a locale name is: | 661 // The format of a locale name is: |
654 // language[_territory][.codeset][@modifier], where territory is an ISO 3166 | 662 // language[_territory][.codeset][@modifier], where territory is an ISO 3166 |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 | 1280 |
1273 GURL GetLogoURL(const TemplateURL& template_url, LogoSize size) { | 1281 GURL GetLogoURL(const TemplateURL& template_url, LogoSize size) { |
1274 if (GetEngineType(template_url.url()) == SEARCH_ENGINE_GOOGLE) { | 1282 if (GetEngineType(template_url.url()) == SEARCH_ENGINE_GOOGLE) { |
1275 return GURL((size == LOGO_200_PERCENT) ? | 1283 return GURL((size == LOGO_200_PERCENT) ? |
1276 google_logos.logo_200_percent_url : | 1284 google_logos.logo_200_percent_url : |
1277 google_logos.logo_100_percent_url); | 1285 google_logos.logo_100_percent_url); |
1278 } | 1286 } |
1279 return GURL(); | 1287 return GURL(); |
1280 } | 1288 } |
1281 | 1289 |
1282 #if defined(OS_ANDROID) | |
1283 | |
1284 void InitCountryCode(const std::string& country_code) { | |
1285 if (country_code.size() != 2) { | |
1286 DLOG(ERROR) << "Invalid country code: " << country_code; | |
1287 g_country_code_at_install = kCountryIDUnknown; | |
1288 } else { | |
1289 g_country_code_at_install = | |
1290 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); | |
1291 } | |
1292 } | |
1293 | |
1294 #endif | |
1295 | |
1296 } // namespace TemplateURLPrepopulateData | 1290 } // namespace TemplateURLPrepopulateData |
OLD | NEW |