Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: chrome/browser/chromeos/base/locale_util.cc

Issue 1055863002: ChromeOS: switch UI language before apps are loaded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove empty line. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
62 if (data->login_layouts_only) { 67 if (data->login_layouts_only) {
63 // Enable the hardware keyboard layouts and locale-specific layouts 68 // Enable the hardware keyboard layouts and locale-specific layouts
64 // suitable for use on the login screen. This will also switch to the 69 // suitable for use on the login screen. This will also switch to the
65 // first hardware keyboard layout since the input method currently in 70 // first hardware keyboard layout since the input method currently in
66 // use may not be supported by the new locale. 71 // use may not be supported by the new locale.
67 ime_state->EnableLoginLayouts( 72 ime_state->EnableLoginLayouts(
68 data->result.loaded_locale, 73 data->result.loaded_locale,
69 manager->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); 74 manager->GetInputMethodUtil()->GetHardwareLoginInputMethodIds());
70 } else { 75 } else {
71 // Enable all hardware keyboard layouts. This will also switch to the 76 // Enable all hardware keyboard layouts. This will also switch to the
(...skipping 27 matching lines...) Expand all
99 const std::string& loaded_locale, 104 const std::string& loaded_locale,
100 bool success) 105 bool success)
101 : requested_locale(requested_locale), 106 : requested_locale(requested_locale),
102 loaded_locale(loaded_locale), 107 loaded_locale(loaded_locale),
103 success(success) { 108 success(success) {
104 } 109 }
105 110
106 void SwitchLanguage(const std::string& locale, 111 void SwitchLanguage(const std::string& locale,
107 const bool enable_locale_keyboard_layouts, 112 const bool enable_locale_keyboard_layouts,
108 const bool login_layouts_only, 113 const bool login_layouts_only,
109 const SwitchLanguageCallback& callback) { 114 const SwitchLanguageCallback& callback,
115 Profile* profile) {
110 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 116 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
111 scoped_ptr<SwitchLanguageData> data(new SwitchLanguageData( 117 scoped_ptr<SwitchLanguageData> data(
112 locale, enable_locale_keyboard_layouts, login_layouts_only, callback)); 118 new SwitchLanguageData(locale, enable_locale_keyboard_layouts,
119 login_layouts_only, callback, profile));
113 base::Closure reloader( 120 base::Closure reloader(
114 base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get()))); 121 base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get())));
115 content::BrowserThread::PostBlockingPoolTaskAndReply( 122 content::BrowserThread::PostBlockingPoolTaskAndReply(
116 FROM_HERE, 123 FROM_HERE,
117 reloader, 124 reloader,
118 base::Bind(&FinishSwitchLanguage, base::Passed(data.Pass()))); 125 base::Bind(&FinishSwitchLanguage, base::Passed(data.Pass())));
119 } 126 }
120 127
121 } // namespace locale_util 128 } // namespace locale_util
122 } // namespace chromeos 129 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698