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

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: rebase 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/values.h" 29 #include "base/values.h"
30 #include "chrome/browser/browser_process.h" 30 #include "chrome/browser/browser_process.h"
31 #include "chrome/browser/chromeos/customization/customization_document.h" 31 #include "chrome/browser/chromeos/customization/customization_document.h"
32 #include "chrome/browser/chromeos/input_method/input_method_util.h" 32 #include "chrome/browser/chromeos/input_method/input_method_util.h"
33 #include "chrome/browser/chromeos/profiles/profile_helper.h" 33 #include "chrome/browser/chromeos/profiles/profile_helper.h"
34 #include "chrome/browser/profiles/profile_manager.h" 34 #include "chrome/browser/profiles/profile_manager.h"
35 #include "chrome/grit/generated_resources.h" 35 #include "chrome/grit/generated_resources.h"
36 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
37 #include "ui/base/ime/chromeos/component_extension_ime_manager.h" 37 #include "ui/base/ime/chromeos/component_extension_ime_manager.h"
38 #include "ui/base/ime/chromeos/input_method_descriptor.h" 38 #include "ui/base/ime/chromeos/input_method_descriptor.h"
39 #include "ui/base/ime/chromeos/input_method_manager.h" 39 #include "ui/base/ime/chromeos/input_method_manager.h"
40 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
41 41
42 namespace chromeos { 42 namespace chromeos {
43 43
44 const char kMostRelevantLanguagesDivider[] = "MOST_RELEVANT_LANGUAGES_DIVIDER"; 44 const char kMostRelevantLanguagesDivider[] = "MOST_RELEVANT_LANGUAGES_DIVIDER";
45 45
46 namespace { 46 namespace {
47 47
48 const char kSequenceToken[] = "chromeos_login_l10n_util";
49
50 std::unique_ptr<base::DictionaryValue> CreateInputMethodsEntry( 48 std::unique_ptr<base::DictionaryValue> CreateInputMethodsEntry(
51 const input_method::InputMethodDescriptor& method, 49 const input_method::InputMethodDescriptor& method,
52 const std::string selected) { 50 const std::string selected) {
53 input_method::InputMethodUtil* util = 51 input_method::InputMethodUtil* util =
54 input_method::InputMethodManager::Get()->GetInputMethodUtil(); 52 input_method::InputMethodManager::Get()->GetInputMethodUtil();
55 const std::string& ime_id = method.id(); 53 const std::string& ime_id = method.id();
56 std::unique_ptr<base::DictionaryValue> input_method( 54 std::unique_ptr<base::DictionaryValue> input_method(
57 new base::DictionaryValue); 55 new base::DictionaryValue);
58 input_method->SetString("value", ime_id); 56 input_method->SetString("value", ime_id);
59 input_method->SetString( 57 input_method->SetString(
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 std::string resolved_locale; 337 std::string resolved_locale;
340 if (!l10n_util::CheckAndResolveLocale(requested_locale, &resolved_locale)) 338 if (!l10n_util::CheckAndResolveLocale(requested_locale, &resolved_locale))
341 return loaded_locale; 339 return loaded_locale;
342 340
343 if (resolved_locale == loaded_locale) 341 if (resolved_locale == loaded_locale)
344 return requested_locale; 342 return requested_locale;
345 343
346 return loaded_locale; 344 return loaded_locale;
347 } 345 }
348 346
349 void ResolveLanguageListOnBlockingPool( 347 void ResolveLanguageListInThreadPool(
350 std::unique_ptr<chromeos::locale_util::LanguageSwitchResult> 348 std::unique_ptr<chromeos::locale_util::LanguageSwitchResult>
351 language_switch_result, 349 language_switch_result,
352 const scoped_refptr<base::TaskRunner> task_runner, 350 const scoped_refptr<base::TaskRunner> task_runner,
353 const UILanguageListResolvedCallback& resolved_callback) { 351 const UILanguageListResolvedCallback& resolved_callback) {
354 // DCHECK(task_runner->RunsTasksInCurrentSequence());
achuithb 2017/05/18 21:36:51 Is there an appropriate DCHECK to assert the right
355 base::ThreadRestrictions::AssertIOAllowed(); 352 base::ThreadRestrictions::AssertIOAllowed();
emaxx 2017/05/19 17:58:16 nit: While you're here - please add #include "base
fdoray 2017/05/19 18:34:28 Done.
356 353
357 std::string selected_language; 354 std::string selected_language;
358 if (!language_switch_result) { 355 if (!language_switch_result) {
359 selected_language = 356 selected_language =
360 StartupCustomizationDocument::GetInstance()->initial_locale_default(); 357 StartupCustomizationDocument::GetInstance()->initial_locale_default();
361 } else { 358 } else {
362 if (language_switch_result->success) { 359 if (language_switch_result->success) {
363 if (language_switch_result->requested_locale == 360 if (language_switch_result->requested_locale ==
364 language_switch_result->loaded_locale) { 361 language_switch_result->loaded_locale) {
365 selected_language = language_switch_result->requested_locale; 362 selected_language = language_switch_result->requested_locale;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 418 }
422 419
423 } // namespace 420 } // namespace
424 421
425 void ResolveUILanguageList( 422 void ResolveUILanguageList(
426 std::unique_ptr<chromeos::locale_util::LanguageSwitchResult> 423 std::unique_ptr<chromeos::locale_util::LanguageSwitchResult>
427 language_switch_result, 424 language_switch_result,
428 const UILanguageListResolvedCallback& callback) { 425 const UILanguageListResolvedCallback& callback) {
429 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 426 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
430 427
431 content::BrowserThread::GetBlockingPool()->PostTask( 428 base::PostTaskWithTraits(
432 FROM_HERE, base::Bind(&ResolveLanguageListOnBlockingPool, 429 FROM_HERE, {base::MayBlock()},
433 base::Passed(&language_switch_result), 430 base::BindOnce(&ResolveLanguageListInThreadPool,
434 base::ThreadTaskRunnerHandle::Get(), callback)); 431 base::Passed(&language_switch_result),
432 base::SequencedTaskRunnerHandle::Get(), callback));
435 } 433 }
436 434
437 std::unique_ptr<base::ListValue> GetMinimalUILanguageList() { 435 std::unique_ptr<base::ListValue> GetMinimalUILanguageList() {
438 const std::string application_locale = 436 const std::string application_locale =
439 g_browser_process->GetApplicationLocale(); 437 g_browser_process->GetApplicationLocale();
440 base::string16 language_native_display_name = 438 base::string16 language_native_display_name =
441 l10n_util::GetDisplayNameForLocale( 439 l10n_util::GetDisplayNameForLocale(
442 application_locale, application_locale, true); 440 application_locale, application_locale, true);
443 441
444 std::unique_ptr<base::ListValue> language_list(new base::ListValue()); 442 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( 569 input_methods_list->Append(
572 CreateInputMethodsEntry(*us_eng_descriptor, selected)); 570 CreateInputMethodsEntry(*us_eng_descriptor, selected));
573 manager->GetActiveIMEState()->EnableInputMethod(us_keyboard_id); 571 manager->GetActiveIMEState()->EnableInputMethod(us_keyboard_id);
574 } 572 }
575 return input_methods_list; 573 return input_methods_list;
576 } 574 }
577 575
578 void GetKeyboardLayoutsForLocale( 576 void GetKeyboardLayoutsForLocale(
579 const GetKeyboardLayoutsForLocaleCallback& callback, 577 const GetKeyboardLayoutsForLocaleCallback& callback,
580 const std::string& locale) { 578 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);
emaxx 2017/05/19 17:58:16 Is there a reason for not keeping the SKIP_ON_SHUT
fdoray 2017/05/19 18:34:28 No. Added it back.
587
588 // Resolve |locale| on a background thread, then continue on the current 579 // Resolve |locale| on a background thread, then continue on the current
589 // thread. 580 // thread.
590 std::string (*get_application_locale)(const std::string&, bool) = 581 std::string (*get_application_locale)(const std::string&, bool) =
591 &l10n_util::GetApplicationLocale; 582 &l10n_util::GetApplicationLocale;
592 base::PostTaskAndReplyWithResult( 583 base::PostTaskWithTraitsAndReplyWithResult(
fdoray 2017/05/17 17:52:16 Is it important to have mutual exclusion between t
emaxx 2017/05/19 17:58:16 Looking at implementation of l10n_util::GetApplica
593 background_task_runner.get(), FROM_HERE, 584 FROM_HERE, {base::MayBlock()},
594 base::Bind(get_application_locale, locale, false /* set_icu_locale */), 585 base::BindOnce(get_application_locale, locale,
595 base::Bind(&GetKeyboardLayoutsForResolvedLocale, locale, callback)); 586 false /* set_icu_locale */),
587 base::BindOnce(&GetKeyboardLayoutsForResolvedLocale, locale, callback));
596 } 588 }
597 589
598 std::unique_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { 590 std::unique_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() {
599 const input_method::InputMethodDescriptor current_input_method = 591 const input_method::InputMethodDescriptor current_input_method =
600 input_method::InputMethodManager::Get() 592 input_method::InputMethodManager::Get()
601 ->GetActiveIMEState() 593 ->GetActiveIMEState()
602 ->GetCurrentInputMethod(); 594 ->GetCurrentInputMethod();
603 return CreateInputMethodsEntry(current_input_method, 595 return CreateInputMethodsEntry(current_input_method,
604 current_input_method.id()); 596 current_input_method.id());
605 } 597 }
606 598
607 } // namespace chromeos 599 } // 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