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

Unified Diff: chrome/browser/chromeos/base/locale_util.cc

Issue 664503003: Revert of Revert of Revert of ChromeOS NetworkScreenHandler should not call CheckAndResolveLocale on UI thread. (patchs… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/base/locale_util.h ('k') | chrome/browser/chromeos/chrome_browser_main_chromeos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/base/locale_util.cc
diff --git a/chrome/browser/chromeos/base/locale_util.cc b/chrome/browser/chromeos/base/locale_util.cc
index 288b335e5accbbfa3d95a002385bbd695761ec61..57d23a84cfe376b2c8e4fb5a4c755dc212477576 100644
--- a/chrome/browser/chromeos/base/locale_util.cc
+++ b/chrome/browser/chromeos/base/locale_util.cc
@@ -21,17 +21,20 @@
SwitchLanguageData(const std::string& locale,
const bool enable_locale_keyboard_layouts,
const bool login_layouts_only,
- const locale_util::SwitchLanguageCallback& callback)
- : callback(callback),
- result(locale, std::string(), false),
+ scoped_ptr<locale_util::SwitchLanguageCallback> callback)
+ : callback(callback.Pass()),
+ locale(locale),
enable_locale_keyboard_layouts(enable_locale_keyboard_layouts),
- login_layouts_only(login_layouts_only) {}
+ login_layouts_only(login_layouts_only),
+ success(false) {}
- const locale_util::SwitchLanguageCallback callback;
+ scoped_ptr<locale_util::SwitchLanguageCallback> callback;
- locale_util::LanguageSwitchResult result;
+ const std::string locale;
const bool enable_locale_keyboard_layouts;
const bool login_layouts_only;
+ std::string loaded_locale;
+ bool success;
};
// Runs on SequencedWorkerPool thread under PostTaskAndReply().
@@ -39,11 +42,10 @@
void SwitchLanguageDoReloadLocale(SwitchLanguageData* data) {
DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- data->result.loaded_locale =
- ResourceBundle::GetSharedInstance().ReloadLocaleResources(
- data->result.requested_locale);
+ data->loaded_locale =
+ ResourceBundle::GetSharedInstance().ReloadLocaleResources(data->locale);
- data->result.success = !data->result.loaded_locale.empty();
+ data->success = !data->loaded_locale.empty();
ResourceBundle::GetSharedInstance().ReloadFonts();
}
@@ -51,8 +53,8 @@
// Callback after SwitchLanguageDoReloadLocale() back in UI thread.
void FinishSwitchLanguage(scoped_ptr<SwitchLanguageData> data) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- if (data->result.success) {
- g_browser_process->SetApplicationLocale(data->result.loaded_locale);
+ if (data->success) {
+ g_browser_process->SetApplicationLocale(data->loaded_locale);
if (data->enable_locale_keyboard_layouts) {
input_method::InputMethodManager* manager =
@@ -65,7 +67,7 @@
// first hardware keyboard layout since the input method currently in
// use may not be supported by the new locale.
ime_state->EnableLoginLayouts(
- data->result.loaded_locale,
+ data->loaded_locale,
manager->GetInputMethodUtil()->GetHardwareLoginInputMethodIds());
} else {
// Enable all hardware keyboard layouts. This will also switch to the
@@ -76,7 +78,7 @@
// Enable all locale-specific layouts.
std::vector<std::string> input_methods;
manager->GetInputMethodUtil()->GetInputMethodIdsFromLanguageCode(
- data->result.loaded_locale,
+ data->loaded_locale,
input_method::kKeyboardLayoutsOnly,
&input_methods);
for (std::vector<std::string>::const_iterator it =
@@ -87,29 +89,24 @@
}
}
gfx::PlatformFontPango::ReloadDefaultFont();
- if (!data->callback.is_null())
- data->callback.Run(data->result);
+ if (data->callback)
+ data->callback->Run(data->locale, data->loaded_locale, data->success);
}
} // namespace
namespace locale_util {
-LanguageSwitchResult::LanguageSwitchResult(const std::string& requested_locale,
- const std::string& loaded_locale,
- bool success)
- : requested_locale(requested_locale),
- loaded_locale(loaded_locale),
- success(success) {
-}
-
void SwitchLanguage(const std::string& locale,
const bool enable_locale_keyboard_layouts,
const bool login_layouts_only,
- const SwitchLanguageCallback& callback) {
+ scoped_ptr<SwitchLanguageCallback> callback) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- scoped_ptr<SwitchLanguageData> data(new SwitchLanguageData(
- locale, enable_locale_keyboard_layouts, login_layouts_only, callback));
+ scoped_ptr<SwitchLanguageData> data(
+ new SwitchLanguageData(locale,
+ enable_locale_keyboard_layouts,
+ login_layouts_only,
+ callback.Pass()));
base::Closure reloader(
base::Bind(&SwitchLanguageDoReloadLocale, base::Unretained(data.get())));
content::BrowserThread::PostBlockingPoolTaskAndReply(
« no previous file with comments | « chrome/browser/chromeos/base/locale_util.h ('k') | chrome/browser/chromeos/chrome_browser_main_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698