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

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

Issue 2884973004: Remove usage of SequencedWorkerPool::GetNamedSequenceToken from GetKeyboardLayoutsForLocale. (Closed)
Patch Set: CR-emaxx-18 Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/policy/device_local_account_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/ui/webui/chromeos/login/l10n_util.h" 5 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <iterator> 9 #include <iterator>
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <set> 12 #include <set>
13 #include <utility> 13 #include <utility>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
21 #include "base/sequenced_task_runner.h" 21 #include "base/sequenced_task_runner.h"
22 #include "base/stl_util.h" 22 #include "base/stl_util.h"
23 #include "base/strings/string16.h" 23 #include "base/strings/string16.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
26 #include "base/task_runner_util.h" 26 #include "base/task_runner_util.h"
27 #include "base/threading/sequenced_worker_pool.h" 27 #include "base/task_scheduler/post_task.h"
28 #include "base/threading/thread_task_runner_handle.h" 28 #include "base/threading/sequenced_task_runner_handle.h"
29 #include "base/threading/thread_restrictions.h"
29 #include "base/values.h" 30 #include "base/values.h"
30 #include "chrome/browser/browser_process.h" 31 #include "chrome/browser/browser_process.h"
31 #include "chrome/browser/chromeos/customization/customization_document.h" 32 #include "chrome/browser/chromeos/customization/customization_document.h"
32 #include "chrome/browser/chromeos/input_method/input_method_util.h" 33 #include "chrome/browser/chromeos/input_method/input_method_util.h"
33 #include "chrome/browser/chromeos/profiles/profile_helper.h" 34 #include "chrome/browser/chromeos/profiles/profile_helper.h"
34 #include "chrome/browser/profiles/profile_manager.h" 35 #include "chrome/browser/profiles/profile_manager.h"
35 #include "chrome/grit/generated_resources.h" 36 #include "chrome/grit/generated_resources.h"
36 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
37 #include "ui/base/ime/chromeos/component_extension_ime_manager.h" 38 #include "ui/base/ime/chromeos/component_extension_ime_manager.h"
38 #include "ui/base/ime/chromeos/input_method_descriptor.h" 39 #include "ui/base/ime/chromeos/input_method_descriptor.h"
39 #include "ui/base/ime/chromeos/input_method_manager.h" 40 #include "ui/base/ime/chromeos/input_method_manager.h"
40 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
41 42
42 namespace chromeos { 43 namespace chromeos {
43 44
44 const char kMostRelevantLanguagesDivider[] = "MOST_RELEVANT_LANGUAGES_DIVIDER"; 45 const char kMostRelevantLanguagesDivider[] = "MOST_RELEVANT_LANGUAGES_DIVIDER";
45 46
46 namespace { 47 namespace {
47 48
48 const char kSequenceToken[] = "chromeos_login_l10n_util";
49
50 std::unique_ptr<base::DictionaryValue> CreateInputMethodsEntry( 49 std::unique_ptr<base::DictionaryValue> CreateInputMethodsEntry(
51 const input_method::InputMethodDescriptor& method, 50 const input_method::InputMethodDescriptor& method,
52 const std::string selected) { 51 const std::string selected) {
53 input_method::InputMethodUtil* util = 52 input_method::InputMethodUtil* util =
54 input_method::InputMethodManager::Get()->GetInputMethodUtil(); 53 input_method::InputMethodManager::Get()->GetInputMethodUtil();
55 const std::string& ime_id = method.id(); 54 const std::string& ime_id = method.id();
56 std::unique_ptr<base::DictionaryValue> input_method( 55 std::unique_ptr<base::DictionaryValue> input_method(
57 new base::DictionaryValue); 56 new base::DictionaryValue);
58 input_method->SetString("value", ime_id); 57 input_method->SetString("value", ime_id);
59 input_method->SetString( 58 input_method->SetString(
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 std::string resolved_locale; 338 std::string resolved_locale;
340 if (!l10n_util::CheckAndResolveLocale(requested_locale, &resolved_locale)) 339 if (!l10n_util::CheckAndResolveLocale(requested_locale, &resolved_locale))
341 return loaded_locale; 340 return loaded_locale;
342 341
343 if (resolved_locale == loaded_locale) 342 if (resolved_locale == loaded_locale)
344 return requested_locale; 343 return requested_locale;
345 344
346 return loaded_locale; 345 return loaded_locale;
347 } 346 }
348 347
349 void ResolveLanguageListOnBlockingPool( 348 void ResolveLanguageListInThreadPool(
350 std::unique_ptr<chromeos::locale_util::LanguageSwitchResult> 349 std::unique_ptr<chromeos::locale_util::LanguageSwitchResult>
351 language_switch_result, 350 language_switch_result,
352 const scoped_refptr<base::TaskRunner> task_runner, 351 const scoped_refptr<base::TaskRunner> task_runner,
353 const UILanguageListResolvedCallback& resolved_callback) { 352 const UILanguageListResolvedCallback& resolved_callback) {
354 // DCHECK(task_runner->RunsTasksInCurrentSequence());
355 base::ThreadRestrictions::AssertIOAllowed(); 353 base::ThreadRestrictions::AssertIOAllowed();
356 354
357 std::string selected_language; 355 std::string selected_language;
358 if (!language_switch_result) { 356 if (!language_switch_result) {
359 selected_language = 357 selected_language =
360 StartupCustomizationDocument::GetInstance()->initial_locale_default(); 358 StartupCustomizationDocument::GetInstance()->initial_locale_default();
361 } else { 359 } else {
362 if (language_switch_result->success) { 360 if (language_switch_result->success) {
363 if (language_switch_result->requested_locale == 361 if (language_switch_result->requested_locale ==
364 language_switch_result->loaded_locale) { 362 language_switch_result->loaded_locale) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 419 }
422 420
423 } // namespace 421 } // namespace
424 422
425 void ResolveUILanguageList( 423 void ResolveUILanguageList(
426 std::unique_ptr<chromeos::locale_util::LanguageSwitchResult> 424 std::unique_ptr<chromeos::locale_util::LanguageSwitchResult>
427 language_switch_result, 425 language_switch_result,
428 const UILanguageListResolvedCallback& callback) { 426 const UILanguageListResolvedCallback& callback) {
429 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 427 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
430 428
431 content::BrowserThread::GetBlockingPool()->PostTask( 429 base::PostTaskWithTraits(
432 FROM_HERE, base::Bind(&ResolveLanguageListOnBlockingPool, 430 FROM_HERE, {base::MayBlock()},
433 base::Passed(&language_switch_result), 431 base::BindOnce(&ResolveLanguageListInThreadPool,
434 base::ThreadTaskRunnerHandle::Get(), callback)); 432 base::Passed(&language_switch_result),
433 base::SequencedTaskRunnerHandle::Get(), callback));
435 } 434 }
436 435
437 std::unique_ptr<base::ListValue> GetMinimalUILanguageList() { 436 std::unique_ptr<base::ListValue> GetMinimalUILanguageList() {
438 const std::string application_locale = 437 const std::string application_locale =
439 g_browser_process->GetApplicationLocale(); 438 g_browser_process->GetApplicationLocale();
440 base::string16 language_native_display_name = 439 base::string16 language_native_display_name =
441 l10n_util::GetDisplayNameForLocale( 440 l10n_util::GetDisplayNameForLocale(
442 application_locale, application_locale, true); 441 application_locale, application_locale, true);
443 442
444 std::unique_ptr<base::ListValue> language_list(new base::ListValue()); 443 std::unique_ptr<base::ListValue> language_list(new base::ListValue());
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 input_methods_list->Append( 570 input_methods_list->Append(
572 CreateInputMethodsEntry(*us_eng_descriptor, selected)); 571 CreateInputMethodsEntry(*us_eng_descriptor, selected));
573 manager->GetActiveIMEState()->EnableInputMethod(us_keyboard_id); 572 manager->GetActiveIMEState()->EnableInputMethod(us_keyboard_id);
574 } 573 }
575 return input_methods_list; 574 return input_methods_list;
576 } 575 }
577 576
578 void GetKeyboardLayoutsForLocale( 577 void GetKeyboardLayoutsForLocale(
579 const GetKeyboardLayoutsForLocaleCallback& callback, 578 const GetKeyboardLayoutsForLocaleCallback& callback,
580 const std::string& locale) { 579 const std::string& locale) {
581 base::SequencedWorkerPool* worker_pool =
582 content::BrowserThread::GetBlockingPool();
583 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
584 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
585 worker_pool->GetNamedSequenceToken(kSequenceToken),
586 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
587
588 // Resolve |locale| on a background thread, then continue on the current 580 // Resolve |locale| on a background thread, then continue on the current
589 // thread. 581 // thread.
590 std::string (*get_application_locale)(const std::string&, bool) = 582 std::string (*get_application_locale)(const std::string&, bool) =
591 &l10n_util::GetApplicationLocale; 583 &l10n_util::GetApplicationLocale;
592 base::PostTaskAndReplyWithResult( 584 base::PostTaskWithTraitsAndReplyWithResult(
593 background_task_runner.get(), FROM_HERE, 585 FROM_HERE,
594 base::Bind(get_application_locale, locale, false /* set_icu_locale */), 586 {base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
595 base::Bind(&GetKeyboardLayoutsForResolvedLocale, locale, callback)); 587 base::BindOnce(get_application_locale, locale,
588 false /* set_icu_locale */),
589 base::BindOnce(&GetKeyboardLayoutsForResolvedLocale, locale, callback));
596 } 590 }
597 591
598 std::unique_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { 592 std::unique_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() {
599 const input_method::InputMethodDescriptor current_input_method = 593 const input_method::InputMethodDescriptor current_input_method =
600 input_method::InputMethodManager::Get() 594 input_method::InputMethodManager::Get()
601 ->GetActiveIMEState() 595 ->GetActiveIMEState()
602 ->GetCurrentInputMethod(); 596 ->GetCurrentInputMethod();
603 return CreateInputMethodsEntry(current_input_method, 597 return CreateInputMethodsEntry(current_input_method,
604 current_input_method.id()); 598 current_input_method.id());
605 } 599 }
606 600
607 } // namespace chromeos 601 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/device_local_account_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698