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/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/metrics/statistics_recorder.h" | 13 #include "base/metrics/statistics_recorder.h" |
14 #include "content/browser/browser_main_loop.h" | 14 #include "content/browser/browser_main_loop.h" |
| 15 #include "content/browser/browser_shutdown_profile_dumper.h" |
15 #include "content/browser/notification_service_impl.h" | 16 #include "content/browser/notification_service_impl.h" |
16 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
17 #include "content/public/common/main_function_params.h" | 18 #include "content/public/common/main_function_params.h" |
18 #include "ui/base/ime/input_method_initializer.h" | 19 #include "ui/base/ime/input_method_initializer.h" |
19 | 20 |
20 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
21 #include "base/win/metro.h" | 22 #include "base/win/metro.h" |
22 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
23 #include "ui/base/win/scoped_ole_initializer.h" | 24 #include "ui/base/win/scoped_ole_initializer.h" |
24 #endif | 25 #endif |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 virtual int Run() OVERRIDE { | 118 virtual int Run() OVERRIDE { |
118 DCHECK(initialization_started_); | 119 DCHECK(initialization_started_); |
119 DCHECK(!is_shutdown_); | 120 DCHECK(!is_shutdown_); |
120 main_loop_->RunMainMessageLoopParts(); | 121 main_loop_->RunMainMessageLoopParts(); |
121 return main_loop_->GetResultCode(); | 122 return main_loop_->GetResultCode(); |
122 } | 123 } |
123 | 124 |
124 virtual void Shutdown() OVERRIDE { | 125 virtual void Shutdown() OVERRIDE { |
125 DCHECK(initialization_started_); | 126 DCHECK(initialization_started_); |
126 DCHECK(!is_shutdown_); | 127 DCHECK(!is_shutdown_); |
127 g_exited_main_message_loop = true; | 128 // The shutdown tracing got enabled in AttemptUserExit earlier, but someone |
| 129 // needs to write the result to disc. For that a dumper needs to get created |
| 130 // which will dump the traces to disc when it gets destroyed. |
| 131 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 132 scoped_ptr<BrowserShutdownProfileDumper> profiler; |
| 133 if (command_line.HasSwitch(switches::kTraceShutdown)) |
| 134 profiler.reset(new BrowserShutdownProfileDumper()); |
128 | 135 |
129 main_loop_->ShutdownThreadsAndCleanUp(); | 136 { |
| 137 // The trace event has to stay between profiler creation and destruction. |
| 138 TRACE_EVENT0("shutdown", "BrowserMainRunner"); |
| 139 g_exited_main_message_loop = true; |
130 | 140 |
131 ui::ShutdownInputMethod(); | 141 main_loop_->ShutdownThreadsAndCleanUp(); |
132 #if defined(OS_WIN) | |
133 ole_initializer_.reset(NULL); | |
134 #endif | |
135 | 142 |
136 main_loop_.reset(NULL); | 143 ui::ShutdownInputMethod(); |
| 144 #if defined(OS_WIN) |
| 145 ole_initializer_.reset(NULL); |
| 146 #endif |
137 | 147 |
138 notification_service_.reset(NULL); | 148 main_loop_.reset(NULL); |
139 | 149 |
140 is_shutdown_ = true; | 150 notification_service_.reset(NULL); |
| 151 |
| 152 is_shutdown_ = true; |
| 153 } |
141 } | 154 } |
142 | 155 |
143 protected: | 156 protected: |
144 // True if we have started to initialize the runner. | 157 // True if we have started to initialize the runner. |
145 bool initialization_started_; | 158 bool initialization_started_; |
146 | 159 |
147 // True if the runner has been shut down. | 160 // True if the runner has been shut down. |
148 bool is_shutdown_; | 161 bool is_shutdown_; |
149 | 162 |
150 scoped_ptr<NotificationServiceImpl> notification_service_; | 163 scoped_ptr<NotificationServiceImpl> notification_service_; |
151 scoped_ptr<BrowserMainLoop> main_loop_; | 164 scoped_ptr<BrowserMainLoop> main_loop_; |
152 #if defined(OS_WIN) | 165 #if defined(OS_WIN) |
153 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; | 166 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; |
154 #endif | 167 #endif |
155 | 168 |
156 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); | 169 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); |
157 }; | 170 }; |
158 | 171 |
159 // static | 172 // static |
160 BrowserMainRunner* BrowserMainRunner::Create() { | 173 BrowserMainRunner* BrowserMainRunner::Create() { |
161 return new BrowserMainRunnerImpl(); | 174 return new BrowserMainRunnerImpl(); |
162 } | 175 } |
163 | 176 |
164 } // namespace content | 177 } // namespace content |
OLD | NEW |