Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 #include "base/metrics/user_metrics.h" | 24 #include "base/metrics/user_metrics.h" |
| 25 #include "base/pending_task.h" | 25 #include "base/pending_task.h" |
| 26 #include "base/power_monitor/power_monitor.h" | 26 #include "base/power_monitor/power_monitor.h" |
| 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/system_monitor/system_monitor.h" | 33 #include "base/system_monitor/system_monitor.h" |
| 34 #include "base/task_scheduler/initialization_util.h" | |
| 35 #include "base/task_scheduler/scheduler_worker_pool_params.h" | |
| 36 #include "base/task_scheduler/task_scheduler.h" | |
| 37 #include "base/task_scheduler/task_traits.h" | |
| 34 #include "base/threading/sequenced_worker_pool.h" | 38 #include "base/threading/sequenced_worker_pool.h" |
| 35 #include "base/threading/thread_restrictions.h" | 39 #include "base/threading/thread_restrictions.h" |
| 36 #include "base/threading/thread_task_runner_handle.h" | 40 #include "base/threading/thread_task_runner_handle.h" |
| 41 #include "base/time/time.h" | |
| 37 #include "base/timer/hi_res_timer_manager.h" | 42 #include "base/timer/hi_res_timer_manager.h" |
| 38 #include "base/trace_event/memory_dump_manager.h" | 43 #include "base/trace_event/memory_dump_manager.h" |
| 39 #include "base/trace_event/trace_event.h" | 44 #include "base/trace_event/trace_event.h" |
| 40 #include "build/build_config.h" | 45 #include "build/build_config.h" |
| 41 #include "components/discardable_memory/service/discardable_shared_memory_manage r.h" | 46 #include "components/discardable_memory/service/discardable_shared_memory_manage r.h" |
| 42 #include "components/tracing/browser/trace_config_file.h" | 47 #include "components/tracing/browser/trace_config_file.h" |
| 43 #include "components/tracing/common/process_metrics_memory_dump_provider.h" | 48 #include "components/tracing/common/process_metrics_memory_dump_provider.h" |
| 44 #include "components/tracing/common/trace_to_console.h" | 49 #include "components/tracing/common/trace_to_console.h" |
| 45 #include "components/tracing/common/tracing_switches.h" | 50 #include "components/tracing/common/tracing_switches.h" |
| 46 #include "content/browser/audio_device_thread.h" | 51 #include "content/browser/audio_device_thread.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 critical_threshold_mb >= 0) { | 373 critical_threshold_mb >= 0) { |
| 369 return base::MakeUnique<base::win::MemoryPressureMonitor>( | 374 return base::MakeUnique<base::win::MemoryPressureMonitor>( |
| 370 moderate_threshold_mb, critical_threshold_mb); | 375 moderate_threshold_mb, critical_threshold_mb); |
| 371 } | 376 } |
| 372 | 377 |
| 373 // In absence of valid switches use the automatic defaults. | 378 // In absence of valid switches use the automatic defaults. |
| 374 return base::MakeUnique<base::win::MemoryPressureMonitor>(); | 379 return base::MakeUnique<base::win::MemoryPressureMonitor>(); |
| 375 } | 380 } |
| 376 #endif // defined(OS_WIN) | 381 #endif // defined(OS_WIN) |
| 377 | 382 |
| 383 enum WorkerPoolType : size_t { | |
| 384 BACKGROUND = 0, | |
| 385 BACKGROUND_FILE_IO, | |
| 386 FOREGROUND, | |
| 387 FOREGROUND_FILE_IO, | |
| 388 WORKER_POOL_COUNT // Always last. | |
| 389 }; | |
| 390 | |
| 391 std::vector<base::SchedulerWorkerPoolParams> | |
| 392 GetDefaultSchedulerWorkerPoolParams() { | |
| 393 using StandbyThreadPolicy = | |
| 394 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; | |
| 395 using ThreadPriority = base::ThreadPriority; | |
| 396 std::vector<base::SchedulerWorkerPoolParams> params_vector; | |
| 397 #if defined(OS_ANDROID) | |
| 398 params_vector.emplace_back( | |
| 399 "Background", ThreadPriority::BACKGROUND, StandbyThreadPolicy::ONE, | |
| 400 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), | |
| 401 base::TimeDelta::FromSeconds(30)); | |
| 402 params_vector.emplace_back( | |
| 403 "BackgroundFileIO", ThreadPriority::BACKGROUND, StandbyThreadPolicy::ONE, | |
| 404 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0), | |
| 405 base::TimeDelta::FromSeconds(30)); | |
| 406 params_vector.emplace_back( | |
| 407 "Foreground", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | |
| 408 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0), | |
| 409 base::TimeDelta::FromSeconds(30)); | |
| 410 params_vector.emplace_back( | |
| 411 "ForegroundFileIO", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | |
| 412 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), | |
| 413 base::TimeDelta::FromSeconds(30)); | |
| 414 #else | |
| 415 params_vector.emplace_back( | |
| 416 "Background", ThreadPriority::BACKGROUND, StandbyThreadPolicy::ONE, | |
| 417 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), | |
| 418 base::TimeDelta::FromSeconds(30)); | |
| 419 params_vector.emplace_back( | |
| 420 "BackgroundFileIO", ThreadPriority::BACKGROUND, StandbyThreadPolicy::ONE, | |
| 421 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0), | |
| 422 base::TimeDelta::FromSeconds(30)); | |
| 423 params_vector.emplace_back( | |
| 424 "Foreground", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | |
| 425 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0), | |
| 426 base::TimeDelta::FromSeconds(30)); | |
| 427 params_vector.emplace_back( | |
| 428 "ForegroundFileIO", ThreadPriority::NORMAL, StandbyThreadPolicy::ONE, | |
| 429 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0), | |
| 430 base::TimeDelta::FromSeconds(30)); | |
| 431 #endif | |
| 432 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); | |
| 433 return params_vector; | |
| 434 } | |
| 435 | |
| 436 // Returns the worker pool index for |traits| defaulting to FOREGROUND or | |
| 437 // FOREGROUND_FILE_IO on any other priorities based off of worker pools defined | |
| 438 // in GetDefaultSchedulerWorkerPoolParams(). | |
| 439 size_t BrowserWorkerPoolIndexForTraits(const base::TaskTraits& traits) { | |
|
gab
2016/12/07 16:05:20
DefaultBrowserWorkerPoolIndexForTraits() or someth
robliao
2016/12/08 01:04:22
Done.
| |
| 440 using ThreadPriority = base::ThreadPriority; | |
| 441 const bool is_background = | |
| 442 traits.priority() == base::TaskPriority::BACKGROUND; | |
| 443 if (traits.with_file_io()) | |
| 444 return is_background ? BACKGROUND_FILE_IO : FOREGROUND_FILE_IO; | |
| 445 | |
| 446 return is_background ? BACKGROUND : FOREGROUND; | |
| 447 } | |
| 448 | |
| 378 } // namespace | 449 } // namespace |
| 379 | 450 |
| 380 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 451 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| 381 namespace internal { | 452 namespace internal { |
| 382 | 453 |
| 383 // Forwards GPUInfo updates to ui::XVisualManager | 454 // Forwards GPUInfo updates to ui::XVisualManager |
| 384 class GpuDataManagerVisualProxy : public GpuDataManagerObserver { | 455 class GpuDataManagerVisualProxy : public GpuDataManagerObserver { |
| 385 public: | 456 public: |
| 386 explicit GpuDataManagerVisualProxy(GpuDataManagerImpl* gpu_data_manager) | 457 explicit GpuDataManagerVisualProxy(GpuDataManagerImpl* gpu_data_manager) |
| 387 : gpu_data_manager_(gpu_data_manager) { | 458 : gpu_data_manager_(gpu_data_manager) { |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 startup_task_runner_->RunAllTasksNow(); | 932 startup_task_runner_->RunAllTasksNow(); |
| 862 } | 933 } |
| 863 #else | 934 #else |
| 864 startup_task_runner_->RunAllTasksNow(); | 935 startup_task_runner_->RunAllTasksNow(); |
| 865 #endif | 936 #endif |
| 866 } | 937 } |
| 867 | 938 |
| 868 int BrowserMainLoop::CreateThreads() { | 939 int BrowserMainLoop::CreateThreads() { |
| 869 TRACE_EVENT0("startup,rail", "BrowserMainLoop::CreateThreads"); | 940 TRACE_EVENT0("startup,rail", "BrowserMainLoop::CreateThreads"); |
| 870 | 941 |
| 942 std::vector<base::SchedulerWorkerPoolParams> params_vector; | |
| 943 base::TaskScheduler::WorkerPoolIndexForTraitsCallback | |
| 944 index_to_traits_callback; | |
| 945 GetContentClient()->browser()->GetTaskSchedulerInitializationParams( | |
| 946 ¶ms_vector, &index_to_traits_callback); | |
| 947 | |
| 948 if (params_vector.empty() || index_to_traits_callback.is_null()) { | |
| 949 params_vector = GetDefaultSchedulerWorkerPoolParams(); | |
| 950 index_to_traits_callback = base::Bind(&BrowserWorkerPoolIndexForTraits); | |
| 951 } | |
| 952 | |
| 953 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | |
| 954 params_vector, index_to_traits_callback); | |
| 955 | |
| 956 GetContentClient()->browser()->PerformRedirectionToTaskScheduler(); | |
| 957 | |
| 871 base::Thread::Options io_message_loop_options; | 958 base::Thread::Options io_message_loop_options; |
| 872 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; | 959 io_message_loop_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 873 base::Thread::Options ui_message_loop_options; | 960 base::Thread::Options ui_message_loop_options; |
| 874 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; | 961 ui_message_loop_options.message_loop_type = base::MessageLoop::TYPE_UI; |
| 875 | 962 |
| 876 // Start threads in the order they occur in the BrowserThread::ID | 963 // Start threads in the order they occur in the BrowserThread::ID |
| 877 // enumeration, except for BrowserThread::UI which is the main | 964 // enumeration, except for BrowserThread::UI which is the main |
| 878 // thread. | 965 // thread. |
| 879 // | 966 // |
| 880 // Must be size_t so we can increment it. | 967 // Must be size_t so we can increment it. |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1155 // Close the blocking I/O pool after the other threads. Other threads such | 1242 // Close the blocking I/O pool after the other threads. Other threads such |
| 1156 // as the I/O thread may need to schedule work like closing files or flushing | 1243 // as the I/O thread may need to schedule work like closing files or flushing |
| 1157 // data during shutdown, so the blocking pool needs to be available. There | 1244 // data during shutdown, so the blocking pool needs to be available. There |
| 1158 // may also be slow operations pending that will blcok shutdown, so closing | 1245 // may also be slow operations pending that will blcok shutdown, so closing |
| 1159 // it here (which will block until required operations are complete) gives | 1246 // it here (which will block until required operations are complete) gives |
| 1160 // more head start for those operations to finish. | 1247 // more head start for those operations to finish. |
| 1161 { | 1248 { |
| 1162 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:ThreadPool"); | 1249 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:ThreadPool"); |
| 1163 BrowserThreadImpl::ShutdownThreadPool(); | 1250 BrowserThreadImpl::ShutdownThreadPool(); |
| 1164 } | 1251 } |
| 1252 { | |
| 1253 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:TaskScheduler"); | |
| 1254 base::TaskScheduler::GetInstance()->Shutdown(); | |
| 1255 } | |
| 1256 | |
| 1165 // Must happen after the IO thread is shutdown since this may be accessed from | 1257 // Must happen after the IO thread is shutdown since this may be accessed from |
| 1166 // it. | 1258 // it. |
| 1167 { | 1259 { |
| 1168 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:GPUChannelFactory"); | 1260 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:GPUChannelFactory"); |
| 1169 if (BrowserGpuChannelHostFactory::instance()) { | 1261 if (BrowserGpuChannelHostFactory::instance()) { |
| 1170 #if defined(OS_ANDROID) | 1262 #if defined(OS_ANDROID) |
| 1171 // Clean up the references to the factory before terminating it. | 1263 // Clean up the references to the factory before terminating it. |
| 1172 ui::ContextProviderFactory::SetInstance(nullptr); | 1264 ui::ContextProviderFactory::SetInstance(nullptr); |
| 1173 ContextProviderFactoryImpl::Terminate(); | 1265 ContextProviderFactoryImpl::Terminate(); |
| 1174 #endif | 1266 #endif |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1609 if (!audio_manager_) { | 1701 if (!audio_manager_) { |
| 1610 audio_thread_ = base::MakeUnique<AudioDeviceThread>(); | 1702 audio_thread_ = base::MakeUnique<AudioDeviceThread>(); |
| 1611 audio_manager_ = media::AudioManager::Create( | 1703 audio_manager_ = media::AudioManager::Create( |
| 1612 audio_thread_->GetTaskRunner(), audio_thread_->worker_task_runner(), | 1704 audio_thread_->GetTaskRunner(), audio_thread_->worker_task_runner(), |
| 1613 MediaInternals::GetInstance()); | 1705 MediaInternals::GetInstance()); |
| 1614 } | 1706 } |
| 1615 CHECK(audio_manager_); | 1707 CHECK(audio_manager_); |
| 1616 } | 1708 } |
| 1617 | 1709 |
| 1618 } // namespace content | 1710 } // namespace content |
| OLD | NEW |