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 23 matching lines...) Expand all Loading... |
34 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 34 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
35 #include "content/browser/histogram_synchronizer.h" | 35 #include "content/browser/histogram_synchronizer.h" |
36 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 36 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
37 #include "content/browser/net/browser_online_state_observer.h" | 37 #include "content/browser/net/browser_online_state_observer.h" |
38 #include "content/browser/plugin_service_impl.h" | 38 #include "content/browser/plugin_service_impl.h" |
39 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" | 39 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" |
40 #include "content/browser/renderer_host/media/media_stream_manager.h" | 40 #include "content/browser/renderer_host/media/media_stream_manager.h" |
41 #include "content/browser/renderer_host/render_process_host_impl.h" | 41 #include "content/browser/renderer_host/render_process_host_impl.h" |
42 #include "content/browser/speech/speech_recognition_manager_impl.h" | 42 #include "content/browser/speech/speech_recognition_manager_impl.h" |
43 #include "content/browser/startup_task_runner.h" | 43 #include "content/browser/startup_task_runner.h" |
44 #include "content/browser/tracing/trace_controller_impl.h" | |
45 #include "content/browser/webui/content_web_ui_controller_factory.h" | 44 #include "content/browser/webui/content_web_ui_controller_factory.h" |
46 #include "content/browser/webui/url_data_manager.h" | 45 #include "content/browser/webui/url_data_manager.h" |
47 #include "content/public/browser/browser_main_parts.h" | 46 #include "content/public/browser/browser_main_parts.h" |
48 #include "content/public/browser/browser_shutdown.h" | 47 #include "content/public/browser/browser_shutdown.h" |
49 #include "content/public/browser/content_browser_client.h" | 48 #include "content/public/browser/content_browser_client.h" |
50 #include "content/public/browser/render_process_host.h" | 49 #include "content/public/browser/render_process_host.h" |
| 50 #include "content/public/browser/tracing_controller.h" |
51 #include "content/public/common/content_switches.h" | 51 #include "content/public/common/content_switches.h" |
52 #include "content/public/common/main_function_params.h" | 52 #include "content/public/common/main_function_params.h" |
53 #include "content/public/common/result_codes.h" | 53 #include "content/public/common/result_codes.h" |
54 #include "crypto/nss_util.h" | 54 #include "crypto/nss_util.h" |
55 #include "media/audio/audio_manager.h" | 55 #include "media/audio/audio_manager.h" |
56 #include "media/base/media.h" | 56 #include "media/base/media.h" |
57 #include "media/base/user_input_monitor.h" | 57 #include "media/base/user_input_monitor.h" |
58 #include "media/midi/midi_manager.h" | 58 #include "media/midi/midi_manager.h" |
59 #include "net/base/network_change_notifier.h" | 59 #include "net/base/network_change_notifier.h" |
60 #include "net/socket/client_socket_factory.h" | 60 #include "net/socket/client_socket_factory.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 311 |
312 BrowserMainLoop* BrowserMainLoop::GetInstance() { | 312 BrowserMainLoop* BrowserMainLoop::GetInstance() { |
313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
314 return g_current_browser_main_loop; | 314 return g_current_browser_main_loop; |
315 } | 315 } |
316 | 316 |
317 BrowserMainLoop::BrowserMainLoop(const MainFunctionParams& parameters) | 317 BrowserMainLoop::BrowserMainLoop(const MainFunctionParams& parameters) |
318 : parameters_(parameters), | 318 : parameters_(parameters), |
319 parsed_command_line_(parameters.command_line), | 319 parsed_command_line_(parameters.command_line), |
320 result_code_(RESULT_CODE_NORMAL_EXIT), | 320 result_code_(RESULT_CODE_NORMAL_EXIT), |
321 created_threads_(false) { | 321 created_threads_(false), |
| 322 // ContentMainRunner should have enabled tracing of the browser process |
| 323 // when kTraceStartup is in the command line. |
| 324 is_tracing_startup_(base::debug::TraceLog::GetInstance()->IsEnabled()) { |
322 DCHECK(!g_current_browser_main_loop); | 325 DCHECK(!g_current_browser_main_loop); |
323 g_current_browser_main_loop = this; | 326 g_current_browser_main_loop = this; |
324 } | 327 } |
325 | 328 |
326 BrowserMainLoop::~BrowserMainLoop() { | 329 BrowserMainLoop::~BrowserMainLoop() { |
327 DCHECK_EQ(this, g_current_browser_main_loop); | 330 DCHECK_EQ(this, g_current_browser_main_loop); |
328 #if !defined(OS_IOS) | 331 #if !defined(OS_IOS) |
329 ui::Clipboard::DestroyClipboardForCurrentThread(); | 332 ui::Clipboard::DestroyClipboardForCurrentThread(); |
330 #endif // !defined(OS_IOS) | 333 #endif // !defined(OS_IOS) |
331 g_current_browser_main_loop = NULL; | 334 g_current_browser_main_loop = NULL; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 WebUIControllerFactory::RegisterFactory( | 470 WebUIControllerFactory::RegisterFactory( |
468 ContentWebUIControllerFactory::GetInstance()); | 471 ContentWebUIControllerFactory::GetInstance()); |
469 } | 472 } |
470 | 473 |
471 { | 474 { |
472 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:AudioMirroringManager") | 475 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:AudioMirroringManager") |
473 audio_mirroring_manager_.reset(new AudioMirroringManager()); | 476 audio_mirroring_manager_.reset(new AudioMirroringManager()); |
474 } | 477 } |
475 | 478 |
476 // Start tracing to a file if needed. | 479 // Start tracing to a file if needed. |
477 if (base::debug::TraceLog::GetInstance()->IsEnabled()) { | 480 if (is_tracing_startup_) { |
478 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracing") | 481 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracing") |
479 TraceControllerImpl::GetInstance()->InitStartupTracing( | 482 InitStartupTracing(parsed_command_line_); |
480 parsed_command_line_); | |
481 } | 483 } |
482 | 484 |
483 { | 485 { |
484 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:OnlineStateObserver") | 486 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:OnlineStateObserver") |
485 online_state_observer_.reset(new BrowserOnlineStateObserver); | 487 online_state_observer_.reset(new BrowserOnlineStateObserver); |
486 } | 488 } |
487 | 489 |
488 { | 490 { |
489 system_stats_monitor_.reset(new base::debug::TraceEventSystemStatsMonitor( | 491 system_stats_monitor_.reset(new base::debug::TraceEventSystemStatsMonitor( |
490 base::ThreadTaskRunnerHandle::Get())); | 492 base::ThreadTaskRunnerHandle::Get())); |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type()); | 1069 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type()); |
1068 if (parameters_.ui_task) | 1070 if (parameters_.ui_task) |
1069 base::MessageLoopForUI::current()->PostTask(FROM_HERE, | 1071 base::MessageLoopForUI::current()->PostTask(FROM_HERE, |
1070 *parameters_.ui_task); | 1072 *parameters_.ui_task); |
1071 | 1073 |
1072 base::RunLoop run_loop; | 1074 base::RunLoop run_loop; |
1073 run_loop.Run(); | 1075 run_loop.Run(); |
1074 #endif | 1076 #endif |
1075 } | 1077 } |
1076 | 1078 |
| 1079 void BrowserMainLoop::InitStartupTracing(const CommandLine& command_line) { |
| 1080 DCHECK(is_tracing_startup_); |
| 1081 |
| 1082 base::FilePath trace_file = command_line.GetSwitchValuePath( |
| 1083 switches::kTraceStartupFile); |
| 1084 // trace_file = "none" means that startup events will show up for the next |
| 1085 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ |
| 1086 // EndTracing, for example). |
| 1087 if (trace_file == base::FilePath().AppendASCII("none")) |
| 1088 return; |
| 1089 |
| 1090 if (trace_file.empty()) { |
| 1091 // Default to saving the startup trace into the current dir. |
| 1092 trace_file = base::FilePath().AppendASCII("chrometrace.log"); |
| 1093 } |
| 1094 |
| 1095 std::string delay_str = command_line.GetSwitchValueASCII( |
| 1096 switches::kTraceStartupDuration); |
| 1097 int delay_secs = 5; |
| 1098 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { |
| 1099 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration |
| 1100 << "=" << delay_str << " defaulting to 5 (secs)"; |
| 1101 delay_secs = 5; |
| 1102 } |
| 1103 |
| 1104 BrowserThread::PostDelayedTask( |
| 1105 BrowserThread::UI, FROM_HERE, |
| 1106 base::Bind(&BrowserMainLoop::EndStartupTracing, |
| 1107 base::Unretained(this), trace_file), |
| 1108 base::TimeDelta::FromSeconds(delay_secs)); |
| 1109 } |
| 1110 |
| 1111 void BrowserMainLoop::EndStartupTracing(const base::FilePath& trace_file) { |
| 1112 is_tracing_startup_ = false; |
| 1113 TracingController::GetInstance()->DisableRecording( |
| 1114 trace_file, TracingController::TracingFileResultCallback()); |
| 1115 } |
| 1116 |
1077 } // namespace content | 1117 } // namespace content |
OLD | NEW |