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 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 URLDataManager::DeleteDataSources(); | 893 URLDataManager::DeleteDataSources(); |
894 } | 894 } |
895 #endif // !defined(OS_IOS) | 895 #endif // !defined(OS_IOS) |
896 | 896 |
897 if (parts_) { | 897 if (parts_) { |
898 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:PostDestroyThreads"); | 898 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:PostDestroyThreads"); |
899 parts_->PostDestroyThreads(); | 899 parts_->PostDestroyThreads(); |
900 } | 900 } |
901 } | 901 } |
902 | 902 |
903 void BrowserMainLoop::StopStartupTracingTimer() { | |
904 startup_trace_timer_.Stop(); | |
905 } | |
906 | |
903 void BrowserMainLoop::InitializeMainThread() { | 907 void BrowserMainLoop::InitializeMainThread() { |
904 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeMainThread"); | 908 TRACE_EVENT0("startup", "BrowserMainLoop::InitializeMainThread"); |
905 const char* kThreadName = "CrBrowserMain"; | 909 const char* kThreadName = "CrBrowserMain"; |
906 base::PlatformThread::SetName(kThreadName); | 910 base::PlatformThread::SetName(kThreadName); |
907 if (main_message_loop_) | 911 if (main_message_loop_) |
908 main_message_loop_->set_thread_name(kThreadName); | 912 main_message_loop_->set_thread_name(kThreadName); |
909 | 913 |
910 // Register the main thread by instantiating it, but don't call any methods. | 914 // Register the main thread by instantiating it, but don't call any methods. |
911 main_thread_.reset( | 915 main_thread_.reset( |
912 new BrowserThreadImpl(BrowserThread::UI, base::MessageLoop::current())); | 916 new BrowserThreadImpl(BrowserThread::UI, base::MessageLoop::current())); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1097 DCHECK(base::MessageLoopForUI::IsCurrent()); | 1101 DCHECK(base::MessageLoopForUI::IsCurrent()); |
1098 if (parameters_.ui_task) | 1102 if (parameters_.ui_task) |
1099 base::MessageLoopForUI::current()->PostTask(FROM_HERE, | 1103 base::MessageLoopForUI::current()->PostTask(FROM_HERE, |
1100 *parameters_.ui_task); | 1104 *parameters_.ui_task); |
1101 | 1105 |
1102 base::RunLoop run_loop; | 1106 base::RunLoop run_loop; |
1103 run_loop.Run(); | 1107 run_loop.Run(); |
1104 #endif | 1108 #endif |
1105 } | 1109 } |
1106 | 1110 |
1107 void BrowserMainLoop::InitStartupTracing(const CommandLine& command_line) { | 1111 base::FilePath BrowserMainLoop::GetStartupTraceFileName( |
1108 DCHECK(is_tracing_startup_); | 1112 const base::CommandLine& command_line) const { |
sky
2014/06/27 22:27:25
How come this and GetShutdownProfileFileName can't
Alexander Alekseev
2014/06/30 16:19:40
They are different in semantics.
Startup trace fi
| |
1109 | |
1110 base::FilePath trace_file = command_line.GetSwitchValuePath( | 1113 base::FilePath trace_file = command_line.GetSwitchValuePath( |
1111 switches::kTraceStartupFile); | 1114 switches::kTraceStartupFile); |
1112 // trace_file = "none" means that startup events will show up for the next | 1115 // trace_file = "none" means that startup events will show up for the next |
1113 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ | 1116 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ |
1114 // EndTracing, for example). | 1117 // EndTracing, for example). |
1115 if (trace_file == base::FilePath().AppendASCII("none")) | 1118 if (trace_file == base::FilePath().AppendASCII("none")) |
1116 return; | 1119 return trace_file; |
1117 | 1120 |
1118 if (trace_file.empty()) { | 1121 if (trace_file.empty()) { |
1119 #if defined(OS_ANDROID) | 1122 #if defined(OS_ANDROID) |
1120 TracingControllerAndroid::GenerateTracingFilePath(&trace_file); | 1123 TracingControllerAndroid::GenerateTracingFilePath(&trace_file); |
1121 #else | 1124 #else |
1122 // Default to saving the startup trace into the current dir. | 1125 // Default to saving the startup trace into the current dir. |
1123 trace_file = base::FilePath().AppendASCII("chrometrace.log"); | 1126 trace_file = base::FilePath().AppendASCII("chrometrace.log"); |
1124 #endif | 1127 #endif |
1125 } | 1128 } |
1126 | 1129 |
1130 return trace_file; | |
1131 } | |
1132 | |
1133 void BrowserMainLoop::InitStartupTracing(const CommandLine& command_line) { | |
1134 DCHECK(is_tracing_startup_); | |
1135 | |
1136 startup_trace_file_ = GetStartupTraceFileName(parsed_command_line_); | |
1137 | |
1127 std::string delay_str = command_line.GetSwitchValueASCII( | 1138 std::string delay_str = command_line.GetSwitchValueASCII( |
1128 switches::kTraceStartupDuration); | 1139 switches::kTraceStartupDuration); |
1129 int delay_secs = 5; | 1140 int delay_secs = 5; |
1130 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { | 1141 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { |
1131 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration | 1142 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration |
1132 << "=" << delay_str << " defaulting to 5 (secs)"; | 1143 << "=" << delay_str << " defaulting to 5 (secs)"; |
1133 delay_secs = 5; | 1144 delay_secs = 5; |
1134 } | 1145 } |
1135 | 1146 |
1136 BrowserThread::PostDelayedTask( | 1147 startup_trace_timer_.Start(FROM_HERE, |
1137 BrowserThread::UI, FROM_HERE, | 1148 base::TimeDelta::FromSeconds(delay_secs), |
1138 base::Bind(&BrowserMainLoop::EndStartupTracing, | 1149 this, |
1139 base::Unretained(this), trace_file), | 1150 &BrowserMainLoop::EndStartupTracing); |
1140 base::TimeDelta::FromSeconds(delay_secs)); | |
1141 } | 1151 } |
1142 | 1152 |
1143 void BrowserMainLoop::EndStartupTracing(const base::FilePath& trace_file) { | 1153 void BrowserMainLoop::EndStartupTracing() { |
1144 is_tracing_startup_ = false; | 1154 is_tracing_startup_ = false; |
1145 TracingController::GetInstance()->DisableRecording( | 1155 TracingController::GetInstance()->DisableRecording( |
1146 trace_file, base::Bind(&OnStoppedStartupTracing)); | 1156 startup_trace_file_, base::Bind(&OnStoppedStartupTracing)); |
1147 } | 1157 } |
1148 | 1158 |
1149 } // namespace content | 1159 } // namespace content |
OLD | NEW |