This source file includes following definitions.
- HandleTestParameters
- AddFirstRunNewTabs
- InitializeLocalState
- CreatePrimaryProfile
- KeychainCallback
- RegisterComponentsForUpdate
- ProcessSingletonNotificationCallback
- LaunchDevToolsHandlerIfNeeded
- Observe
- restart_last_session_
- SetupMetricsAndFieldTrials
- StartMetricsRecording
- IsMetricsReportingEnabled
- RecordBrowserStartupTime
- RelaunchChromeBrowserWithNewCommandLineIfNeeded
- PreEarlyInitialization
- PostEarlyInitialization
- ToolkitInitialized
- PreMainMessageLoopStart
- PostMainMessageLoopStart
- PreCreateThreads
- PreCreateThreadsImpl
- PreMainMessageLoopRun
- PreProfileInit
- PostProfileInit
- PreBrowserStart
- PostBrowserStart
- PreMainMessageLoopRunImpl
- MainMessageLoopRun
- PostMainMessageLoopRun
- PostDestroyThreads
- AddParts
#include "chrome/browser/chrome_browser_main.h"
#if defined(TOOLKIT_GTK)
#include <gtk/gtk.h>
#endif
#include <set>
#include <string>
#include <vector>
#include "base/at_exit.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/debug/crash_logging.h"
#include "base/debug/debugger.h"
#include "base/debug/trace_event.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/prefs/json_pref_store.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/pref_value_store.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/process/process_info.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/sys_info.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/about_flags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_impl.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/chrome_browser_main_extra_parts.h"
#include "chrome/browser/component_updater/component_updater_service.h"
#include "chrome/browser/component_updater/flash_component_installer.h"
#include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
#include "chrome/browser/component_updater/recovery_component_installer.h"
#include "chrome/browser/component_updater/swiftshader_component_installer.h"
#include "chrome/browser/component_updater/widevine_cdm_component_installer.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/extension_protocols.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/startup_helper.h"
#include "chrome/browser/feedback/feedback_profile_observer.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/first_run/upgrade_util.h"
#include "chrome/browser/google/google_search_counter.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/gpu/gl_string_manager.h"
#include "chrome/browser/jankometer.h"
#include "chrome/browser/media/media_capture_devices_dispatcher.h"
#include "chrome/browser/metrics/field_trial_synchronizer.h"
#include "chrome/browser/metrics/metrics_log.h"
#include "chrome/browser/metrics/metrics_service.h"
#include "chrome/browser/metrics/thread_watcher.h"
#include "chrome/browser/metrics/tracking_synchronizer.h"
#include "chrome/browser/metrics/variations/variations_http_header_provider.h"
#include "chrome/browser/metrics/variations/variations_service.h"
#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/crl_set_fetcher.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/notifications/desktop_notification_service_factory.h"
#include "chrome/browser/performance_monitor/performance_monitor.h"
#include "chrome/browser/performance_monitor/startup_timer.h"
#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/pref_service_flags_storage.h"
#include "chrome/browser/prefs/chrome_pref_service_factory.h"
#include "chrome/browser/prefs/command_line_pref_store.h"
#include "chrome/browser/prefs/pref_metrics_service.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
#include "chrome/browser/process_singleton.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/three_d_api_observer.h"
#include "chrome/browser/translate/translate_service.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/startup/bad_flags_prompt.h"
#include "chrome/browser/ui/startup/default_browser_prompt.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/uma_browsing_activity_observer.h"
#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_result_codes.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/crash_keys.h"
#include "chrome/common/env_vars.h"
#include "chrome/common/logging_chrome.h"
#include "chrome/common/net/net_resource_provider.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/profile_management_switches.h"
#include "chrome/common/profiling.h"
#include "chrome/installer/util/google_update_settings.h"
#include "components/language_usage_metrics/language_usage_metrics.h"
#include "components/nacl/browser/nacl_browser.h"
#include "components/nacl/browser/nacl_process_host.h"
#include "components/rappor/rappor_service.h"
#include "components/startup_metric_utils/startup_metric_utils.h"
#include "components/translate/core/browser/translate_download_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/site_instance.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
#include "extensions/browser/extension_system.h"
#include "grit/app_locale_settings.h"
#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/platform_locale_settings.h"
#include "net/base/net_module.h"
#include "net/base/sdch_manager.h"
#include "net/cookies/cookie_monster.h"
#include "net/http/http_network_layer.h"
#include "net/http/http_stream_factory.h"
#include "net/url_request/url_request.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#include "chrome/browser/first_run/upgrade_util_linux.h"
#include "chrome/browser/sxs_linux.h"
#endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/settings/cros_settings_names.h"
#endif
#if defined(OS_WIN)
#include "base/environment.h"
#include "base/win/windows_version.h"
#include "chrome/browser/browser_util_win.h"
#include "chrome/browser/chrome_browser_main_win.h"
#include "chrome/browser/first_run/try_chrome_dialog_view.h"
#include "chrome/browser/first_run/upgrade_util_win.h"
#include "chrome/browser/ui/network_profile_bubble.h"
#include "chrome/common/net/url_fixer_upper.h"
#include "chrome/installer/util/helper.h"
#include "chrome/installer/util/install_util.h"
#include "chrome/installer/util/shell_util.h"
#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util_win.h"
#include "ui/gfx/win/dpi.h"
#endif
#if defined(OS_MACOSX)
#include <Security/Security.h>
#include "base/mac/scoped_nsautorelease_pool.h"
#include "chrome/browser/mac/keystone_glue.h"
#endif
#if defined(ENABLE_FULL_PRINTING) && !defined(OFFICIAL_BUILD)
#include "printing/printed_document.h"
#endif
#if defined(ENABLE_RLZ)
#include "chrome/browser/rlz/rlz.h"
#endif
#if defined(ENABLE_WEBRTC)
#include "chrome/browser/media/webrtc_log_util.h"
#endif
#if defined(USE_AURA)
#include "ui/aura/env.h"
#endif
using content::BrowserThread;
namespace {
void HandleTestParameters(const CommandLine& command_line) {
if (command_line.HasSwitch(switches::kBrowserAssertTest)) {
DCHECK(false);
}
if (command_line.HasSwitch(switches::kBrowserCrashTest)) {
int* bad_pointer = NULL;
*bad_pointer = 0;
}
}
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator,
const std::vector<GURL>& new_tabs) {
for (std::vector<GURL>::const_iterator it = new_tabs.begin();
it != new_tabs.end(); ++it) {
if (it->is_valid())
browser_creator->AddFirstRunTab(*it);
}
}
#endif
PrefService* InitializeLocalState(
base::SequencedTaskRunner* local_state_task_runner,
const CommandLine& parsed_command_line) {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState")
base::FilePath local_state_path;
PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
bool local_state_file_exists = base::PathExists(local_state_path);
PrefService* local_state = g_browser_process->local_state();
DCHECK(local_state);
#if defined(OS_WIN)
if (first_run::IsChromeFirstRun()) {
base::string16 install_lang;
if (GoogleUpdateSettings::GetLanguage(&install_lang)) {
local_state->SetString(prefs::kApplicationLocale,
base::UTF16ToASCII(install_lang));
}
}
#endif
if (!local_state_file_exists &&
parsed_command_line.HasSwitch(switches::kParentProfile)) {
base::FilePath parent_profile =
parsed_command_line.GetSwitchValuePath(switches::kParentProfile);
scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple();
scoped_ptr<PrefService> parent_local_state(
chrome_prefs::CreateLocalState(
parent_profile,
local_state_task_runner,
g_browser_process->policy_service(),
registry,
false));
registry->RegisterStringPref(prefs::kApplicationLocale, std::string());
local_state->SetString(
prefs::kApplicationLocale,
parent_local_state->GetString(prefs::kApplicationLocale));
}
#if defined(OS_CHROMEOS)
if (parsed_command_line.HasSwitch(chromeos::switches::kLoginManager)) {
std::string owner_locale = local_state->GetString(prefs::kOwnerLocale);
if (!owner_locale.empty() &&
local_state->GetString(prefs::kApplicationLocale) != owner_locale &&
!local_state->IsManagedPreference(prefs::kApplicationLocale)) {
local_state->SetString(prefs::kApplicationLocale, owner_locale);
}
}
#endif
return local_state;
}
Profile* CreatePrimaryProfile(const content::MainFunctionParams& parameters,
const base::FilePath& user_data_dir,
const CommandLine& parsed_command_line) {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::CreateProfile")
base::Time start = base::Time::Now();
if (profiles::IsMultipleProfilesEnabled() &&
parsed_command_line.HasSwitch(switches::kProfileDirectory)) {
g_browser_process->local_state()->SetString(prefs::kProfileLastUsed,
parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory));
ListPrefUpdate update(g_browser_process->local_state(),
prefs::kProfilesLastActive);
base::ListValue* profile_list = update.Get();
profile_list->Clear();
}
Profile* profile = NULL;
#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
DCHECK_EQ(user_data_dir.value(),
g_browser_process->profile_manager()->user_data_dir().value());
profile = ProfileManager::GetActiveUserProfile();
#else
base::FilePath profile_path =
GetStartupProfilePath(user_data_dir, parsed_command_line);
profile = g_browser_process->profile_manager()->GetProfile(
profile_path);
if (switches::IsNewProfileManagement() && !profile->IsGuestSession()) {
ProfileInfoCache& cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
size_t profile_index = cache.GetIndexOfProfileWithPath(profile_path);
if (cache.ProfileIsSigninRequiredAtIndex(profile_index))
profile = g_browser_process->profile_manager()->GetProfile(
ProfileManager::GetGuestProfilePath());
}
#endif
if (profile) {
UMA_HISTOGRAM_LONG_TIMES(
"Startup.CreateFirstProfile", base::Time::Now() - start);
return profile;
}
#if !defined(OS_WIN)
CHECK(profile) << "Cannot get default profile.";
#endif
return NULL;
}
#if defined(OS_MACOSX)
OSStatus KeychainCallback(SecKeychainEvent keychain_event,
SecKeychainCallbackInfo* info, void* context) {
return noErr;
}
#endif
void RegisterComponentsForUpdate(const CommandLine& command_line) {
component_updater::ComponentUpdateService* cus =
g_browser_process->component_updater();
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
RegisterRecoveryComponent(cus, g_browser_process->local_state());
RegisterPepperFlashComponent(cus);
RegisterSwiftShaderComponent(cus);
#endif
#if !defined(OS_ANDROID)
g_browser_process->pnacl_component_installer()->RegisterPnaclComponent(
cus, command_line);
#endif
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
RegisterWidevineCdmComponent(cus);
#endif
#if !defined(OS_CHROMEOS)
if (!command_line.HasSwitch(switches::kDisableCRLSets))
g_browser_process->crl_set_fetcher()->StartInitialLoad(cus);
#endif
cus->Start();
}
#if !defined(OS_ANDROID)
bool ProcessSingletonNotificationCallback(
const CommandLine& command_line,
const base::FilePath& current_directory) {
if (!g_browser_process || g_browser_process->IsShuttingDown())
return false;
if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) {
std::string start_time_string =
command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime);
int64 remote_start_time;
if (base::StringToInt64(start_time_string, &remote_start_time)) {
base::TimeDelta elapsed =
base::Time::Now() - base::Time::FromInternalValue(remote_start_time);
if (command_line.HasSwitch(switches::kFastStart)) {
UMA_HISTOGRAM_LONG_TIMES(
"Startup.WarmStartTimeFromRemoteProcessStartFast", elapsed);
} else {
UMA_HISTOGRAM_LONG_TIMES(
"Startup.WarmStartTimeFromRemoteProcessStart", elapsed);
}
}
}
g_browser_process->platform_part()->PlatformSpecificCommandLineProcessing(
command_line);
if (command_line.HasSwitch(switches::kUninstallExtension)) {
DCHECK(!command_line.HasSwitch(switches::kProfileDirectory));
Profile* profile = ProfileManager::GetLastUsedProfile();
if (!profile) {
NOTREACHED();
return true;
}
extensions::StartupHelper extension_startup_helper;
extension_startup_helper.UninstallExtension(command_line, profile);
return true;
}
base::FilePath user_data_dir =
g_browser_process->profile_manager()->user_data_dir();
base::FilePath startup_profile_dir =
GetStartupProfilePath(user_data_dir, command_line);
StartupBrowserCreator::ProcessCommandLineAlreadyRunning(
command_line, current_directory, startup_profile_dir);
return true;
}
#endif
void LaunchDevToolsHandlerIfNeeded(const CommandLine& command_line) {
if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) {
std::string port_str =
command_line.GetSwitchValueASCII(::switches::kRemoteDebuggingPort);
int port;
if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) {
g_browser_process->CreateDevToolsHttpProtocolHandler(
chrome::HOST_DESKTOP_TYPE_NATIVE,
"127.0.0.1",
port);
} else {
DLOG(WARNING) << "Invalid http debugger port number " << port;
}
}
}
class LoadCompleteListener : public content::NotificationObserver {
public:
LoadCompleteListener() {
registrar_.Add(this,
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
}
virtual ~LoadCompleteListener() {}
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
DCHECK_EQ(content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, type);
startup_metric_utils::OnInitialPageLoadComplete();
delete this;
}
private:
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(LoadCompleteListener);
};
}
namespace chrome_browser {
#if defined(OS_WIN)
const char kMissingLocaleDataTitle[] = "Missing File Error";
#endif
#if defined(OS_WIN) || defined(TOOLKIT_GTK)
const char kMissingLocaleDataMessage[] =
"Unable to find locale data files. Please reinstall.";
#endif
}
bool ChromeBrowserMainParts::disable_enforcing_cookie_policies_for_tests_ =
false;
ChromeBrowserMainParts::ChromeBrowserMainParts(
const content::MainFunctionParams& parameters)
: parameters_(parameters),
parsed_command_line_(parameters.command_line),
result_code_(content::RESULT_CODE_NORMAL_EXIT),
startup_watcher_(new StartupTimeBomb()),
shutdown_watcher_(new ShutdownWatcherHelper()),
startup_timer_(new performance_monitor::StartupTimer()),
browser_field_trials_(parameters.command_line),
profile_(NULL),
run_message_loop_(true),
notify_result_(ProcessSingleton::PROCESS_NONE),
local_state_(NULL),
restart_last_session_(false) {
if (parameters.ui_task)
browser_defaults::enable_help_app = false;
if (!disable_enforcing_cookie_policies_for_tests_)
net::URLRequest::SetDefaultCookiePolicyToBlock();
}
ChromeBrowserMainParts::~ChromeBrowserMainParts() {
for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i)
delete chrome_extra_parts_[i];
chrome_extra_parts_.clear();
}
void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::SetupMetricsAndFieldTrials");
#if defined(ARCH_CPU_64_BITS)
MetricsLog::set_version_extension("-64");
#endif
MetricsService* metrics = browser_process_->metrics_service();
MetricsService::ReportingState reporting_state =
IsMetricsReportingEnabled() ? MetricsService::REPORTING_ENABLED :
MetricsService::REPORTING_DISABLED;
if (reporting_state == MetricsService::REPORTING_ENABLED)
metrics->ForceClientIdCreation();
field_trial_list_.reset(
new base::FieldTrialList(
metrics->CreateEntropyProvider(reporting_state).release()));
const CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kEnableBenchmarking))
base::FieldTrial::EnableBenchmarking();
if (command_line->HasSwitch(switches::kForceFieldTrials)) {
std::set<std::string> unforceable_field_trials;
#if defined(OFFICIAL_BUILD)
unforceable_field_trials.insert("SettingsEnforcement");
#endif
bool result = base::FieldTrialList::CreateTrialsFromString(
command_line->GetSwitchValueASCII(switches::kForceFieldTrials),
base::FieldTrialList::DONT_ACTIVATE_TRIALS,
unforceable_field_trials);
CHECK(result) << "Invalid --" << switches::kForceFieldTrials
<< " list specified.";
}
if (command_line->HasSwitch(switches::kForceVariationIds)) {
chrome_variations::VariationsHttpHeaderProvider* provider =
chrome_variations::VariationsHttpHeaderProvider::GetInstance();
bool result = provider->SetDefaultVariationIds(
command_line->GetSwitchValueASCII(switches::kForceVariationIds));
CHECK(result) << "Invalid --" << switches::kForceVariationIds
<< " list specified.";
}
chrome_variations::VariationsService* variations_service =
browser_process_->variations_service();
if (variations_service)
variations_service->CreateTrialsFromSeed();
browser_field_trials_.SetupFieldTrials(local_state_);
field_trial_synchronizer_ = new FieldTrialSynchronizer();
metrics->InitializeMetricsRecordingState(reporting_state);
}
void ChromeBrowserMainParts::StartMetricsRecording() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording");
MetricsService* metrics = g_browser_process->metrics_service();
const bool only_do_metrics_recording =
parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) ||
parsed_command_line_.HasSwitch(switches::kEnableBenchmarking);
if (only_do_metrics_recording) {
metrics->StartRecordingForTests();
return;
}
metrics->CheckForClonedInstall();
if (IsMetricsReportingEnabled())
metrics->Start();
}
bool ChromeBrowserMainParts::IsMetricsReportingEnabled() {
const CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kEnableMetricsReportingForTesting))
return true;
bool enabled = false;
if (command_line->HasSwitch(switches::kForceFieldTrials))
return false;
#if defined(GOOGLE_CHROME_BUILD)
#if defined(OS_CHROMEOS)
chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
&enabled);
#else
enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled);
#endif
#endif
return enabled;
}
void ChromeBrowserMainParts::RecordBrowserStartupTime() {
if (startup_metric_utils::WasNonBrowserUIDisplayed())
return;
#if defined(OS_ANDROID)
bool is_first_run = false;
#else
bool is_first_run = first_run::IsChromeFirstRun();
#endif
#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
const base::Time process_creation_time =
base::CurrentProcessInfo::CreationTime();
if (!is_first_run && !process_creation_time.is_null()) {
base::TimeDelta delay = base::Time::Now() - process_creation_time;
UMA_HISTOGRAM_LONG_TIMES_100("Startup.BrowserMessageLoopStartTime", delay);
}
#endif
startup_metric_utils::OnBrowserStartupComplete(is_first_run);
new LoadCompleteListener();
}
#if defined(OS_WIN)
#define DLLEXPORT __declspec(dllexport)
extern "C" {
DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded();
}
DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
base::AtExitManager exit_manager;
upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded();
}
#endif
void ChromeBrowserMainParts::PreEarlyInitialization() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreEarlyInitialization");
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PreEarlyInitialization();
}
void ChromeBrowserMainParts::PostEarlyInitialization() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostEarlyInitialization");
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PostEarlyInitialization();
}
void ChromeBrowserMainParts::ToolkitInitialized() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::ToolkitInitialized");
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->ToolkitInitialized();
}
void ChromeBrowserMainParts::PreMainMessageLoopStart() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopStart");
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PreMainMessageLoopStart();
}
void ChromeBrowserMainParts::PostMainMessageLoopStart() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostMainMessageLoopStart");
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PostMainMessageLoopStart();
}
int ChromeBrowserMainParts::PreCreateThreads() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreCreateThreads");
result_code_ = PreCreateThreadsImpl();
if (result_code_ == content::RESULT_CODE_NORMAL_EXIT) {
#if !defined(OS_ANDROID)
DCHECK(master_prefs_.get());
DCHECK(browser_creator_.get());
#endif
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PreCreateThreads();
}
return result_code_;
}
int ChromeBrowserMainParts::PreCreateThreadsImpl() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreCreateThreadsImpl")
run_message_loop_ = false;
#if !defined(OS_ANDROID)
chrome::MaybeShowInvalidUserDataDirWarningDialog();
#endif
if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
return chrome::RESULT_CODE_MISSING_DATA;
MediaCaptureDevicesDispatcher::GetInstance();
#if !defined(OS_ANDROID)
process_singleton_.reset(new ChromeProcessSingleton(
user_data_dir_, base::Bind(&ProcessSingletonNotificationCallback)));
first_run::IsChromeFirstRun();
#endif
scoped_refptr<base::SequencedTaskRunner> local_state_task_runner =
JsonPrefStore::GetTaskRunnerForFile(
base::FilePath(chrome::kLocalStorePoolName),
BrowserThread::GetBlockingPool());
{
TRACE_EVENT0("startup",
"ChromeBrowserMainParts::PreCreateThreadsImpl:InitBrowswerProcessImpl");
browser_process_.reset(new BrowserProcessImpl(local_state_task_runner.get(),
parsed_command_line()));
}
if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) {
TRACE_EVENT0("startup",
"ChromeBrowserMainParts::PreCreateThreadsImpl:InitProfiling");
std::string flag =
parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling);
tracked_objects::ThreadData::Status status =
tracked_objects::ThreadData::PROFILING_ACTIVE;
if (flag.compare("0") != 0)
status = tracked_objects::ThreadData::DEACTIVATED;
else if (flag.compare("child") != 0)
status = tracked_objects::ThreadData::PROFILING_CHILDREN_ACTIVE;
tracked_objects::ThreadData::InitializeAndSetTrackingStatus(status);
}
if (parsed_command_line().HasSwitch(switches::kProfilingOutputFile)) {
tracking_objects_.set_output_file_path(
parsed_command_line().GetSwitchValuePath(
switches::kProfilingOutputFile));
}
local_state_ = InitializeLocalState(
local_state_task_runner.get(), parsed_command_line());
#if !defined(OS_ANDROID)
master_prefs_.reset(new first_run::MasterPrefs);
browser_creator_.reset(new StartupBrowserCreator);
chrome::UMABrowsingActivityObserver::Init();
#endif
#if !defined(OS_CHROMEOS)
{
TRACE_EVENT0("startup",
"ChromeBrowserMainParts::PreCreateThreadsImpl:ConvertFlags");
about_flags::PrefServiceFlagsStorage flags_storage_(
g_browser_process->local_state());
about_flags::ConvertFlagsToSwitches(&flags_storage_,
CommandLine::ForCurrentProcess(),
about_flags::kAddSentinels);
}
#endif
local_state_->UpdateCommandLinePrefStore(
new CommandLinePrefStore(CommandLine::ForCurrentProcess()));
crash_keys::SetSwitchesFromCommandLine(CommandLine::ForCurrentProcess());
#if defined(OS_MACOSX)
std::string locale =
parameters().ui_task ? "en-US" : l10n_util::GetLocaleOverride();
browser_process_->SetApplicationLocale(locale);
#else
const std::string locale =
local_state_->GetString(prefs::kApplicationLocale);
TRACE_EVENT_BEGIN0("startup",
"ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle");
const std::string loaded_locale =
ResourceBundle::InitSharedInstanceWithLocale(locale, NULL);
TRACE_EVENT_END0("startup",
"ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle");
if (loaded_locale.empty() &&
!parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) {
ShowMissingLocaleMessageBox();
return chrome::RESULT_CODE_MISSING_DATA;
}
CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
browser_process_->SetApplicationLocale(loaded_locale);
base::FilePath resources_pack_path;
PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
{
TRACE_EVENT0("startup",
"ChromeBrowserMainParts::PreCreateThreadsImpl:AddDataPack");
ResourceBundle::GetSharedInstance().AddDataPackFromPath(
resources_pack_path, ui::SCALE_FACTOR_NONE);
}
#endif
#if defined(TOOLKIT_GTK)
g_set_application_name(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str());
#endif
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
if (first_run::IsChromeFirstRun()) {
first_run::ProcessMasterPreferencesResult pmp_result =
first_run::ProcessMasterPreferences(user_data_dir_,
master_prefs_.get());
if (pmp_result == first_run::EULA_EXIT_NOW)
return chrome::RESULT_CODE_EULA_REFUSED;
if (!parsed_command_line().HasSwitch(switches::kApp) &&
!parsed_command_line().HasSwitch(switches::kAppId) &&
!parsed_command_line().HasSwitch(switches::kShowAppList)) {
AddFirstRunNewTabs(browser_creator_.get(), master_prefs_->new_tabs);
}
if (!master_prefs_->variations_seed.empty()) {
local_state_->SetString(prefs::kVariationsSeed,
master_prefs_->variations_seed);
if (!master_prefs_->variations_seed_signature.empty()) {
local_state_->SetString(prefs::kVariationsSeedSignature,
master_prefs_->variations_seed_signature);
}
local_state_->SetInt64(prefs::kVariationsSeedDate,
base::Time::Now().ToInternalValue());
}
if (!master_prefs_->suppress_default_browser_prompt_for_version.empty()) {
local_state_->SetString(
prefs::kBrowserSuppressDefaultBrowserPrompt,
master_prefs_->suppress_default_browser_prompt_for_version);
}
AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)->HandleFirstRun();
}
#endif
#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_MACOSX)
base::debug::SetCrashKeyValue(crash_keys::kChannel,
chrome::VersionInfo::GetVersionStringModifier());
#endif
tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer();
int64 install_date = local_state_->GetInt64(prefs::kInstallDate);
if (install_date == 0)
local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT());
#if defined(OS_MACOSX)
SecKeychainAddCallback(&KeychainCallback, 0, NULL);
#endif
#if defined(OS_CHROMEOS)
chromeos::CrosSettings::Initialize();
#endif
SetupMetricsAndFieldTrials();
browser_process_->PreCreateThreads();
return content::RESULT_CODE_NORMAL_EXIT;
}
void ChromeBrowserMainParts::PreMainMessageLoopRun() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRun");
result_code_ = PreMainMessageLoopRunImpl();
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PreMainMessageLoopRun();
}
void ChromeBrowserMainParts::PreProfileInit() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreProfileInit");
feedback::FeedbackProfileObserver::Initialize();
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PreProfileInit();
#if !defined(OS_ANDROID)
ProfileManager* profile_manager = g_browser_process->profile_manager();
ProfileInfoCache& profile_cache = profile_manager->GetProfileInfoCache();
size_t profiles_count = profile_cache.GetNumberOfProfiles();
std::vector<base::FilePath> profiles_to_delete;
for (size_t i = 0;i < profiles_count; ++i) {
if (profile_cache.ProfileIsEphemeralAtIndex(i))
profiles_to_delete.push_back(profile_cache.GetPathOfProfileAtIndex(i));
}
if (profiles_to_delete.size()) {
for (size_t i = 0;i < profiles_to_delete.size(); ++i) {
profile_manager->ScheduleProfileForDeletion(
profiles_to_delete[i], ProfileManager::CreateCallback());
}
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&ProfileManager::CleanUpStaleProfiles, profiles_to_delete));
}
#endif
}
void ChromeBrowserMainParts::PostProfileInit() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostProfileInit");
LaunchDevToolsHandlerIfNeeded(parsed_command_line());
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PostProfileInit();
}
void ChromeBrowserMainParts::PreBrowserStart() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreBrowserStart");
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PreBrowserStart();
three_d_observer_.reset(new ThreeDAPIObserver());
}
void ChromeBrowserMainParts::PostBrowserStart() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostBrowserStart");
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PostBrowserStart();
#if !defined(OS_ANDROID)
process_singleton_->Unlock();
#endif
#if defined(ENABLE_WEBRTC)
BrowserThread::PostDelayedTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&WebRtcLogUtil::DeleteOldWebRtcLogFilesForAllProfiles),
base::TimeDelta::FromMinutes(1));
#endif
}
int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl");
#if !defined(OS_ANDROID)
StartMetricsRecording();
#endif
if (IsMetricsReportingEnabled()) {
browser_process_->rappor_service()->Start(
browser_process_->local_state(),
browser_process_->system_request_context());
}
browser_process_->watchdog_thread();
browser_process_->PreMainMessageLoopRun();
browser_shutdown::ReadLastShutdownInfo();
#if defined(OS_WIN)
bool already_running = browser_util::IsBrowserAlreadyRunning();
if (parsed_command_line().HasSwitch(switches::kUninstall)) {
return DoUninstallTasks(already_running);
}
if (parsed_command_line().HasSwitch(switches::kHideIcons) ||
parsed_command_line().HasSwitch(switches::kShowIcons)) {
return ChromeBrowserMainPartsWin::HandleIconsCommands(
parsed_command_line_);
}
#endif
if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) {
return ShellIntegration::SetAsDefaultBrowser() ?
static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) :
static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED);
}
#if defined(USE_AURA)
aura::Env::CreateInstance();
#endif
#if !defined(OS_ANDROID)
if (parsed_command_line().HasSwitch(switches::kPackExtension)) {
extensions::StartupHelper extension_startup_helper;
if (extension_startup_helper.PackExtension(parsed_command_line()))
return content::RESULT_CODE_NORMAL_EXIT;
return chrome::RESULT_CODE_PACK_EXTENSION_ERROR;
}
bool pass_command_line = !parsed_command_line().HasSwitch(
switches::kCheckCloudPrintConnectorPolicy);
if (pass_command_line) {
notify_result_ = process_singleton_->NotifyOtherProcessOrCreate();
switch (notify_result_) {
case ProcessSingleton::PROCESS_NONE:
break;
case ProcessSingleton::PROCESS_NOTIFIED:
#if defined(OS_POSIX) && !defined(OS_MACOSX)
printf("%s\n", base::SysWideToNativeMB(base::UTF16ToWide(
l10n_util::GetStringUTF16(IDS_USED_EXISTING_BROWSER))).c_str());
#endif
if (parsed_command_line().HasSwitch(switches::kTestType))
return chrome::RESULT_CODE_NORMAL_EXIT_PROCESS_NOTIFIED;
return content::RESULT_CODE_NORMAL_EXIT;
case ProcessSingleton::PROFILE_IN_USE:
return chrome::RESULT_CODE_PROFILE_IN_USE;
case ProcessSingleton::LOCK_ERROR:
LOG(ERROR) << "Failed to create a ProcessSingleton for your profile "
"directory. This means that running multiple instances "
"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;
default:
NOTREACHED();
}
}
#endif
std::string try_chrome =
parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain);
if (!try_chrome.empty()) {
#if defined(OS_WIN)
int try_chrome_int;
base::StringToInt(try_chrome, &try_chrome_int);
TryChromeDialogView::Result answer = TryChromeDialogView::Show(
try_chrome_int,
base::Bind(&ChromeProcessSingleton::SetActiveModalDialog,
base::Unretained(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;
if (answer == TryChromeDialogView::TRY_CHROME_AS_DEFAULT) {
if (ShellIntegration::CanSetAsDefaultBrowser() ==
ShellIntegration::SET_DEFAULT_UNATTENDED)
ShellIntegration::SetAsDefaultBrowser();
}
#else
return content::RESULT_CODE_NORMAL_EXIT;
#endif
}
#if defined(OS_WIN)
if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line()))
return content::RESULT_CODE_NORMAL_EXIT;
if (ChromeBrowserMainPartsWin::CheckMachineLevelInstall())
return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS;
#endif
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
if (sxs_linux::ShouldMigrateUserDataDir())
return sxs_linux::MigrateUserDataDir();
#endif
PreProfileInit();
MetricsService::SetExecutionPhase(MetricsService::CREATE_PROFILE);
profile_ = CreatePrimaryProfile(parameters(),
user_data_dir_,
parsed_command_line());
if (!profile_)
return content::RESULT_CODE_NORMAL_EXIT;
#if !defined(OS_ANDROID)
first_run::CreateSentinelIfNeeded();
#endif
#if defined(ENABLE_BACKGROUND)
browser_process_->profile_manager()->AutoloadProfiles();
#endif
TranslateService::Initialize();
content::WebUIControllerFactory::RegisterFactory(
ChromeWebUIControllerFactory::GetInstance());
#if !defined(DISABLE_NACL)
NaClBrowserDelegateImpl* delegate = new NaClBrowserDelegateImpl(
extensions::ExtensionSystem::Get(profile_)->info_map());
nacl::NaClBrowser::SetDelegate(delegate);
#endif
PostProfileInit();
if (g_browser_process->gl_string_manager())
g_browser_process->gl_string_manager()->Initialize();
g_browser_process->gpu_mode_manager();
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
if (first_run::IsChromeFirstRun()) {
first_run::AutoImport(profile_,
master_prefs_->homepage_defined,
master_prefs_->do_import_items,
master_prefs_->dont_import_items,
master_prefs_->import_bookmarks_path);
first_run::DoPostImportTasks(profile_,
master_prefs_->make_chrome_default_for_user);
if (!master_prefs_->suppress_first_run_default_browser_prompt) {
browser_creator_->set_show_main_browser_window(
!chrome::ShowFirstRunDefaultBrowserPrompt(profile_));
} else {
browser_creator_->set_is_default_browser_dialog_suppressed(true);
}
}
#endif
#if defined(OS_WIN)
ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment(
parsed_command_line());
if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
ChromeBrowserMainPartsWin::RegisterApplicationRestart(
parsed_command_line());
}
if (NetworkProfileBubble::ShouldCheckNetworkProfile(profile_)) {
content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
base::Bind(&NetworkProfileBubble::CheckNetworkProfile,
profile_->GetPath()));
}
#endif
#if defined(ENABLE_RLZ) && !defined(OS_CHROMEOS)
PrefService* pref_service = profile_->GetPrefs();
int ping_delay = first_run::IsChromeFirstRun() ? master_prefs_->ping_delay :
pref_service->GetInteger(first_run::GetPingDelayPrefName().c_str());
RLZTracker::InitRlzFromProfileDelayed(
profile_, first_run::IsChromeFirstRun(), ping_delay < 0,
base::TimeDelta::FromMilliseconds(abs(ping_delay)));
#endif
net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider);
browser_process_->intranet_redirect_detector();
GoogleSearchCounter::RegisterForNotifications();
if (parsed_command_line().HasSwitch(switches::kEnableSdchOverHttps)) {
net::SdchManager::EnableSecureSchemeSupport(true);
} else {
const char kSdchFieldTrialName[] = "SDCH";
const char kEnabledAllGroupName[] = "EnabledAll";
const char kEnabledHttpOnlyGroupName[] = "EnabledHttpOnly";
const char kDisabledAllGroupName[] = "DisabledAll";
base::StringPiece sdch_trial_group =
base::FieldTrialList::FindFullName(kSdchFieldTrialName);
if (sdch_trial_group.starts_with(kEnabledAllGroupName)) {
net::SdchManager::EnableSecureSchemeSupport(true);
net::SdchManager::EnableSdchSupport(true);
} else if (sdch_trial_group.starts_with(kEnabledHttpOnlyGroupName)) {
net::SdchManager::EnableSdchSupport(true);
} else if (sdch_trial_group.starts_with(kDisabledAllGroupName)) {
net::SdchManager::EnableSdchSupport(false);
}
}
if (parsed_command_line().HasSwitch(switches::kEnableWatchdog))
InstallJankometer(parsed_command_line());
#if defined(ENABLE_FULL_PRINTING) && !defined(OFFICIAL_BUILD)
if (parsed_command_line().HasSwitch(switches::kDebugPrint)) {
base::FilePath path =
parsed_command_line().GetSwitchValuePath(switches::kDebugPrint);
printing::PrintedDocument::set_debug_dump_path(path);
}
#endif
HandleTestParameters(parsed_command_line());
browser_process_->metrics_service()->RecordBreakpadHasDebugger(
base::debug::BeingDebugged());
language_usage_metrics::LanguageUsageMetrics::RecordAcceptLanguages(
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
language_usage_metrics::LanguageUsageMetrics::RecordApplicationLanguage(
browser_process_->GetApplicationLocale());
if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) {
extensions::StartupHelper extension_startup_helper;
if (extension_startup_helper.UninstallExtension(
parsed_command_line(), profile_))
return content::RESULT_CODE_NORMAL_EXIT;
return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR;
}
MetricsService::SetExecutionPhase(MetricsService::STARTUP_TIMEBOMB_ARM);
startup_watcher_->Arm(base::TimeDelta::FromSeconds(300));
#if !defined(OS_ANDROID)
MetricsService::LogNeedForCleanShutdown();
#endif
#if defined(ENABLE_FULL_PRINTING)
CloudPrintProxyServiceFactory::GetForProfile(profile_);
#endif
MetricsService::SetExecutionPhase(MetricsService::THREAD_WATCHER_START);
ThreadWatcherList::StartWatchingAll(parsed_command_line());
#if !defined(DISABLE_NACL)
content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
base::Bind(nacl::NaClProcessHost::EarlyStartup));
#endif
PrefMetricsService::Factory::GetForProfile(profile_);
PreBrowserStart();
browser_process_->notification_ui_manager();
if (!parsed_command_line().HasSwitch(switches::kDisableComponentUpdate))
RegisterComponentsForUpdate(parsed_command_line());
#if defined(OS_ANDROID)
chrome_variations::VariationsService* variations_service =
browser_process_->variations_service();
if (variations_service) {
variations_service->set_policy_pref_service(profile_->GetPrefs());
variations_service->StartRepeatedVariationsSeedFetch();
}
TranslateDownloadManager::RequestLanguageList(profile_->GetPrefs());
#else
base::TimeTicks browser_open_start = base::TimeTicks::Now();
int result_code;
#if defined(OS_CHROMEOS)
std::vector<Profile*> last_opened_profiles;
#else
std::vector<Profile*> last_opened_profiles =
g_browser_process->profile_manager()->GetLastOpenedProfiles();
#endif
if (browser_creator_->Start(parsed_command_line(), base::FilePath(),
profile_, last_opened_profiles, &result_code)) {
#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
browser_process_->StartAutoupdateTimer();
#endif
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
upgrade_util::SaveLastModifiedTimeOfExe();
#endif
GoogleUpdateSettings::SetLastRunTime();
#if defined(OS_MACOSX)
if (parameters().autorelease_pool)
parameters().autorelease_pool->Recycle();
#endif
base::TimeDelta delay = base::TimeTicks::Now() - browser_open_start;
UMA_HISTOGRAM_LONG_TIMES_100("Startup.BrowserOpenTabs", delay);
if (parameters().ui_task == NULL) {
chrome_variations::VariationsService* variations_service =
browser_process_->variations_service();
if (variations_service) {
variations_service->StartRepeatedVariationsSeedFetch();
#if defined(OS_WIN)
variations_service->StartGoogleUpdateRegistrySync();
#endif
}
TranslateDownloadManager::RequestLanguageList(profile_->GetPrefs());
}
run_message_loop_ = true;
} else {
run_message_loop_ = false;
}
browser_creator_.reset();
#endif
performance_monitor::PerformanceMonitor::GetInstance()->Initialize();
PostBrowserStart();
chrome_prefs::SchedulePrefHashStoresUpdateCheck(profile_->GetPath());
if (parameters().ui_task) {
startup_timer_->SignalStartupComplete(
performance_monitor::StartupTimer::STARTUP_TEST);
parameters().ui_task->Run();
delete parameters().ui_task;
run_message_loop_ = false;
}
#if defined(OS_ANDROID)
if (result_code_ <= 0) {
RecordBrowserStartupTime();
}
#endif
return result_code_;
}
bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::MainMessageLoopRun");
#if defined(OS_ANDROID)
NOTREACHED();
return true;
#else
*result_code = result_code_;
if (!run_message_loop_)
return true;
RecordBrowserStartupTime();
startup_timer_->SignalStartupComplete(
performance_monitor::StartupTimer::STARTUP_NORMAL);
DCHECK(base::MessageLoopForUI::IsCurrent());
base::RunLoop run_loop;
performance_monitor::PerformanceMonitor::GetInstance()->StartGatherCycle();
MetricsService::SetExecutionPhase(MetricsService::MAIN_MESSAGE_LOOP_RUN);
run_loop.Run();
return true;
#endif
}
void ChromeBrowserMainParts::PostMainMessageLoopRun() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostMainMessageLoopRun");
#if defined(OS_ANDROID)
NOTREACHED();
#else
MetricsService::SetExecutionPhase(MetricsService::SHUTDOWN_TIMEBOMB_ARM);
shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(300));
startup_watcher_->Disarm();
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
chrome_extra_parts_[i]->PostMainMessageLoopRun();
TranslateService::Shutdown(parameters().ui_task == NULL);
if (notify_result_ == ProcessSingleton::PROCESS_NONE)
process_singleton_->Cleanup();
ThreadWatcherList::StopWatchingAll();
browser_process_->metrics_service()->Stop();
restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop();
browser_process_->StartTearDown();
#endif
}
void ChromeBrowserMainParts::PostDestroyThreads() {
#if defined(OS_ANDROID)
NOTREACHED();
#else
browser_process_->PostDestroyThreads();
ignore_result(browser_process_.release());
browser_shutdown::ShutdownPostThreadsStop(restart_last_session_);
master_prefs_.reset();
process_singleton_.reset();
CHECK(MetricsService::UmaMetricsProperlyShutdown());
#if defined(OS_CHROMEOS)
chromeos::CrosSettings::Shutdown();
#endif
#endif
}
void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
chrome_extra_parts_.push_back(parts);
}