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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 10 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
11 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
12 #include "ui/base/ime/chromeos/input_method_manager.h" | 14 #include "ui/base/ime/chromeos/input_method_manager.h" |
13 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
14 #include "ui/gfx/platform_font_linux.h" | 16 #include "ui/gfx/platform_font_linux.h" |
15 | 17 |
16 namespace chromeos { | 18 namespace chromeos { |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 struct SwitchLanguageData { | 22 struct SwitchLanguageData { |
21 SwitchLanguageData(const std::string& locale, | 23 SwitchLanguageData(const std::string& locale, |
22 const bool enable_locale_keyboard_layouts, | 24 const bool enable_locale_keyboard_layouts, |
23 const bool login_layouts_only, | 25 const bool login_layouts_only, |
24 const locale_util::SwitchLanguageCallback& callback) | 26 const locale_util::SwitchLanguageCallback& callback, |
27 Profile* profile) | |
25 : callback(callback), | 28 : callback(callback), |
26 result(locale, std::string(), false), | 29 result(locale, std::string(), false), |
27 enable_locale_keyboard_layouts(enable_locale_keyboard_layouts), | 30 enable_locale_keyboard_layouts(enable_locale_keyboard_layouts), |
28 login_layouts_only(login_layouts_only) {} | 31 login_layouts_only(login_layouts_only), |
32 profile(profile) {} | |
29 | 33 |
30 const locale_util::SwitchLanguageCallback callback; | 34 const locale_util::SwitchLanguageCallback callback; |
31 | 35 |
32 locale_util::LanguageSwitchResult result; | 36 locale_util::LanguageSwitchResult result; |
33 const bool enable_locale_keyboard_layouts; | 37 const bool enable_locale_keyboard_layouts; |
34 const bool login_layouts_only; | 38 const bool login_layouts_only; |
39 Profile* profile; | |
35 }; | 40 }; |
36 | 41 |
37 // Runs on SequencedWorkerPool thread under PostTaskAndReply(). | 42 // Runs on SequencedWorkerPool thread under PostTaskAndReply(). |
38 // So data is owned by "Reply" part of PostTaskAndReply() process. | 43 // So data is owned by "Reply" part of PostTaskAndReply() process. |
39 void SwitchLanguageDoReloadLocale(SwitchLanguageData* data) { | 44 void SwitchLanguageDoReloadLocale(SwitchLanguageData* data) { |
40 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 45 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
41 | 46 |
42 data->result.loaded_locale = | 47 data->result.loaded_locale = |
43 ResourceBundle::GetSharedInstance().ReloadLocaleResources( | 48 ResourceBundle::GetSharedInstance().ReloadLocaleResources( |
44 data->result.requested_locale); | 49 data->result.requested_locale); |
45 | 50 |
46 data->result.success = !data->result.loaded_locale.empty(); | 51 data->result.success = !data->result.loaded_locale.empty(); |
47 | 52 |
48 ResourceBundle::GetSharedInstance().ReloadFonts(); | 53 ResourceBundle::GetSharedInstance().ReloadFonts(); |
49 } | 54 } |
50 | 55 |
51 // Callback after SwitchLanguageDoReloadLocale() back in UI thread. | 56 // Callback after SwitchLanguageDoReloadLocale() back in UI thread. |
52 void FinishSwitchLanguage(scoped_ptr<SwitchLanguageData> data) { | 57 void FinishSwitchLanguage(scoped_ptr<SwitchLanguageData> data) { |
53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
54 if (data->result.success) { | 59 if (data->result.success) { |
55 g_browser_process->SetApplicationLocale(data->result.loaded_locale); | 60 g_browser_process->SetApplicationLocale(data->result.loaded_locale); |
56 | 61 |
57 if (data->enable_locale_keyboard_layouts) { | 62 if (data->enable_locale_keyboard_layouts) { |
58 input_method::InputMethodManager* manager = | 63 input_method::InputMethodManager* manager = |
59 input_method::InputMethodManager::Get(); | 64 input_method::InputMethodManager::Get(); |
60 scoped_refptr<input_method::InputMethodManager::State> ime_state = | 65 scoped_refptr<input_method::InputMethodManager::State> ime_state = |
61 manager->GetActiveIMEState(); | 66 UserSessionManager::GetInstance()->GetDefaultIMEState(data->profile); |
67 | |
robliao
2015/05/12 20:16:28
Nit: Remove extra line.
Alexander Alekseev
2015/05/12 20:24:21
Done.
| |
62 if (data->login_layouts_only) { | 68 if (data->login_layouts_only) { |
63 // Enable the hardware keyboard layouts and locale-specific layouts | 69 // Enable the hardware keyboard layouts and locale-specific layouts |
64 // suitable for use on the login screen. This will also switch to the | 70 // suitable for use on the login screen. This will also switch to the |
65 // first hardware keyboard layout since the input method currently in | 71 // first hardware keyboard layout since the input method currently in |
66 // use may not be supported by the new locale. | 72 // use may not be supported by the new locale. |
67 ime_state->EnableLoginLayouts( | 73 ime_state->EnableLoginLayouts( |
68 data->result.loaded_locale, | 74 data->result.loaded_locale, |
69 manager->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); | 75 manager->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); |
70 } else { | 76 } else { |
71 // Enable all hardware keyboard layouts. This will also switch to the | 77 // Enable all hardware keyboard layouts. This will also switch to the |
(...skipping 27 matching lines...) Expand all Loading... | |
99 const std::string& loaded_locale, | 105 const std::string& loaded_locale, |
100 bool success) | 106 bool success) |
101 : requested_locale(requested_locale), | 107 : requested_locale(requested_locale), |
102 loaded_locale(loaded_locale), | 108 loaded_locale(loaded_locale), |
103 success(success) { | 109 success(success) { |
104 } | 110 } |
105 | 111 |
106 void SwitchLanguage(const std::string& locale, | 112 void SwitchLanguage(const std::string& locale, |
107 const bool enable_locale_keyboard_layouts, | 113 const bool enable_locale_keyboard_layouts, |
108 const bool login_layouts_only, | 114 const bool login_layouts_only, |
109 const SwitchLanguageCallback& callback) { | 115 const SwitchLanguageCallback& callback, |
116 Profile* profile) { | |
110 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 117 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
111 scoped_ptr<SwitchLanguageData> data(new SwitchLanguageData( | 118 scoped_ptr<SwitchLanguageData> data( |
112 locale, enable_locale_keyboard_layouts, login_layouts_only, callback)); | 119 new SwitchLanguageData(locale, enable_locale_keyboard_layouts, |
120 login_layouts_only, callback, profile)); | |
113 base::Closure reloader( | 121 base::Closure reloader( |
114 base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get()))); | 122 base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get()))); |
115 content::BrowserThread::PostBlockingPoolTaskAndReply( | 123 content::BrowserThread::PostBlockingPoolTaskAndReply( |
116 FROM_HERE, | 124 FROM_HERE, |
117 reloader, | 125 reloader, |
118 base::Bind(&FinishSwitchLanguage, base::Passed(data.Pass()))); | 126 base::Bind(&FinishSwitchLanguage, base::Passed(data.Pass()))); |
119 } | 127 } |
120 | 128 |
121 } // namespace locale_util | 129 } // namespace locale_util |
122 } // namespace chromeos | 130 } // namespace chromeos |
OLD | NEW |