Index: chrome/browser/browser_main.cc |
=================================================================== |
--- chrome/browser/browser_main.cc (revision 100153) |
+++ chrome/browser/browser_main.cc (working copy) |
@@ -24,21 +24,18 @@ |
#include "base/string_util.h" |
#include "base/sys_string_conversions.h" |
#include "base/threading/platform_thread.h" |
-#include "base/threading/thread_restrictions.h" |
#include "base/time.h" |
#include "base/utf_string_conversions.h" |
#include "base/values.h" |
#include "build/build_config.h" |
#include "chrome/browser/about_flags.h" |
#include "chrome/browser/browser_main_win.h" |
-#include "chrome/browser/browser_process.h" |
#include "chrome/browser/browser_process_impl.h" |
#include "chrome/browser/browser_shutdown.h" |
#include "chrome/browser/defaults.h" |
#include "chrome/browser/extensions/extension_protocols.h" |
#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/extensions/extensions_startup.h" |
-#include "chrome/browser/first_run/first_run.h" |
#include "chrome/browser/first_run/first_run_browser_process.h" |
#include "chrome/browser/first_run/upgrade_util.h" |
#include "chrome/browser/google/google_url_tracker.h" |
@@ -155,7 +152,6 @@ |
#if defined(OS_WIN) |
#include "base/environment.h" // For PreRead experiment. |
-#include "base/win/scoped_com_initializer.h" |
#include "base/win/windows_version.h" |
#include "chrome/browser/browser_trial.h" |
#include "chrome/browser/browser_util_win.h" |
@@ -228,33 +224,6 @@ |
#endif |
} |
-void RunUIMessageLoop(BrowserProcess* browser_process) { |
- TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
- // This should be invoked as close to the start of the browser's |
- // UI thread message loop as possible to get a stable measurement |
- // across versions. |
- RecordBrowserStartupTime(); |
- |
- // If the UI thread blocks, the whole UI is unresponsive. |
- // Do not allow disk IO from the UI thread. |
- base::ThreadRestrictions::SetIOAllowed(false); |
- |
-#if defined(TOOLKIT_VIEWS) |
- views::AcceleratorHandler accelerator_handler; |
- MessageLoopForUI::current()->Run(&accelerator_handler); |
-#elif defined(USE_X11) |
- MessageLoopForUI::current()->Run(NULL); |
-#elif defined(OS_POSIX) |
- MessageLoopForUI::current()->Run(); |
-#endif |
-#if defined(OS_CHROMEOS) |
- chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("UIMessageLoopEnded", |
- true); |
-#endif |
- |
- TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); |
-} |
- |
void AddFirstRunNewTabs(BrowserInit* browser_init, |
const std::vector<GURL>& new_tabs) { |
for (std::vector<GURL>::const_iterator it = new_tabs.begin(); |
@@ -698,7 +667,12 @@ |
ChromeBrowserMainParts::ChromeBrowserMainParts( |
const MainFunctionParams& parameters) |
: BrowserMainParts(parameters), |
- shutdown_watcher_(new ShutdownWatcherHelper()) { |
+ shutdown_watcher_(new ShutdownWatcherHelper()), |
+ record_search_engine_(false), |
+ translate_manager_(NULL), |
+ metrics_(NULL), |
+ profile_(NULL), |
+ run_message_loop_(true) { |
// If we're running tests (ui_task is non-null). |
if (parameters.ui_task) |
browser_defaults::enable_help_app = false; |
@@ -707,10 +681,6 @@ |
ChromeBrowserMainParts::~ChromeBrowserMainParts() { |
} |
-void ChromeBrowserMainParts::SetupHistogramSynchronizer() { |
- histogram_synchronizer_ = new HistogramSynchronizer(); |
-} |
- |
// This will be called after the command-line has been mutated by about:flags |
MetricsService* ChromeBrowserMainParts::SetupMetricsAndFieldTrials( |
const CommandLine& parsed_command_line, |
@@ -1108,25 +1078,8 @@ |
Profiling::MainMessageLoopStarted(); |
} |
-void ChromeBrowserMainParts::ToolkitInitialized() { |
-#if defined(TOOLKIT_VIEWS) |
- // The delegate needs to be set before any UI is created so that windows |
- // display the correct icon. |
- if (!views::ViewsDelegate::views_delegate) |
- views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; |
- |
- // TODO(beng): Move to WidgetImpl and implement on Windows too! |
- if (parameters().command_line_.HasSwitch(switches::kDebugViewsPaint)) |
- views::Widget::SetDebugPaintEnabled(true); |
-#endif |
- |
-#if defined(OS_WIN) |
- gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; |
- gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; |
-#endif |
-} |
- |
-int ChromeBrowserMainParts::TemporaryContinue() { |
+void ChromeBrowserMainParts::PreMainMessageLoopRun() { |
+ run_message_loop_ = false; |
FilePath user_data_dir; |
#if defined(OS_WIN) |
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
@@ -1140,21 +1093,20 @@ |
<< "Must be able to get user data directory!"; |
#endif |
- ProcessSingleton process_singleton(user_data_dir); |
+ process_singleton_.reset(new ProcessSingleton(user_data_dir)); |
bool is_first_run = FirstRun::IsChromeFirstRun() || |
parsed_command_line().HasSwitch(switches::kFirstRun); |
- scoped_ptr<BrowserProcessImpl> browser_process; |
if (parsed_command_line().HasSwitch(switches::kImport) || |
parsed_command_line().HasSwitch(switches::kImportFromFile)) { |
// We use different BrowserProcess when importing so no GoogleURLTracker is |
// instantiated (as it makes a net::URLRequest and we don't have an IO |
// thread, see bug #1292702). |
- browser_process.reset(new FirstRunBrowserProcess(parsed_command_line())); |
+ browser_process_.reset(new FirstRunBrowserProcess(parsed_command_line())); |
is_first_run = false; |
} else { |
- browser_process.reset(new BrowserProcessImpl(parsed_command_line())); |
+ browser_process_.reset(new BrowserProcessImpl(parsed_command_line())); |
} |
// This forces the TabCloseableStateWatcher to be created and, on chromeos, |
@@ -1195,7 +1147,8 @@ |
if (loaded_locale.empty() && |
!parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { |
ShowMissingLocaleMessageBox(); |
- return chrome::RESULT_CODE_MISSING_DATA; |
+ set_result_code(chrome::RESULT_CODE_MISSING_DATA); |
+ return; |
} |
CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; |
g_browser_process->SetApplicationLocale(loaded_locale); |
@@ -1216,24 +1169,26 @@ |
#if defined(OS_WIN) && !defined(USE_AURA) |
// Setup.exe has determined that we need to run a retention experiment |
// and has lauched chrome to show the experiment UI. |
- if (process_singleton.FoundOtherProcessWindow()) { |
+ if (process_singleton_->FoundOtherProcessWindow()) { |
// It seems that we don't need to run the experiment since chrome |
// in the same profile is already running. |
VLOG(1) << "Retention experiment not required"; |
- return TryChromeDialogView::NOT_NOW; |
+ set_result_code(TryChromeDialogView::NOT_NOW); |
+ return; |
} |
int try_chrome_int; |
base::StringToInt(try_chrome, &try_chrome_int); |
TryChromeDialogView::Result answer = |
- TryChromeDialogView::Show(try_chrome_int, &process_singleton); |
+ TryChromeDialogView::Show(try_chrome_int, process_singleton_.get()); |
if (answer == TryChromeDialogView::NOT_NOW) |
- return chrome::RESULT_CODE_NORMAL_EXIT_CANCEL; |
- if (answer == TryChromeDialogView::UNINSTALL_CHROME) |
- return chrome::RESULT_CODE_NORMAL_EXIT_EXP2; |
+ set_result_code(chrome::RESULT_CODE_NORMAL_EXIT_CANCEL); |
+ else if (answer == TryChromeDialogView::UNINSTALL_CHROME) |
+ set_result_code(chrome::RESULT_CODE_NORMAL_EXIT_EXP2); |
#else |
// We don't support retention experiments on Mac or Linux. |
- return content::RESULT_CODE_NORMAL_EXIT; |
+ set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
#endif // defined(OS_WIN) |
+ return; |
} |
#if defined(OS_CHROMEOS) |
@@ -1269,12 +1224,12 @@ |
// On first run, we need to process the predictor preferences before the |
// browser's profile_manager object is created, but after ResourceBundle |
// is initialized. |
- FirstRun::MasterPrefs master_prefs; |
+ master_prefs_.reset(new FirstRun::MasterPrefs); |
bool first_run_ui_bypass = false; // True to skip first run UI. |
if (is_first_run) { |
first_run_ui_bypass = |
- !FirstRun::ProcessMasterPreferences(user_data_dir, &master_prefs); |
- AddFirstRunNewTabs(&browser_init, master_prefs.new_tabs); |
+ !FirstRun::ProcessMasterPreferences(user_data_dir, master_prefs_.get()); |
+ AddFirstRunNewTabs(&browser_init, master_prefs_->new_tabs); |
// If we are running in App mode, we do not want to show the importer |
// (first run) UI. |
@@ -1305,18 +1260,17 @@ |
CommandLine::ForCurrentProcess()); |
InitializeNetworkOptions(parsed_command_line()); |
- InitializeURLRequestThrottlerManager(browser_process->net_log()); |
+ InitializeURLRequestThrottlerManager(browser_process_->net_log()); |
// Initialize histogram synchronizer system. This is a singleton and is used |
// for posting tasks via NewRunnableMethod. Its deleted when it goes out of |
// scope. Even though NewRunnableMethod does AddRef and Release, the object |
// will not be deleted after the Task is executed. |
- SetupHistogramSynchronizer(); |
+ histogram_synchronizer_ = new HistogramSynchronizer(); |
// Now the command line has been mutated based on about:flags, we can |
// set up metrics and initialize field trials. |
- MetricsService* metrics = SetupMetricsAndFieldTrials( |
- parsed_command_line(), local_state); |
+ metrics_ = SetupMetricsAndFieldTrials(parsed_command_line(), local_state); |
// Now that all preferences have been registered, set the install date |
// for the uninstall metrics if this is our first run. This only actually |
@@ -1338,7 +1292,7 @@ |
SecKeychainAddCallback(&KeychainCallback, 0, NULL); |
#endif |
- CreateChildThreads(browser_process.get()); |
+ CreateChildThreads(browser_process_.get()); |
#if defined(OS_CHROMEOS) |
// Now that the file thread exists we can record our stats. |
@@ -1364,17 +1318,22 @@ |
// If the command line specifies 'uninstall' then we need to work here |
// unless we detect another chrome browser running. |
- if (parsed_command_line().HasSwitch(switches::kUninstall)) |
- return DoUninstallTasks(already_running); |
+ if (parsed_command_line().HasSwitch(switches::kUninstall)) { |
+ set_result_code(DoUninstallTasks(already_running)); |
+ return; |
+ } |
#endif |
if (parsed_command_line().HasSwitch(switches::kHideIcons) || |
- parsed_command_line().HasSwitch(switches::kShowIcons)) |
- return HandleIconsCommands(parsed_command_line()); |
+ parsed_command_line().HasSwitch(switches::kShowIcons)) { |
+ set_result_code(HandleIconsCommands(parsed_command_line())); |
+ return; |
+ } |
if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) { |
- return ShellIntegration::SetAsDefaultBrowser() ? |
+ set_result_code(ShellIntegration::SetAsDefaultBrowser() ? |
static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) : |
- static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED); |
+ static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED)); |
+ return; |
} |
// If the command line specifies --pack-extension, attempt the pack extension |
@@ -1382,10 +1341,11 @@ |
if (parsed_command_line().HasSwitch(switches::kPackExtension)) { |
ExtensionsStartupUtil extension_startup_util; |
if (extension_startup_util.PackExtension(parsed_command_line())) { |
- return content::RESULT_CODE_NORMAL_EXIT; |
+ set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
} else { |
- return chrome::RESULT_CODE_PACK_EXTENSION_ERROR; |
+ set_result_code(chrome::RESULT_CODE_PACK_EXTENSION_ERROR); |
} |
+ return; |
} |
#if !defined(OS_MACOSX) |
@@ -1400,7 +1360,7 @@ |
// new one. NotifyOtherProcess will currently give the other process up to |
// 20 seconds to respond. Note that this needs to be done before we attempt |
// to read the profile. |
- switch (process_singleton.NotifyOtherProcessOrCreate()) { |
+ switch (process_singleton_->NotifyOtherProcessOrCreate()) { |
case ProcessSingleton::PROCESS_NONE: |
// No process already running, fall through to starting a new one. |
break; |
@@ -1410,10 +1370,12 @@ |
printf("%s\n", base::SysWideToNativeMB(UTF16ToWide( |
l10n_util::GetStringUTF16(IDS_USED_EXISTING_BROWSER))).c_str()); |
#endif |
- return content::RESULT_CODE_NORMAL_EXIT; |
+ set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
+ return; |
case ProcessSingleton::PROFILE_IN_USE: |
- return chrome::RESULT_CODE_PROFILE_IN_USE; |
+ set_result_code(chrome::RESULT_CODE_PROFILE_IN_USE); |
+ return; |
case ProcessSingleton::LOCK_ERROR: |
LOG(ERROR) << "Failed to create a ProcessSingleton for your profile " |
@@ -1421,7 +1383,8 @@ |
"would start multiple browser processes rather than " |
"opening a new window in the existing process. Aborting " |
"now to avoid profile corruption."; |
- return chrome::RESULT_CODE_PROFILE_IN_USE; |
+ set_result_code(chrome::RESULT_CODE_PROFILE_IN_USE); |
+ return; |
default: |
NOTREACHED(); |
@@ -1478,10 +1441,11 @@ |
g_browser_process->profile_manager()->SetWillImport(); |
} |
- Profile* profile = CreateProfile(parameters(), user_data_dir, |
- parsed_command_line()); |
- if (!profile) |
- return content::RESULT_CODE_NORMAL_EXIT; |
+ profile_ = CreateProfile(parameters(), user_data_dir, parsed_command_line()); |
+ if (!profile_) { |
+ set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
+ return; |
+ } |
// Post-profile init --------------------------------------------------------- |
@@ -1492,17 +1456,17 @@ |
if (parsed_command_line().HasSwitch(switches::kLoginUser) && |
!parsed_command_line().HasSwitch(switches::kLoginPassword)) { |
g_browser_process->browser_policy_connector()->SetUserPolicyTokenService( |
- profile->GetTokenService()); |
+ profile_->GetTokenService()); |
} |
#endif |
- PrefService* user_prefs = profile->GetPrefs(); |
+ PrefService* user_prefs = profile_->GetPrefs(); |
DCHECK(user_prefs); |
// Tests should be able to tune login manager before showing it. |
// Thus only show login manager in normal (non-testing) mode. |
if (!parameters().ui_task) { |
- OptionallyRunChromeOSLoginManager(parsed_command_line(), profile); |
+ OptionallyRunChromeOSLoginManager(parsed_command_line(), profile_); |
} |
#if !defined(OS_MACOSX) |
@@ -1512,14 +1476,17 @@ |
// replace this implementation. http://crbug.com/22142 |
if (parsed_command_line().HasSwitch(switches::kImport) || |
parsed_command_line().HasSwitch(switches::kImportFromFile)) { |
- return FirstRun::ImportNow(profile, parsed_command_line()); |
+ set_result_code(FirstRun::ImportNow(profile_, parsed_command_line())); |
+ return; |
} |
#endif |
#if defined(OS_WIN) |
// Do the tasks if chrome has been upgraded while it was last running. |
- if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line())) |
- return content::RESULT_CODE_NORMAL_EXIT; |
+ if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line())) { |
+ set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
+ return; |
+ } |
#endif |
// Check if there is any machine level Chrome installed on the current |
@@ -1531,12 +1498,14 @@ |
// processes etc). |
// Do not allow this to occur for Chrome Frame user-to-system handoffs. |
if (!parsed_command_line().HasSwitch(switches::kChromeFrame) && |
- CheckMachineLevelInstall()) |
- return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS; |
+ CheckMachineLevelInstall()) { |
+ set_result_code(chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS); |
+ return; |
+ } |
// Create the TranslateManager singleton. |
- TranslateManager* translate_manager = TranslateManager::GetInstance(); |
- DCHECK(translate_manager != NULL); |
+ translate_manager_ = TranslateManager::GetInstance(); |
+ DCHECK(translate_manager_ != NULL); |
#if defined(OS_MACOSX) |
if (!parsed_command_line().HasSwitch(switches::kNoFirstRun)) { |
@@ -1545,7 +1514,8 @@ |
if (MaybeInstallFromDiskImage()) { |
// The application was installed and the installed copy has been |
// launched. This process is now obsolete. Exit. |
- return content::RESULT_CODE_NORMAL_EXIT; |
+ set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
+ return; |
} |
} |
#endif |
@@ -1557,14 +1527,14 @@ |
// touches reads preferences. |
if (is_first_run) { |
if (!first_run_ui_bypass) { |
- FirstRun::AutoImport(profile, |
- master_prefs.homepage_defined, |
- master_prefs.do_import_items, |
- master_prefs.dont_import_items, |
- master_prefs.run_search_engine_experiment, |
- master_prefs.randomize_search_engine_experiment, |
- master_prefs.make_chrome_default, |
- &process_singleton); |
+ FirstRun::AutoImport(profile_, |
+ master_prefs_->homepage_defined, |
+ master_prefs_->do_import_items, |
+ master_prefs_->dont_import_items, |
+ master_prefs_->run_search_engine_experiment, |
+ master_prefs_->randomize_search_engine_experiment, |
+ master_prefs_->make_chrome_default, |
+ process_singleton_.get()); |
#if defined(OS_POSIX) |
// On Windows, the download is tagged with enable/disable stats so there |
// is no need for this code. |
@@ -1577,7 +1547,7 @@ |
} // if (!first_run_ui_bypass) |
Browser::SetNewHomePagePrefs(user_prefs); |
- g_browser_process->profile_manager()->OnImportFinished(profile); |
+ g_browser_process->profile_manager()->OnImportFinished(profile_); |
} // if (is_first_run) |
// Sets things up so that if we crash from this point on, a dialog will |
@@ -1609,16 +1579,13 @@ |
local_state, |
preconnect_enabled); |
-#if defined(OS_WIN) |
- base::win::ScopedCOMInitializer com_initializer; |
- |
-#if defined(GOOGLE_CHROME_BUILD) |
+#if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
// Init the RLZ library. This just binds the dll and schedules a task on the |
// file thread to be run sometime later. If this is the first run we record |
// the installation event. |
bool google_search_default = false; |
TemplateURLService* template_url_service = |
- TemplateURLServiceFactory::GetForProfile(profile); |
+ TemplateURLServiceFactory::GetForProfile(profile_); |
if (template_url_service) { |
const TemplateURL* url_template = |
template_url_service->GetDefaultSearchProvider(); |
@@ -1631,24 +1598,22 @@ |
} |
bool google_search_homepage = false; |
- PrefService* pref_service = profile->GetPrefs(); |
+ PrefService* pref_service = profile_->GetPrefs(); |
if (pref_service) { |
std::string homepage = pref_service->GetString(prefs::kHomePage); |
google_search_homepage = |
homepage == GoogleURLTracker::kDefaultGoogleHomepage; |
} |
- RLZTracker::InitRlzDelayed(is_first_run, master_prefs.ping_delay, |
+ RLZTracker::InitRlzDelayed(is_first_run, master_prefs_->ping_delay, |
google_search_default, google_search_homepage); |
// Prime the RLZ cache for the home page access point so that its avaiable |
// for the startup page if needed (i.e., when the startup page is set to |
// the home page). |
RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, NULL); |
+#endif // GOOGLE_CHROME_BUILD && OS_WIN |
-#endif // GOOGLE_CHROME_BUILD |
-#endif // OS_WIN |
- |
// Configure modules that need access to resources. |
net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider); |
@@ -1664,8 +1629,8 @@ |
// |
// These can't be created in the BrowserProcessImpl constructor because they |
// need to read prefs that get set after that runs. |
- browser_process->google_url_tracker(); |
- browser_process->intranet_redirect_detector(); |
+ browser_process_->google_url_tracker(); |
+ browser_process_->intranet_redirect_detector(); |
// Prepare for memory caching of SDCH dictionaries. |
// Perform A/B test to measure global impact of SDCH support. |
@@ -1711,15 +1676,15 @@ |
#endif |
HandleTestParameters(parsed_command_line()); |
- RecordBreakpadStatusUMA(metrics); |
+ RecordBreakpadStatusUMA(metrics_); |
about_flags::RecordUMAStatistics(local_state); |
LanguageUsageMetrics::RecordAcceptLanguages( |
- profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
+ profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
LanguageUsageMetrics::RecordApplicationLanguage( |
g_browser_process->GetApplicationLocale()); |
#if defined(OS_CHROMEOS) |
- metrics->StartExternalMetrics(); |
+ metrics_->StartExternalMetrics(); |
// Initialize the brightness observer so that we'll display an onscreen |
// indication of brightness changes during login. |
@@ -1741,17 +1706,18 @@ |
// action. |
if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) { |
ExtensionsStartupUtil ext_startup_util; |
- if (ext_startup_util.UninstallExtension(parsed_command_line(), profile)) { |
- return content::RESULT_CODE_NORMAL_EXIT; |
+ if (ext_startup_util.UninstallExtension(parsed_command_line(), profile_)) { |
+ set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
} else { |
- return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; |
+ set_result_code(chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR); |
} |
+ return; |
} |
#if defined(OS_WIN) |
// We check this here because if the profile is OTR (chromeos possibility) |
// it won't still be accessible after browser is destroyed. |
- bool record_search_engine = is_first_run && !profile->IsOffTheRecord(); |
+ record_search_engine_ = is_first_run && !profile_->IsOffTheRecord(); |
#endif |
// ChildProcess:: is a misnomer unless you consider context. Use |
@@ -1777,7 +1743,7 @@ |
// might have shutdown because an update was available. |
// TODO(torne): this should maybe be done with |
// ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead? |
- CloudPrintProxyServiceFactory::GetForProfile(profile); |
+ CloudPrintProxyServiceFactory::GetForProfile(profile_); |
// Initialize GpuDataManager and collect preliminary gpu info on FILE thread. |
// Upon completion, it posts GpuBlacklist auto update task on UI thread. |
@@ -1788,6 +1754,7 @@ |
// Start watching all browser threads for responsiveness. |
ThreadWatcherList::StartWatchingAll(parsed_command_line()); |
jam
2011/09/08 16:21:06
fixed this spacing and also 1766
|
+ |
int result_code = content::RESULT_CODE_NORMAL_EXIT; |
base::mac::ScopedNSAutoreleasePool* pool = parameters().autorelease_pool_; |
if (parameters().ui_task) { |
@@ -1796,14 +1763,14 @@ |
pool->Recycle(); |
parameters().ui_task->Run(); |
delete parameters().ui_task; |
- } else { |
+ } else { |
// Most general initialization is behind us, but opening a |
// tab and/or session restore and such is still to be done. |
base::TimeTicks browser_open_start = base::TimeTicks::Now(); |
// We are in regular browser boot sequence. Open initial tabs and enter the |
// main message loop. |
- if (browser_init.Start(parsed_command_line(), FilePath(), profile, |
+ if (browser_init.Start(parsed_command_line(), FilePath(), profile_, |
&result_code)) { |
#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
// Initialize autoupdate timer. Timer callback costs basically nothing |
@@ -1836,20 +1803,45 @@ |
#if !defined(OS_CHROMEOS) |
// If we're running tests (ui_task is non-null), then we don't want to |
// call FetchLanguageListFromTranslateServer |
- if (parameters().ui_task == NULL && translate_manager != NULL) { |
+ if (parameters().ui_task == NULL && translate_manager_ != NULL) { |
// TODO(willchan): Get rid of this after TranslateManager doesn't use |
// the default request context. http://crbug.com/89396. |
// This is necessary to force |default_request_context_| to be |
// initialized. |
- profile->GetRequestContext(); |
- translate_manager->FetchLanguageListFromTranslateServer(user_prefs); |
+ profile_->GetRequestContext(); |
+ translate_manager_->FetchLanguageListFromTranslateServer(user_prefs); |
} |
#endif |
- RunUIMessageLoop(browser_process.get()); |
+ run_message_loop_ = true; |
} |
} |
+} |
+void ChromeBrowserMainParts::MainMessageLoopRun() { |
+ if (!run_message_loop_) |
+ return; |
+ |
+ // This should be invoked as close to the start of the browser's |
+ // UI thread message loop as possible to get a stable measurement |
+ // across versions. |
+ RecordBrowserStartupTime(); |
+ |
+#if defined(TOOLKIT_VIEWS) |
+ views::AcceleratorHandler accelerator_handler; |
+ MessageLoopForUI::current()->Run(&accelerator_handler); |
+#elif defined(USE_X11) |
+ MessageLoopForUI::current()->Run(NULL); |
+#elif defined(OS_POSIX) |
+ MessageLoopForUI::current()->Run(); |
+#endif |
+#if defined(OS_CHROMEOS) |
+ chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("UIMessageLoopEnded", |
+ true); |
+#endif |
+} |
+ |
+void ChromeBrowserMainParts::PostMainMessageLoopRun() { |
// Start watching for jank during shutdown. It gets disarmed when |
// |shutdown_watcher_| object is destructed. |
shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(45)); |
@@ -1859,9 +1851,9 @@ |
// shutdown because otherwise we can't be sure the user has finished |
// selecting a search engine through the dialog reached from the first run |
// bubble link. |
- if (record_search_engine) { |
+ if (record_search_engine_) { |
TemplateURLService* url_service = |
- TemplateURLServiceFactory::GetForProfile(profile); |
+ TemplateURLServiceFactory::GetForProfile(profile_); |
const TemplateURL* default_search_engine = |
url_service->GetDefaultSearchProvider(); |
// The default engine can be NULL if the administrator has disabled |
@@ -1870,13 +1862,13 @@ |
default_search_engine ? default_search_engine->search_engine_type() : |
SEARCH_ENGINE_OTHER; |
// Record the search engine chosen. |
- if (master_prefs.run_search_engine_experiment) { |
+ if (master_prefs_->run_search_engine_experiment) { |
UMA_HISTOGRAM_ENUMERATION( |
"Chrome.SearchSelectExperiment", |
search_engine_type, |
SEARCH_ENGINE_MAX); |
// If the selection has been randomized, also record the winner by slot. |
- if (master_prefs.randomize_search_engine_experiment) { |
+ if (master_prefs_->randomize_search_engine_experiment) { |
size_t engine_pos = url_service->GetSearchEngineDialogSlot(); |
if (engine_pos < 4) { |
std::string experiment_type = "Chrome.SearchSelectExperimentSlot"; |
@@ -1902,23 +1894,40 @@ |
// Some tests don't set parameters.ui_task, so they started translate |
// language fetch that was never completed so we need to cleanup here |
// otherwise it will be done by the destructor in a wrong thread. |
- if (parameters().ui_task == NULL && translate_manager != NULL) |
- translate_manager->CleanupPendingUlrFetcher(); |
+ if (parameters().ui_task == NULL && translate_manager_ != NULL) |
tony
2011/09/08 17:21:04
Do we need to make a member variable for translate
jam
2011/09/08 17:43:01
I had done this so that we don't end up constructi
|
+ translate_manager_->CleanupPendingUlrFetcher(); |
+ process_singleton_->Cleanup(); |
- process_singleton.Cleanup(); |
- |
// Stop all tasks that might run on WatchDogThread. |
ThreadWatcherList::StopWatchingAll(); |
- metrics->Stop(); |
+ metrics_->Stop(); |
tony
2011/09/08 17:21:04
It looks like this is g_browser_process->metrics_s
jam
2011/09/08 17:43:01
Done.
|
// browser_shutdown takes care of deleting browser_process, so we need to |
// release it. |
- ignore_result(browser_process.release()); |
+ ignore_result(browser_process_.release()); |
browser_shutdown::Shutdown(); |
+ master_prefs_.reset(); |
+ process_singleton_.reset(); |
+} |
- return result_code; |
+void ChromeBrowserMainParts::ToolkitInitialized() { |
+#if defined(TOOLKIT_VIEWS) |
+ // The delegate needs to be set before any UI is created so that windows |
+ // display the correct icon. |
+ if (!views::ViewsDelegate::views_delegate) |
+ views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; |
+ |
+ // TODO(beng): Move to WidgetImpl and implement on Windows too! |
+ if (parameters().command_line_.HasSwitch(switches::kDebugViewsPaint)) |
+ views::Widget::SetDebugPaintEnabled(true); |
+#endif |
+ |
+#if defined(OS_WIN) |
+ gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; |
+ gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; |
+#endif |
} |
// This code is specific to the Windows-only PreReadExperiment field-trial. |