| OLD | NEW |
| 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 "chrome/browser/chromeos/base/locale_util.h" | 5 #include "chrome/browser/chromeos/base/locale_util.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 8 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 9 #include "chromeos/ime/input_method_manager.h" | 9 #include "chromeos/ime/input_method_manager.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/platform_font_pango.h" | 12 #include "ui/gfx/platform_font_pango.h" |
| 13 | 13 |
| 14 namespace chromeos { | 14 namespace chromeos { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 struct SwitchLanguageData { | 18 struct SwitchLanguageData { |
| 19 SwitchLanguageData(const std::string& locale, | 19 SwitchLanguageData(const std::string& locale, |
| 20 const bool enableLocaleKeyboardLayouts, | 20 const bool enableLocaleKeyboardLayouts, |
| 21 const bool login_layouts_only, |
| 21 scoped_ptr<locale_util::SwitchLanguageCallback> callback) | 22 scoped_ptr<locale_util::SwitchLanguageCallback> callback) |
| 22 : callback(callback.Pass()), | 23 : callback(callback.Pass()), |
| 23 locale(locale), | 24 locale(locale), |
| 24 enableLocaleKeyboardLayouts(enableLocaleKeyboardLayouts), | 25 enableLocaleKeyboardLayouts(enableLocaleKeyboardLayouts), |
| 26 login_layouts_only(login_layouts_only), |
| 25 success(false) {} | 27 success(false) {} |
| 26 | 28 |
| 27 scoped_ptr<locale_util::SwitchLanguageCallback> callback; | 29 scoped_ptr<locale_util::SwitchLanguageCallback> callback; |
| 28 | 30 |
| 29 const std::string locale; | 31 const std::string locale; |
| 30 const bool enableLocaleKeyboardLayouts; | 32 const bool enableLocaleKeyboardLayouts; |
| 33 const bool login_layouts_only; |
| 31 std::string loaded_locale; | 34 std::string loaded_locale; |
| 32 bool success; | 35 bool success; |
| 33 }; | 36 }; |
| 34 | 37 |
| 35 // Runs on SequencedWorkerPool thread under PostTaskAndReply(). | 38 // Runs on SequencedWorkerPool thread under PostTaskAndReply(). |
| 36 // So data is owned by "Reply" part of PostTaskAndReply() process. | 39 // So data is owned by "Reply" part of PostTaskAndReply() process. |
| 37 void SwitchLanguageDoReloadLocale(SwitchLanguageData* data) { | 40 void SwitchLanguageDoReloadLocale(SwitchLanguageData* data) { |
| 38 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 41 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 39 | 42 |
| 40 data->loaded_locale = | 43 data->loaded_locale = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 53 | 56 |
| 54 if (data->enableLocaleKeyboardLayouts) { | 57 if (data->enableLocaleKeyboardLayouts) { |
| 55 // If we have switched the locale, enable the keyboard layouts that | 58 // If we have switched the locale, enable the keyboard layouts that |
| 56 // are necessary for the new locale. Change the current input method | 59 // are necessary for the new locale. Change the current input method |
| 57 // to the hardware keyboard layout since the input method currently in | 60 // to the hardware keyboard layout since the input method currently in |
| 58 // use may not be supported by the new locale (3rd parameter). | 61 // use may not be supported by the new locale (3rd parameter). |
| 59 input_method::InputMethodManager* manager = | 62 input_method::InputMethodManager* manager = |
| 60 input_method::InputMethodManager::Get(); | 63 input_method::InputMethodManager::Get(); |
| 61 manager->EnableLayouts( | 64 manager->EnableLayouts( |
| 62 data->locale, | 65 data->locale, |
| 63 manager->GetInputMethodUtil()->GetHardwareInputMethodId()); | 66 manager->GetInputMethodUtil()->GetHardwareLoginInputMethodId(), |
| 67 data->login_layouts_only); |
| 64 } | 68 } |
| 65 } | 69 } |
| 66 gfx::PlatformFontPango::ReloadDefaultFont(); | 70 gfx::PlatformFontPango::ReloadDefaultFont(); |
| 67 if (data->callback) | 71 if (data->callback) |
| 68 data->callback->Run(data->locale, data->loaded_locale, data->success); | 72 data->callback->Run(data->locale, data->loaded_locale, data->success); |
| 69 } | 73 } |
| 70 | 74 |
| 71 } // namespace | 75 } // namespace |
| 72 | 76 |
| 73 namespace locale_util { | 77 namespace locale_util { |
| 74 | 78 |
| 75 void SwitchLanguage(const std::string& locale, | 79 void SwitchLanguage(const std::string& locale, |
| 76 bool enableLocaleKeyboardLayouts, | 80 const bool enableLocaleKeyboardLayouts, |
| 81 const bool login_layouts_only, |
| 77 scoped_ptr<SwitchLanguageCallback> callback) { | 82 scoped_ptr<SwitchLanguageCallback> callback) { |
| 78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 83 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 79 scoped_ptr<SwitchLanguageData> data(new SwitchLanguageData( | 84 scoped_ptr<SwitchLanguageData> data( |
| 80 locale, enableLocaleKeyboardLayouts, callback.Pass())); | 85 new SwitchLanguageData(locale, |
| 86 enableLocaleKeyboardLayouts, |
| 87 login_layouts_only, |
| 88 callback.Pass())); |
| 81 base::Closure reloader( | 89 base::Closure reloader( |
| 82 base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get()))); | 90 base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get()))); |
| 83 content::BrowserThread::PostBlockingPoolTaskAndReply( | 91 content::BrowserThread::PostBlockingPoolTaskAndReply( |
| 84 FROM_HERE, | 92 FROM_HERE, |
| 85 reloader, | 93 reloader, |
| 86 base::Bind(&FinishSwitchLanguage, base::Passed(data.Pass()))); | 94 base::Bind(&FinishSwitchLanguage, base::Passed(data.Pass()))); |
| 87 } | 95 } |
| 88 | 96 |
| 89 } // namespace locale_util | 97 } // namespace locale_util |
| 90 } // namespace chromeos | 98 } // namespace chromeos |
| OLD | NEW |