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/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/memory_pressure_monitor.h" | 11 #include "base/memory/memory_pressure_monitor.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/single_thread_task_runner.h" |
21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
23 #include "base/system_monitor/system_monitor.h" | 23 #include "base/system_monitor/system_monitor.h" |
24 #include "base/thread_task_runner_handle.h" | 24 #include "base/thread_task_runner_handle.h" |
25 #include "base/threading/thread_restrictions.h" | 25 #include "base/threading/thread_restrictions.h" |
26 #include "base/timer/hi_res_timer_manager.h" | 26 #include "base/timer/hi_res_timer_manager.h" |
27 #include "base/trace_event/memory_dump_manager.h" | 27 #include "base/trace_event/memory_dump_manager.h" |
28 #include "base/trace_event/trace_event.h" | 28 #include "base/trace_event/trace_event.h" |
| 29 #include "components/tracing/trace_config_file.h" |
29 #include "components/tracing/tracing_switches.h" | 30 #include "components/tracing/tracing_switches.h" |
30 #include "content/browser/browser_thread_impl.h" | 31 #include "content/browser/browser_thread_impl.h" |
31 #include "content/browser/device_sensors/device_inertial_sensor_service.h" | 32 #include "content/browser/device_sensors/device_inertial_sensor_service.h" |
32 #include "content/browser/dom_storage/dom_storage_area.h" | 33 #include "content/browser/dom_storage/dom_storage_area.h" |
33 #include "content/browser/download/save_file_manager.h" | 34 #include "content/browser/download/save_file_manager.h" |
34 #include "content/browser/gamepad/gamepad_service.h" | 35 #include "content/browser/gamepad/gamepad_service.h" |
35 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 36 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
36 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 37 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
37 #include "content/browser/gpu/compositor_util.h" | 38 #include "content/browser/gpu/compositor_util.h" |
38 #include "content/browser/gpu/gpu_data_manager_impl.h" | 39 #include "content/browser/gpu/gpu_data_manager_impl.h" |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 384 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
384 return g_current_browser_main_loop; | 385 return g_current_browser_main_loop; |
385 } | 386 } |
386 | 387 |
387 BrowserMainLoop::BrowserMainLoop(const MainFunctionParams& parameters) | 388 BrowserMainLoop::BrowserMainLoop(const MainFunctionParams& parameters) |
388 : parameters_(parameters), | 389 : parameters_(parameters), |
389 parsed_command_line_(parameters.command_line), | 390 parsed_command_line_(parameters.command_line), |
390 result_code_(RESULT_CODE_NORMAL_EXIT), | 391 result_code_(RESULT_CODE_NORMAL_EXIT), |
391 created_threads_(false), | 392 created_threads_(false), |
392 // ContentMainRunner should have enabled tracing of the browser process | 393 // ContentMainRunner should have enabled tracing of the browser process |
393 // when kTraceStartup is in the command line. | 394 // when kTraceStartup or kTraceConfigFile is in the command line. |
394 is_tracing_startup_( | 395 is_tracing_startup_for_duration_( |
395 parameters.command_line.HasSwitch(switches::kTraceStartup)) { | 396 parameters.command_line.HasSwitch(switches::kTraceStartup) || |
| 397 (tracing::TraceConfigFile::GetInstance()->IsEnabled() && |
| 398 tracing::TraceConfigFile::GetInstance()->GetStartupDuration() > 0)) { |
396 DCHECK(!g_current_browser_main_loop); | 399 DCHECK(!g_current_browser_main_loop); |
397 g_current_browser_main_loop = this; | 400 g_current_browser_main_loop = this; |
398 } | 401 } |
399 | 402 |
400 BrowserMainLoop::~BrowserMainLoop() { | 403 BrowserMainLoop::~BrowserMainLoop() { |
401 DCHECK_EQ(this, g_current_browser_main_loop); | 404 DCHECK_EQ(this, g_current_browser_main_loop); |
402 #if !defined(OS_IOS) | 405 #if !defined(OS_IOS) |
403 ui::Clipboard::DestroyClipboardForCurrentThread(); | 406 ui::Clipboard::DestroyClipboardForCurrentThread(); |
404 #endif // !defined(OS_IOS) | 407 #endif // !defined(OS_IOS) |
405 g_current_browser_main_loop = NULL; | 408 g_current_browser_main_loop = NULL; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 system_message_window_.reset(new SystemMessageWindowWin); | 574 system_message_window_.reset(new SystemMessageWindowWin); |
572 #endif | 575 #endif |
573 | 576 |
574 if (parts_) | 577 if (parts_) |
575 parts_->PostMainMessageLoopStart(); | 578 parts_->PostMainMessageLoopStart(); |
576 | 579 |
577 #if !defined(OS_IOS) | 580 #if !defined(OS_IOS) |
578 // Start tracing to a file if needed. Only do this after starting the main | 581 // Start tracing to a file if needed. Only do this after starting the main |
579 // message loop to avoid calling MessagePumpForUI::ScheduleWork() before | 582 // message loop to avoid calling MessagePumpForUI::ScheduleWork() before |
580 // MessagePumpForUI::Start() as it will crash the browser. | 583 // MessagePumpForUI::Start() as it will crash the browser. |
581 if (is_tracing_startup_) { | 584 if (is_tracing_startup_for_duration_) { |
582 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracing"); | 585 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracingForDuration"); |
583 InitStartupTracing(parsed_command_line_); | 586 InitStartupTracingForDuration(parsed_command_line_); |
584 } | 587 } |
585 #endif // !defined(OS_IOS) | 588 #endif // !defined(OS_IOS) |
586 | 589 |
587 #if defined(OS_ANDROID) | 590 #if defined(OS_ANDROID) |
588 { | 591 { |
589 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager"); | 592 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager"); |
590 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) { | 593 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) { |
591 SurfaceTextureManager::SetInstance( | 594 SurfaceTextureManager::SetInstance( |
592 InProcessSurfaceTextureManager::GetInstance()); | 595 InProcessSurfaceTextureManager::GetInstance()); |
593 } else { | 596 } else { |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1309 *parameters_.ui_task); | 1312 *parameters_.ui_task); |
1310 } | 1313 } |
1311 | 1314 |
1312 base::RunLoop run_loop; | 1315 base::RunLoop run_loop; |
1313 run_loop.Run(); | 1316 run_loop.Run(); |
1314 #endif | 1317 #endif |
1315 } | 1318 } |
1316 | 1319 |
1317 base::FilePath BrowserMainLoop::GetStartupTraceFileName( | 1320 base::FilePath BrowserMainLoop::GetStartupTraceFileName( |
1318 const base::CommandLine& command_line) const { | 1321 const base::CommandLine& command_line) const { |
1319 base::FilePath trace_file = command_line.GetSwitchValuePath( | 1322 base::FilePath trace_file; |
1320 switches::kTraceStartupFile); | 1323 if (command_line.HasSwitch(switches::kTraceStartup)) { |
1321 // trace_file = "none" means that startup events will show up for the next | 1324 trace_file = command_line.GetSwitchValuePath( |
1322 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ | 1325 switches::kTraceStartupFile); |
1323 // EndTracing, for example). | 1326 // trace_file = "none" means that startup events will show up for the next |
1324 if (trace_file == base::FilePath().AppendASCII("none")) | 1327 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ |
1325 return trace_file; | 1328 // EndTracing, for example). |
| 1329 if (trace_file == base::FilePath().AppendASCII("none")) |
| 1330 return trace_file; |
1326 | 1331 |
1327 if (trace_file.empty()) { | 1332 if (trace_file.empty()) { |
| 1333 #if defined(OS_ANDROID) |
| 1334 TracingControllerAndroid::GenerateTracingFilePath(&trace_file); |
| 1335 #else |
| 1336 // Default to saving the startup trace into the current dir. |
| 1337 trace_file = base::FilePath().AppendASCII("chrometrace.log"); |
| 1338 #endif |
| 1339 } |
| 1340 } else { |
1328 #if defined(OS_ANDROID) | 1341 #if defined(OS_ANDROID) |
1329 TracingControllerAndroid::GenerateTracingFilePath(&trace_file); | 1342 TracingControllerAndroid::GenerateTracingFilePath(&trace_file); |
1330 #else | 1343 #else |
1331 // Default to saving the startup trace into the current dir. | 1344 trace_file = tracing::TraceConfigFile::GetInstance()->GetResultFile(); |
1332 trace_file = base::FilePath().AppendASCII("chrometrace.log"); | |
1333 #endif | 1345 #endif |
1334 } | 1346 } |
1335 | 1347 |
1336 return trace_file; | 1348 return trace_file; |
1337 } | 1349 } |
1338 | 1350 |
1339 void BrowserMainLoop::InitStartupTracing( | 1351 void BrowserMainLoop::InitStartupTracingForDuration( |
1340 const base::CommandLine& command_line) { | 1352 const base::CommandLine& command_line) { |
1341 DCHECK(is_tracing_startup_); | 1353 DCHECK(is_tracing_startup_for_duration_); |
1342 | 1354 |
1343 startup_trace_file_ = GetStartupTraceFileName(parsed_command_line_); | 1355 startup_trace_file_ = GetStartupTraceFileName(parsed_command_line_); |
1344 | 1356 |
1345 std::string delay_str = command_line.GetSwitchValueASCII( | |
1346 switches::kTraceStartupDuration); | |
1347 int delay_secs = 5; | 1357 int delay_secs = 5; |
1348 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { | 1358 if (command_line.HasSwitch(switches::kTraceStartup)) { |
1349 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration | 1359 std::string delay_str = command_line.GetSwitchValueASCII( |
1350 << "=" << delay_str << " defaulting to 5 (secs)"; | 1360 switches::kTraceStartupDuration); |
1351 delay_secs = 5; | 1361 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { |
| 1362 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration |
| 1363 << "=" << delay_str << " defaulting to 5 (secs)"; |
| 1364 delay_secs = 5; |
| 1365 } |
| 1366 } else { |
| 1367 delay_secs = tracing::TraceConfigFile::GetInstance()->GetStartupDuration(); |
1352 } | 1368 } |
1353 | 1369 |
1354 startup_trace_timer_.Start(FROM_HERE, | 1370 startup_trace_timer_.Start(FROM_HERE, |
1355 base::TimeDelta::FromSeconds(delay_secs), | 1371 base::TimeDelta::FromSeconds(delay_secs), |
1356 this, | 1372 this, |
1357 &BrowserMainLoop::EndStartupTracing); | 1373 &BrowserMainLoop::EndStartupTracing); |
1358 } | 1374 } |
1359 | 1375 |
1360 void BrowserMainLoop::EndStartupTracing() { | 1376 void BrowserMainLoop::EndStartupTracing() { |
1361 DCHECK(is_tracing_startup_); | 1377 DCHECK(is_tracing_startup_for_duration_); |
1362 | 1378 |
1363 is_tracing_startup_ = false; | 1379 is_tracing_startup_for_duration_ = false; |
1364 TracingController::GetInstance()->DisableRecording( | 1380 TracingController::GetInstance()->DisableRecording( |
1365 TracingController::CreateFileSink( | 1381 TracingController::CreateFileSink( |
1366 startup_trace_file_, | 1382 startup_trace_file_, |
1367 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); | 1383 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); |
1368 } | 1384 } |
1369 | 1385 |
1370 } // namespace content | 1386 } // namespace content |
OLD | NEW |