Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/task_scheduler/post_task.h" | 10 #include "base/task_scheduler/post_task.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 // Runs on SequencedWorkerPool thread under PostTaskAndReply(). | 44 // Runs on SequencedWorkerPool thread under PostTaskAndReply(). |
| 45 // So data is owned by "Reply" part of PostTaskAndReply() process. | 45 // So data is owned by "Reply" part of PostTaskAndReply() process. |
| 46 void SwitchLanguageDoReloadLocale(SwitchLanguageData* data) { | 46 void SwitchLanguageDoReloadLocale(SwitchLanguageData* data) { |
| 47 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 47 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 48 | 48 |
| 49 data->result.loaded_locale = | 49 data->result.loaded_locale = |
| 50 ResourceBundle::GetSharedInstance().ReloadLocaleResources( | 50 ResourceBundle::GetSharedInstance().ReloadLocaleResources( |
| 51 data->result.requested_locale); | 51 data->result.requested_locale); |
| 52 | 52 |
| 53 data->result.success = !data->result.loaded_locale.empty(); | 53 data->result.success = !data->result.loaded_locale.empty(); |
| 54 | |
| 55 ResourceBundle::GetSharedInstance().ReloadFonts(); | |
| 56 } | 54 } |
| 57 | 55 |
| 58 // Callback after SwitchLanguageDoReloadLocale() back in UI thread. | 56 // Callback after SwitchLanguageDoReloadLocale() back in UI thread. |
| 59 void FinishSwitchLanguage(std::unique_ptr<SwitchLanguageData> data) { | 57 void FinishSwitchLanguage(std::unique_ptr<SwitchLanguageData> data) { |
| 60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 61 if (data->result.success) { | 59 if (data->result.success) { |
| 62 g_browser_process->SetApplicationLocale(data->result.loaded_locale); | 60 g_browser_process->SetApplicationLocale(data->result.loaded_locale); |
| 63 | 61 |
| 64 if (data->enable_locale_keyboard_layouts) { | 62 if (data->enable_locale_keyboard_layouts) { |
| 65 input_method::InputMethodManager* manager = | 63 input_method::InputMethodManager* manager = |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 86 data->result.loaded_locale, | 84 data->result.loaded_locale, |
| 87 input_method::kKeyboardLayoutsOnly, | 85 input_method::kKeyboardLayoutsOnly, |
| 88 &input_methods); | 86 &input_methods); |
| 89 for (std::vector<std::string>::const_iterator it = | 87 for (std::vector<std::string>::const_iterator it = |
| 90 input_methods.begin(); it != input_methods.end(); ++it) { | 88 input_methods.begin(); it != input_methods.end(); ++it) { |
| 91 ime_state->EnableInputMethod(*it); | 89 ime_state->EnableInputMethod(*it); |
| 92 } | 90 } |
| 93 } | 91 } |
| 94 } | 92 } |
| 95 } | 93 } |
| 94 | |
| 95 // The font clean up of ResourceBundle should be done on UI thread, since the | |
| 96 // cached fonts are thread unsafe. | |
| 97 ResourceBundle::GetSharedInstance().ReloadFonts(); | |
|
sky
2017/02/21 17:51:06
Could you make ReloadFonts DCHECK it's on the main
| |
| 96 gfx::PlatformFontLinux::ReloadDefaultFont(); | 98 gfx::PlatformFontLinux::ReloadDefaultFont(); |
| 97 if (!data->callback.is_null()) | 99 if (!data->callback.is_null()) |
| 98 data->callback.Run(data->result); | 100 data->callback.Run(data->result); |
| 99 } | 101 } |
| 100 | 102 |
| 101 } // namespace | 103 } // namespace |
| 102 | 104 |
| 103 namespace locale_util { | 105 namespace locale_util { |
| 104 | 106 |
| 105 LanguageSwitchResult::LanguageSwitchResult(const std::string& requested_locale, | 107 LanguageSwitchResult::LanguageSwitchResult(const std::string& requested_locale, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 123 base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get()))); | 125 base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get()))); |
| 124 base::PostTaskWithTraitsAndReply( | 126 base::PostTaskWithTraitsAndReply( |
| 125 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 127 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( |
| 126 base::TaskPriority::BACKGROUND), | 128 base::TaskPriority::BACKGROUND), |
| 127 reloader, | 129 reloader, |
| 128 base::Bind(&FinishSwitchLanguage, base::Passed(std::move(data)))); | 130 base::Bind(&FinishSwitchLanguage, base::Passed(std::move(data)))); |
| 129 } | 131 } |
| 130 | 132 |
| 131 } // namespace locale_util | 133 } // namespace locale_util |
| 132 } // namespace chromeos | 134 } // namespace chromeos |
| OLD | NEW |