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