Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(859)

Side by Side Diff: chrome/browser/chrome_browser_main.cc

Issue 1955773002: Enable MD by default on Windows for Canary/Dev and local builds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't break first run Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
994 981
995 #if defined(OS_WIN) 982 #if defined(OS_WIN)
996 // This is needed to enable ETW exporting when requested in about:flags. 983 // This is needed to enable ETW exporting when requested in about:flags.
997 // Normally, we enable it in ContentMainRunnerImpl::Initialize when the flag 984 // Normally, we enable it in ContentMainRunnerImpl::Initialize when the flag
998 // is present on the command line but flags in about:flags are converted only 985 // is present on the command line but flags in about:flags are converted only
999 // after this function runs. Note that this starts exporting later which 986 // after this function runs. Note that this starts exporting later which
1000 // affects tracing the browser startup. Also, this is only relevant for the 987 // affects tracing the browser startup. Also, this is only relevant for the
1001 // browser process, as other processes will get all the flags on their command 988 // browser process, as other processes will get all the flags on their command
1002 // line regardless of the origin (command line or about:flags). 989 // line regardless of the origin (command line or about:flags).
1003 if (parsed_command_line().HasSwitch(switches::kTraceExportEventsToETW)) 990 if (parsed_command_line().HasSwitch(switches::kTraceExportEventsToETW))
1004 base::trace_event::TraceEventETWExport::EnableETWExport(); 991 base::trace_event::TraceEventETWExport::EnableETWExport();
1005 #endif // OS_WIN 992 #endif // OS_WIN
1006 993
1007 local_state_->UpdateCommandLinePrefStore( 994 local_state_->UpdateCommandLinePrefStore(
1008 new CommandLinePrefStore(base::CommandLine::ForCurrentProcess())); 995 new CommandLinePrefStore(base::CommandLine::ForCurrentProcess()));
1009 996
1010 // Reset the command line in the crash report details, since we may have 997 // Reset the command line in the crash report details, since we may have
1011 // just changed it to include experiments. 998 // just changed it to include experiments.
1012 crash_keys::SetCrashKeysFromCommandLine( 999 crash_keys::SetCrashKeysFromCommandLine(
1013 *base::CommandLine::ForCurrentProcess()); 1000 *base::CommandLine::ForCurrentProcess());
1014 1001
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
1059 // Android does first run in Java instead of native. 1002 // Android does first run in Java instead of native.
1060 // Chrome OS has its own out-of-box-experience code. 1003 // Chrome OS has its own out-of-box-experience code.
1061 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 1004 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
1062 // On first run, we need to process the predictor preferences before the 1005 // On first run, we need to process the predictor preferences before the
1063 // browser's profile_manager object is created, but after ResourceBundle 1006 // browser's profile_manager object is created.
1064 // is initialized.
1065 if (first_run::IsChromeFirstRun()) { 1007 if (first_run::IsChromeFirstRun()) {
1066 first_run::ProcessMasterPreferencesResult pmp_result = 1008 first_run::ProcessMasterPreferencesResult pmp_result =
1067 first_run::ProcessMasterPreferences(user_data_dir_, 1009 first_run::ProcessMasterPreferences(user_data_dir_,
1068 master_prefs_.get()); 1010 master_prefs_.get());
1069 if (pmp_result == first_run::EULA_EXIT_NOW) 1011 if (pmp_result == first_run::EULA_EXIT_NOW)
1070 return chrome::RESULT_CODE_EULA_REFUSED; 1012 return chrome::RESULT_CODE_EULA_REFUSED;
1071 1013
1072 if (!parsed_command_line().HasSwitch(switches::kApp) && 1014 if (!parsed_command_line().HasSwitch(switches::kApp) &&
1073 !parsed_command_line().HasSwitch(switches::kAppId) && 1015 !parsed_command_line().HasSwitch(switches::kAppId) &&
1074 !parsed_command_line().HasSwitch(switches::kShowAppList)) { 1016 !parsed_command_line().HasSwitch(switches::kShowAppList)) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 // Must be done after g_browser_process is constructed, before 1085 // Must be done after g_browser_process is constructed, before
1144 // SetupMetricsAndFieldTrials(). 1086 // SetupMetricsAndFieldTrials().
1145 chromeos::CrosSettings::Initialize(); 1087 chromeos::CrosSettings::Initialize();
1146 #endif // defined(OS_CHROMEOS) 1088 #endif // defined(OS_CHROMEOS)
1147 1089
1148 // Now the command line has been mutated based on about:flags, we can setup 1090 // Now the command line has been mutated based on about:flags, we can setup
1149 // metrics and initialize field trials. The field trials are needed by 1091 // metrics and initialize field trials. The field trials are needed by
1150 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. 1092 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads.
1151 SetupMetricsAndFieldTrials(); 1093 SetupMetricsAndFieldTrials();
1152 1094
1095 #if defined(OS_WIN)
1096 const version_info::Channel channel = chrome::GetChannel();
1097 ui::MaterialDesignController::SetDefaultToMaterial(
1098 (channel == version_info::Channel::UNKNOWN) ||
1099 (channel == version_info::Channel::CANARY) ||
1100 (channel == version_info::Channel::DEV));
varkha 2016/05/14 05:03:08 Could this channel check be done inside MaterialDe
Peter Kasting 2016/05/16 19:53:16 No. That's why this unorthodox design exists. Ma
1101 #endif
1102
1103 // The MaterialDesignController needs to look at command line flags and field
1104 // trials, which are not available until this point. Now that they are,
1105 // proceed with initializing the MaterialDesignController.
1106 ui::MaterialDesignController::Initialize();
1107 #if defined(OS_CHROMEOS)
1108 ash::MaterialDesignController::Initialize();
1109 #endif // !defined(OS_CHROMEOS)
1110
1111 #if defined(OS_MACOSX)
1112 // Material Design resource packs can be loaded now that command line flags
1113 // are set. See https://crbug.com/585290 .
1114 ui::ResourceBundle::GetSharedInstance().LoadMaterialDesignResources();
1115 #endif
1116
1117 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is
1118 // needed when loading the MainMenu.nib and the language doesn't depend on
1119 // anything since it comes from Cocoa.
1120 #if defined(OS_MACOSX)
1121 std::string locale =
1122 parameters().ui_task ? "en-US" : l10n_util::GetLocaleOverride();
1123 browser_process_->SetApplicationLocale(locale);
1124 #else
1125 const std::string locale =
1126 local_state_->GetString(prefs::kApplicationLocale);
1127
1128 // On a POSIX OS other than ChromeOS, the parameter that is passed to the
1129 // method InitSharedInstance is ignored.
1130
1131 TRACE_EVENT_BEGIN0("startup",
1132 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle");
1133 const std::string loaded_locale =
1134 ui::ResourceBundle::InitSharedInstanceWithLocale(
sky 2016/05/13 15:49:56 Is resourcebundle set up to have Init called multi
Peter Kasting 2016/05/16 19:53:16 It should be OK if and only if you unload the shar
1135 locale, NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
sky 2016/05/13 15:49:56 nullptr
Peter Kasting 2016/05/16 19:53:16 Done.
1136 TRACE_EVENT_END0("startup",
1137 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle");
1138
1139 if (loaded_locale.empty() &&
1140 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) {
1141 ShowMissingLocaleMessageBox();
1142 return chrome::RESULT_CODE_MISSING_DATA;
1143 }
1144 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
1145 browser_process_->SetApplicationLocale(loaded_locale);
1146
1147 {
1148 TRACE_EVENT0("startup",
1149 "ChromeBrowserMainParts::PreCreateThreadsImpl:AddDataPack");
1150 base::FilePath resources_pack_path;
1151 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
1152 #if defined(OS_ANDROID)
1153 ui::LoadMainAndroidPackFile("assets/resources.pak", resources_pack_path);
1154 #else
1155 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
1156 resources_pack_path, ui::SCALE_FACTOR_NONE);
1157 #endif // defined(OS_ANDROID)
1158 }
1159 #endif // defined(OS_MACOSX)
1160
1153 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. 1161 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this.
1154 browser_process_->PreCreateThreads(); 1162 browser_process_->PreCreateThreads();
1155 1163
1156 return content::RESULT_CODE_NORMAL_EXIT; 1164 return content::RESULT_CODE_NORMAL_EXIT;
1157 } 1165 }
1158 1166
1159 void ChromeBrowserMainParts::PreMainMessageLoopRun() { 1167 void ChromeBrowserMainParts::PreMainMessageLoopRun() {
1160 #if defined(MOJO_SHELL_CLIENT) 1168 #if defined(MOJO_SHELL_CLIENT)
1161 if (content::MojoShellConnection::Get() && 1169 if (content::MojoShellConnection::Get() &&
1162 content::MojoShellConnection::Get()->UsingExternalShell()) { 1170 content::MojoShellConnection::Get()->UsingExternalShell()) {
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1994 chromeos::CrosSettings::Shutdown(); 2002 chromeos::CrosSettings::Shutdown();
1995 #endif // defined(OS_CHROMEOS) 2003 #endif // defined(OS_CHROMEOS)
1996 #endif // defined(OS_ANDROID) 2004 #endif // defined(OS_ANDROID)
1997 } 2005 }
1998 2006
1999 // Public members: 2007 // Public members:
2000 2008
2001 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { 2009 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
2002 chrome_extra_parts_.push_back(parts); 2010 chrome_extra_parts_.push_back(parts);
2003 } 2011 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698