| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/login/language_switch_menu.h" | 5 #include "chrome/browser/chromeos/login/language_switch_menu.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/threading/thread_restrictions.h" |
| 8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 11 #include "chrome/browser/chromeos/cros/keyboard_library.h" | 12 #include "chrome/browser/chromeos/cros/keyboard_library.h" |
| 12 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 13 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 13 #include "chrome/browser/chromeos/language_preferences.h" | 14 #include "chrome/browser/chromeos/language_preferences.h" |
| 14 #include "chrome/browser/chromeos/login/screen_observer.h" | 15 #include "chrome/browser/chromeos/login/screen_observer.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 85 } |
| 85 // Save new locale. | 86 // Save new locale. |
| 86 PrefService* prefs = g_browser_process->local_state(); | 87 PrefService* prefs = g_browser_process->local_state(); |
| 87 // TODO(markusheintz): If the preference is managed and can not be changed by | 88 // TODO(markusheintz): If the preference is managed and can not be changed by |
| 88 // the user, changing the language should be disabled in the UI. | 89 // the user, changing the language should be disabled in the UI. |
| 89 // TODO(markusheintz): Change the if condition to prefs->IsUserModifiable() | 90 // TODO(markusheintz): Change the if condition to prefs->IsUserModifiable() |
| 90 // once Mattias landed his pending patch. | 91 // once Mattias landed his pending patch. |
| 91 if (!prefs->IsManagedPreference(prefs::kApplicationLocale)) { | 92 if (!prefs->IsManagedPreference(prefs::kApplicationLocale)) { |
| 92 prefs->SetString(prefs::kApplicationLocale, locale); | 93 prefs->SetString(prefs::kApplicationLocale, locale); |
| 93 prefs->SavePersistentPrefs(); | 94 prefs->SavePersistentPrefs(); |
| 94 | 95 std::string loaded_locale; |
| 95 // Switch the locale. | 96 { |
| 96 const std::string loaded_locale = | 97 // Reloading resource bundle causes us to do blocking IO on UI thread. |
| 97 ResourceBundle::ReloadSharedInstance(locale); | 98 // Temporarily allow it until we fix http://crosbug.com/11102 |
| 99 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 100 // Switch the locale. |
| 101 loaded_locale = ResourceBundle::ReloadSharedInstance(locale); |
| 102 } |
| 98 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; | 103 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; |
| 99 | 104 |
| 100 // Enable the keyboard layouts that are necessary for the new locale. | 105 // Enable the keyboard layouts that are necessary for the new locale. |
| 101 input_method::EnableInputMethods( | 106 input_method::EnableInputMethods( |
| 102 locale, input_method::kKeyboardLayoutsOnly, | 107 locale, input_method::kKeyboardLayoutsOnly, |
| 103 CrosLibrary::Get()->GetKeyboardLibrary()-> | 108 CrosLibrary::Get()->GetKeyboardLibrary()-> |
| 104 GetHardwareKeyboardLayoutName()); | 109 GetHardwareKeyboardLayoutName()); |
| 105 | 110 |
| 106 // The following line does not seem to affect locale anyhow. Maybe in | 111 // The following line does not seem to affect locale anyhow. Maybe in |
| 107 // future.. | 112 // future.. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 void LanguageSwitchMenu::ExecuteCommand(int command_id) { | 152 void LanguageSwitchMenu::ExecuteCommand(int command_id) { |
| 148 const std::string locale = language_list_->GetLocaleFromIndex(command_id); | 153 const std::string locale = language_list_->GetLocaleFromIndex(command_id); |
| 149 SwitchLanguage(locale); | 154 SwitchLanguage(locale); |
| 150 InitLanguageMenu(); | 155 InitLanguageMenu(); |
| 151 | 156 |
| 152 // Update all view hierarchies that the locale has changed. | 157 // Update all view hierarchies that the locale has changed. |
| 153 views::Widget::NotifyLocaleChanged(); | 158 views::Widget::NotifyLocaleChanged(); |
| 154 } | 159 } |
| 155 | 160 |
| 156 } // namespace chromeos | 161 } // namespace chromeos |
| OLD | NEW |