| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_browser_main.h" | 5 #include "chrome/browser/chrome_browser_main.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 { | 971 { |
| 972 TRACE_EVENT0("startup", | 972 TRACE_EVENT0("startup", |
| 973 "ChromeBrowserMainParts::PreCreateThreadsImpl:ConvertFlags"); | 973 "ChromeBrowserMainParts::PreCreateThreadsImpl:ConvertFlags"); |
| 974 flags_ui::PrefServiceFlagsStorage flags_storage_( | 974 flags_ui::PrefServiceFlagsStorage flags_storage_( |
| 975 g_browser_process->local_state()); | 975 g_browser_process->local_state()); |
| 976 about_flags::ConvertFlagsToSwitches(&flags_storage_, | 976 about_flags::ConvertFlagsToSwitches(&flags_storage_, |
| 977 base::CommandLine::ForCurrentProcess(), | 977 base::CommandLine::ForCurrentProcess(), |
| 978 flags_ui::kAddSentinels); | 978 flags_ui::kAddSentinels); |
| 979 } | 979 } |
| 980 #endif // !defined(OS_CHROMEOS) | 980 #endif // !defined(OS_CHROMEOS) |
| 981 // The MaterialDesignController needs to look at command line flags, which |
| 982 // are not available until this point. Now that they are, proceed with |
| 983 // initializing the MaterialDesignController. |
| 984 ui::MaterialDesignController::Initialize(); |
| 985 #if defined(OS_CHROMEOS) |
| 986 ash::MaterialDesignController::Initialize(); |
| 987 #endif // !defined(OS_CHROMEOS) |
| 988 |
| 989 #if defined(OS_MACOSX) |
| 990 // Material Design resource packs can be loaded now that command line flags |
| 991 // are set. See https://crbug.com/585290 . |
| 992 ui::ResourceBundle::GetSharedInstance().LoadMaterialDesignResources(); |
| 993 #endif |
| 981 | 994 |
| 982 #if defined(OS_WIN) | 995 #if defined(OS_WIN) |
| 983 // This is needed to enable ETW exporting when requested in about:flags. | 996 // This is needed to enable ETW exporting when requested in about:flags. |
| 984 // Normally, we enable it in ContentMainRunnerImpl::Initialize when the flag | 997 // Normally, we enable it in ContentMainRunnerImpl::Initialize when the flag |
| 985 // is present on the command line but flags in about:flags are converted only | 998 // is present on the command line but flags in about:flags are converted only |
| 986 // after this function runs. Note that this starts exporting later which | 999 // after this function runs. Note that this starts exporting later which |
| 987 // affects tracing the browser startup. Also, this is only relevant for the | 1000 // affects tracing the browser startup. Also, this is only relevant for the |
| 988 // browser process, as other processes will get all the flags on their command | 1001 // browser process, as other processes will get all the flags on their command |
| 989 // line regardless of the origin (command line or about:flags). | 1002 // line regardless of the origin (command line or about:flags). |
| 990 if (parsed_command_line().HasSwitch(switches::kTraceExportEventsToETW)) | 1003 if (parsed_command_line().HasSwitch(switches::kTraceExportEventsToETW)) |
| 991 base::trace_event::TraceEventETWExport::EnableETWExport(); | 1004 base::trace_event::TraceEventETWExport::EnableETWExport(); |
| 992 #endif // OS_WIN | 1005 #endif // OS_WIN |
| 993 | 1006 |
| 994 local_state_->UpdateCommandLinePrefStore( | 1007 local_state_->UpdateCommandLinePrefStore( |
| 995 new CommandLinePrefStore(base::CommandLine::ForCurrentProcess())); | 1008 new CommandLinePrefStore(base::CommandLine::ForCurrentProcess())); |
| 996 | 1009 |
| 997 // Reset the command line in the crash report details, since we may have | 1010 // Reset the command line in the crash report details, since we may have |
| 998 // just changed it to include experiments. | 1011 // just changed it to include experiments. |
| 999 crash_keys::SetCrashKeysFromCommandLine( | 1012 crash_keys::SetCrashKeysFromCommandLine( |
| 1000 *base::CommandLine::ForCurrentProcess()); | 1013 *base::CommandLine::ForCurrentProcess()); |
| 1001 | 1014 |
| 1015 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is |
| 1016 // needed when loading the MainMenu.nib and the language doesn't depend on |
| 1017 // anything since it comes from Cocoa. |
| 1018 #if defined(OS_MACOSX) |
| 1019 std::string locale = |
| 1020 parameters().ui_task ? "en-US" : l10n_util::GetLocaleOverride(); |
| 1021 browser_process_->SetApplicationLocale(locale); |
| 1022 #else |
| 1023 const std::string locale = |
| 1024 local_state_->GetString(prefs::kApplicationLocale); |
| 1025 |
| 1026 // On a POSIX OS other than ChromeOS, the parameter that is passed to the |
| 1027 // method InitSharedInstance is ignored. |
| 1028 |
| 1029 TRACE_EVENT_BEGIN0("startup", |
| 1030 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle"); |
| 1031 const std::string loaded_locale = |
| 1032 ui::ResourceBundle::InitSharedInstanceWithLocale( |
| 1033 locale, NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES); |
| 1034 TRACE_EVENT_END0("startup", |
| 1035 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle"); |
| 1036 |
| 1037 if (loaded_locale.empty() && |
| 1038 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { |
| 1039 ShowMissingLocaleMessageBox(); |
| 1040 return chrome::RESULT_CODE_MISSING_DATA; |
| 1041 } |
| 1042 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; |
| 1043 browser_process_->SetApplicationLocale(loaded_locale); |
| 1044 |
| 1045 { |
| 1046 TRACE_EVENT0("startup", |
| 1047 "ChromeBrowserMainParts::PreCreateThreadsImpl:AddDataPack"); |
| 1048 base::FilePath resources_pack_path; |
| 1049 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
| 1050 #if defined(OS_ANDROID) |
| 1051 ui::LoadMainAndroidPackFile("assets/resources.pak", resources_pack_path); |
| 1052 #else |
| 1053 ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
| 1054 resources_pack_path, ui::SCALE_FACTOR_NONE); |
| 1055 #endif // defined(OS_ANDROID) |
| 1056 } |
| 1057 #endif // defined(OS_MACOSX) |
| 1058 |
| 1002 // Android does first run in Java instead of native. | 1059 // Android does first run in Java instead of native. |
| 1003 // Chrome OS has its own out-of-box-experience code. | 1060 // Chrome OS has its own out-of-box-experience code. |
| 1004 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 1061 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 1005 // On first run, we need to process the predictor preferences before the | 1062 // On first run, we need to process the predictor preferences before the |
| 1006 // browser's profile_manager object is created. | 1063 // browser's profile_manager object is created, but after ResourceBundle |
| 1064 // is initialized. |
| 1007 if (first_run::IsChromeFirstRun()) { | 1065 if (first_run::IsChromeFirstRun()) { |
| 1008 first_run::ProcessMasterPreferencesResult pmp_result = | 1066 first_run::ProcessMasterPreferencesResult pmp_result = |
| 1009 first_run::ProcessMasterPreferences(user_data_dir_, | 1067 first_run::ProcessMasterPreferences(user_data_dir_, |
| 1010 master_prefs_.get()); | 1068 master_prefs_.get()); |
| 1011 if (pmp_result == first_run::EULA_EXIT_NOW) | 1069 if (pmp_result == first_run::EULA_EXIT_NOW) |
| 1012 return chrome::RESULT_CODE_EULA_REFUSED; | 1070 return chrome::RESULT_CODE_EULA_REFUSED; |
| 1013 | 1071 |
| 1014 if (!parsed_command_line().HasSwitch(switches::kApp) && | 1072 if (!parsed_command_line().HasSwitch(switches::kApp) && |
| 1015 !parsed_command_line().HasSwitch(switches::kAppId) && | 1073 !parsed_command_line().HasSwitch(switches::kAppId) && |
| 1016 !parsed_command_line().HasSwitch(switches::kShowAppList)) { | 1074 !parsed_command_line().HasSwitch(switches::kShowAppList)) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 // Must be done after g_browser_process is constructed, before | 1143 // Must be done after g_browser_process is constructed, before |
| 1086 // SetupMetricsAndFieldTrials(). | 1144 // SetupMetricsAndFieldTrials(). |
| 1087 chromeos::CrosSettings::Initialize(); | 1145 chromeos::CrosSettings::Initialize(); |
| 1088 #endif // defined(OS_CHROMEOS) | 1146 #endif // defined(OS_CHROMEOS) |
| 1089 | 1147 |
| 1090 // Now the command line has been mutated based on about:flags, we can setup | 1148 // Now the command line has been mutated based on about:flags, we can setup |
| 1091 // metrics and initialize field trials. The field trials are needed by | 1149 // metrics and initialize field trials. The field trials are needed by |
| 1092 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. | 1150 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. |
| 1093 SetupMetricsAndFieldTrials(); | 1151 SetupMetricsAndFieldTrials(); |
| 1094 | 1152 |
| 1095 // The MaterialDesignController needs to look at command line flags and field | |
| 1096 // trials, which are not available until this point. Now that they are, | |
| 1097 // proceed with initializing the MaterialDesignController. | |
| 1098 #if defined(OS_WIN) | |
| 1099 const version_info::Channel channel = chrome::GetChannel(); | |
| 1100 ui::MaterialDesignController::InitializeWithDefaultMode( | |
| 1101 ((channel == version_info::Channel::UNKNOWN) || | |
| 1102 (channel == version_info::Channel::CANARY) || | |
| 1103 (channel == version_info::Channel::DEV)) | |
| 1104 ? ui::MaterialDesignController::MATERIAL_NORMAL | |
| 1105 : ui::MaterialDesignController::NON_MATERIAL); | |
| 1106 #else | |
| 1107 ui::MaterialDesignController::Initialize(); | |
| 1108 #if defined(OS_CHROMEOS) | |
| 1109 ash::MaterialDesignController::Initialize(); | |
| 1110 #endif // !defined(OS_CHROMEOS) | |
| 1111 #endif // !defined(OS_WIN) | |
| 1112 | |
| 1113 #if defined(OS_MACOSX) | |
| 1114 // Material Design resource packs can be loaded now that command line flags | |
| 1115 // are set. See https://crbug.com/585290 . | |
| 1116 ui::ResourceBundle::GetSharedInstance().LoadMaterialDesignResources(); | |
| 1117 #endif | |
| 1118 | |
| 1119 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is | |
| 1120 // needed when loading the MainMenu.nib and the language doesn't depend on | |
| 1121 // anything since it comes from Cocoa. | |
| 1122 #if defined(OS_MACOSX) | |
| 1123 std::string locale = | |
| 1124 parameters().ui_task ? "en-US" : l10n_util::GetLocaleOverride(); | |
| 1125 browser_process_->SetApplicationLocale(locale); | |
| 1126 #else | |
| 1127 const std::string locale = | |
| 1128 local_state_->GetString(prefs::kApplicationLocale); | |
| 1129 | |
| 1130 // On a POSIX OS other than ChromeOS, the parameter that is passed to the | |
| 1131 // method InitSharedInstance is ignored. | |
| 1132 | |
| 1133 TRACE_EVENT_BEGIN0("startup", | |
| 1134 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle"); | |
| 1135 const std::string loaded_locale = | |
| 1136 ui::ResourceBundle::InitSharedInstanceWithLocale( | |
| 1137 locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES); | |
| 1138 TRACE_EVENT_END0("startup", | |
| 1139 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle"); | |
| 1140 | |
| 1141 if (loaded_locale.empty() && | |
| 1142 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { | |
| 1143 ShowMissingLocaleMessageBox(); | |
| 1144 return chrome::RESULT_CODE_MISSING_DATA; | |
| 1145 } | |
| 1146 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; | |
| 1147 browser_process_->SetApplicationLocale(loaded_locale); | |
| 1148 | |
| 1149 { | |
| 1150 TRACE_EVENT0("startup", | |
| 1151 "ChromeBrowserMainParts::PreCreateThreadsImpl:AddDataPack"); | |
| 1152 base::FilePath resources_pack_path; | |
| 1153 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); | |
| 1154 #if defined(OS_ANDROID) | |
| 1155 ui::LoadMainAndroidPackFile("assets/resources.pak", resources_pack_path); | |
| 1156 #else | |
| 1157 ResourceBundle::GetSharedInstance().AddDataPackFromPath( | |
| 1158 resources_pack_path, ui::SCALE_FACTOR_NONE); | |
| 1159 #endif // defined(OS_ANDROID) | |
| 1160 } | |
| 1161 #endif // defined(OS_MACOSX) | |
| 1162 | |
| 1163 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. | 1153 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. |
| 1164 browser_process_->PreCreateThreads(); | 1154 browser_process_->PreCreateThreads(); |
| 1165 | 1155 |
| 1166 return content::RESULT_CODE_NORMAL_EXIT; | 1156 return content::RESULT_CODE_NORMAL_EXIT; |
| 1167 } | 1157 } |
| 1168 | 1158 |
| 1169 void ChromeBrowserMainParts::PreMainMessageLoopRun() { | 1159 void ChromeBrowserMainParts::PreMainMessageLoopRun() { |
| 1170 #if defined(MOJO_SHELL_CLIENT) | 1160 #if defined(MOJO_SHELL_CLIENT) |
| 1171 if (content::MojoShellConnection::Get() && | 1161 if (content::MojoShellConnection::Get() && |
| 1172 content::MojoShellConnection::Get()->UsingExternalShell()) { | 1162 content::MojoShellConnection::Get()->UsingExternalShell()) { |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2004 chromeos::CrosSettings::Shutdown(); | 1994 chromeos::CrosSettings::Shutdown(); |
| 2005 #endif // defined(OS_CHROMEOS) | 1995 #endif // defined(OS_CHROMEOS) |
| 2006 #endif // defined(OS_ANDROID) | 1996 #endif // defined(OS_ANDROID) |
| 2007 } | 1997 } |
| 2008 | 1998 |
| 2009 // Public members: | 1999 // Public members: |
| 2010 | 2000 |
| 2011 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 2001 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
| 2012 chrome_extra_parts_.push_back(parts); | 2002 chrome_extra_parts_.push_back(parts); |
| 2013 } | 2003 } |
| OLD | NEW |