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/logging.h" | 10 #include "base/logging.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 // has already been initialized. | 283 // has already been initialized. |
284 if (!parameters_.ui_task) { | 284 if (!parameters_.ui_task) { |
285 // Override the configured locale with the user's preferred UI language. | 285 // Override the configured locale with the user's preferred UI language. |
286 l10n_util::OverrideLocaleWithUILanguageList(); | 286 l10n_util::OverrideLocaleWithUILanguageList(); |
287 } | 287 } |
288 #endif | 288 #endif |
289 | 289 |
290 // Must first NULL pointer or we hit a DCHECK that the newly constructed | 290 // Must first NULL pointer or we hit a DCHECK that the newly constructed |
291 // message loop is the current one. | 291 // message loop is the current one. |
292 main_message_loop_.reset(); | 292 main_message_loop_.reset(); |
293 main_message_loop_.reset(parts_->GetMainMessageLoop()); | 293 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); |
294 if (!main_message_loop_.get()) | |
295 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); | |
296 | 294 |
297 InitializeMainThread(); | 295 InitializeMainThread(); |
298 | 296 |
299 // Start tracing to a file if needed. | 297 // Start tracing to a file if needed. |
300 if (base::debug::TraceLog::GetInstance()->IsEnabled()) | 298 if (base::debug::TraceLog::GetInstance()->IsEnabled()) |
301 TraceController::GetInstance()->InitStartupTracing(parsed_command_line_); | 299 TraceController::GetInstance()->InitStartupTracing(parsed_command_line_); |
302 | 300 |
303 system_monitor_.reset(new base::SystemMonitor); | 301 system_monitor_.reset(new base::SystemMonitor); |
304 hi_res_timer_manager_.reset(new HighResolutionTimerManager); | 302 hi_res_timer_manager_.reset(new HighResolutionTimerManager); |
305 | 303 |
306 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 304 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
307 | 305 |
308 #if defined(OS_WIN) | 306 #if defined(OS_WIN) |
309 system_message_window_.reset(new SystemMessageWindowWin); | 307 system_message_window_.reset(new SystemMessageWindowWin); |
310 #endif | 308 #endif |
311 | 309 |
312 // Prior to any processing happening on the io thread, we create the | 310 // Prior to any processing happening on the io thread, we create the |
313 // plugin service as it is predominantly used from the io thread, | 311 // plugin service as it is predominantly used from the io thread, |
314 // but must be created on the main thread. The service ctor is | 312 // but must be created on the main thread. The service ctor is |
315 // inexpensive and does not invoke the io_thread() accessor. | 313 // inexpensive and does not invoke the io_thread() accessor. |
316 PluginService::GetInstance()->Init(); | 314 PluginService::GetInstance()->Init(); |
317 | 315 |
318 if (parts_.get()) | 316 if (parts_.get()) |
319 parts_->PostMainMessageLoopStart(); | 317 parts_->PostMainMessageLoopStart(); |
320 } | 318 } |
321 | 319 |
322 void BrowserMainLoop::CreateThreads() { | 320 void BrowserMainLoop::RunMainMessageLoopParts( |
| 321 bool* completed_main_message_loop) { |
323 if (parts_.get()) | 322 if (parts_.get()) |
324 result_code_ = parts_->PreCreateThreads(); | 323 result_code_ = parts_->PreCreateThreads(); |
325 | 324 |
326 if (result_code_ > 0) | 325 if (result_code_ > 0) |
327 return; | 326 return; |
328 | 327 |
329 base::Thread::Options default_options; | 328 base::Thread::Options default_options; |
330 base::Thread::Options io_message_loop_options; | 329 base::Thread::Options io_message_loop_options; |
331 io_message_loop_options.message_loop_type = MessageLoop::TYPE_IO; | 330 io_message_loop_options.message_loop_type = MessageLoop::TYPE_IO; |
332 base::Thread::Options ui_message_loop_options; | 331 base::Thread::Options ui_message_loop_options; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 } else { | 393 } else { |
395 NOTREACHED(); | 394 NOTREACHED(); |
396 } | 395 } |
397 } | 396 } |
398 | 397 |
399 BrowserThreadsStarted(); | 398 BrowserThreadsStarted(); |
400 | 399 |
401 if (parts_.get()) | 400 if (parts_.get()) |
402 parts_->PreMainMessageLoopRun(); | 401 parts_->PreMainMessageLoopRun(); |
403 | 402 |
| 403 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
404 // If the UI thread blocks, the whole UI is unresponsive. | 404 // If the UI thread blocks, the whole UI is unresponsive. |
405 // Do not allow disk IO from the UI thread. | 405 // Do not allow disk IO from the UI thread. |
406 base::ThreadRestrictions::SetIOAllowed(false); | 406 base::ThreadRestrictions::SetIOAllowed(false); |
407 } | |
408 | |
409 void BrowserMainLoop::RunMainMessageLoopParts() { | |
410 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | |
411 | 407 |
412 bool ran_main_loop = false; | 408 bool ran_main_loop = false; |
413 if (parts_.get()) | 409 if (parts_.get()) |
414 ran_main_loop = parts_->MainMessageLoopRun(&result_code_); | 410 ran_main_loop = parts_->MainMessageLoopRun(&result_code_); |
415 | 411 |
416 if (!ran_main_loop) | 412 if (!ran_main_loop) |
417 MainMessageLoopRun(); | 413 MainMessageLoopRun(); |
418 | 414 |
419 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | 415 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
| 416 |
| 417 if (completed_main_message_loop) |
| 418 *completed_main_message_loop = true; |
| 419 |
| 420 ShutdownThreadsAndCleanUp(); |
420 } | 421 } |
421 | 422 |
422 void BrowserMainLoop::ShutdownThreadsAndCleanUp() { | 423 void BrowserMainLoop::ShutdownThreadsAndCleanUp() { |
423 // Teardown may start in PostMainMessageLoopRun, and during teardown we | 424 // Teardown may start in PostMainMessageLoopRun, and during teardown we |
424 // need to be able to perform IO. | 425 // need to be able to perform IO. |
425 base::ThreadRestrictions::SetIOAllowed(true); | 426 base::ThreadRestrictions::SetIOAllowed(true); |
426 BrowserThread::PostTask( | 427 BrowserThread::PostTask( |
427 BrowserThread::IO, FROM_HERE, | 428 BrowserThread::IO, FROM_HERE, |
428 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), | 429 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), |
429 true)); | 430 true)); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); | 599 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); |
599 | 600 |
600 #if defined(OS_MACOSX) | 601 #if defined(OS_MACOSX) |
601 MessageLoopForUI::current()->Run(); | 602 MessageLoopForUI::current()->Run(); |
602 #else | 603 #else |
603 MessageLoopForUI::current()->RunWithDispatcher(NULL); | 604 MessageLoopForUI::current()->RunWithDispatcher(NULL); |
604 #endif | 605 #endif |
605 } | 606 } |
606 | 607 |
607 } // namespace content | 608 } // namespace content |
OLD | NEW |