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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "content/browser/histogram_synchronizer.h" | 36 #include "content/browser/histogram_synchronizer.h" |
37 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 37 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
38 #include "content/browser/media/capture/audio_mirroring_manager.h" | 38 #include "content/browser/media/capture/audio_mirroring_manager.h" |
39 #include "content/browser/media/media_internals.h" | 39 #include "content/browser/media/media_internals.h" |
40 #include "content/browser/net/browser_online_state_observer.h" | 40 #include "content/browser/net/browser_online_state_observer.h" |
41 #include "content/browser/plugin_service_impl.h" | 41 #include "content/browser/plugin_service_impl.h" |
42 #include "content/browser/renderer_host/media/media_stream_manager.h" | 42 #include "content/browser/renderer_host/media/media_stream_manager.h" |
43 #include "content/browser/speech/speech_recognition_manager_impl.h" | 43 #include "content/browser/speech/speech_recognition_manager_impl.h" |
44 #include "content/browser/startup_task_runner.h" | 44 #include "content/browser/startup_task_runner.h" |
45 #include "content/browser/time_zone_monitor.h" | 45 #include "content/browser/time_zone_monitor.h" |
| 46 #include "content/browser/tracing/add_new_file_index.h" |
46 #include "content/browser/webui/content_web_ui_controller_factory.h" | 47 #include "content/browser/webui/content_web_ui_controller_factory.h" |
47 #include "content/browser/webui/url_data_manager.h" | 48 #include "content/browser/webui/url_data_manager.h" |
48 #include "content/public/browser/browser_main_parts.h" | 49 #include "content/public/browser/browser_main_parts.h" |
49 #include "content/public/browser/browser_shutdown.h" | 50 #include "content/public/browser/browser_shutdown.h" |
50 #include "content/public/browser/content_browser_client.h" | 51 #include "content/public/browser/content_browser_client.h" |
51 #include "content/public/browser/render_process_host.h" | 52 #include "content/public/browser/render_process_host.h" |
52 #include "content/public/browser/tracing_controller.h" | 53 #include "content/public/browser/tracing_controller.h" |
53 #include "content/public/common/content_switches.h" | 54 #include "content/public/common/content_switches.h" |
54 #include "content/public/common/main_function_params.h" | 55 #include "content/public/common/main_function_params.h" |
55 #include "content/public/common/result_codes.h" | 56 #include "content/public/common/result_codes.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 333 |
333 void BrowserMainLoop::EarlyInitialization() { | 334 void BrowserMainLoop::EarlyInitialization() { |
334 TRACE_EVENT0("startup", "BrowserMainLoop::EarlyInitialization"); | 335 TRACE_EVENT0("startup", "BrowserMainLoop::EarlyInitialization"); |
335 | 336 |
336 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 337 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
337 // No thread should be created before this call, as SetupSandbox() | 338 // No thread should be created before this call, as SetupSandbox() |
338 // will end-up using fork(). | 339 // will end-up using fork(). |
339 SetupSandbox(parsed_command_line_); | 340 SetupSandbox(parsed_command_line_); |
340 #endif | 341 #endif |
341 | 342 |
| 343 if (is_tracing_startup_) |
| 344 startup_trace_file_ = GetStartupTraceFileName(parsed_command_line_); |
| 345 |
342 #if defined(USE_X11) | 346 #if defined(USE_X11) |
343 if (parsed_command_line_.HasSwitch(switches::kSingleProcess) || | 347 if (parsed_command_line_.HasSwitch(switches::kSingleProcess) || |
344 parsed_command_line_.HasSwitch(switches::kInProcessGPU)) { | 348 parsed_command_line_.HasSwitch(switches::kInProcessGPU)) { |
345 if (!gfx::InitializeThreadedX11()) { | 349 if (!gfx::InitializeThreadedX11()) { |
346 LOG(ERROR) << "Failed to put Xlib into threaded mode."; | 350 LOG(ERROR) << "Failed to put Xlib into threaded mode."; |
347 } | 351 } |
348 } | 352 } |
349 #endif | 353 #endif |
350 | 354 |
351 // GLib's spawning of new processes is buggy, so it's important that at this | 355 // GLib's spawning of new processes is buggy, so it's important that at this |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 URLDataManager::DeleteDataSources(); | 898 URLDataManager::DeleteDataSources(); |
895 } | 899 } |
896 #endif // !defined(OS_IOS) | 900 #endif // !defined(OS_IOS) |
897 | 901 |
898 if (parts_) { | 902 if (parts_) { |
899 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:PostDestroyThreads"); | 903 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:PostDestroyThreads"); |
900 parts_->PostDestroyThreads(); | 904 parts_->PostDestroyThreads(); |
901 } | 905 } |
902 } | 906 } |
903 | 907 |
| 908 void BrowserMainLoop::StopStartupTracingTimer() { |
| 909 startup_trace_timer_.Stop(); |
| 910 } |
| 911 |
904 void BrowserMainLoop::InitializeMainThread() { | 912 void BrowserMainLoop::InitializeMainThread() { |
905 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeMainThread"); | 913 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeMainThread"); |
906 const char* kThreadName = "CrBrowserMain"; | 914 const char* kThreadName = "CrBrowserMain"; |
907 base::PlatformThread::SetName(kThreadName); | 915 base::PlatformThread::SetName(kThreadName); |
908 if (main_message_loop_) | 916 if (main_message_loop_) |
909 main_message_loop_->set_thread_name(kThreadName); | 917 main_message_loop_->set_thread_name(kThreadName); |
910 | 918 |
911 // Register the main thread by instantiating it, but don't call any methods. | 919 // Register the main thread by instantiating it, but don't call any methods. |
912 main_thread_.reset( | 920 main_thread_.reset( |
913 new BrowserThreadImpl(BrowserThread::UI, base::MessageLoop::current())); | 921 new BrowserThreadImpl(BrowserThread::UI, base::MessageLoop::current())); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 DCHECK(base::MessageLoopForUI::IsCurrent()); | 1102 DCHECK(base::MessageLoopForUI::IsCurrent()); |
1095 if (parameters_.ui_task) | 1103 if (parameters_.ui_task) |
1096 base::MessageLoopForUI::current()->PostTask(FROM_HERE, | 1104 base::MessageLoopForUI::current()->PostTask(FROM_HERE, |
1097 *parameters_.ui_task); | 1105 *parameters_.ui_task); |
1098 | 1106 |
1099 base::RunLoop run_loop; | 1107 base::RunLoop run_loop; |
1100 run_loop.Run(); | 1108 run_loop.Run(); |
1101 #endif | 1109 #endif |
1102 } | 1110 } |
1103 | 1111 |
1104 void BrowserMainLoop::InitStartupTracing(const CommandLine& command_line) { | 1112 base::FilePath BrowserMainLoop::GetStartupTraceFileName( |
1105 DCHECK(is_tracing_startup_); | 1113 const base::CommandLine& command_line) const { |
1106 | |
1107 base::FilePath trace_file = command_line.GetSwitchValuePath( | 1114 base::FilePath trace_file = command_line.GetSwitchValuePath( |
1108 switches::kTraceStartupFile); | 1115 switches::kTraceStartupFile); |
1109 // trace_file = "none" means that startup events will show up for the next | 1116 // trace_file = "none" means that startup events will show up for the next |
1110 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ | 1117 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ |
1111 // EndTracing, for example). | 1118 // EndTracing, for example). |
1112 if (trace_file == base::FilePath().AppendASCII("none")) | 1119 if (trace_file == base::FilePath().AppendASCII("none")) |
1113 return; | 1120 return trace_file; |
1114 | 1121 |
1115 if (trace_file.empty()) { | 1122 if (trace_file.empty()) { |
1116 #if defined(OS_ANDROID) | 1123 #if defined(OS_ANDROID) |
1117 TracingControllerAndroid::GenerateTracingFilePath(&trace_file); | 1124 TracingControllerAndroid::GenerateTracingFilePath(&trace_file); |
1118 #else | 1125 #else |
1119 // Default to saving the startup trace into the current dir. | 1126 // Default to saving the startup trace into the current dir. |
1120 trace_file = base::FilePath().AppendASCII("chrometrace.log"); | 1127 trace_file = base::FilePath().AppendASCII("chrometrace.log"); |
1121 #endif | 1128 #endif |
1122 } | 1129 } |
1123 | 1130 |
| 1131 if (command_line.HasSwitch(switches::kTraceRotateStartupFile)) |
| 1132 trace_file = AddNewLogFileIndex(trace_file); |
| 1133 |
| 1134 return trace_file; |
| 1135 } |
| 1136 |
| 1137 void BrowserMainLoop::InitStartupTracing(const CommandLine& command_line) { |
| 1138 DCHECK(is_tracing_startup_); |
| 1139 |
1124 std::string delay_str = command_line.GetSwitchValueASCII( | 1140 std::string delay_str = command_line.GetSwitchValueASCII( |
1125 switches::kTraceStartupDuration); | 1141 switches::kTraceStartupDuration); |
1126 int delay_secs = 5; | 1142 int delay_secs = 5; |
1127 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { | 1143 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { |
1128 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration | 1144 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration |
1129 << "=" << delay_str << " defaulting to 5 (secs)"; | 1145 << "=" << delay_str << " defaulting to 5 (secs)"; |
1130 delay_secs = 5; | 1146 delay_secs = 5; |
1131 } | 1147 } |
1132 | 1148 |
1133 BrowserThread::PostDelayedTask( | 1149 startup_trace_timer_.Start(FROM_HERE, |
1134 BrowserThread::UI, FROM_HERE, | 1150 base::TimeDelta::FromSeconds(delay_secs), |
1135 base::Bind(&BrowserMainLoop::EndStartupTracing, | 1151 this, |
1136 base::Unretained(this), trace_file), | 1152 &BrowserMainLoop::EndStartupTracing); |
1137 base::TimeDelta::FromSeconds(delay_secs)); | |
1138 } | 1153 } |
1139 | 1154 |
1140 void BrowserMainLoop::EndStartupTracing(const base::FilePath& trace_file) { | 1155 void BrowserMainLoop::EndStartupTracing() { |
1141 is_tracing_startup_ = false; | 1156 is_tracing_startup_ = false; |
1142 TracingController::GetInstance()->DisableRecording( | 1157 TracingController::GetInstance()->DisableRecording( |
1143 trace_file, base::Bind(&OnStoppedStartupTracing)); | 1158 startup_trace_file_, base::Bind(&OnStoppedStartupTracing)); |
1144 } | 1159 } |
1145 | 1160 |
1146 } // namespace content | 1161 } // namespace content |
OLD | NEW |