Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(786)

Side by Side Diff: content/browser/browser_main_loop.cc

Issue 9190018: Support sharing of ContentMain and BrowserMain code with embedded use cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // has already been initialized. 270 // has already been initialized.
271 if (!parameters_.ui_task) { 271 if (!parameters_.ui_task) {
272 // Override the configured locale with the user's preferred UI language. 272 // Override the configured locale with the user's preferred UI language.
273 l10n_util::OverrideLocaleWithUILanguageList(); 273 l10n_util::OverrideLocaleWithUILanguageList();
274 } 274 }
275 #endif 275 #endif
276 276
277 // Must first NULL pointer or we hit a DCHECK that the newly constructed 277 // Must first NULL pointer or we hit a DCHECK that the newly constructed
278 // message loop is the current one. 278 // message loop is the current one.
279 main_message_loop_.reset(); 279 main_message_loop_.reset();
280 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); 280 main_message_loop_.reset(parts_->GetMainMessageLoop());
281 if (!main_message_loop_.get())
282 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
281 283
282 InitializeMainThread(); 284 InitializeMainThread();
283 285
284 // Start tracing to a file if needed. 286 // Start tracing to a file if needed.
285 if (base::debug::TraceLog::GetInstance()->IsEnabled()) 287 if (base::debug::TraceLog::GetInstance()->IsEnabled())
286 TraceController::GetInstance()->InitStartupTracing(parsed_command_line_); 288 TraceController::GetInstance()->InitStartupTracing(parsed_command_line_);
287 289
288 system_monitor_.reset(new base::SystemMonitor); 290 system_monitor_.reset(new base::SystemMonitor);
289 hi_res_timer_manager_.reset(new HighResolutionTimerManager); 291 hi_res_timer_manager_.reset(new HighResolutionTimerManager);
290 292
291 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 293 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
292 294
293 #if defined(OS_WIN) 295 #if defined(OS_WIN)
294 system_message_window_.reset(new SystemMessageWindowWin); 296 system_message_window_.reset(new SystemMessageWindowWin);
295 #endif 297 #endif
296 298
297 // Prior to any processing happening on the io thread, we create the 299 // Prior to any processing happening on the io thread, we create the
298 // plugin service as it is predominantly used from the io thread, 300 // plugin service as it is predominantly used from the io thread,
299 // but must be created on the main thread. The service ctor is 301 // but must be created on the main thread. The service ctor is
300 // inexpensive and does not invoke the io_thread() accessor. 302 // inexpensive and does not invoke the io_thread() accessor.
301 PluginService::GetInstance()->Init(); 303 PluginService::GetInstance()->Init();
302 304
303 if (parts_.get()) 305 if (parts_.get())
304 parts_->PostMainMessageLoopStart(); 306 parts_->PostMainMessageLoopStart();
305 } 307 }
306 308
307 void BrowserMainLoop::RunMainMessageLoopParts( 309 void BrowserMainLoop::CreateThreads() {
308 bool* completed_main_message_loop) {
309 if (parts_.get()) 310 if (parts_.get())
310 parts_->PreCreateThreads(); 311 parts_->PreCreateThreads();
311 312
312 base::Thread::Options default_options; 313 base::Thread::Options default_options;
313 base::Thread::Options io_message_loop_options; 314 base::Thread::Options io_message_loop_options;
314 io_message_loop_options.message_loop_type = MessageLoop::TYPE_IO; 315 io_message_loop_options.message_loop_type = MessageLoop::TYPE_IO;
315 base::Thread::Options ui_message_loop_options; 316 base::Thread::Options ui_message_loop_options;
316 ui_message_loop_options.message_loop_type = MessageLoop::TYPE_UI; 317 ui_message_loop_options.message_loop_type = MessageLoop::TYPE_UI;
317 318
318 // Start threads in the order they occur in the BrowserThread::ID 319 // Start threads in the order they occur in the BrowserThread::ID
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } else { 378 } else {
378 NOTREACHED(); 379 NOTREACHED();
379 } 380 }
380 } 381 }
381 382
382 BrowserThreadsStarted(); 383 BrowserThreadsStarted();
383 384
384 if (parts_.get()) 385 if (parts_.get())
385 parts_->PreMainMessageLoopRun(); 386 parts_->PreMainMessageLoopRun();
386 387
387 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
388 // If the UI thread blocks, the whole UI is unresponsive. 388 // If the UI thread blocks, the whole UI is unresponsive.
389 // Do not allow disk IO from the UI thread. 389 // Do not allow disk IO from the UI thread.
390 base::ThreadRestrictions::SetIOAllowed(false); 390 base::ThreadRestrictions::SetIOAllowed(false);
391 }
392
393 void BrowserMainLoop::RunMainMessageLoopParts() {
394 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
391 395
392 bool ran_main_loop = false; 396 bool ran_main_loop = false;
393 if (parts_.get()) 397 if (parts_.get())
394 ran_main_loop = parts_->MainMessageLoopRun(&result_code_); 398 ran_main_loop = parts_->MainMessageLoopRun(&result_code_);
395 399
396 if (!ran_main_loop) 400 if (!ran_main_loop)
397 MainMessageLoopRun(); 401 MainMessageLoopRun();
398 402
399 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); 403 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
400
401 if (completed_main_message_loop)
402 *completed_main_message_loop = true;
403
404 ShutdownThreadsAndCleanUp();
405 } 404 }
406 405
407 void BrowserMainLoop::ShutdownThreadsAndCleanUp() { 406 void BrowserMainLoop::ShutdownThreadsAndCleanUp() {
408 // Teardown may start in PostMainMessageLoopRun, and during teardown we 407 // Teardown may start in PostMainMessageLoopRun, and during teardown we
409 // need to be able to perform IO. 408 // need to be able to perform IO.
410 base::ThreadRestrictions::SetIOAllowed(true); 409 base::ThreadRestrictions::SetIOAllowed(true);
411 BrowserThread::PostTask( 410 BrowserThread::PostTask(
412 BrowserThread::IO, FROM_HERE, 411 BrowserThread::IO, FROM_HERE,
413 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), 412 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed),
414 true)); 413 true));
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); 568 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task);
570 569
571 #if defined(OS_MACOSX) 570 #if defined(OS_MACOSX)
572 MessageLoopForUI::current()->Run(); 571 MessageLoopForUI::current()->Run();
573 #else 572 #else
574 MessageLoopForUI::current()->RunWithDispatcher(NULL); 573 MessageLoopForUI::current()->RunWithDispatcher(NULL);
575 #endif 574 #endif
576 } 575 }
577 576
578 } // namespace content 577 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698