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