OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters) | 151 BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters) |
152 : parameters_(parameters), | 152 : parameters_(parameters), |
153 parsed_command_line_(parameters.command_line), | 153 parsed_command_line_(parameters.command_line), |
154 result_code_(content::RESULT_CODE_NORMAL_EXIT) { | 154 result_code_(content::RESULT_CODE_NORMAL_EXIT) { |
155 #if defined(OS_WIN) | 155 #if defined(OS_WIN) |
156 OleInitialize(NULL); | 156 OleInitialize(NULL); |
157 #endif | 157 #endif |
158 } | 158 } |
159 | 159 |
160 BrowserMainLoop::~BrowserMainLoop() { | 160 BrowserMainLoop::~BrowserMainLoop() { |
161 // Release/destroy parts here, before OleUninitialize() and before other | 161 // Destroy added parts in reverse order. |
162 // members are destroyed (in particular main_message_loop_). | 162 for (int i = static_cast<int>(parts_list_.size())-1; i >= 0; --i) |
163 parts_.reset(); | 163 delete parts_list_[i]; |
| 164 parts_list_.clear(); |
164 | 165 |
165 #if defined(OS_WIN) | 166 #if defined(OS_WIN) |
166 OleUninitialize(); | 167 OleUninitialize(); |
167 #endif | 168 #endif |
168 } | 169 } |
169 | 170 |
170 void BrowserMainLoop::Init() { | 171 void BrowserMainLoop::Init() { |
171 parts_.reset( | 172 GetContentClient()->browser()->CreateBrowserMainParts( |
172 GetContentClient()->browser()->CreateBrowserMainParts(parameters_)); | 173 parameters_, &parts_list_); |
173 } | 174 } |
174 | 175 |
175 // BrowserMainLoop stages ================================================== | 176 // BrowserMainLoop stages ================================================== |
176 | 177 |
177 void BrowserMainLoop::EarlyInitialization() { | 178 void BrowserMainLoop::EarlyInitialization() { |
178 if (parts_.get()) | 179 for (size_t i = 0; i < parts_list_.size(); ++i) |
179 parts_->PreEarlyInitialization(); | 180 parts_list_[i]->PreEarlyInitialization(); |
180 | 181 |
181 #if defined(OS_WIN) | 182 #if defined(OS_WIN) |
182 net::EnsureWinsockInit(); | 183 net::EnsureWinsockInit(); |
183 #endif | 184 #endif |
184 | 185 |
185 #if !defined(USE_OPENSSL) | 186 #if !defined(USE_OPENSSL) |
186 // Use NSS for SSL by default. | 187 // Use NSS for SSL by default. |
187 // The default client socket factory uses NSS for SSL by default on | 188 // The default client socket factory uses NSS for SSL by default on |
188 // Windows and Mac. | 189 // Windows and Mac. |
189 bool init_nspr = false; | 190 bool init_nspr = false; |
(...skipping 25 matching lines...) Expand all Loading... |
215 if (parsed_command_line_.HasSwitch( | 216 if (parsed_command_line_.HasSwitch( |
216 switches::kEnableDNSCertProvenanceChecking)) { | 217 switches::kEnableDNSCertProvenanceChecking)) { |
217 net::SSLConfigService::EnableDNSCertProvenanceChecking(); | 218 net::SSLConfigService::EnableDNSCertProvenanceChecking(); |
218 } | 219 } |
219 | 220 |
220 // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't | 221 // TODO(abarth): Should this move to InitializeNetworkOptions? This doesn't |
221 // seem dependent on SSL initialization(). | 222 // seem dependent on SSL initialization(). |
222 if (parsed_command_line_.HasSwitch(switches::kEnableTcpFastOpen)) | 223 if (parsed_command_line_.HasSwitch(switches::kEnableTcpFastOpen)) |
223 net::set_tcp_fastopen_enabled(true); | 224 net::set_tcp_fastopen_enabled(true); |
224 | 225 |
225 if (parts_.get()) | 226 for (size_t i = 0; i < parts_list_.size(); ++i) |
226 parts_->PostEarlyInitialization(); | 227 parts_list_[i]->PostEarlyInitialization(); |
227 } | 228 } |
228 | 229 |
229 void BrowserMainLoop::MainMessageLoopStart() { | 230 void BrowserMainLoop::MainMessageLoopStart() { |
230 if (parts_.get()) | 231 for (size_t i = 0; i < parts_list_.size(); ++i) |
231 parts_->PreMainMessageLoopStart(); | 232 parts_list_[i]->PreMainMessageLoopStart(); |
232 | 233 |
233 #if defined(OS_WIN) | 234 #if defined(OS_WIN) |
234 // If we're running tests (ui_task is non-null), then the ResourceBundle | 235 // If we're running tests (ui_task is non-null), then the ResourceBundle |
235 // has already been initialized. | 236 // has already been initialized. |
236 if (!parameters_.ui_task) { | 237 if (!parameters_.ui_task) { |
237 // Override the configured locale with the user's preferred UI language. | 238 // Override the configured locale with the user's preferred UI language. |
238 l10n_util::OverrideLocaleWithUILanguageList(); | 239 l10n_util::OverrideLocaleWithUILanguageList(); |
239 } | 240 } |
240 #endif | 241 #endif |
241 | 242 |
(...skipping 10 matching lines...) Expand all Loading... |
252 | 253 |
253 system_monitor_.reset(new base::SystemMonitor); | 254 system_monitor_.reset(new base::SystemMonitor); |
254 hi_res_timer_manager_.reset(new HighResolutionTimerManager); | 255 hi_res_timer_manager_.reset(new HighResolutionTimerManager); |
255 | 256 |
256 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 257 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
257 | 258 |
258 #if defined(OS_WIN) | 259 #if defined(OS_WIN) |
259 system_message_window_.reset(new SystemMessageWindowWin); | 260 system_message_window_.reset(new SystemMessageWindowWin); |
260 #endif | 261 #endif |
261 | 262 |
262 if (parts_.get()) | 263 for (size_t i = 0; i < parts_list_.size(); ++i) |
263 parts_->PostMainMessageLoopStart(); | 264 parts_list_[i]->PostMainMessageLoopStart(); |
264 } | 265 } |
265 | 266 |
266 void BrowserMainLoop::RunMainMessageLoopParts( | 267 void BrowserMainLoop::RunMainMessageLoopParts( |
267 bool* completed_main_message_loop) { | 268 bool* completed_main_message_loop) { |
268 if (parts_.get()) | 269 for (size_t i = 0; i < parts_list_.size(); ++i) |
269 parts_->PreMainMessageLoopRun(); | 270 parts_list_[i]->PreMainMessageLoopRun(); |
270 | 271 |
271 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 272 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
272 // If the UI thread blocks, the whole UI is unresponsive. | 273 // If the UI thread blocks, the whole UI is unresponsive. |
273 // Do not allow disk IO from the UI thread. | 274 // Do not allow disk IO from the UI thread. |
274 base::ThreadRestrictions::SetIOAllowed(false); | 275 base::ThreadRestrictions::SetIOAllowed(false); |
275 | 276 |
| 277 // Iterate through each of the parts. If any of them ran the main |
| 278 // message loop then they should return |true|. Otherwise |
| 279 // BrowserMainLoop::MainMessageLoopRun loop will be run. |
276 bool ran_main_loop = false; | 280 bool ran_main_loop = false; |
277 if (parts_.get()) | 281 for (size_t i = 0; i < parts_list_.size(); ++i) { |
278 ran_main_loop = parts_->MainMessageLoopRun(&result_code_); | 282 int result_code = result_code_; |
279 | 283 if (parts_list_[i]->MainMessageLoopRun(&result_code)) { |
| 284 ran_main_loop = true; |
| 285 result_code_ = result_code; |
| 286 } |
| 287 } |
280 if (!ran_main_loop) | 288 if (!ran_main_loop) |
281 MainMessageLoopRun(); | 289 MainMessageLoopRun(); |
282 | 290 |
283 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 291 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
284 | 292 |
285 if (completed_main_message_loop) | 293 if (completed_main_message_loop) |
286 *completed_main_message_loop = true; | 294 *completed_main_message_loop = true; |
287 | 295 |
288 if (parts_.get()) | 296 for (size_t i = 0; i < parts_list_.size(); ++i) |
289 parts_->PostMainMessageLoopRun(); | 297 parts_list_[i]->PostMainMessageLoopRun(); |
290 } | 298 } |
291 | 299 |
292 void BrowserMainLoop::InitializeMainThread() { | 300 void BrowserMainLoop::InitializeMainThread() { |
293 const char* kThreadName = "CrBrowserMain"; | 301 const char* kThreadName = "CrBrowserMain"; |
294 base::PlatformThread::SetName(kThreadName); | 302 base::PlatformThread::SetName(kThreadName); |
295 main_message_loop_->set_thread_name(kThreadName); | 303 main_message_loop_->set_thread_name(kThreadName); |
296 | 304 |
297 // Register the main thread by instantiating it, but don't call any methods. | 305 // Register the main thread by instantiating it, but don't call any methods. |
298 main_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, | 306 main_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, |
299 MessageLoop::current())); | 307 MessageLoop::current())); |
(...skipping 28 matching lines...) Expand all Loading... |
328 | 336 |
329 #if defined(OS_WIN) | 337 #if defined(OS_WIN) |
330 // Init common control sex. | 338 // Init common control sex. |
331 INITCOMMONCONTROLSEX config; | 339 INITCOMMONCONTROLSEX config; |
332 config.dwSize = sizeof(config); | 340 config.dwSize = sizeof(config); |
333 config.dwICC = ICC_WIN95_CLASSES; | 341 config.dwICC = ICC_WIN95_CLASSES; |
334 if (!InitCommonControlsEx(&config)) | 342 if (!InitCommonControlsEx(&config)) |
335 LOG_GETLASTERROR(FATAL); | 343 LOG_GETLASTERROR(FATAL); |
336 #endif | 344 #endif |
337 | 345 |
338 if (parts_.get()) | 346 for (size_t i = 0; i < parts_list_.size(); ++i) |
339 parts_->ToolkitInitialized(); | 347 parts_list_[i]->ToolkitInitialized(); |
340 } | 348 } |
341 | 349 |
342 void BrowserMainLoop::MainMessageLoopRun() { | 350 void BrowserMainLoop::MainMessageLoopRun() { |
343 if (parameters_.ui_task) | 351 if (parameters_.ui_task) |
344 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters_.ui_task); | 352 MessageLoopForUI::current()->PostTask(FROM_HERE, parameters_.ui_task); |
345 | 353 |
346 #if defined(OS_MACOSX) | 354 #if defined(OS_MACOSX) |
347 MessageLoopForUI::current()->Run(); | 355 MessageLoopForUI::current()->Run(); |
348 #else | 356 #else |
349 MessageLoopForUI::current()->RunWithDispatcher(NULL); | 357 MessageLoopForUI::current()->RunWithDispatcher(NULL); |
350 #endif | 358 #endif |
351 } | 359 } |
352 | 360 |
353 } // namespace content | 361 } // namespace content |
OLD | NEW |