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

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

Issue 9375017: Support sharing of ContentMain and BrowserMain code with embedded use cases (try #3). (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
« no previous file with comments | « content/browser/browser_main_loop.h ('k') | content/browser/browser_main_runner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(new MessageLoop(MessageLoop::TYPE_UI)); 293 main_message_loop_.reset(parts_->GetMainMessageLoop());
294 if (!main_message_loop_.get())
295 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
294 296
295 InitializeMainThread(); 297 InitializeMainThread();
296 298
297 // Start tracing to a file if needed. 299 // Start tracing to a file if needed.
298 if (base::debug::TraceLog::GetInstance()->IsEnabled()) 300 if (base::debug::TraceLog::GetInstance()->IsEnabled())
299 TraceController::GetInstance()->InitStartupTracing(parsed_command_line_); 301 TraceController::GetInstance()->InitStartupTracing(parsed_command_line_);
300 302
301 system_monitor_.reset(new base::SystemMonitor); 303 system_monitor_.reset(new base::SystemMonitor);
302 hi_res_timer_manager_.reset(new HighResolutionTimerManager); 304 hi_res_timer_manager_.reset(new HighResolutionTimerManager);
303 305
304 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 306 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
305 307
306 #if defined(OS_WIN) 308 #if defined(OS_WIN)
307 system_message_window_.reset(new SystemMessageWindowWin); 309 system_message_window_.reset(new SystemMessageWindowWin);
308 #endif 310 #endif
309 311
310 // Prior to any processing happening on the io thread, we create the 312 // Prior to any processing happening on the io thread, we create the
311 // plugin service as it is predominantly used from the io thread, 313 // plugin service as it is predominantly used from the io thread,
312 // but must be created on the main thread. The service ctor is 314 // but must be created on the main thread. The service ctor is
313 // inexpensive and does not invoke the io_thread() accessor. 315 // inexpensive and does not invoke the io_thread() accessor.
314 PluginService::GetInstance()->Init(); 316 PluginService::GetInstance()->Init();
315 317
316 if (parts_.get()) 318 if (parts_.get())
317 parts_->PostMainMessageLoopStart(); 319 parts_->PostMainMessageLoopStart();
318 } 320 }
319 321
320 void BrowserMainLoop::RunMainMessageLoopParts( 322 void BrowserMainLoop::CreateThreads() {
321 bool* completed_main_message_loop) {
322 if (parts_.get()) 323 if (parts_.get())
323 result_code_ = parts_->PreCreateThreads(); 324 result_code_ = parts_->PreCreateThreads();
324 325
325 if (result_code_ > 0) 326 if (result_code_ > 0)
326 return; 327 return;
327 328
328 base::Thread::Options default_options; 329 base::Thread::Options default_options;
329 base::Thread::Options io_message_loop_options; 330 base::Thread::Options io_message_loop_options;
330 io_message_loop_options.message_loop_type = MessageLoop::TYPE_IO; 331 io_message_loop_options.message_loop_type = MessageLoop::TYPE_IO;
331 base::Thread::Options ui_message_loop_options; 332 base::Thread::Options ui_message_loop_options;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } else { 394 } else {
394 NOTREACHED(); 395 NOTREACHED();
395 } 396 }
396 } 397 }
397 398
398 BrowserThreadsStarted(); 399 BrowserThreadsStarted();
399 400
400 if (parts_.get()) 401 if (parts_.get())
401 parts_->PreMainMessageLoopRun(); 402 parts_->PreMainMessageLoopRun();
402 403
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, "");
407 411
408 bool ran_main_loop = false; 412 bool ran_main_loop = false;
409 if (parts_.get()) 413 if (parts_.get())
410 ran_main_loop = parts_->MainMessageLoopRun(&result_code_); 414 ran_main_loop = parts_->MainMessageLoopRun(&result_code_);
411 415
412 if (!ran_main_loop) 416 if (!ran_main_loop)
413 MainMessageLoopRun(); 417 MainMessageLoopRun();
414 418
415 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); 419 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
416
417 if (completed_main_message_loop)
418 *completed_main_message_loop = true;
419
420 ShutdownThreadsAndCleanUp();
421 } 420 }
422 421
423 void BrowserMainLoop::ShutdownThreadsAndCleanUp() { 422 void BrowserMainLoop::ShutdownThreadsAndCleanUp() {
424 // Teardown may start in PostMainMessageLoopRun, and during teardown we 423 // Teardown may start in PostMainMessageLoopRun, and during teardown we
425 // need to be able to perform IO. 424 // need to be able to perform IO.
426 base::ThreadRestrictions::SetIOAllowed(true); 425 base::ThreadRestrictions::SetIOAllowed(true);
427 BrowserThread::PostTask( 426 BrowserThread::PostTask(
428 BrowserThread::IO, FROM_HERE, 427 BrowserThread::IO, FROM_HERE,
429 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), 428 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed),
430 true)); 429 true));
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task); 598 MessageLoopForUI::current()->PostTask(FROM_HERE, *parameters_.ui_task);
600 599
601 #if defined(OS_MACOSX) 600 #if defined(OS_MACOSX)
602 MessageLoopForUI::current()->Run(); 601 MessageLoopForUI::current()->Run();
603 #else 602 #else
604 MessageLoopForUI::current()->RunWithDispatcher(NULL); 603 MessageLoopForUI::current()->RunWithDispatcher(NULL);
605 #endif 604 #endif
606 } 605 }
607 606
608 } // namespace content 607 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_main_loop.h ('k') | content/browser/browser_main_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698