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/public/browser/browser_main_runner.h" | 5 #include "content/public/browser/browser_main_runner.h" |
6 | 6 |
7 #include "base/allocator/allocator_shim.h" | 7 #include "base/allocator/allocator_shim.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 DCHECK(initialization_started_); | 123 DCHECK(initialization_started_); |
124 DCHECK(!is_shutdown_); | 124 DCHECK(!is_shutdown_); |
125 #ifdef LEAK_SANITIZER | 125 #ifdef LEAK_SANITIZER |
126 // Invoke leak detection now, to avoid dealing with shutdown-only leaks. | 126 // Invoke leak detection now, to avoid dealing with shutdown-only leaks. |
127 // Normally this will have already happened in | 127 // Normally this will have already happened in |
128 // BroserProcessImpl::ReleaseModule(), so this call has no effect. This is | 128 // BroserProcessImpl::ReleaseModule(), so this call has no effect. This is |
129 // only for processes which do not instantiate a BrowserProcess. | 129 // only for processes which do not instantiate a BrowserProcess. |
130 // If leaks are found, the process will exit here. | 130 // If leaks are found, the process will exit here. |
131 __lsan_do_leak_check(); | 131 __lsan_do_leak_check(); |
132 #endif | 132 #endif |
133 // If startup tracing has not been finished yet, replace it's dumper. | |
sky
2014/06/26 16:39:27
It's not clear to me why this is done. Update comm
Alexander Alekseev
2014/06/27 20:09:50
Done.
| |
134 scoped_ptr<BrowserShutdownProfileDumper> startup_profiler; | |
135 if (main_loop_->is_tracing_startup()) { | |
136 startup_profiler.reset( | |
137 new BrowserShutdownProfileDumper(main_loop_->startup_trace_file())); | |
138 main_loop_->StopStartupTracingTimer(); | |
139 } | |
140 | |
133 // The shutdown tracing got enabled in AttemptUserExit earlier, but someone | 141 // The shutdown tracing got enabled in AttemptUserExit earlier, but someone |
134 // needs to write the result to disc. For that a dumper needs to get created | 142 // needs to write the result to disc. For that a dumper needs to get created |
135 // which will dump the traces to disc when it gets destroyed. | 143 // which will dump the traces to disc when it gets destroyed. |
136 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 144 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
137 scoped_ptr<BrowserShutdownProfileDumper> profiler; | 145 scoped_ptr<BrowserShutdownProfileDumper> shutdown_profiler; |
138 if (command_line.HasSwitch(switches::kTraceShutdown)) | 146 if (command_line.HasSwitch(switches::kTraceShutdown)) { |
139 profiler.reset(new BrowserShutdownProfileDumper()); | 147 shutdown_profiler.reset( |
148 new BrowserShutdownProfileDumper(GetShutdownProfileFileName())); | |
149 } | |
140 | 150 |
141 { | 151 { |
142 // The trace event has to stay between profiler creation and destruction. | 152 // The trace event has to stay between profiler creation and destruction. |
143 TRACE_EVENT0("shutdown", "BrowserMainRunner"); | 153 TRACE_EVENT0("shutdown", "BrowserMainRunner"); |
144 g_exited_main_message_loop = true; | 154 g_exited_main_message_loop = true; |
145 | 155 |
146 main_loop_->ShutdownThreadsAndCleanUp(); | 156 main_loop_->ShutdownThreadsAndCleanUp(); |
147 | 157 |
148 ui::ShutdownInputMethod(); | 158 ui::ShutdownInputMethod(); |
149 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
150 ole_initializer_.reset(NULL); | 160 ole_initializer_.reset(NULL); |
151 #endif | 161 #endif |
152 #if defined(OS_ANDROID) | 162 #if defined(OS_ANDROID) |
153 // Forcefully terminates the RunLoop inside MessagePumpForUI, ensuring | 163 // Forcefully terminates the RunLoop inside MessagePumpForUI, ensuring |
154 // proper shutdown for content_browsertests. Shutdown() is not used by | 164 // proper shutdown for content_browsertests. Shutdown() is not used by |
155 // the actual browser. | 165 // the actual browser. |
156 base::MessageLoop::current()->QuitNow(); | 166 base::MessageLoop::current()->QuitNow(); |
157 #endif | 167 #endif |
158 main_loop_.reset(NULL); | 168 main_loop_.reset(NULL); |
159 | 169 |
160 notification_service_.reset(NULL); | 170 notification_service_.reset(NULL); |
161 | 171 |
162 is_shutdown_ = true; | 172 is_shutdown_ = true; |
163 } | 173 } |
164 } | 174 } |
165 | 175 |
166 protected: | 176 protected: |
177 // Returns the file name where we should save the shutdown trace dump to. | |
178 static base::FilePath GetShutdownProfileFileName() { | |
sky
2014/06/26 16:39:27
Move this to a common place so it isn't duplicated
Alexander Alekseev
2014/06/27 20:09:49
It's now a static method of BrowserShutdownProfile
| |
179 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
180 base::FilePath trace_file = | |
181 command_line.GetSwitchValuePath(switches::kTraceShutdownFile); | |
182 | |
183 if (!trace_file.empty()) | |
184 return trace_file; | |
185 | |
186 // Default to saving the startup trace into the current dir. | |
187 return base::FilePath().AppendASCII("chrometrace.log"); | |
188 } | |
189 | |
167 // True if we have started to initialize the runner. | 190 // True if we have started to initialize the runner. |
168 bool initialization_started_; | 191 bool initialization_started_; |
169 | 192 |
170 // True if the runner has been shut down. | 193 // True if the runner has been shut down. |
171 bool is_shutdown_; | 194 bool is_shutdown_; |
172 | 195 |
173 scoped_ptr<NotificationServiceImpl> notification_service_; | 196 scoped_ptr<NotificationServiceImpl> notification_service_; |
174 scoped_ptr<BrowserMainLoop> main_loop_; | 197 scoped_ptr<BrowserMainLoop> main_loop_; |
175 #if defined(OS_WIN) | 198 #if defined(OS_WIN) |
176 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; | 199 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; |
177 #endif | 200 #endif |
178 | 201 |
179 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); | 202 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); |
180 }; | 203 }; |
181 | 204 |
182 // static | 205 // static |
183 BrowserMainRunner* BrowserMainRunner::Create() { | 206 BrowserMainRunner* BrowserMainRunner::Create() { |
184 return new BrowserMainRunnerImpl(); | 207 return new BrowserMainRunnerImpl(); |
185 } | 208 } |
186 | 209 |
187 } // namespace content | 210 } // namespace content |
OLD | NEW |