| Index: chrome/browser/chrome_browser_main.cc
|
| ===================================================================
|
| --- chrome/browser/chrome_browser_main.cc (revision 111697)
|
| +++ chrome/browser/chrome_browser_main.cc (working copy)
|
| @@ -76,6 +76,7 @@
|
| #include "chrome/browser/shell_integration.h"
|
| #include "chrome/browser/translate/translate_manager.h"
|
| #include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/browser_init.h"
|
| #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
|
| #include "chrome/browser/web_resource/gpu_blacklist_updater.h"
|
| #include "chrome/common/child_process_logging.h"
|
| @@ -310,6 +311,23 @@
|
| net::URLRequestThrottlerManager::GetInstance()->set_net_log(net_log);
|
| }
|
|
|
| +// Creates key child threads. We need to do this explicitly since
|
| +// BrowserThread::PostTask silently deletes a posted task if the target message
|
| +// loop isn't created.
|
| +void CreateChildThreads(BrowserProcessImpl* process) {
|
| + process->db_thread();
|
| + process->file_thread();
|
| + process->process_launcher_thread();
|
| + process->cache_thread();
|
| + process->io_thread();
|
| +#if defined(OS_CHROMEOS)
|
| + process->web_socket_proxy_thread();
|
| +#endif
|
| + // Create watchdog thread after creating all other threads because it will
|
| + // watch the other threads and they must be running.
|
| + process->watchdog_thread();
|
| +}
|
| +
|
| // Returns the new local state object, guaranteed non-NULL.
|
| PrefService* InitializeLocalState(const CommandLine& parsed_command_line,
|
| bool is_first_run) {
|
| @@ -669,12 +687,7 @@
|
| translate_manager_(NULL),
|
| profile_(NULL),
|
| run_message_loop_(true),
|
| - notify_result_(ProcessSingleton::PROCESS_NONE),
|
| - is_first_run_(false),
|
| - first_run_ui_bypass_(false),
|
| - metrics_(NULL),
|
| - local_state_(NULL),
|
| - restart_last_session_(false) {
|
| + notify_result_(ProcessSingleton::PROCESS_NONE) {
|
| // If we're running tests (ui_task is non-null).
|
| if (parameters.ui_task)
|
| browser_defaults::enable_help_app = false;
|
| @@ -1194,55 +1207,31 @@
|
| chrome_extra_parts_[i]->PostMainMessageLoopStart();
|
| }
|
|
|
| -void ChromeBrowserMainParts::PreCreateThreads() {
|
| - result_code_ = PreCreateThreadsImpl();
|
| +void ChromeBrowserMainParts::PreMainMessageLoopRun() {
|
| + result_code_ = PreMainMessageLoopRunImpl();
|
|
|
| for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
| chrome_extra_parts_[i]->PreMainMessageLoopRun();
|
| }
|
|
|
| -void ChromeBrowserMainParts::PreStartThread(
|
| - content::BrowserThread::ID thread_id) {
|
| - browser_process_->PreStartThread(thread_id);
|
| -}
|
| -
|
| -void ChromeBrowserMainParts::PostStartThread(
|
| - content::BrowserThread::ID thread_id) {
|
| - browser_process_->PostStartThread(thread_id);
|
| - switch (thread_id) {
|
| - case BrowserThread::FILE:
|
| - // Now the command line has been mutated based on about:flags,
|
| - // and the file thread has been started, we can set up metrics
|
| - // and initialize field trials.
|
| - metrics_ = SetupMetricsAndFieldTrials(local_state_);
|
| - break;
|
| -
|
| - default:
|
| - break;
|
| - }
|
| -}
|
| -
|
| -void ChromeBrowserMainParts::PreMainMessageLoopRun() {
|
| - result_code_ = PreMainMessageLoopRunImpl();
|
| -}
|
| -
|
| -int ChromeBrowserMainParts::PreCreateThreadsImpl() {
|
| +int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
|
| run_message_loop_ = false;
|
| + FilePath user_data_dir;
|
| #if defined(OS_WIN)
|
| - PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_);
|
| + PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
|
| #else
|
| // Getting the user data dir can fail if the directory isn't
|
| // creatable, for example; on Windows in code below we bring up a
|
| // dialog prompting the user to pick a different directory.
|
| // However, ProcessSingleton needs a real user_data_dir on Mac/Linux,
|
| // so it's better to fail here than fail mysteriously elsewhere.
|
| - CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
|
| + CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
|
| << "Must be able to get user data directory!";
|
| #endif
|
|
|
| - process_singleton_.reset(new ProcessSingleton(user_data_dir_));
|
| + process_singleton_.reset(new ProcessSingleton(user_data_dir));
|
|
|
| - is_first_run_ = FirstRun::IsChromeFirstRun() ||
|
| + bool is_first_run = FirstRun::IsChromeFirstRun() ||
|
| parsed_command_line().HasSwitch(switches::kFirstRun);
|
|
|
| if (parsed_command_line().HasSwitch(switches::kImport) ||
|
| @@ -1251,7 +1240,7 @@
|
| // 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()));
|
| - is_first_run_ = false;
|
| + is_first_run = false;
|
| } else {
|
| browser_process_.reset(new BrowserProcessImpl(parsed_command_line()));
|
| }
|
| @@ -1269,8 +1258,8 @@
|
| // tabs.
|
| g_browser_process->tab_closeable_state_watcher();
|
|
|
| - local_state_ = InitializeLocalState(parsed_command_line(),
|
| - is_first_run_);
|
| + PrefService* local_state = InitializeLocalState(parsed_command_line(),
|
| + is_first_run);
|
|
|
| #if defined(USE_LINUX_BREAKPAD)
|
| // Needs to be called after we have chrome::DIR_USER_DATA and
|
| @@ -1278,7 +1267,7 @@
|
| g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE,
|
| new GetLinuxDistroTask());
|
|
|
| - if (IsCrashReportingEnabled(local_state_))
|
| + if (IsCrashReportingEnabled(local_state))
|
| InitCrashReporter();
|
| #endif
|
|
|
| @@ -1294,7 +1283,7 @@
|
| g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride());
|
| #else
|
| const std::string locale =
|
| - local_state_->GetString(prefs::kApplicationLocale);
|
| + local_state->GetString(prefs::kApplicationLocale);
|
| // On a POSIX OS other than ChromeOS, the parameter that is passed to the
|
| // method InitSharedInstance is ignored.
|
| const std::string loaded_locale =
|
| @@ -1354,19 +1343,19 @@
|
| // browser's profile_manager object is created, but after ResourceBundle
|
| // is initialized.
|
| master_prefs_.reset(new FirstRun::MasterPrefs);
|
| - 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_.get());
|
| + 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_.get());
|
| AddFirstRunNewTabs(browser_init_.get(), master_prefs_->new_tabs);
|
|
|
| // If we are running in App mode, we do not want to show the importer
|
| // (first run) UI.
|
| - if (!first_run_ui_bypass_ &&
|
| + if (!first_run_ui_bypass &&
|
| (parsed_command_line().HasSwitch(switches::kApp) ||
|
| parsed_command_line().HasSwitch(switches::kAppId) ||
|
| parsed_command_line().HasSwitch(switches::kNoFirstRun)))
|
| - first_run_ui_bypass_ = true;
|
| + first_run_ui_bypass = true;
|
| }
|
|
|
| // TODO(viettrungluu): why don't we run this earlier?
|
| @@ -1375,17 +1364,17 @@
|
|
|
| // Enable print preview once for supported platforms.
|
| #if defined(GOOGLE_CHROME_BUILD)
|
| - local_state_->RegisterBooleanPref(prefs::kPrintingPrintPreviewEnabledOnce,
|
| + local_state->RegisterBooleanPref(prefs::kPrintingPrintPreviewEnabledOnce,
|
| false,
|
| PrefService::UNSYNCABLE_PREF);
|
| - if (!local_state_->GetBoolean(prefs::kPrintingPrintPreviewEnabledOnce)) {
|
| - local_state_->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true);
|
| - about_flags::SetExperimentEnabled(local_state_, "print-preview", true);
|
| + if (!local_state->GetBoolean(prefs::kPrintingPrintPreviewEnabledOnce)) {
|
| + local_state->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true);
|
| + about_flags::SetExperimentEnabled(local_state, "print-preview", true);
|
| }
|
| #endif
|
|
|
| // Convert active labs into switches. Modifies the current command line.
|
| - about_flags::ConvertFlagsToSwitches(local_state_,
|
| + about_flags::ConvertFlagsToSwitches(local_state,
|
| CommandLine::ForCurrentProcess());
|
|
|
| // Reset the command line in the crash report details, since we may have
|
| @@ -1402,6 +1391,10 @@
|
| histogram_synchronizer_ = new HistogramSynchronizer();
|
| tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer();
|
|
|
| + // Now the command line has been mutated based on about:flags, we can
|
| + // set up metrics and initialize field trials.
|
| + MetricsService* metrics = SetupMetricsAndFieldTrials(local_state);
|
| +
|
| #if defined(USE_WEBKIT_COMPOSITOR)
|
| // We need to ensure WebKit has been initialized before we start the WebKit
|
| // compositor. This is done by the ResourceDispatcherHost on creation.
|
| @@ -1412,9 +1405,9 @@
|
| // for the uninstall metrics if this is our first run. This only actually
|
| // gets used if the user has metrics reporting enabled at uninstall time.
|
| int64 install_date =
|
| - local_state_->GetInt64(prefs::kUninstallMetricsInstallDate);
|
| + local_state->GetInt64(prefs::kUninstallMetricsInstallDate);
|
| if (install_date == 0) {
|
| - local_state_->SetInt64(prefs::kUninstallMetricsInstallDate,
|
| + local_state->SetInt64(prefs::kUninstallMetricsInstallDate,
|
| base::Time::Now().ToTimeT());
|
| }
|
|
|
| @@ -1428,14 +1421,8 @@
|
| SecKeychainAddCallback(&KeychainCallback, 0, NULL);
|
| #endif
|
|
|
| - return content::RESULT_CODE_NORMAL_EXIT;
|
| -}
|
| + CreateChildThreads(browser_process_.get());
|
|
|
| -int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
|
| - // Create watchdog thread after creating all other threads because it will
|
| - // watch the other threads and they must be running.
|
| - browser_process_->watchdog_thread();
|
| -
|
| #if defined(OS_CHROMEOS)
|
| // Now that the file thread exists we can record our stats.
|
| chromeos::BootTimesLoader::Get()->RecordChromeMainStats();
|
| @@ -1584,13 +1571,13 @@
|
| }
|
| #endif
|
|
|
| - if (is_first_run_) {
|
| + if (is_first_run) {
|
| // Warn the ProfileManager that an import process will run, possibly
|
| // locking the WebDataService directory of the next Profile created.
|
| g_browser_process->profile_manager()->SetWillImport();
|
| }
|
|
|
| - profile_ = CreateProfile(parameters(), user_data_dir_, parsed_command_line());
|
| + profile_ = CreateProfile(parameters(), user_data_dir, parsed_command_line());
|
| if (!profile_)
|
| return content::RESULT_CODE_NORMAL_EXIT;
|
|
|
| @@ -1674,8 +1661,8 @@
|
| // Note that this be done _after_ the PrefService is initialized and all
|
| // preferences are registered, since some of the code that the importer
|
| // touches reads preferences.
|
| - if (is_first_run_) {
|
| - if (!first_run_ui_bypass_) {
|
| + if (is_first_run) {
|
| + if (!first_run_ui_bypass) {
|
| FirstRun::AutoImport(profile_,
|
| master_prefs_->homepage_defined,
|
| master_prefs_->do_import_items,
|
| @@ -1691,9 +1678,9 @@
|
| // If stats reporting was turned on by the first run dialog then toggle
|
| // the pref.
|
| if (GoogleUpdateSettings::GetCollectStatsConsent())
|
| - local_state_->SetBoolean(prefs::kMetricsReportingEnabled, true);
|
| + local_state->SetBoolean(prefs::kMetricsReportingEnabled, true);
|
| #endif // OS_POSIX
|
| - } // if (!first_run_ui_bypass_)
|
| + } // if (!first_run_ui_bypass)
|
|
|
| Browser::SetNewHomePagePrefs(profile_->GetPrefs());
|
| g_browser_process->profile_manager()->OnImportFinished(profile_);
|
| @@ -1812,8 +1799,8 @@
|
| #endif
|
|
|
| HandleTestParameters(parsed_command_line());
|
| - RecordBreakpadStatusUMA(metrics_);
|
| - about_flags::RecordUMAStatistics(local_state_);
|
| + RecordBreakpadStatusUMA(metrics);
|
| + about_flags::RecordUMAStatistics(local_state);
|
| LanguageUsageMetrics::RecordAcceptLanguages(
|
| profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
|
| LanguageUsageMetrics::RecordApplicationLanguage(
|
| @@ -1824,7 +1811,7 @@
|
| #endif
|
|
|
| #if defined(OS_CHROMEOS)
|
| - metrics_->StartExternalMetrics();
|
| + metrics->StartExternalMetrics();
|
|
|
| // Initialize the audio handler on ChromeOS.
|
| chromeos::AudioHandler::Initialize();
|
| @@ -1857,7 +1844,7 @@
|
| #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.
|
| - 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
|
| @@ -1913,9 +1900,8 @@
|
|
|
| // We are in regular browser boot sequence. Open initial tabs and enter the
|
| // main message loop.
|
| - int result_code;
|
| if (browser_init_->Start(parsed_command_line(), FilePath(), profile_,
|
| - &result_code)) {
|
| + &result_code_)) {
|
| #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
|
| // Initialize autoupdate timer. Timer callback costs basically nothing
|
| // when browser is not in persistent mode, so it's OK to let it ride on
|
| @@ -2082,23 +2068,10 @@
|
| chromeos::AudioHandler::Shutdown();
|
| #endif
|
|
|
| - restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop();
|
| - browser_process_->StartTearDown();
|
| -}
|
| -
|
| -void ChromeBrowserMainParts::PreStopThread(BrowserThread::ID identifier) {
|
| - browser_process_->PreStopThread(identifier);
|
| -}
|
| -
|
| -void ChromeBrowserMainParts::PostStopThread(BrowserThread::ID identifier) {
|
| - browser_process_->PostStopThread(identifier);
|
| -}
|
| -
|
| -void ChromeBrowserMainParts::PostDestroyThreads() {
|
| // browser_shutdown takes care of deleting browser_process, so we need to
|
| // release it.
|
| ignore_result(browser_process_.release());
|
| - browser_shutdown::ShutdownPostThreadsStop(restart_last_session_);
|
| + browser_shutdown::Shutdown();
|
| master_prefs_.reset();
|
| process_singleton_.reset();
|
|
|
|
|