Commit 2d9fa0de authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Call BrowserProcess::GetApplicationLocale() on the right thread.

GetApplicationLocale() should only be called on the UI thread. In
r303655, GetApplicationLocale() calls in ResolveUILanguageList() got
moved off the UI thread but nobody noticed because
GetApplicationLocale() didn't have any DCHECKs. In the process of adding
the DCHECKs, this issue now becomes apparent.

Fix the issue by calling GetApplicationLocale() on the UI thread first,
before posting a task to ResolveLanguageListInThreadPool(). This also
replaces 4 GetApplicationLocale() calls with 1. Rearrange the logic
inside ResolveLanguageListInThreadPool() slightly as well.

Bug: 1033644
Change-Id: I3c350c34cf253052bad18b850381e2c92003b7f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036373Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738055}
parent 4a68d257
...@@ -345,6 +345,7 @@ std::string CalculateSelectedLanguage(const std::string& requested_locale, ...@@ -345,6 +345,7 @@ std::string CalculateSelectedLanguage(const std::string& requested_locale,
} }
void ResolveLanguageListInThreadPool( void ResolveLanguageListInThreadPool(
const std::string& locale,
std::unique_ptr<chromeos::locale_util::LanguageSwitchResult> std::unique_ptr<chromeos::locale_util::LanguageSwitchResult>
language_switch_result, language_switch_result,
const scoped_refptr<base::TaskRunner> task_runner, const scoped_refptr<base::TaskRunner> task_runner,
...@@ -353,14 +354,7 @@ void ResolveLanguageListInThreadPool( ...@@ -353,14 +354,7 @@ void ResolveLanguageListInThreadPool(
base::BlockingType::MAY_BLOCK); base::BlockingType::MAY_BLOCK);
std::string selected_language; std::string selected_language;
if (!language_switch_result) { if (language_switch_result) {
if (!g_browser_process->GetApplicationLocale().empty()) {
selected_language = g_browser_process->GetApplicationLocale();
} else {
selected_language =
StartupCustomizationDocument::GetInstance()->initial_locale_default();
}
} else {
if (language_switch_result->success) { if (language_switch_result->success) {
if (language_switch_result->requested_locale == if (language_switch_result->requested_locale ==
language_switch_result->loaded_locale) { language_switch_result->loaded_locale) {
...@@ -373,14 +367,17 @@ void ResolveLanguageListInThreadPool( ...@@ -373,14 +367,17 @@ void ResolveLanguageListInThreadPool(
} else { } else {
selected_language = language_switch_result->loaded_locale; selected_language = language_switch_result->loaded_locale;
} }
} else {
selected_language = !locale.empty()
? locale
: StartupCustomizationDocument::GetInstance()
->initial_locale_default();
} }
const std::string selected_code = const std::string selected_code =
selected_language.empty() ? g_browser_process->GetApplicationLocale() selected_language.empty() ? locale : selected_language;
: selected_language;
const std::string list_locale = const std::string list_locale =
language_switch_result ? language_switch_result->loaded_locale language_switch_result ? language_switch_result->loaded_locale : locale;
: g_browser_process->GetApplicationLocale();
std::unique_ptr<base::ListValue> language_list( std::unique_ptr<base::ListValue> language_list(
chromeos::GetUILanguageList(nullptr, selected_code)); chromeos::GetUILanguageList(nullptr, selected_code));
...@@ -433,7 +430,8 @@ void ResolveUILanguageList( ...@@ -433,7 +430,8 @@ void ResolveUILanguageList(
base::PostTask( base::PostTask(
FROM_HERE, {base::ThreadPool(), base::MayBlock()}, FROM_HERE, {base::ThreadPool(), base::MayBlock()},
base::BindOnce(&ResolveLanguageListInThreadPool, base::BindOnce(&ResolveLanguageListInThreadPool,
base::Passed(&language_switch_result), g_browser_process->GetApplicationLocale(),
std::move(language_switch_result),
base::SequencedTaskRunnerHandle::Get(), callback)); base::SequencedTaskRunnerHandle::Get(), callback));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment