OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/browser_main_loop.h" | 5 #include "content/browser/browser_main_loop.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "base/power_monitor/power_monitor_device_source.h" | 27 #include "base/power_monitor/power_monitor_device_source.h" |
28 #include "base/process/process_metrics.h" | 28 #include "base/process/process_metrics.h" |
29 #include "base/run_loop.h" | 29 #include "base/run_loop.h" |
30 #include "base/single_thread_task_runner.h" | 30 #include "base/single_thread_task_runner.h" |
31 #include "base/strings/string_number_conversions.h" | 31 #include "base/strings/string_number_conversions.h" |
32 #include "base/strings/string_split.h" | 32 #include "base/strings/string_split.h" |
33 #include "base/synchronization/waitable_event.h" | 33 #include "base/synchronization/waitable_event.h" |
34 #include "base/system_monitor/system_monitor.h" | 34 #include "base/system_monitor/system_monitor.h" |
35 #include "base/task_scheduler/initialization_util.h" | 35 #include "base/task_scheduler/initialization_util.h" |
36 #include "base/task_scheduler/post_task.h" | 36 #include "base/task_scheduler/post_task.h" |
37 #include "base/task_scheduler/scheduler_worker_pool_params.h" | |
38 #include "base/task_scheduler/task_scheduler.h" | 37 #include "base/task_scheduler/task_scheduler.h" |
39 #include "base/task_scheduler/task_traits.h" | 38 #include "base/task_scheduler/task_traits.h" |
40 #include "base/threading/sequenced_worker_pool.h" | 39 #include "base/threading/sequenced_worker_pool.h" |
41 #include "base/threading/thread_restrictions.h" | 40 #include "base/threading/thread_restrictions.h" |
42 #include "base/threading/thread_task_runner_handle.h" | 41 #include "base/threading/thread_task_runner_handle.h" |
43 #include "base/time/time.h" | 42 #include "base/time/time.h" |
44 #include "base/timer/hi_res_timer_manager.h" | 43 #include "base/timer/hi_res_timer_manager.h" |
45 #include "base/trace_event/memory_dump_manager.h" | 44 #include "base/trace_event/memory_dump_manager.h" |
46 #include "base/trace_event/trace_event.h" | 45 #include "base/trace_event/trace_event.h" |
47 #include "build/build_config.h" | 46 #include "build/build_config.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 #endif // defined(OS_WIN) | 411 #endif // defined(OS_WIN) |
413 | 412 |
414 enum WorkerPoolType : size_t { | 413 enum WorkerPoolType : size_t { |
415 BACKGROUND = 0, | 414 BACKGROUND = 0, |
416 BACKGROUND_BLOCKING, | 415 BACKGROUND_BLOCKING, |
417 FOREGROUND, | 416 FOREGROUND, |
418 FOREGROUND_BLOCKING, | 417 FOREGROUND_BLOCKING, |
419 WORKER_POOL_COUNT // Always last. | 418 WORKER_POOL_COUNT // Always last. |
420 }; | 419 }; |
421 | 420 |
422 std::vector<base::SchedulerWorkerPoolParams> | 421 std::unique_ptr<base::TaskSchedulerInitParams> |
423 GetDefaultSchedulerWorkerPoolParams() { | 422 GetDefaultTaskSchedulerInitParams() { |
424 using StandbyThreadPolicy = | 423 using StandbyThreadPolicy = |
425 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; | 424 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; |
426 using ThreadPriority = base::ThreadPriority; | |
427 std::vector<base::SchedulerWorkerPoolParams> params_vector; | |
428 #if defined(OS_ANDROID) | 425 #if defined(OS_ANDROID) |
429 params_vector.emplace_back( | 426 return base::MakeUnique<base::TaskSchedulerInitParams>( |
430 "Background", ThreadPriority::BACKGROUND, StandbyThreadPolicy::ONE, | 427 base::SchedulerWorkerPoolParams( |
431 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), | 428 StandbyThreadPolicy::ONE, |
432 base::TimeDelta::FromSeconds(30)); | 429 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), |
433 params_vector.emplace_back( | 430 base::TimeDelta::FromSeconds(30)), |
434 "BackgroundBlocking", ThreadPriority::BACKGROUND, | 431 base::SchedulerWorkerPoolParams( |
435 StandbyThreadPolicy::ONE, | 432 StandbyThreadPolicy::ONE, |
436 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), | 433 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), |
437 base::TimeDelta::FromSeconds(30)); | 434 base::TimeDelta::FromSeconds(30)), |
438 params_vector.emplace_back( | 435 base::SchedulerWorkerPoolParams( |
439 "Foreground", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | 436 StandbyThreadPolicy::ONE, |
440 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0), | 437 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0), |
441 base::TimeDelta::FromSeconds(30)); | 438 base::TimeDelta::FromSeconds(30)), |
442 params_vector.emplace_back( | 439 base::SchedulerWorkerPoolParams( |
443 "ForegroundBlocking", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | 440 StandbyThreadPolicy::ONE, |
444 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0), | 441 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0), |
445 base::TimeDelta::FromSeconds(30)); | 442 base::TimeDelta::FromSeconds(30))); |
446 #else | 443 #else |
447 params_vector.emplace_back( | 444 return base::MakeUnique<base::TaskSchedulerInitParams>( |
448 "Background", ThreadPriority::BACKGROUND, StandbyThreadPolicy::ONE, | 445 base::SchedulerWorkerPoolParams( |
449 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), | 446 StandbyThreadPolicy::ONE, |
450 base::TimeDelta::FromSeconds(30)); | 447 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), |
451 params_vector.emplace_back( | 448 base::TimeDelta::FromSeconds(30)), |
452 "BackgroundBlocking", ThreadPriority::BACKGROUND, | 449 base::SchedulerWorkerPoolParams( |
453 StandbyThreadPolicy::ONE, | 450 StandbyThreadPolicy::ONE, |
454 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), | 451 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), |
455 base::TimeDelta::FromSeconds(30)); | 452 base::TimeDelta::FromSeconds(30)), |
456 params_vector.emplace_back( | 453 base::SchedulerWorkerPoolParams( |
457 "Foreground", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | 454 StandbyThreadPolicy::ONE, |
458 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0), | 455 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0), |
459 base::TimeDelta::FromSeconds(30)); | 456 base::TimeDelta::FromSeconds(30)), |
460 // Tasks posted to SequencedWorkerPool or BrowserThreadImpl may be redirected | 457 // Tasks posted to SequencedWorkerPool or BrowserThreadImpl may be |
461 // to this pool. Since COM STA is initialized in these environments, it must | 458 // redirected to this pool. Since COM STA is initialized in these |
462 // also be initialized in this pool. | 459 // environments, it must also be initialized in this pool. |
463 params_vector.emplace_back( | 460 base::SchedulerWorkerPoolParams( |
464 "ForegroundBlocking", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | 461 StandbyThreadPolicy::ONE, |
465 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0), | 462 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0), |
466 base::TimeDelta::FromSeconds(30), | 463 base::TimeDelta::FromSeconds(30), |
467 base::SchedulerBackwardCompatibility::INIT_COM_STA); | 464 base::SchedulerBackwardCompatibility::INIT_COM_STA)); |
468 #endif | 465 #endif |
469 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); | |
470 return params_vector; | |
471 } | |
472 | |
473 // Returns the worker pool index for |traits| defaulting to FOREGROUND or | |
474 // FOREGROUND_BLOCKING on any other priorities based off of worker pools defined | |
475 // in GetDefaultSchedulerWorkerPoolParams(). | |
476 size_t DefaultBrowserWorkerPoolIndexForTraits(const base::TaskTraits& traits) { | |
477 const bool is_background = | |
478 traits.priority() == base::TaskPriority::BACKGROUND; | |
479 if (traits.may_block() || traits.with_base_sync_primitives()) | |
480 return is_background ? BACKGROUND_BLOCKING : FOREGROUND_BLOCKING; | |
481 | |
482 return is_background ? BACKGROUND : FOREGROUND; | |
483 } | 466 } |
484 | 467 |
485 } // namespace | 468 } // namespace |
486 | 469 |
487 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 470 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
488 namespace internal { | 471 namespace internal { |
489 | 472 |
490 // Forwards GPUInfo updates to ui::XVisualManager | 473 // Forwards GPUInfo updates to ui::XVisualManager |
491 class GpuDataManagerVisualProxy : public GpuDataManagerObserver { | 474 class GpuDataManagerVisualProxy : public GpuDataManagerObserver { |
492 public: | 475 public: |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 startup_task_runner_->RunAllTasksNow(); | 969 startup_task_runner_->RunAllTasksNow(); |
987 } | 970 } |
988 #else | 971 #else |
989 startup_task_runner_->RunAllTasksNow(); | 972 startup_task_runner_->RunAllTasksNow(); |
990 #endif | 973 #endif |
991 } | 974 } |
992 | 975 |
993 int BrowserMainLoop::CreateThreads() { | 976 int BrowserMainLoop::CreateThreads() { |
994 TRACE_EVENT0("startup,rail", "BrowserMainLoop::CreateThreads"); | 977 TRACE_EVENT0("startup,rail", "BrowserMainLoop::CreateThreads"); |
995 | 978 |
996 std::vector<base::SchedulerWorkerPoolParams> params_vector; | 979 auto task_scheduler_init_params = |
997 base::TaskScheduler::WorkerPoolIndexForTraitsCallback | 980 GetContentClient()->browser()->GetTaskSchedulerInitParams(); |
998 index_to_traits_callback; | 981 if (!task_scheduler_init_params) { |
999 GetContentClient()->browser()->GetTaskSchedulerInitializationParams( | 982 task_scheduler_init_params = GetDefaultTaskSchedulerInitParams(); |
1000 ¶ms_vector, &index_to_traits_callback); | |
1001 | |
1002 if (params_vector.empty() || index_to_traits_callback.is_null()) { | |
1003 params_vector = GetDefaultSchedulerWorkerPoolParams(); | |
1004 index_to_traits_callback = | |
1005 base::Bind(&DefaultBrowserWorkerPoolIndexForTraits); | |
1006 } | 983 } |
| 984 DCHECK(task_scheduler_init_params); |
| 985 DCHECK(task_scheduler_init_params->IsValid()); |
1007 | 986 |
1008 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | 987 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( |
1009 params_vector, index_to_traits_callback); | 988 "", *task_scheduler_init_params.get()); |
1010 | 989 |
1011 GetContentClient()->browser()->PerformExperimentalTaskSchedulerRedirections(); | 990 GetContentClient()->browser()->PerformExperimentalTaskSchedulerRedirections(); |
1012 | 991 |
1013 base::Thread::Options io_message_loop_options; | 992 base::Thread::Options io_message_loop_options; |
1014 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; | 993 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; |
1015 base::Thread::Options ui_message_loop_options; | 994 base::Thread::Options ui_message_loop_options; |
1016 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; | 995 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
1017 | 996 |
1018 const bool redirect_nonUInonIO_browser_threads = | 997 const bool redirect_nonUInonIO_browser_threads = |
1019 GetContentClient() | 998 GetContentClient() |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), | 1771 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), |
1793 MediaInternals::GetInstance()); | 1772 MediaInternals::GetInstance()); |
1794 } | 1773 } |
1795 CHECK(audio_manager_); | 1774 CHECK(audio_manager_); |
1796 | 1775 |
1797 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 1776 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
1798 CHECK(audio_system_); | 1777 CHECK(audio_system_); |
1799 } | 1778 } |
1800 | 1779 |
1801 } // namespace content | 1780 } // namespace content |
OLD | NEW |