OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_LINUX) | |
8 #include <locale.h> | |
9 #endif | |
10 | |
7 #include "base/command_line.h" | 11 #include "base/command_line.h" |
8 #include "base/string_util.h" | 12 #include "base/string_util.h" |
9 #include "chrome/browser/search_engines/template_url.h" | 13 #include "chrome/browser/search_engines/template_url.h" |
10 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
12 #include "chrome/common/pref_service.h" | 16 #include "chrome/common/pref_service.h" |
13 | 17 |
14 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
15 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. | 19 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. |
16 #elif defined(OS_MACOSX) | 20 #elif defined(OS_MACOSX) |
(...skipping 2761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2778 CFRange char_range = CFRangeMake(0, 2); | 2782 CFRange char_range = CFRangeMake(0, 2); |
2779 CFStringGetCharacters(country, char_range, isobuf); | 2783 CFStringGetCharacters(country, char_range, isobuf); |
2780 | 2784 |
2781 return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]), | 2785 return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]), |
2782 static_cast<char>(isobuf[1])); | 2786 static_cast<char>(isobuf[1])); |
2783 } | 2787 } |
2784 | 2788 |
2785 #elif defined(OS_LINUX) | 2789 #elif defined(OS_LINUX) |
2786 | 2790 |
2787 int GetCurrentCountryID() { | 2791 int GetCurrentCountryID() { |
2788 NOTIMPLEMENTED(); | 2792 const char* locale = setlocale(LC_MESSAGES, NULL); |
2793 | |
2794 if (!locale) | |
2795 return kCountryIDUnknown; | |
2796 | |
2797 // The format of a locale name is: | |
2798 // language[_territory][.codeset][@modifier], where territory is an ISO 3166 | |
2799 // country code, which is what we want. | |
2800 std::string locale_str(locale); | |
2801 std::string::size_type begin = locale_str.find('_'); | |
Peter Kasting
2009/09/16 23:35:10
Nit: After some discussion a while back, we agreed
| |
2802 if (begin == std::string::npos || locale_str.size() - begin < 3) | |
2803 return kCountryIDUnknown; | |
2804 | |
2805 begin++; | |
Peter Kasting
2009/09/16 23:35:10
Nit: I'd prefer preincrement to post except where
| |
2806 std::string::size_type end = locale_str.find_first_of(".@", begin); | |
2807 if (end == std::string::npos) | |
2808 end = locale_str.size(); | |
2809 | |
2810 // The territory part must contain exactly two characters. | |
2811 if (end - begin == 2) { | |
2812 return CountryCharsToCountryIDWithUpdate( | |
2813 ToUpperASCII(locale_str[begin]), ToUpperASCII(locale_str[begin + 1])); | |
2814 } | |
2815 | |
2789 return kCountryIDUnknown; | 2816 return kCountryIDUnknown; |
2790 } | 2817 } |
2791 | 2818 |
2792 #endif // OS_* | 2819 #endif // OS_* |
2793 | 2820 |
2794 int GetCountryIDFromPrefs(PrefService* prefs) { | 2821 int GetCountryIDFromPrefs(PrefService* prefs) { |
2795 // See if the user overrode the country on the command line. | 2822 // See if the user overrode the country on the command line. |
2796 const std::wstring country( | 2823 const std::wstring country( |
2797 CommandLine::ForCurrentProcess()->GetSwitchValue(switches::kCountry)); | 2824 CommandLine::ForCurrentProcess()->GetSwitchValue(switches::kCountry)); |
2798 if (country.length() == 2) | 2825 if (country.length() == 2) |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3214 new_turl->set_date_created(Time()); | 3241 new_turl->set_date_created(Time()); |
3215 std::vector<std::string> turl_encodings; | 3242 std::vector<std::string> turl_encodings; |
3216 turl_encodings.push_back(engines[i]->encoding); | 3243 turl_encodings.push_back(engines[i]->encoding); |
3217 new_turl->set_input_encodings(turl_encodings); | 3244 new_turl->set_input_encodings(turl_encodings); |
3218 new_turl->set_prepopulate_id(engines[i]->id); | 3245 new_turl->set_prepopulate_id(engines[i]->id); |
3219 t_urls->push_back(new_turl); | 3246 t_urls->push_back(new_turl); |
3220 } | 3247 } |
3221 } | 3248 } |
3222 | 3249 |
3223 } // namespace TemplateURLPrepopulateData | 3250 } // namespace TemplateURLPrepopulateData |
OLD | NEW |