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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/location.h" | |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/memory/memory_pressure_monitor.h" | 11 #include "base/memory/memory_pressure_monitor.h" |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/pending_task.h" | 14 #include "base/pending_task.h" |
| 15 #include "base/power_monitor/power_monitor.h" | 15 #include "base/power_monitor/power_monitor.h" |
| 16 #include "base/power_monitor/power_monitor_device_source.h" | 16 #include "base/power_monitor/power_monitor_device_source.h" |
| 17 #include "base/process/process_metrics.h" | 17 #include "base/process/process_metrics.h" |
| 18 #include "base/profiler/scoped_profile.h" | 18 #include "base/profiler/scoped_profile.h" |
| 19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 20 #include "base/single_thread_task_runner.h" | |
| 20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
| 22 #include "base/system_monitor/system_monitor.h" | 23 #include "base/system_monitor/system_monitor.h" |
| 23 #include "base/thread_task_runner_handle.h" | 24 #include "base/thread_task_runner_handle.h" |
| 24 #include "base/threading/thread_restrictions.h" | 25 #include "base/threading/thread_restrictions.h" |
| 25 #include "base/timer/hi_res_timer_manager.h" | 26 #include "base/timer/hi_res_timer_manager.h" |
| 26 #include "base/trace_event/memory_dump_manager.h" | 27 #include "base/trace_event/memory_dump_manager.h" |
| 27 #include "base/trace_event/trace_event.h" | 28 #include "base/trace_event/trace_event.h" |
| 28 #include "content/browser/browser_thread_impl.h" | 29 #include "content/browser/browser_thread_impl.h" |
| 29 #include "content/browser/device_sensors/device_inertial_sensor_service.h" | 30 #include "content/browser/device_sensors/device_inertial_sensor_service.h" |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 } | 614 } |
| 614 | 615 |
| 615 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(); | 616 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(); |
| 616 | 617 |
| 617 // Enable the dump providers. | 618 // Enable the dump providers. |
| 618 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 619 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 619 HostSharedBitmapManager::current()); | 620 HostSharedBitmapManager::current()); |
| 620 | 621 |
| 621 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) | 622 #if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED) |
| 622 trace_memory_controller_.reset(new base::trace_event::TraceMemoryController( | 623 trace_memory_controller_.reset(new base::trace_event::TraceMemoryController( |
| 623 base::MessageLoop::current()->message_loop_proxy(), | 624 base::MessageLoop::current()->task_runner(), |
| 624 ::HeapProfilerWithPseudoStackStart, ::HeapProfilerStop, | 625 ::HeapProfilerWithPseudoStackStart, ::HeapProfilerStop, |
| 625 ::GetHeapProfile)); | 626 ::GetHeapProfile)); |
| 626 #endif | 627 #endif |
| 627 } | 628 } |
| 628 | 629 |
| 629 int BrowserMainLoop::PreCreateThreads() { | 630 int BrowserMainLoop::PreCreateThreads() { |
| 630 if (parts_) { | 631 if (parts_) { |
| 631 TRACE_EVENT0("startup", | 632 TRACE_EVENT0("startup", |
| 632 "BrowserMainLoop::CreateThreads:PreCreateThreads"); | 633 "BrowserMainLoop::CreateThreads:PreCreateThreads"); |
| 633 TRACK_SCOPED_REGION("Startup", "BrowserMainLoop::PreCreateThreads"); | 634 TRACK_SCOPED_REGION("Startup", "BrowserMainLoop::PreCreateThreads"); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 return result_code_; | 699 return result_code_; |
| 699 } | 700 } |
| 700 | 701 |
| 701 void BrowserMainLoop::CreateStartupTasks() { | 702 void BrowserMainLoop::CreateStartupTasks() { |
| 702 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks"); | 703 TRACE_EVENT0("startup", "BrowserMainLoop::CreateStartupTasks"); |
| 703 TRACK_SCOPED_REGION("Startup", "BrowserMainLoop::CreateStartupTasks"); | 704 TRACK_SCOPED_REGION("Startup", "BrowserMainLoop::CreateStartupTasks"); |
| 704 | 705 |
| 705 // First time through, we really want to create all the tasks | 706 // First time through, we really want to create all the tasks |
| 706 if (!startup_task_runner_.get()) { | 707 if (!startup_task_runner_.get()) { |
| 707 #if defined(OS_ANDROID) | 708 #if defined(OS_ANDROID) |
| 708 startup_task_runner_ = make_scoped_ptr(new StartupTaskRunner( | 709 startup_task_runner_ = make_scoped_ptr( |
| 709 base::Bind(&BrowserStartupComplete), | 710 new StartupTaskRunner(base::Bind(&BrowserStartupComplete), |
| 710 base::MessageLoop::current()->message_loop_proxy())); | 711 base::ThreadTaskRunnerHandle::Get())); |
| 711 #else | 712 #else |
| 712 startup_task_runner_ = make_scoped_ptr(new StartupTaskRunner( | 713 startup_task_runner_ = make_scoped_ptr( |
| 713 base::Callback<void(int)>(), | 714 new StartupTaskRunner(base::Callback<void(int)>(), |
| 714 base::MessageLoop::current()->message_loop_proxy())); | 715 base::MessageLoop::current()->task_runner())); |
|
no sievers
2015/06/01 23:30:47
Should this also be base::ThreadTaskRunnerHandle::
Sami
2015/06/03 14:55:21
Thanks, fixed.
| |
| 715 #endif | 716 #endif |
| 716 StartupTask pre_create_threads = | 717 StartupTask pre_create_threads = |
| 717 base::Bind(&BrowserMainLoop::PreCreateThreads, base::Unretained(this)); | 718 base::Bind(&BrowserMainLoop::PreCreateThreads, base::Unretained(this)); |
| 718 startup_task_runner_->AddTask(pre_create_threads); | 719 startup_task_runner_->AddTask(pre_create_threads); |
| 719 | 720 |
| 720 StartupTask create_threads = | 721 StartupTask create_threads = |
| 721 base::Bind(&BrowserMainLoop::CreateThreads, base::Unretained(this)); | 722 base::Bind(&BrowserMainLoop::CreateThreads, base::Unretained(this)); |
| 722 startup_task_runner_->AddTask(create_threads); | 723 startup_task_runner_->AddTask(create_threads); |
| 723 | 724 |
| 724 StartupTask browser_thread_started = base::Bind( | 725 StartupTask browser_thread_started = base::Bind( |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1189 "BrowserMainLoop::BrowserThreadsStarted:InitSpeechRecognition"); | 1190 "BrowserMainLoop::BrowserThreadsStarted:InitSpeechRecognition"); |
| 1190 speech_recognition_manager_.reset(new SpeechRecognitionManagerImpl( | 1191 speech_recognition_manager_.reset(new SpeechRecognitionManagerImpl( |
| 1191 audio_manager_.get(), media_stream_manager_.get())); | 1192 audio_manager_.get(), media_stream_manager_.get())); |
| 1192 } | 1193 } |
| 1193 | 1194 |
| 1194 { | 1195 { |
| 1195 TRACE_EVENT0( | 1196 TRACE_EVENT0( |
| 1196 "startup", | 1197 "startup", |
| 1197 "BrowserMainLoop::BrowserThreadsStarted::InitUserInputMonitor"); | 1198 "BrowserMainLoop::BrowserThreadsStarted::InitUserInputMonitor"); |
| 1198 user_input_monitor_ = media::UserInputMonitor::Create( | 1199 user_input_monitor_ = media::UserInputMonitor::Create( |
| 1199 io_thread_->message_loop_proxy(), main_thread_->message_loop_proxy()); | 1200 io_thread_->task_runner(), main_thread_->task_runner()); |
| 1200 } | 1201 } |
| 1201 | 1202 |
| 1202 { | 1203 { |
| 1203 TRACE_EVENT0("startup", | 1204 TRACE_EVENT0("startup", |
| 1204 "BrowserMainLoop::BrowserThreadsStarted::TimeZoneMonitor"); | 1205 "BrowserMainLoop::BrowserThreadsStarted::TimeZoneMonitor"); |
| 1205 time_zone_monitor_ = TimeZoneMonitor::Create(); | 1206 time_zone_monitor_ = TimeZoneMonitor::Create(); |
| 1206 } | 1207 } |
| 1207 | 1208 |
| 1208 // Alert the clipboard class to which threads are allowed to access the | 1209 // Alert the clipboard class to which threads are allowed to access the |
| 1209 // clipboard: | 1210 // clipboard: |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1291 return true; | 1292 return true; |
| 1292 } | 1293 } |
| 1293 | 1294 |
| 1294 void BrowserMainLoop::MainMessageLoopRun() { | 1295 void BrowserMainLoop::MainMessageLoopRun() { |
| 1295 #if defined(OS_ANDROID) | 1296 #if defined(OS_ANDROID) |
| 1296 // Android's main message loop is the Java message loop. | 1297 // Android's main message loop is the Java message loop. |
| 1297 NOTREACHED(); | 1298 NOTREACHED(); |
| 1298 #else | 1299 #else |
| 1299 DCHECK(base::MessageLoopForUI::IsCurrent()); | 1300 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 1300 if (parameters_.ui_task) { | 1301 if (parameters_.ui_task) { |
| 1301 base::MessageLoopForUI::current()->PostTask(FROM_HERE, | 1302 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 1302 *parameters_.ui_task); | 1303 *parameters_.ui_task); |
| 1303 } | 1304 } |
| 1304 | 1305 |
| 1305 base::RunLoop run_loop; | 1306 base::RunLoop run_loop; |
| 1306 run_loop.Run(); | 1307 run_loop.Run(); |
| 1307 #endif | 1308 #endif |
| 1308 } | 1309 } |
| 1309 | 1310 |
| 1310 base::FilePath BrowserMainLoop::GetStartupTraceFileName( | 1311 base::FilePath BrowserMainLoop::GetStartupTraceFileName( |
| 1311 const base::CommandLine& command_line) const { | 1312 const base::CommandLine& command_line) const { |
| 1312 base::FilePath trace_file = command_line.GetSwitchValuePath( | 1313 base::FilePath trace_file = command_line.GetSwitchValuePath( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1354 DCHECK(is_tracing_startup_); | 1355 DCHECK(is_tracing_startup_); |
| 1355 | 1356 |
| 1356 is_tracing_startup_ = false; | 1357 is_tracing_startup_ = false; |
| 1357 TracingController::GetInstance()->DisableRecording( | 1358 TracingController::GetInstance()->DisableRecording( |
| 1358 TracingController::CreateFileSink( | 1359 TracingController::CreateFileSink( |
| 1359 startup_trace_file_, | 1360 startup_trace_file_, |
| 1360 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); | 1361 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); |
| 1361 } | 1362 } |
| 1362 | 1363 |
| 1363 } // namespace content | 1364 } // namespace content |
| OLD | NEW |