OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/browser_main.h" | 5 #include "chrome/browser/browser_main.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 #include "chrome/browser/views/browser_dialogs.h" | 152 #include "chrome/browser/views/browser_dialogs.h" |
153 #endif | 153 #endif |
154 | 154 |
155 // BrowserMainParts ------------------------------------------------------------ | 155 // BrowserMainParts ------------------------------------------------------------ |
156 | 156 |
157 BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters) | 157 BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters) |
158 : parameters_(parameters), | 158 : parameters_(parameters), |
159 parsed_command_line_(parameters.command_line_) { | 159 parsed_command_line_(parameters.command_line_) { |
160 } | 160 } |
161 | 161 |
162 // BrowserMainParts: EarlyInitialization() and related ------------------------- | 162 BrowserMainParts::~BrowserMainParts() { |
| 163 } |
| 164 |
| 165 // BrowserMainParts: |EarlyInitialization()| and related ----------------------- |
163 | 166 |
164 void BrowserMainParts::EarlyInitialization() { | 167 void BrowserMainParts::EarlyInitialization() { |
165 PreEarlyInitialization(); | 168 PreEarlyInitialization(); |
166 | 169 |
167 ConnectionFieldTrial(); | 170 ConnectionFieldTrial(); |
168 SocketTimeoutFieldTrial(); | 171 SocketTimeoutFieldTrial(); |
169 SpdyFieldTrial(); | 172 SpdyFieldTrial(); |
170 InitializeSSL(); // TODO(viettrungluu): move to platform-specific method(s) | 173 InitializeSSL(); // TODO(viettrungluu): move to platform-specific method(s) |
171 | 174 |
172 PostEarlyInitialization(); | 175 PostEarlyInitialization(); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 // default on Windows. | 314 // default on Windows. |
312 if (!parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { | 315 if (!parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { |
313 net::ClientSocketFactory::SetSSLClientSocketFactory( | 316 net::ClientSocketFactory::SetSSLClientSocketFactory( |
314 net::SSLClientSocketNSSFactory); | 317 net::SSLClientSocketNSSFactory); |
315 // We want to be sure to init NSPR on the main thread. | 318 // We want to be sure to init NSPR on the main thread. |
316 base::EnsureNSPRInit(); | 319 base::EnsureNSPRInit(); |
317 } | 320 } |
318 #endif | 321 #endif |
319 } | 322 } |
320 | 323 |
| 324 // BrowserMainParts: |MainMessageLoopStart()| and related ---------------------- |
| 325 |
| 326 void BrowserMainParts::MainMessageLoopStart() { |
| 327 PreMainMessageLoopStart(); |
| 328 |
| 329 main_message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI)); |
| 330 |
| 331 // TODO(viettrungluu): should these really go before setting the thread name? |
| 332 system_monitor_.reset(new SystemMonitor); |
| 333 hi_res_timer_manager_.reset(new HighResolutionTimerManager); |
| 334 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 335 |
| 336 InitializeMainThread(); |
| 337 |
| 338 PostMainMessageLoopStart(); |
| 339 } |
| 340 |
| 341 void BrowserMainParts::InitializeMainThread() { |
| 342 const char* kThreadName = "CrBrowserMain"; |
| 343 PlatformThread::SetName(kThreadName); |
| 344 main_message_loop().set_thread_name(kThreadName); |
| 345 |
| 346 // Register the main thread by instantiating it, but don't call any methods. |
| 347 main_thread_.reset(new ChromeThread(ChromeThread::UI, |
| 348 MessageLoop::current())); |
| 349 } |
| 350 |
321 // ----------------------------------------------------------------------------- | 351 // ----------------------------------------------------------------------------- |
322 // TODO(viettrungluu): move more/rest of BrowserMain() into above structure | 352 // TODO(viettrungluu): move more/rest of BrowserMain() into above structure |
323 | 353 |
324 namespace { | 354 namespace { |
325 | 355 |
326 // This function provides some ways to test crash and assertion handling | 356 // This function provides some ways to test crash and assertion handling |
327 // behavior of the program. | 357 // behavior of the program. |
328 void HandleTestParameters(const CommandLine& command_line) { | 358 void HandleTestParameters(const CommandLine& command_line) { |
329 // This parameter causes an assertion. | 359 // This parameter causes an assertion. |
330 if (command_line.HasSwitch(switches::kBrowserAssertTest)) { | 360 if (command_line.HasSwitch(switches::kBrowserAssertTest)) { |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 734 Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
705 } | 735 } |
706 #endif | 736 #endif |
707 | 737 |
708 // Main routine for running as the Browser process. | 738 // Main routine for running as the Browser process. |
709 int BrowserMain(const MainFunctionParams& parameters) { | 739 int BrowserMain(const MainFunctionParams& parameters) { |
710 scoped_ptr<BrowserMainParts> | 740 scoped_ptr<BrowserMainParts> |
711 parts(BrowserMainParts::CreateBrowserMainParts(parameters)); | 741 parts(BrowserMainParts::CreateBrowserMainParts(parameters)); |
712 | 742 |
713 parts->EarlyInitialization(); | 743 parts->EarlyInitialization(); |
| 744 parts->MainMessageLoopStart(); |
714 | 745 |
715 // TODO(viettrungluu): put the remainder into BrowserMainParts | 746 // WARNING: If we get a WM_ENDSESSION, objects created on the stack here |
716 const CommandLine& parsed_command_line = parameters.command_line_; | |
717 base::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_; | |
718 | |
719 // WARNING: If we get a WM_ENDSESSION objects created on the stack here | |
720 // are NOT deleted. If you need something to run during WM_ENDSESSION add it | 747 // are NOT deleted. If you need something to run during WM_ENDSESSION add it |
721 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. | 748 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. |
722 | 749 |
723 // TODO(beng, brettw): someday, break this out into sub functions with well | 750 // TODO(beng, brettw): someday, break this out into sub functions with well |
724 // defined roles (e.g. pre/post-profile startup, etc). | 751 // defined roles (e.g. pre/post-profile startup, etc). |
725 | 752 |
726 // Do platform-specific things (such as finishing initializing Cocoa) | 753 // TODO(viettrungluu): put the remainder into BrowserMainParts |
727 // prior to instantiating the message loop. This could be turned into a | 754 const CommandLine& parsed_command_line = parameters.command_line_; |
728 // broadcast notification. | 755 base::ScopedNSAutoreleasePool* pool = parameters.autorelease_pool_; |
729 WillInitializeMainMessageLoop(parameters); | |
730 | |
731 MessageLoop main_message_loop(MessageLoop::TYPE_UI); | |
732 | |
733 SystemMonitor system_monitor; | |
734 HighResolutionTimerManager hi_res_timer_manager; | |
735 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( | |
736 net::NetworkChangeNotifier::Create()); | |
737 | |
738 const char* kThreadName = "CrBrowserMain"; | |
739 PlatformThread::SetName(kThreadName); | |
740 main_message_loop.set_thread_name(kThreadName); | |
741 | |
742 // Register the main thread by instantiating it, but don't call any methods. | |
743 ChromeThread main_thread(ChromeThread::UI, MessageLoop::current()); | |
744 | |
745 // TODO(viettrungluu): temporary while I refactor BrowserMain() | |
746 parts->TemporaryPosix_1(); | |
747 | 756 |
748 FilePath user_data_dir; | 757 FilePath user_data_dir; |
749 #if defined(OS_WIN) | 758 #if defined(OS_WIN) |
750 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 759 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
751 #else | 760 #else |
752 // Getting the user data dir can fail if the directory isn't | 761 // Getting the user data dir can fail if the directory isn't |
753 // creatable, for example; on Windows in code below we bring up a | 762 // creatable, for example; on Windows in code below we bring up a |
754 // dialog prompting the user to pick a different directory. | 763 // dialog prompting the user to pick a different directory. |
755 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, | 764 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, |
756 // so it's better to fail here than fail mysteriously elsewhere. | 765 // so it's better to fail here than fail mysteriously elsewhere. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 PrefService* local_state = InitializeLocalState(parsed_command_line, | 809 PrefService* local_state = InitializeLocalState(parsed_command_line, |
801 is_first_run); | 810 is_first_run); |
802 | 811 |
803 InitializeToolkit(); // Must happen before we try to display any UI. | 812 InitializeToolkit(); // Must happen before we try to display any UI. |
804 | 813 |
805 // If we're running tests (ui_task is non-null), then the ResourceBundle | 814 // If we're running tests (ui_task is non-null), then the ResourceBundle |
806 // has already been initialized. | 815 // has already been initialized. |
807 if (parameters.ui_task) { | 816 if (parameters.ui_task) { |
808 g_browser_process->SetApplicationLocale("en-US"); | 817 g_browser_process->SetApplicationLocale("en-US"); |
809 } else { | 818 } else { |
810 // Mac starts it earlier in WillInitializeMainMessageLoop (because | 819 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is |
811 // it is needed when loading the MainMenu.nib and the language doesn't | 820 // needed when loading the MainMenu.nib and the language doesn't depend on |
812 // depend on anything since it comes from Cocoa. | 821 // anything since it comes from Cocoa. |
813 #if defined(OS_MACOSX) | 822 #if defined(OS_MACOSX) |
814 g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride()); | 823 g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride()); |
815 #else | 824 #else |
816 // On a POSIX OS other than ChromeOS, the parameter that is passed to the | 825 // On a POSIX OS other than ChromeOS, the parameter that is passed to the |
817 // method InitSharedInstance is ignored. | 826 // method InitSharedInstance is ignored. |
818 std::string app_locale = ResourceBundle::InitSharedInstance( | 827 std::string app_locale = ResourceBundle::InitSharedInstance( |
819 ASCIIToWide(local_state->GetString(prefs::kApplicationLocale))); | 828 ASCIIToWide(local_state->GetString(prefs::kApplicationLocale))); |
820 g_browser_process->SetApplicationLocale(app_locale); | 829 g_browser_process->SetApplicationLocale(app_locale); |
821 | 830 |
822 FilePath resources_pack_path; | 831 FilePath resources_pack_path; |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 | 1313 |
1305 metrics->Stop(); | 1314 metrics->Stop(); |
1306 | 1315 |
1307 // browser_shutdown takes care of deleting browser_process, so we need to | 1316 // browser_shutdown takes care of deleting browser_process, so we need to |
1308 // release it. | 1317 // release it. |
1309 ignore_result(browser_process.release()); | 1318 ignore_result(browser_process.release()); |
1310 browser_shutdown::Shutdown(); | 1319 browser_shutdown::Shutdown(); |
1311 | 1320 |
1312 return result_code; | 1321 return result_code; |
1313 } | 1322 } |
OLD | NEW |