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

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, 10 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) 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
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 parts_->PreCreateThreads(); 322 parts_->PreCreateThreads();
322 323
323 base::Thread::Options default_options; 324 base::Thread::Options default_options;
324 base::Thread::Options io_message_loop_options; 325 base::Thread::Options io_message_loop_options;
325 io_message_loop_options.message_loop_type = MessageLoop::TYPE_IO; 326 io_message_loop_options.message_loop_type = MessageLoop::TYPE_IO;
326 base::Thread::Options ui_message_loop_options; 327 base::Thread::Options ui_message_loop_options;
327 ui_message_loop_options.message_loop_type = MessageLoop::TYPE_UI; 328 ui_message_loop_options.message_loop_type = MessageLoop::TYPE_UI;
328 329
329 // Start threads in the order they occur in the BrowserThread::ID 330 // Start threads in the order they occur in the BrowserThread::ID
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } else { 389 } else {
389 NOTREACHED(); 390 NOTREACHED();
390 } 391 }
391 } 392 }
392 393
393 BrowserThreadsStarted(); 394 BrowserThreadsStarted();
394 395
395 if (parts_.get()) 396 if (parts_.get())
396 parts_->PreMainMessageLoopRun(); 397 parts_->PreMainMessageLoopRun();
397 398
398 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
399 // If the UI thread blocks, the whole UI is unresponsive. 399 // If the UI thread blocks, the whole UI is unresponsive.
400 // Do not allow disk IO from the UI thread. 400 // Do not allow disk IO from the UI thread.
401 base::ThreadRestrictions::SetIOAllowed(false); 401 base::ThreadRestrictions::SetIOAllowed(false);
402 }
403
404 void BrowserMainLoop::RunMainMessageLoopParts() {
405 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
402 406
403 bool ran_main_loop = false; 407 bool ran_main_loop = false;
404 if (parts_.get()) 408 if (parts_.get())
405 ran_main_loop = parts_->MainMessageLoopRun(&result_code_); 409 ran_main_loop = parts_->MainMessageLoopRun(&result_code_);
406 410
407 if (!ran_main_loop) 411 if (!ran_main_loop)
408 MainMessageLoopRun(); 412 MainMessageLoopRun();
409 413
410 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); 414 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
411
412 if (completed_main_message_loop)
413 *completed_main_message_loop = true;
414
415 ShutdownThreadsAndCleanUp();
416 } 415 }
417 416
418 void BrowserMainLoop::ShutdownThreadsAndCleanUp() { 417 void BrowserMainLoop::ShutdownThreadsAndCleanUp() {
419 // Teardown may start in PostMainMessageLoopRun, and during teardown we 418 // Teardown may start in PostMainMessageLoopRun, and during teardown we
420 // need to be able to perform IO. 419 // need to be able to perform IO.
421 base::ThreadRestrictions::SetIOAllowed(true); 420 base::ThreadRestrictions::SetIOAllowed(true);
422 BrowserThread::PostTask( 421 BrowserThread::PostTask(
423 BrowserThread::IO, FROM_HERE, 422 BrowserThread::IO, FROM_HERE,
424 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), 423 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed),
425 true)); 424 true));
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); 587 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task);
589 588
590 #if defined(OS_MACOSX) 589 #if defined(OS_MACOSX)
591 MessageLoopForUI::current()->Run(); 590 MessageLoopForUI::current()->Run();
592 #else 591 #else
593 MessageLoopForUI::current()->RunWithDispatcher(NULL); 592 MessageLoopForUI::current()->RunWithDispatcher(NULL);
594 #endif 593 #endif
595 } 594 }
596 595
597 } // namespace content 596 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698