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

Unified Diff: chrome/browser/ui/webui/chromeos/login/l10n_util.cc

Issue 653123002: 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
Index: chrome/browser/ui/webui/chromeos/login/l10n_util.cc
diff --git a/chrome/browser/ui/webui/chromeos/login/l10n_util.cc b/chrome/browser/ui/webui/chromeos/login/l10n_util.cc
index 1613b4d2485d3884fdc4faaba1bbd940d3ebb14c..98ef4523ca474c953ae6f4fce8a54a08c5309fd1 100644
--- a/chrome/browser/ui/webui/chromeos/login/l10n_util.cc
+++ b/chrome/browser/ui/webui/chromeos/login/l10n_util.cc
@@ -26,8 +26,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/customization_document.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
-#include "chrome/browser/chromeos/profiles/profile_helper.h"
-#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/ime/component_extension_ime_manager.h"
#include "chromeos/ime/input_method_descriptor.h"
@@ -37,8 +35,6 @@
namespace chromeos {
-const char kMostRelevantLanguagesDivider[] = "MOST_RELEVANT_LANGUAGES_DIVIDER";
-
namespace {
const char kSequenceToken[] = "chromeos_login_l10n_util";
@@ -75,27 +71,6 @@ void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) {
}
#endif
-base::DictionaryValue* CreateLanguageEntry(
- const std::string& language_code,
- const base::string16& language_display_name,
- const base::string16& language_native_display_name) {
- base::string16 display_name = language_display_name;
- const bool markup_removal =
- base::i18n::UnadjustStringForLocaleDirection(&display_name);
- DCHECK(markup_removal);
-
- const bool has_rtl_chars =
- base::i18n::StringContainsStrongRTLChars(display_name);
- const std::string directionality = has_rtl_chars ? "rtl" : "ltr";
-
- scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue());
- dictionary->SetString("code", language_code);
- dictionary->SetString("displayName", language_display_name);
- dictionary->SetString("textDirection", directionality);
- dictionary->SetString("nativeDisplayName", language_native_display_name);
- return dictionary.release();
-}
-
// Gets the list of languages with |descriptors| based on |base_language_codes|.
// The |most_relevant_language_codes| will be first in the list. If
// |insert_divider| is true, an entry with its "code" attribute set to
@@ -280,10 +255,20 @@ scoped_ptr<base::ListValue> GetLanguageList(
language_list->Append(dictionary);
continue;
}
+ const bool markup_removal =
+ base::i18n::UnadjustStringForLocaleDirection(&display_name);
+ DCHECK(markup_removal);
+ const bool has_rtl_chars =
+ base::i18n::StringContainsStrongRTLChars(display_name);
+ const std::string directionality = has_rtl_chars ? "rtl" : "ltr";
const LanguagePair& pair = language_map[out_display_names[i]];
- language_list->Append(
- CreateLanguageEntry(pair.first, out_display_names[i], pair.second));
+ base::DictionaryValue* dictionary = new base::DictionaryValue();
+ dictionary->SetString("code", pair.first);
+ dictionary->SetString("displayName", out_display_names[i]);
+ dictionary->SetString("textDirection", directionality);
+ dictionary->SetString("nativeDisplayName", pair.second);
+ language_list->Append(dictionary);
}
return language_list.Pass();
@@ -326,68 +311,26 @@ void GetKeyboardLayoutsForResolvedLocale(
callback.Run(input_methods_list.Pass());
}
-// For "UI Language" drop-down menu at OOBE screen we need to decide which
-// entry to mark "selected". If user has just selected "requested_locale",
-// but "loaded_locale" was actually loaded, we mark original user choice
-// "selected" only if loaded_locale is a backup for "requested_locale".
-std::string CalculateSelectedLanguage(const std::string& requested_locale,
- const std::string& loaded_locale) {
- std::string resolved_locale;
- if (!l10n_util::CheckAndResolveLocale(requested_locale, &resolved_locale))
- return loaded_locale;
-
- if (resolved_locale == loaded_locale)
- return requested_locale;
-
- return loaded_locale;
-}
+} // namespace
-void ResolveLanguageListOnBlockingPool(
- const chromeos::locale_util::LanguageSwitchResult* language_switch_result,
- scoped_ptr<base::ListValue>* list,
- std::string* list_locale,
- std::string* selected_language) {
- DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
-
- if (!language_switch_result) {
- *selected_language =
- StartupCustomizationDocument::GetInstance()->initial_locale_default();
- } else {
- if (language_switch_result->success) {
- if (language_switch_result->requested_locale ==
- language_switch_result->loaded_locale) {
- *selected_language = language_switch_result->requested_locale;
- } else {
- *selected_language =
- CalculateSelectedLanguage(language_switch_result->requested_locale,
- language_switch_result->loaded_locale);
- }
- } else {
- *selected_language = language_switch_result->loaded_locale;
- }
- }
- const std::string selected_code =
- selected_language->empty() ? g_browser_process->GetApplicationLocale()
- : *selected_language;
-
- *list_locale = language_switch_result
- ? language_switch_result->loaded_locale
- : g_browser_process->GetApplicationLocale();
- list->reset(chromeos::GetUILanguageList(NULL, selected_code).release());
-}
+const char kMostRelevantLanguagesDivider[] = "MOST_RELEVANT_LANGUAGES_DIVIDER";
-void OnLanguageListResolved(
- UILanguageListResolvedCallback callback,
- scoped_ptr<scoped_ptr<base::ListValue>> new_language_list,
- scoped_ptr<std::string> new_language_list_locale,
- scoped_ptr<std::string> new_selected_language) {
- callback.Run(new_language_list->Pass(),
- *new_language_list_locale,
- *new_selected_language);
-}
+scoped_ptr<base::ListValue> GetUILanguageList(
+ const std::vector<std::string>* most_relevant_language_codes,
+ const std::string& selected) {
+ ComponentExtensionIMEManager* manager =
+ input_method::InputMethodManager::Get()->
+ GetComponentExtensionIMEManager();
+ input_method::InputMethodDescriptors descriptors =
+ manager->GetXkbIMEAsInputMethodDescriptor();
+ scoped_ptr<base::ListValue> languages_list(GetLanguageList(
+ descriptors,
+ l10n_util::GetAvailableLocales(),
+ most_relevant_language_codes
+ ? *most_relevant_language_codes
+ : StartupCustomizationDocument::GetInstance()->configured_locales(),
+ true));
-void AdjustUILanguageList(const std::string& selected,
- base::ListValue* languages_list) {
for (size_t i = 0; i < languages_list->GetSize(); ++i) {
base::DictionaryValue* language_info = NULL;
if (!languages_list->GetDictionary(i, &language_info))
@@ -417,70 +360,6 @@ void AdjustUILanguageList(const std::string& selected,
if (value == selected)
language_info->SetBoolean("selected", true);
}
-}
-
-} // namespace
-
-void ResolveUILanguageList(
- scoped_ptr<chromeos::locale_util::LanguageSwitchResult>
- language_switch_result,
- UILanguageListResolvedCallback callback) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
-
- scoped_ptr<scoped_ptr<base::ListValue>> new_language_list(
- new scoped_ptr<base::ListValue>());
- scoped_ptr<std::string> new_language_list_locale(new std::string);
- scoped_ptr<std::string> new_selected_language(new std::string);
-
- base::Closure resolve_on_pool =
- base::Bind(&ResolveLanguageListOnBlockingPool,
- base::Owned(language_switch_result.release()),
- base::Unretained(new_language_list.get()),
- base::Unretained(new_language_list_locale.get()),
- base::Unretained(new_selected_language.get()));
-
- base::Closure on_language_list_resolved =
- base::Bind(&OnLanguageListResolved,
- callback,
- base::Passed(new_language_list.Pass()),
- base::Passed(new_language_list_locale.Pass()),
- base::Passed(new_selected_language.Pass()));
-
- content::BrowserThread::GetBlockingPool()->PostTaskAndReply(
- FROM_HERE, resolve_on_pool, on_language_list_resolved);
-}
-
-scoped_ptr<base::ListValue> GetMinimalUILanguageList() {
- const std::string application_locale =
- g_browser_process->GetApplicationLocale();
- base::string16 language_native_display_name =
- l10n_util::GetDisplayNameForLocale(
- application_locale, application_locale, true);
-
- scoped_ptr<base::ListValue> language_list(new base::ListValue());
- language_list->Append(CreateLanguageEntry(application_locale,
- language_native_display_name,
- language_native_display_name));
- AdjustUILanguageList(std::string(), language_list.get());
- return language_list.Pass();
-}
-
-scoped_ptr<base::ListValue> GetUILanguageList(
- const std::vector<std::string>* most_relevant_language_codes,
- const std::string& selected) {
- ComponentExtensionIMEManager* manager =
- input_method::InputMethodManager::Get()
- ->GetComponentExtensionIMEManager();
- input_method::InputMethodDescriptors descriptors =
- manager->GetXkbIMEAsInputMethodDescriptor();
- scoped_ptr<base::ListValue> languages_list(GetLanguageList(
- descriptors,
- l10n_util::GetAvailableLocales(),
- most_relevant_language_codes
- ? *most_relevant_language_codes
- : StartupCustomizationDocument::GetInstance()->configured_locales(),
- true));
- AdjustUILanguageList(selected, languages_list.get());
return languages_list.Pass();
}
@@ -524,8 +403,7 @@ scoped_ptr<base::ListValue> GetAcceptLanguageList() {
scoped_ptr<base::ListValue> GetAndActivateLoginKeyboardLayouts(
const std::string& locale,
- const std::string& selected,
- bool activate_keyboards) {
+ const std::string& selected) {
scoped_ptr<base::ListValue> input_methods_list(new base::ListValue);
#if !defined(USE_ATHENA)
// TODO(dpolukhin): crbug.com/407579
@@ -536,12 +414,8 @@ scoped_ptr<base::ListValue> GetAndActivateLoginKeyboardLayouts(
const std::vector<std::string>& hardware_login_input_methods =
util->GetHardwareLoginInputMethodIds();
- if (activate_keyboards) {
- DCHECK(
- ProfileHelper::IsSigninProfile(ProfileManager::GetActiveUserProfile()));
- manager->GetActiveIMEState()->EnableLoginLayouts(
- locale, hardware_login_input_methods);
- }
+ manager->GetActiveIMEState()->EnableLoginLayouts(
+ locale, hardware_login_input_methods);
scoped_ptr<input_method::InputMethodDescriptors> input_methods(
manager->GetActiveIMEState()->GetActiveInputMethods());
« no previous file with comments | « chrome/browser/ui/webui/chromeos/login/l10n_util.h ('k') | chrome/browser/ui/webui/chromeos/login/network_screen_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698