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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 #endif // defined(OS_WIN) | 388 #endif // defined(OS_WIN) |
390 | 389 |
391 enum WorkerPoolType : size_t { | 390 enum WorkerPoolType : size_t { |
392 BACKGROUND = 0, | 391 BACKGROUND = 0, |
393 BACKGROUND_BLOCKING, | 392 BACKGROUND_BLOCKING, |
394 FOREGROUND, | 393 FOREGROUND, |
395 FOREGROUND_BLOCKING, | 394 FOREGROUND_BLOCKING, |
396 WORKER_POOL_COUNT // Always last. | 395 WORKER_POOL_COUNT // Always last. |
397 }; | 396 }; |
398 | 397 |
399 std::vector<base::SchedulerWorkerPoolParams> | 398 std::unique_ptr<base::TaskScheduler::InitParams> |
400 GetDefaultSchedulerWorkerPoolParams() { | 399 GetDefaultTaskSchedulerInitParams() { |
401 using StandbyThreadPolicy = | 400 using StandbyThreadPolicy = |
402 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; | 401 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; |
403 using ThreadPriority = base::ThreadPriority; | |
404 std::vector<base::SchedulerWorkerPoolParams> params_vector; | |
405 #if defined(OS_ANDROID) | 402 #if defined(OS_ANDROID) |
406 params_vector.emplace_back( | 403 return base::MakeUnique<base::TaskScheduler::InitParams>( |
407 "Background", ThreadPriority::BACKGROUND, StandbyThreadPolicy::ONE, | 404 base::SchedulerWorkerPoolParams( |
408 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), | 405 StandbyThreadPolicy::ONE, |
409 base::TimeDelta::FromSeconds(30)); | 406 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), |
410 params_vector.emplace_back( | 407 base::TimeDelta::FromSeconds(30)), |
411 "BackgroundBlocking", ThreadPriority::BACKGROUND, | 408 base::SchedulerWorkerPoolParams( |
412 StandbyThreadPolicy::ONE, | 409 StandbyThreadPolicy::ONE, |
413 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), | 410 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), |
414 base::TimeDelta::FromSeconds(30)); | 411 base::TimeDelta::FromSeconds(30)), |
415 params_vector.emplace_back( | 412 base::SchedulerWorkerPoolParams( |
416 "Foreground", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | 413 StandbyThreadPolicy::ONE, |
417 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0), | 414 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0), |
418 base::TimeDelta::FromSeconds(30)); | 415 base::TimeDelta::FromSeconds(30)), |
419 params_vector.emplace_back( | 416 base::SchedulerWorkerPoolParams( |
420 "ForegroundBlocking", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | 417 StandbyThreadPolicy::ONE, |
421 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0), | 418 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0), |
422 base::TimeDelta::FromSeconds(30)); | 419 base::TimeDelta::FromSeconds(30))); |
423 #else | 420 #else |
424 params_vector.emplace_back( | 421 return base::MakeUnique<base::TaskScheduler::InitParams>( |
425 "Background", ThreadPriority::BACKGROUND, StandbyThreadPolicy::ONE, | 422 base::SchedulerWorkerPoolParams( |
426 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), | 423 StandbyThreadPolicy::ONE, |
427 base::TimeDelta::FromSeconds(30)); | 424 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), |
428 params_vector.emplace_back( | 425 base::TimeDelta::FromSeconds(30)), |
429 "BackgroundBlocking", ThreadPriority::BACKGROUND, | 426 base::SchedulerWorkerPoolParams( |
430 StandbyThreadPolicy::ONE, | 427 StandbyThreadPolicy::ONE, |
431 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), | 428 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), |
432 base::TimeDelta::FromSeconds(30)); | 429 base::TimeDelta::FromSeconds(30)), |
433 params_vector.emplace_back( | 430 base::SchedulerWorkerPoolParams( |
434 "Foreground", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | 431 StandbyThreadPolicy::ONE, |
435 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0), | 432 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0), |
436 base::TimeDelta::FromSeconds(30)); | 433 base::TimeDelta::FromSeconds(30)), |
437 // Tasks posted to SequencedWorkerPool or BrowserThreadImpl may be redirected | 434 // Tasks posted to SequencedWorkerPool or BrowserThreadImpl may be |
438 // to this pool. Since COM STA is initialized in these environments, it must | 435 // redirected to this pool. Since COM STA is initialized in these |
439 // also be initialized in this pool. | 436 // environments, it must also be initialized in this pool. |
440 params_vector.emplace_back( | 437 base::SchedulerWorkerPoolParams( |
441 "ForegroundBlocking", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | 438 StandbyThreadPolicy::ONE, |
442 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0), | 439 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0), |
443 base::TimeDelta::FromSeconds(30), | 440 base::TimeDelta::FromSeconds(30), |
444 base::SchedulerBackwardCompatibility::INIT_COM_STA); | 441 base::SchedulerBackwardCompatibility::INIT_COM_STA)); |
445 #endif | 442 #endif |
446 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); | |
447 return params_vector; | |
448 } | |
449 | |
450 // Returns the worker pool index for |traits| defaulting to FOREGROUND or | |
451 // FOREGROUND_BLOCKING on any other priorities based off of worker pools defined | |
452 // in GetDefaultSchedulerWorkerPoolParams(). | |
453 size_t DefaultBrowserWorkerPoolIndexForTraits(const base::TaskTraits& traits) { | |
454 const bool is_background = | |
455 traits.priority() == base::TaskPriority::BACKGROUND; | |
456 if (traits.may_block() || traits.with_base_sync_primitives()) | |
457 return is_background ? BACKGROUND_BLOCKING : FOREGROUND_BLOCKING; | |
458 | |
459 return is_background ? BACKGROUND : FOREGROUND; | |
460 } | 443 } |
461 | 444 |
462 } // namespace | 445 } // namespace |
463 | 446 |
464 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 447 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
465 namespace internal { | 448 namespace internal { |
466 | 449 |
467 // Forwards GPUInfo updates to ui::XVisualManager | 450 // Forwards GPUInfo updates to ui::XVisualManager |
468 class GpuDataManagerVisualProxy : public GpuDataManagerObserver { | 451 class GpuDataManagerVisualProxy : public GpuDataManagerObserver { |
469 public: | 452 public: |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 startup_task_runner_->RunAllTasksNow(); | 941 startup_task_runner_->RunAllTasksNow(); |
959 } | 942 } |
960 #else | 943 #else |
961 startup_task_runner_->RunAllTasksNow(); | 944 startup_task_runner_->RunAllTasksNow(); |
962 #endif | 945 #endif |
963 } | 946 } |
964 | 947 |
965 int BrowserMainLoop::CreateThreads() { | 948 int BrowserMainLoop::CreateThreads() { |
966 TRACE_EVENT0("startup,rail", "BrowserMainLoop::CreateThreads"); | 949 TRACE_EVENT0("startup,rail", "BrowserMainLoop::CreateThreads"); |
967 | 950 |
968 std::vector<base::SchedulerWorkerPoolParams> params_vector; | 951 auto task_scheduler_init_params = |
969 base::TaskScheduler::WorkerPoolIndexForTraitsCallback | 952 GetContentClient()->browser()->GetTaskSchedulerInitParams(); |
970 index_to_traits_callback; | 953 if (!task_scheduler_init_params) |
971 GetContentClient()->browser()->GetTaskSchedulerInitializationParams( | 954 task_scheduler_init_params = GetDefaultTaskSchedulerInitParams(); |
972 ¶ms_vector, &index_to_traits_callback); | 955 DCHECK(task_scheduler_init_params); |
973 | |
974 if (params_vector.empty() || index_to_traits_callback.is_null()) { | |
975 params_vector = GetDefaultSchedulerWorkerPoolParams(); | |
976 index_to_traits_callback = | |
977 base::Bind(&DefaultBrowserWorkerPoolIndexForTraits); | |
978 } | |
979 | 956 |
980 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | 957 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( |
981 params_vector, index_to_traits_callback); | 958 "", *task_scheduler_init_params.get()); |
982 | 959 |
983 GetContentClient()->browser()->PerformExperimentalTaskSchedulerRedirections(); | 960 GetContentClient()->browser()->PerformExperimentalTaskSchedulerRedirections(); |
984 | 961 |
985 base::Thread::Options io_message_loop_options; | 962 base::Thread::Options io_message_loop_options; |
986 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; | 963 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; |
987 base::Thread::Options ui_message_loop_options; | 964 base::Thread::Options ui_message_loop_options; |
988 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; | 965 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
989 | 966 |
990 const bool redirect_nonUInonIO_browser_threads = | 967 const bool redirect_nonUInonIO_browser_threads = |
991 GetContentClient() | 968 GetContentClient() |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), | 1752 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), |
1776 MediaInternals::GetInstance()); | 1753 MediaInternals::GetInstance()); |
1777 } | 1754 } |
1778 CHECK(audio_manager_); | 1755 CHECK(audio_manager_); |
1779 | 1756 |
1780 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 1757 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
1781 CHECK(audio_system_); | 1758 CHECK(audio_system_); |
1782 } | 1759 } |
1783 | 1760 |
1784 } // namespace content | 1761 } // namespace content |
OLD | NEW |