Chromium Code Reviews| 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 ec78933b313c9a0504f14407d6e35eb04f84e9c6..770627320eb7e31def0882e856f33a54097d97e8 100644 |
| --- a/chrome/browser/ui/webui/chromeos/login/l10n_util.cc |
| +++ b/chrome/browser/ui/webui/chromeos/login/l10n_util.cc |
| @@ -11,7 +11,9 @@ |
| #include <utility> |
| #include "base/basictypes.h" |
| +#include "base/bind.h" |
| #include "base/i18n/rtl.h" |
| +#include "base/location.h" |
| #include "base/logging.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/stringprintf.h" |
| @@ -23,6 +25,7 @@ |
| #include "chromeos/ime/component_extension_ime_manager.h" |
| #include "chromeos/ime/input_method_descriptor.h" |
| #include "chromeos/ime/input_method_manager.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "grit/generated_resources.h" |
| #include "ui/base/l10n/l10n_util.h" |
| @@ -30,7 +33,7 @@ namespace chromeos { |
| namespace { |
| -base::DictionaryValue* CreateInputMethodsEntry( |
| +scoped_ptr<base::DictionaryValue> CreateInputMethodsEntry( |
| const input_method::InputMethodDescriptor& method, |
| const std::string selected) { |
| input_method::InputMethodUtil* util = |
| @@ -40,7 +43,7 @@ base::DictionaryValue* CreateInputMethodsEntry( |
| input_method->SetString("value", ime_id); |
| input_method->SetString("title", util->GetInputMethodLongName(method)); |
| input_method->SetBoolean("selected", ime_id == selected); |
| - return input_method.release(); |
| + return input_method.Pass(); |
| } |
| // Returns true if element was inserted. |
| @@ -270,6 +273,43 @@ scoped_ptr<base::ListValue> GetLanguageList( |
| return language_list.Pass(); |
| } |
| +// Invokes |callback| with a list of keyboard layouts that can be used for |
| +// |resolved_locale|. |
| +void GetKeyboardLayoutsForResolvedLocale( |
| + const GetKeyboardLayoutsForLocaleCallback& callback, |
| + const std::string& resolved_locale) { |
| + input_method::InputMethodUtil* util = |
| + input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
| + std::vector<std::string> layouts = util->GetHardwareInputMethodIds(); |
| + std::vector<std::string> layouts_from_locale; |
| + util->GetInputMethodIdsFromLanguageCode( |
| + resolved_locale, |
| + input_method::kKeyboardLayoutsOnly, |
| + &layouts_from_locale); |
| + layouts.insert(layouts.end(), layouts_from_locale.begin(), |
| + layouts_from_locale.end()); |
| + |
| + std::string selected; |
| + if (!layouts_from_locale.empty()) { |
| + selected = |
| + util->GetInputMethodDescriptorFromId(layouts_from_locale[0])->id(); |
| + } |
| + |
| + scoped_ptr<base::ListValue> input_methods_list(new base::ListValue); |
| + std::set<std::string> input_methods_added; |
| + for (std::vector<std::string>::const_iterator it = layouts.begin(); |
| + it != layouts.end(); ++it) { |
| + const input_method::InputMethodDescriptor* ime = |
| + util->GetInputMethodDescriptorFromId(*it); |
| + if (!InsertString(ime->id(), input_methods_added)) |
| + continue; |
| + input_methods_list->Append( |
| + CreateInputMethodsEntry(*ime, selected).release()); |
| + } |
| + |
| + callback.Run(input_methods_list.Pass()); |
| +} |
| + |
| } // namespace |
| const char kMostRelevantLanguagesDivider[] = "MOST_RELEVANT_LANGUAGES_DIVIDER"; |
| @@ -359,7 +399,8 @@ scoped_ptr<base::ListValue> GetLoginKeyboardLayouts( |
| // Do not crash in case of misconfiguration. |
| if (ime) { |
| input_methods_added.insert(*i); |
| - input_methods_list->Append(CreateInputMethodsEntry(*ime, selected)); |
| + input_methods_list->Append( |
| + CreateInputMethodsEntry(*ime, selected).release()); |
| } else { |
| NOTREACHED(); |
| } |
| @@ -376,7 +417,7 @@ scoped_ptr<base::ListValue> GetLoginKeyboardLayouts( |
| AddOptgroupOtherLayouts(input_methods_list.get()); |
| } |
| input_methods_list->Append(CreateInputMethodsEntry((*input_methods)[i], |
| - selected)); |
| + selected).release()); |
| } |
| // "xkb:us::eng" should always be in the list of available layouts. |
| @@ -391,41 +432,29 @@ scoped_ptr<base::ListValue> GetLoginKeyboardLayouts( |
| AddOptgroupOtherLayouts(input_methods_list.get()); |
| } |
| input_methods_list->Append(CreateInputMethodsEntry(*us_eng_descriptor, |
| - selected)); |
| + selected).release()); |
| } |
| return input_methods_list.Pass(); |
| } |
| -scoped_ptr<base::ListValue> GetKeyboardLayoutsForLocale( |
| +void GetKeyboardLayoutsForLocale( |
| + const GetKeyboardLayoutsForLocaleCallback& callback, |
| const std::string& locale) { |
| - input_method::InputMethodUtil* util = |
| - input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
| - std::vector<std::string> layouts = util->GetHardwareInputMethodIds(); |
| - std::vector<std::string> layouts_from_locale; |
| - util->GetInputMethodIdsFromLanguageCode( |
| - l10n_util::GetApplicationLocale(locale), |
| - input_method::kKeyboardLayoutsOnly, |
| - &layouts_from_locale); |
| - layouts.insert(layouts.end(), layouts_from_locale.begin(), |
| - layouts_from_locale.end()); |
| - |
| - std::string selected; |
| - if (!layouts_from_locale.empty()) { |
| - selected = |
| - util->GetInputMethodDescriptorFromId(layouts_from_locale[0])->id(); |
| - } |
| + // Resolve |locale| on the FILE thread, then continue on the UI thread. |
| + content::BrowserThread::PostTaskAndReplyWithResult( |
| + content::BrowserThread::FILE, |
|
Nikita (slow)
2014/07/30 12:08:47
FILE thread is deprecated
https://groups.google.co
bartfab (slow)
2014/07/30 12:55:17
Done.
|
| + FROM_HERE, |
| + base::Bind(&l10n_util::GetApplicationLocale, |
| + locale), |
| + base::Bind(&GetKeyboardLayoutsForResolvedLocale, |
| + callback)); |
| +} |
| - scoped_ptr<base::ListValue> input_methods_list(new base::ListValue); |
| - std::set<std::string> input_methods_added; |
| - for (std::vector<std::string>::const_iterator it = layouts.begin(); |
| - it != layouts.end(); ++it) { |
| - const input_method::InputMethodDescriptor* ime = |
| - util->GetInputMethodDescriptorFromId(*it); |
| - if (!InsertString(ime->id(), input_methods_added)) |
| - continue; |
| - input_methods_list->Append(CreateInputMethodsEntry(*ime, selected)); |
| - } |
| - return input_methods_list.Pass(); |
| +scoped_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { |
| + const input_method::InputMethodDescriptor current_input_method = |
| + input_method::InputMethodManager::Get()->GetCurrentInputMethod(); |
| + return CreateInputMethodsEntry(current_input_method, |
| + current_input_method.id()); |
| } |
| } // namespace chromeos |