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

Unified Diff: chrome/browser/browser_main.cc

Issue 2931007: BrowserMain() refactoring, part 2. (Closed)
Patch Set: Updated per brettw and merged ToT. Created 10 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/browser_main.h ('k') | chrome/browser/browser_main_gtk.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/browser_main.cc
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 7d645fe9fa174e737fbafbc0dc508aa0d6efb5c9..b684c6e61ec7224251e2ce0a1c14e6627377afa6 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -159,7 +159,10 @@ BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters)
parsed_command_line_(parameters.command_line_) {
}
-// BrowserMainParts: EarlyInitialization() and related -------------------------
+BrowserMainParts::~BrowserMainParts() {
+}
+
+// BrowserMainParts: |EarlyInitialization()| and related -----------------------
void BrowserMainParts::EarlyInitialization() {
PreEarlyInitialization();
@@ -318,6 +321,33 @@ void BrowserMainParts::InitializeSSL() {
#endif
}
+// BrowserMainParts: |MainMessageLoopStart()| and related ----------------------
+
+void BrowserMainParts::MainMessageLoopStart() {
+ PreMainMessageLoopStart();
+
+ main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
+
+ // TODO(viettrungluu): should these really go before setting the thread name?
+ system_monitor_.reset(new SystemMonitor);
+ hi_res_timer_manager_.reset(new HighResolutionTimerManager);
+ network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
+
+ InitializeMainThread();
+
+ PostMainMessageLoopStart();
+}
+
+void BrowserMainParts::InitializeMainThread() {
+ const char* kThreadName = "CrBrowserMain";
+ PlatformThread::SetName(kThreadName);
+ main_message_loop().set_thread_name(kThreadName);
+
+ // Register the main thread by instantiating it, but don't call any methods.
+ main_thread_.reset(new ChromeThread(ChromeThread::UI,
+ MessageLoop::current()));
+}
+
// -----------------------------------------------------------------------------
// TODO(viettrungluu): move more/rest of BrowserMain() into above structure
@@ -711,39 +741,18 @@ int BrowserMain(const MainFunctionParams& parameters) {
parts(BrowserMainParts::CreateBrowserMainParts(parameters));
parts->EarlyInitialization();
+ parts->MainMessageLoopStart();
- // TODO(viettrungluu): put the remainder into BrowserMainParts
- const CommandLine& parsed_command_line = parameters.command_line_;
- base::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_;
-
- // WARNING: If we get a WM_ENDSESSION objects created on the stack here
+ // WARNING: If we get a WM_ENDSESSION, objects created on the stack here
// are NOT deleted. If you need something to run during WM_ENDSESSION add it
// to browser_shutdown::Shutdown or BrowserProcess::EndSession.
// TODO(beng, brettw): someday, break this out into sub functions with well
// defined roles (e.g. pre/post-profile startup, etc).
- // Do platform-specific things (such as finishing initializing Cocoa)
- // prior to instantiating the message loop. This could be turned into a
- // broadcast notification.
- WillInitializeMainMessageLoop(parameters);
-
- MessageLoop main_message_loop(MessageLoop::TYPE_UI);
-
- SystemMonitor system_monitor;
- HighResolutionTimerManager hi_res_timer_manager;
- scoped_ptr<net::NetworkChangeNotifier> network_change_notifier(
- net::NetworkChangeNotifier::Create());
-
- const char* kThreadName = "CrBrowserMain";
- PlatformThread::SetName(kThreadName);
- main_message_loop.set_thread_name(kThreadName);
-
- // Register the main thread by instantiating it, but don't call any methods.
- ChromeThread main_thread(ChromeThread::UI, MessageLoop::current());
-
- // TODO(viettrungluu): temporary while I refactor BrowserMain()
- parts->TemporaryPosix_1();
+ // TODO(viettrungluu): put the remainder into BrowserMainParts
+ const CommandLine& parsed_command_line = parameters.command_line_;
+ base::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_;
FilePath user_data_dir;
#if defined(OS_WIN)
@@ -807,9 +816,9 @@ int BrowserMain(const MainFunctionParams& parameters) {
if (parameters.ui_task) {
g_browser_process->SetApplicationLocale("en-US");
} else {
- // Mac starts it earlier in WillInitializeMainMessageLoop (because
- // it is needed when loading the MainMenu.nib and the language doesn't
- // depend on anything since it comes from Cocoa.
+ // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is
+ // needed when loading the MainMenu.nib and the language doesn't depend on
+ // anything since it comes from Cocoa.
#if defined(OS_MACOSX)
g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride());
#else
« no previous file with comments | « chrome/browser/browser_main.h ('k') | chrome/browser/browser_main_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698