Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_main.h" | 5 #include "chrome/browser/browser_main.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 16 #include "base/mac/scoped_nsautorelease_pool.h" | 16 #include "base/mac/scoped_nsautorelease_pool.h" |
| 17 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 20 #include "base/process_util.h" | 20 #include "base/process_util.h" |
| 21 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
| 22 #include "base/string_piece.h" | 22 #include "base/string_piece.h" |
| 23 #include "base/string_split.h" | 23 #include "base/string_split.h" |
| 24 #include "base/string_util.h" | 24 #include "base/string_util.h" |
| 25 #include "base/sys_string_conversions.h" | 25 #include "base/sys_string_conversions.h" |
| 26 #include "base/threading/platform_thread.h" | 26 #include "base/threading/platform_thread.h" |
| 27 #include "base/threading/thread_restrictions.h" | |
| 28 #include "base/time.h" | 27 #include "base/time.h" |
| 29 #include "base/utf_string_conversions.h" | 28 #include "base/utf_string_conversions.h" |
| 30 #include "base/values.h" | 29 #include "base/values.h" |
| 31 #include "build/build_config.h" | 30 #include "build/build_config.h" |
| 32 #include "chrome/browser/about_flags.h" | 31 #include "chrome/browser/about_flags.h" |
| 33 #include "chrome/browser/browser_main_win.h" | 32 #include "chrome/browser/browser_main_win.h" |
| 34 #include "chrome/browser/browser_process.h" | |
| 35 #include "chrome/browser/browser_process_impl.h" | 33 #include "chrome/browser/browser_process_impl.h" |
| 36 #include "chrome/browser/browser_shutdown.h" | 34 #include "chrome/browser/browser_shutdown.h" |
| 37 #include "chrome/browser/defaults.h" | 35 #include "chrome/browser/defaults.h" |
| 38 #include "chrome/browser/extensions/extension_protocols.h" | 36 #include "chrome/browser/extensions/extension_protocols.h" |
| 39 #include "chrome/browser/extensions/extension_service.h" | 37 #include "chrome/browser/extensions/extension_service.h" |
| 40 #include "chrome/browser/extensions/extensions_startup.h" | 38 #include "chrome/browser/extensions/extensions_startup.h" |
| 41 #include "chrome/browser/first_run/first_run.h" | |
| 42 #include "chrome/browser/first_run/first_run_browser_process.h" | 39 #include "chrome/browser/first_run/first_run_browser_process.h" |
| 43 #include "chrome/browser/first_run/upgrade_util.h" | 40 #include "chrome/browser/first_run/upgrade_util.h" |
| 44 #include "chrome/browser/google/google_url_tracker.h" | 41 #include "chrome/browser/google/google_url_tracker.h" |
| 45 #include "chrome/browser/instant/instant_field_trial.h" | 42 #include "chrome/browser/instant/instant_field_trial.h" |
| 46 #include "chrome/browser/jankometer.h" | 43 #include "chrome/browser/jankometer.h" |
| 47 #include "chrome/browser/language_usage_metrics.h" | 44 #include "chrome/browser/language_usage_metrics.h" |
| 48 #include "chrome/browser/metrics/field_trial_synchronizer.h" | 45 #include "chrome/browser/metrics/field_trial_synchronizer.h" |
| 49 #include "chrome/browser/metrics/histogram_synchronizer.h" | 46 #include "chrome/browser/metrics/histogram_synchronizer.h" |
| 50 #include "chrome/browser/metrics/metrics_log.h" | 47 #include "chrome/browser/metrics/metrics_log.h" |
| 51 #include "chrome/browser/metrics/metrics_service.h" | 48 #include "chrome/browser/metrics/metrics_service.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 #endif | 145 #endif |
| 149 | 146 |
| 150 // TODO(port): several win-only methods have been pulled out of this, but | 147 // TODO(port): several win-only methods have been pulled out of this, but |
| 151 // BrowserMain() as a whole needs to be broken apart so that it's usable by | 148 // BrowserMain() as a whole needs to be broken apart so that it's usable by |
| 152 // other platforms. For now, it's just a stub. This is a serious work in | 149 // other platforms. For now, it's just a stub. This is a serious work in |
| 153 // progress and should not be taken as an indication of a real refactoring. | 150 // progress and should not be taken as an indication of a real refactoring. |
| 154 | 151 |
| 155 #if defined(OS_WIN) | 152 #if defined(OS_WIN) |
| 156 | 153 |
| 157 #include "base/environment.h" // For PreRead experiment. | 154 #include "base/environment.h" // For PreRead experiment. |
| 158 #include "base/win/scoped_com_initializer.h" | |
| 159 #include "base/win/windows_version.h" | 155 #include "base/win/windows_version.h" |
| 160 #include "chrome/browser/browser_trial.h" | 156 #include "chrome/browser/browser_trial.h" |
| 161 #include "chrome/browser/browser_util_win.h" | 157 #include "chrome/browser/browser_util_win.h" |
| 162 #include "chrome/browser/first_run/try_chrome_dialog_view.h" | 158 #include "chrome/browser/first_run/try_chrome_dialog_view.h" |
| 163 #include "chrome/browser/first_run/upgrade_util_win.h" | 159 #include "chrome/browser/first_run/upgrade_util_win.h" |
| 164 #include "chrome/browser/net/url_fixer_upper.h" | 160 #include "chrome/browser/net/url_fixer_upper.h" |
| 165 #include "chrome/browser/rlz/rlz.h" | 161 #include "chrome/browser/rlz/rlz.h" |
| 166 #include "chrome/browser/ui/views/user_data_dir_dialog.h" | 162 #include "chrome/browser/ui/views/user_data_dir_dialog.h" |
| 167 #include "chrome/installer/util/helper.h" | 163 #include "chrome/installer/util/helper.h" |
| 168 #include "chrome/installer/util/install_util.h" | 164 #include "chrome/installer/util/install_util.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 | 217 |
| 222 #if defined(OS_CHROMEOS) | 218 #if defined(OS_CHROMEOS) |
| 223 // Test loading libcros and exit. We return 0 if the library could be loaded, | 219 // Test loading libcros and exit. We return 0 if the library could be loaded, |
| 224 // and 1 if it can't be. This is for validation that the library is installed | 220 // and 1 if it can't be. This is for validation that the library is installed |
| 225 // and versioned properly for Chrome to find. | 221 // and versioned properly for Chrome to find. |
| 226 if (command_line.HasSwitch(switches::kTestLoadLibcros)) | 222 if (command_line.HasSwitch(switches::kTestLoadLibcros)) |
| 227 exit(!chromeos::CrosLibrary::Get()->EnsureLoaded()); | 223 exit(!chromeos::CrosLibrary::Get()->EnsureLoaded()); |
| 228 #endif | 224 #endif |
| 229 } | 225 } |
| 230 | 226 |
| 231 void RunUIMessageLoop(BrowserProcess* browser_process) { | |
| 232 TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | |
| 233 // This should be invoked as close to the start of the browser's | |
| 234 // UI thread message loop as possible to get a stable measurement | |
| 235 // across versions. | |
| 236 RecordBrowserStartupTime(); | |
| 237 | |
| 238 // If the UI thread blocks, the whole UI is unresponsive. | |
| 239 // Do not allow disk IO from the UI thread. | |
| 240 base::ThreadRestrictions::SetIOAllowed(false); | |
| 241 | |
| 242 #if defined(TOOLKIT_VIEWS) | |
| 243 views::AcceleratorHandler accelerator_handler; | |
| 244 MessageLoopForUI::current()->Run(&accelerator_handler); | |
| 245 #elif defined(USE_X11) | |
| 246 MessageLoopForUI::current()->Run(NULL); | |
| 247 #elif defined(OS_POSIX) | |
| 248 MessageLoopForUI::current()->Run(); | |
| 249 #endif | |
| 250 #if defined(OS_CHROMEOS) | |
| 251 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("UIMessageLoopEnded", | |
| 252 true); | |
| 253 #endif | |
| 254 | |
| 255 TRACE_EVENT_END_ETW("BrowserMain:MESSAGE_LOOP", 0, ""); | |
| 256 } | |
| 257 | |
| 258 void AddFirstRunNewTabs(BrowserInit* browser_init, | 227 void AddFirstRunNewTabs(BrowserInit* browser_init, |
| 259 const std::vector<GURL>& new_tabs) { | 228 const std::vector<GURL>& new_tabs) { |
| 260 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); | 229 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); |
| 261 it != new_tabs.end(); ++it) { | 230 it != new_tabs.end(); ++it) { |
| 262 if (it->is_valid()) | 231 if (it->is_valid()) |
| 263 browser_init->AddFirstRunTab(*it); | 232 browser_init->AddFirstRunTab(*it); |
| 264 } | 233 } |
| 265 } | 234 } |
| 266 | 235 |
| 267 #if defined(USE_LINUX_BREAKPAD) | 236 #if defined(USE_LINUX_BREAKPAD) |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 691 const char kMissingLocaleDataTitle[] = "Missing File Error"; | 660 const char kMissingLocaleDataTitle[] = "Missing File Error"; |
| 692 const char kMissingLocaleDataMessage[] = | 661 const char kMissingLocaleDataMessage[] = |
| 693 "Unable to find locale data files. Please reinstall."; | 662 "Unable to find locale data files. Please reinstall."; |
| 694 } // namespace chrome_browser | 663 } // namespace chrome_browser |
| 695 | 664 |
| 696 // BrowserMainParts ------------------------------------------------------------ | 665 // BrowserMainParts ------------------------------------------------------------ |
| 697 | 666 |
| 698 ChromeBrowserMainParts::ChromeBrowserMainParts( | 667 ChromeBrowserMainParts::ChromeBrowserMainParts( |
| 699 const MainFunctionParams& parameters) | 668 const MainFunctionParams& parameters) |
| 700 : BrowserMainParts(parameters), | 669 : BrowserMainParts(parameters), |
| 701 shutdown_watcher_(new ShutdownWatcherHelper()) { | 670 shutdown_watcher_(new ShutdownWatcherHelper()), |
| 671 record_search_engine_(false), | |
| 672 translate_manager_(NULL), | |
| 673 metrics_(NULL), | |
| 674 profile_(NULL), | |
| 675 run_message_loop_(true) { | |
| 702 // If we're running tests (ui_task is non-null). | 676 // If we're running tests (ui_task is non-null). |
| 703 if (parameters.ui_task) | 677 if (parameters.ui_task) |
| 704 browser_defaults::enable_help_app = false; | 678 browser_defaults::enable_help_app = false; |
| 705 } | 679 } |
| 706 | 680 |
| 707 ChromeBrowserMainParts::~ChromeBrowserMainParts() { | 681 ChromeBrowserMainParts::~ChromeBrowserMainParts() { |
| 708 } | 682 } |
| 709 | 683 |
| 710 void ChromeBrowserMainParts::SetupHistogramSynchronizer() { | |
| 711 histogram_synchronizer_ = new HistogramSynchronizer(); | |
| 712 } | |
| 713 | |
| 714 // This will be called after the command-line has been mutated by about:flags | 684 // This will be called after the command-line has been mutated by about:flags |
| 715 MetricsService* ChromeBrowserMainParts::SetupMetricsAndFieldTrials( | 685 MetricsService* ChromeBrowserMainParts::SetupMetricsAndFieldTrials( |
| 716 const CommandLine& parsed_command_line, | 686 const CommandLine& parsed_command_line, |
| 717 PrefService* local_state) { | 687 PrefService* local_state) { |
| 718 // Must initialize metrics after labs have been converted into switches, | 688 // Must initialize metrics after labs have been converted into switches, |
| 719 // but before field trials are set up (so that client ID is available for | 689 // but before field trials are set up (so that client ID is available for |
| 720 // one-time randomized field trials). | 690 // one-time randomized field trials). |
| 721 MetricsService* metrics = InitializeMetrics(parsed_command_line, local_state); | 691 MetricsService* metrics = InitializeMetrics(parsed_command_line, local_state); |
| 722 | 692 |
| 723 // Initialize FieldTrialList to support FieldTrials that use one-time | 693 // Initialize FieldTrialList to support FieldTrials that use one-time |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1101 // in ChromeMain() got destructed when the function returned. | 1071 // in ChromeMain() got destructed when the function returned. |
| 1102 base::AtExitManager exit_manager; | 1072 base::AtExitManager exit_manager; |
| 1103 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 1073 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
| 1104 } | 1074 } |
| 1105 #endif | 1075 #endif |
| 1106 | 1076 |
| 1107 void ChromeBrowserMainParts::PostMainMessageLoopStart() { | 1077 void ChromeBrowserMainParts::PostMainMessageLoopStart() { |
| 1108 Profiling::MainMessageLoopStarted(); | 1078 Profiling::MainMessageLoopStarted(); |
| 1109 } | 1079 } |
| 1110 | 1080 |
| 1111 void ChromeBrowserMainParts::ToolkitInitialized() { | 1081 void ChromeBrowserMainParts::PreMainMessageLoopRun() { |
| 1112 #if defined(TOOLKIT_VIEWS) | 1082 run_message_loop_ = false; |
| 1113 // The delegate needs to be set before any UI is created so that windows | |
| 1114 // display the correct icon. | |
| 1115 if (!views::ViewsDelegate::views_delegate) | |
| 1116 views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; | |
| 1117 | |
| 1118 // TODO(beng): Move to WidgetImpl and implement on Windows too! | |
| 1119 if (parameters().command_line_.HasSwitch(switches::kDebugViewsPaint)) | |
| 1120 views::Widget::SetDebugPaintEnabled(true); | |
| 1121 #endif | |
| 1122 | |
| 1123 #if defined(OS_WIN) | |
| 1124 gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; | |
| 1125 gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; | |
| 1126 #endif | |
| 1127 } | |
| 1128 | |
| 1129 int ChromeBrowserMainParts::TemporaryContinue() { | |
| 1130 FilePath user_data_dir; | 1083 FilePath user_data_dir; |
| 1131 #if defined(OS_WIN) | 1084 #if defined(OS_WIN) |
| 1132 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 1085 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 1133 #else | 1086 #else |
| 1134 // Getting the user data dir can fail if the directory isn't | 1087 // Getting the user data dir can fail if the directory isn't |
| 1135 // creatable, for example; on Windows in code below we bring up a | 1088 // creatable, for example; on Windows in code below we bring up a |
| 1136 // dialog prompting the user to pick a different directory. | 1089 // dialog prompting the user to pick a different directory. |
| 1137 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, | 1090 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, |
| 1138 // so it's better to fail here than fail mysteriously elsewhere. | 1091 // so it's better to fail here than fail mysteriously elsewhere. |
| 1139 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) | 1092 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) |
| 1140 << "Must be able to get user data directory!"; | 1093 << "Must be able to get user data directory!"; |
| 1141 #endif | 1094 #endif |
| 1142 | 1095 |
| 1143 ProcessSingleton process_singleton(user_data_dir); | 1096 process_singleton_.reset(new ProcessSingleton(user_data_dir)); |
| 1144 | 1097 |
| 1145 bool is_first_run = FirstRun::IsChromeFirstRun() || | 1098 bool is_first_run = FirstRun::IsChromeFirstRun() || |
| 1146 parsed_command_line().HasSwitch(switches::kFirstRun); | 1099 parsed_command_line().HasSwitch(switches::kFirstRun); |
| 1147 | 1100 |
| 1148 scoped_ptr<BrowserProcessImpl> browser_process; | |
| 1149 if (parsed_command_line().HasSwitch(switches::kImport) || | 1101 if (parsed_command_line().HasSwitch(switches::kImport) || |
| 1150 parsed_command_line().HasSwitch(switches::kImportFromFile)) { | 1102 parsed_command_line().HasSwitch(switches::kImportFromFile)) { |
| 1151 // We use different BrowserProcess when importing so no GoogleURLTracker is | 1103 // We use different BrowserProcess when importing so no GoogleURLTracker is |
| 1152 // instantiated (as it makes a net::URLRequest and we don't have an IO | 1104 // instantiated (as it makes a net::URLRequest and we don't have an IO |
| 1153 // thread, see bug #1292702). | 1105 // thread, see bug #1292702). |
| 1154 browser_process.reset(new FirstRunBrowserProcess(parsed_command_line())); | 1106 browser_process_.reset(new FirstRunBrowserProcess(parsed_command_line())); |
| 1155 is_first_run = false; | 1107 is_first_run = false; |
| 1156 } else { | 1108 } else { |
| 1157 browser_process.reset(new BrowserProcessImpl(parsed_command_line())); | 1109 browser_process_.reset(new BrowserProcessImpl(parsed_command_line())); |
| 1158 } | 1110 } |
| 1159 | 1111 |
| 1160 // This forces the TabCloseableStateWatcher to be created and, on chromeos, | 1112 // This forces the TabCloseableStateWatcher to be created and, on chromeos, |
| 1161 // register for the notifications it needs to track the closeable state of | 1113 // register for the notifications it needs to track the closeable state of |
| 1162 // tabs. | 1114 // tabs. |
| 1163 g_browser_process->tab_closeable_state_watcher(); | 1115 g_browser_process->tab_closeable_state_watcher(); |
| 1164 | 1116 |
| 1165 PrefService* local_state = InitializeLocalState(parsed_command_line(), | 1117 PrefService* local_state = InitializeLocalState(parsed_command_line(), |
| 1166 is_first_run); | 1118 is_first_run); |
| 1167 | 1119 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1188 #else | 1140 #else |
| 1189 const std::string locale = | 1141 const std::string locale = |
| 1190 local_state->GetString(prefs::kApplicationLocale); | 1142 local_state->GetString(prefs::kApplicationLocale); |
| 1191 // On a POSIX OS other than ChromeOS, the parameter that is passed to the | 1143 // On a POSIX OS other than ChromeOS, the parameter that is passed to the |
| 1192 // method InitSharedInstance is ignored. | 1144 // method InitSharedInstance is ignored. |
| 1193 const std::string loaded_locale = | 1145 const std::string loaded_locale = |
| 1194 ResourceBundle::InitSharedInstance(locale); | 1146 ResourceBundle::InitSharedInstance(locale); |
| 1195 if (loaded_locale.empty() && | 1147 if (loaded_locale.empty() && |
| 1196 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { | 1148 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { |
| 1197 ShowMissingLocaleMessageBox(); | 1149 ShowMissingLocaleMessageBox(); |
| 1198 return chrome::RESULT_CODE_MISSING_DATA; | 1150 set_result_code(chrome::RESULT_CODE_MISSING_DATA); |
| 1151 return; | |
| 1199 } | 1152 } |
| 1200 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; | 1153 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; |
| 1201 g_browser_process->SetApplicationLocale(loaded_locale); | 1154 g_browser_process->SetApplicationLocale(loaded_locale); |
| 1202 | 1155 |
| 1203 FilePath resources_pack_path; | 1156 FilePath resources_pack_path; |
| 1204 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); | 1157 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
| 1205 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); | 1158 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); |
| 1206 #endif // defined(OS_MACOSX) | 1159 #endif // defined(OS_MACOSX) |
| 1207 } | 1160 } |
| 1208 | 1161 |
| 1209 #if defined(TOOLKIT_GTK) | 1162 #if defined(TOOLKIT_GTK) |
| 1210 g_set_application_name(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str()); | 1163 g_set_application_name(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str()); |
| 1211 #endif | 1164 #endif |
| 1212 | 1165 |
| 1213 std::string try_chrome = | 1166 std::string try_chrome = |
| 1214 parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain); | 1167 parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain); |
| 1215 if (!try_chrome.empty()) { | 1168 if (!try_chrome.empty()) { |
| 1216 #if defined(OS_WIN) && !defined(USE_AURA) | 1169 #if defined(OS_WIN) && !defined(USE_AURA) |
| 1217 // Setup.exe has determined that we need to run a retention experiment | 1170 // Setup.exe has determined that we need to run a retention experiment |
| 1218 // and has lauched chrome to show the experiment UI. | 1171 // and has lauched chrome to show the experiment UI. |
| 1219 if (process_singleton.FoundOtherProcessWindow()) { | 1172 if (process_singleton_->FoundOtherProcessWindow()) { |
| 1220 // It seems that we don't need to run the experiment since chrome | 1173 // It seems that we don't need to run the experiment since chrome |
| 1221 // in the same profile is already running. | 1174 // in the same profile is already running. |
| 1222 VLOG(1) << "Retention experiment not required"; | 1175 VLOG(1) << "Retention experiment not required"; |
| 1223 return TryChromeDialogView::NOT_NOW; | 1176 set_result_code(TryChromeDialogView::NOT_NOW); |
| 1177 return; | |
| 1224 } | 1178 } |
| 1225 int try_chrome_int; | 1179 int try_chrome_int; |
| 1226 base::StringToInt(try_chrome, &try_chrome_int); | 1180 base::StringToInt(try_chrome, &try_chrome_int); |
| 1227 TryChromeDialogView::Result answer = | 1181 TryChromeDialogView::Result answer = |
| 1228 TryChromeDialogView::Show(try_chrome_int, &process_singleton); | 1182 TryChromeDialogView::Show(try_chrome_int, process_singleton_.get()); |
| 1229 if (answer == TryChromeDialogView::NOT_NOW) | 1183 if (answer == TryChromeDialogView::NOT_NOW) |
| 1230 return chrome::RESULT_CODE_NORMAL_EXIT_CANCEL; | 1184 set_result_code(chrome::RESULT_CODE_NORMAL_EXIT_CANCEL); |
| 1231 if (answer == TryChromeDialogView::UNINSTALL_CHROME) | 1185 else if (answer == TryChromeDialogView::UNINSTALL_CHROME) |
| 1232 return chrome::RESULT_CODE_NORMAL_EXIT_EXP2; | 1186 set_result_code(chrome::RESULT_CODE_NORMAL_EXIT_EXP2); |
| 1233 #else | 1187 #else |
| 1234 // We don't support retention experiments on Mac or Linux. | 1188 // We don't support retention experiments on Mac or Linux. |
| 1235 return content::RESULT_CODE_NORMAL_EXIT; | 1189 set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
| 1236 #endif // defined(OS_WIN) | 1190 #endif // defined(OS_WIN) |
| 1191 return; | |
| 1237 } | 1192 } |
| 1238 | 1193 |
| 1239 #if defined(OS_CHROMEOS) | 1194 #if defined(OS_CHROMEOS) |
| 1240 // This needs to be called after the locale has been set. | 1195 // This needs to be called after the locale has been set. |
| 1241 RegisterTranslateableItems(); | 1196 RegisterTranslateableItems(); |
| 1242 #endif | 1197 #endif |
| 1243 | 1198 |
| 1244 #if defined(TOOLKIT_VIEWS) | 1199 #if defined(TOOLKIT_VIEWS) |
| 1245 views::Widget::SetPureViews( | 1200 views::Widget::SetPureViews( |
| 1246 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePureViews)); | 1201 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePureViews)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1262 chrome_views_delegate->default_parent_view = | 1217 chrome_views_delegate->default_parent_view = |
| 1263 views::desktop::DesktopWindowView::desktop_window_view; | 1218 views::desktop::DesktopWindowView::desktop_window_view; |
| 1264 } | 1219 } |
| 1265 #endif | 1220 #endif |
| 1266 | 1221 |
| 1267 BrowserInit browser_init; | 1222 BrowserInit browser_init; |
| 1268 | 1223 |
| 1269 // On first run, we need to process the predictor preferences before the | 1224 // On first run, we need to process the predictor preferences before the |
| 1270 // browser's profile_manager object is created, but after ResourceBundle | 1225 // browser's profile_manager object is created, but after ResourceBundle |
| 1271 // is initialized. | 1226 // is initialized. |
| 1272 FirstRun::MasterPrefs master_prefs; | 1227 master_prefs_.reset(new FirstRun::MasterPrefs); |
| 1273 bool first_run_ui_bypass = false; // True to skip first run UI. | 1228 bool first_run_ui_bypass = false; // True to skip first run UI. |
| 1274 if (is_first_run) { | 1229 if (is_first_run) { |
| 1275 first_run_ui_bypass = | 1230 first_run_ui_bypass = |
| 1276 !FirstRun::ProcessMasterPreferences(user_data_dir, &master_prefs); | 1231 !FirstRun::ProcessMasterPreferences(user_data_dir, master_prefs_.get()); |
| 1277 AddFirstRunNewTabs(&browser_init, master_prefs.new_tabs); | 1232 AddFirstRunNewTabs(&browser_init, master_prefs_->new_tabs); |
| 1278 | 1233 |
| 1279 // If we are running in App mode, we do not want to show the importer | 1234 // If we are running in App mode, we do not want to show the importer |
| 1280 // (first run) UI. | 1235 // (first run) UI. |
| 1281 if (!first_run_ui_bypass && | 1236 if (!first_run_ui_bypass && |
| 1282 (parsed_command_line().HasSwitch(switches::kApp) || | 1237 (parsed_command_line().HasSwitch(switches::kApp) || |
| 1283 parsed_command_line().HasSwitch(switches::kAppId) || | 1238 parsed_command_line().HasSwitch(switches::kAppId) || |
| 1284 parsed_command_line().HasSwitch(switches::kNoFirstRun))) | 1239 parsed_command_line().HasSwitch(switches::kNoFirstRun))) |
| 1285 first_run_ui_bypass = true; | 1240 first_run_ui_bypass = true; |
| 1286 } | 1241 } |
| 1287 | 1242 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1298 local_state->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true); | 1253 local_state->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true); |
| 1299 about_flags::SetExperimentEnabled(local_state, "print-preview", true); | 1254 about_flags::SetExperimentEnabled(local_state, "print-preview", true); |
| 1300 } | 1255 } |
| 1301 #endif | 1256 #endif |
| 1302 | 1257 |
| 1303 // Convert active labs into switches. Modifies the current command line. | 1258 // Convert active labs into switches. Modifies the current command line. |
| 1304 about_flags::ConvertFlagsToSwitches(local_state, | 1259 about_flags::ConvertFlagsToSwitches(local_state, |
| 1305 CommandLine::ForCurrentProcess()); | 1260 CommandLine::ForCurrentProcess()); |
| 1306 | 1261 |
| 1307 InitializeNetworkOptions(parsed_command_line()); | 1262 InitializeNetworkOptions(parsed_command_line()); |
| 1308 InitializeURLRequestThrottlerManager(browser_process->net_log()); | 1263 InitializeURLRequestThrottlerManager(browser_process_->net_log()); |
| 1309 | 1264 |
| 1310 // Initialize histogram synchronizer system. This is a singleton and is used | 1265 // Initialize histogram synchronizer system. This is a singleton and is used |
| 1311 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of | 1266 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of |
| 1312 // scope. Even though NewRunnableMethod does AddRef and Release, the object | 1267 // scope. Even though NewRunnableMethod does AddRef and Release, the object |
| 1313 // will not be deleted after the Task is executed. | 1268 // will not be deleted after the Task is executed. |
| 1314 SetupHistogramSynchronizer(); | 1269 histogram_synchronizer_ = new HistogramSynchronizer(); |
| 1315 | 1270 |
| 1316 // Now the command line has been mutated based on about:flags, we can | 1271 // Now the command line has been mutated based on about:flags, we can |
| 1317 // set up metrics and initialize field trials. | 1272 // set up metrics and initialize field trials. |
| 1318 MetricsService* metrics = SetupMetricsAndFieldTrials( | 1273 metrics_ = SetupMetricsAndFieldTrials(parsed_command_line(), local_state); |
| 1319 parsed_command_line(), local_state); | |
| 1320 | 1274 |
| 1321 // Now that all preferences have been registered, set the install date | 1275 // Now that all preferences have been registered, set the install date |
| 1322 // for the uninstall metrics if this is our first run. This only actually | 1276 // for the uninstall metrics if this is our first run. This only actually |
| 1323 // gets used if the user has metrics reporting enabled at uninstall time. | 1277 // gets used if the user has metrics reporting enabled at uninstall time. |
| 1324 int64 install_date = | 1278 int64 install_date = |
| 1325 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); | 1279 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); |
| 1326 if (install_date == 0) { | 1280 if (install_date == 0) { |
| 1327 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, | 1281 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, |
| 1328 base::Time::Now().ToTimeT()); | 1282 base::Time::Now().ToTimeT()); |
| 1329 } | 1283 } |
| 1330 | 1284 |
| 1331 #if defined(OS_MACOSX) | 1285 #if defined(OS_MACOSX) |
| 1332 // Get the Keychain API to register for distributed notifications on the main | 1286 // Get the Keychain API to register for distributed notifications on the main |
| 1333 // thread, which has a proper CFRunloop, instead of later on the I/O thread, | 1287 // thread, which has a proper CFRunloop, instead of later on the I/O thread, |
| 1334 // which doesn't. This ensures those notifications will get delivered | 1288 // which doesn't. This ensures those notifications will get delivered |
| 1335 // properly. See issue 37766. | 1289 // properly. See issue 37766. |
| 1336 // (Note that the callback mask here is empty. I don't want to register for | 1290 // (Note that the callback mask here is empty. I don't want to register for |
| 1337 // any callbacks, I just want to initialize the mechanism.) | 1291 // any callbacks, I just want to initialize the mechanism.) |
| 1338 SecKeychainAddCallback(&KeychainCallback, 0, NULL); | 1292 SecKeychainAddCallback(&KeychainCallback, 0, NULL); |
| 1339 #endif | 1293 #endif |
| 1340 | 1294 |
| 1341 CreateChildThreads(browser_process.get()); | 1295 CreateChildThreads(browser_process_.get()); |
| 1342 | 1296 |
| 1343 #if defined(OS_CHROMEOS) | 1297 #if defined(OS_CHROMEOS) |
| 1344 // Now that the file thread exists we can record our stats. | 1298 // Now that the file thread exists we can record our stats. |
| 1345 chromeos::BootTimesLoader::Get()->RecordChromeMainStats(); | 1299 chromeos::BootTimesLoader::Get()->RecordChromeMainStats(); |
| 1346 | 1300 |
| 1347 // Read locale-specific GTK resource information. | 1301 // Read locale-specific GTK resource information. |
| 1348 std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC); | 1302 std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC); |
| 1349 if (!gtkrc.empty()) | 1303 if (!gtkrc.empty()) |
| 1350 gtk_rc_parse_string(gtkrc.c_str()); | 1304 gtk_rc_parse_string(gtkrc.c_str()); |
| 1351 | 1305 |
| 1352 // Trigger prefetching of ownership status. | 1306 // Trigger prefetching of ownership status. |
| 1353 chromeos::OwnershipService::GetSharedInstance()->Prewarm(); | 1307 chromeos::OwnershipService::GetSharedInstance()->Prewarm(); |
| 1354 #endif | 1308 #endif |
| 1355 | 1309 |
| 1356 // Record last shutdown time into a histogram. | 1310 // Record last shutdown time into a histogram. |
| 1357 browser_shutdown::ReadLastShutdownInfo(); | 1311 browser_shutdown::ReadLastShutdownInfo(); |
| 1358 | 1312 |
| 1359 #if defined(OS_WIN) | 1313 #if defined(OS_WIN) |
| 1360 // On Windows, we use our startup as an opportunity to do upgrade/uninstall | 1314 // On Windows, we use our startup as an opportunity to do upgrade/uninstall |
| 1361 // tasks. Those care whether the browser is already running. On Linux/Mac, | 1315 // tasks. Those care whether the browser is already running. On Linux/Mac, |
| 1362 // upgrade/uninstall happen separately. | 1316 // upgrade/uninstall happen separately. |
| 1363 bool already_running = browser_util::IsBrowserAlreadyRunning(); | 1317 bool already_running = browser_util::IsBrowserAlreadyRunning(); |
| 1364 | 1318 |
| 1365 // If the command line specifies 'uninstall' then we need to work here | 1319 // If the command line specifies 'uninstall' then we need to work here |
| 1366 // unless we detect another chrome browser running. | 1320 // unless we detect another chrome browser running. |
| 1367 if (parsed_command_line().HasSwitch(switches::kUninstall)) | 1321 if (parsed_command_line().HasSwitch(switches::kUninstall)) { |
| 1368 return DoUninstallTasks(already_running); | 1322 set_result_code(DoUninstallTasks(already_running)); |
| 1323 return; | |
| 1324 } | |
| 1369 #endif | 1325 #endif |
| 1370 | 1326 |
| 1371 if (parsed_command_line().HasSwitch(switches::kHideIcons) || | 1327 if (parsed_command_line().HasSwitch(switches::kHideIcons) || |
| 1372 parsed_command_line().HasSwitch(switches::kShowIcons)) | 1328 parsed_command_line().HasSwitch(switches::kShowIcons)) { |
| 1373 return HandleIconsCommands(parsed_command_line()); | 1329 set_result_code(HandleIconsCommands(parsed_command_line())); |
| 1330 return; | |
| 1331 } | |
| 1374 if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) { | 1332 if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) { |
| 1375 return ShellIntegration::SetAsDefaultBrowser() ? | 1333 set_result_code(ShellIntegration::SetAsDefaultBrowser() ? |
| 1376 static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) : | 1334 static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) : |
| 1377 static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED); | 1335 static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED)); |
| 1336 return; | |
| 1378 } | 1337 } |
| 1379 | 1338 |
| 1380 // If the command line specifies --pack-extension, attempt the pack extension | 1339 // If the command line specifies --pack-extension, attempt the pack extension |
| 1381 // startup action and exit. | 1340 // startup action and exit. |
| 1382 if (parsed_command_line().HasSwitch(switches::kPackExtension)) { | 1341 if (parsed_command_line().HasSwitch(switches::kPackExtension)) { |
| 1383 ExtensionsStartupUtil extension_startup_util; | 1342 ExtensionsStartupUtil extension_startup_util; |
| 1384 if (extension_startup_util.PackExtension(parsed_command_line())) { | 1343 if (extension_startup_util.PackExtension(parsed_command_line())) { |
| 1385 return content::RESULT_CODE_NORMAL_EXIT; | 1344 set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
| 1386 } else { | 1345 } else { |
| 1387 return chrome::RESULT_CODE_PACK_EXTENSION_ERROR; | 1346 set_result_code(chrome::RESULT_CODE_PACK_EXTENSION_ERROR); |
| 1388 } | 1347 } |
| 1348 return; | |
| 1389 } | 1349 } |
| 1390 | 1350 |
| 1391 #if !defined(OS_MACOSX) | 1351 #if !defined(OS_MACOSX) |
| 1392 // In environments other than Mac OS X we support import of settings | 1352 // In environments other than Mac OS X we support import of settings |
| 1393 // from other browsers. In case this process is a short-lived "import" | 1353 // from other browsers. In case this process is a short-lived "import" |
| 1394 // process that another browser runs just to import the settings, we | 1354 // process that another browser runs just to import the settings, we |
| 1395 // don't want to be checking for another browser process, by design. | 1355 // don't want to be checking for another browser process, by design. |
| 1396 if (!(parsed_command_line().HasSwitch(switches::kImport) || | 1356 if (!(parsed_command_line().HasSwitch(switches::kImport) || |
| 1397 parsed_command_line().HasSwitch(switches::kImportFromFile))) { | 1357 parsed_command_line().HasSwitch(switches::kImportFromFile))) { |
| 1398 #endif | 1358 #endif |
| 1399 // When another process is running, use that process instead of starting a | 1359 // When another process is running, use that process instead of starting a |
| 1400 // new one. NotifyOtherProcess will currently give the other process up to | 1360 // new one. NotifyOtherProcess will currently give the other process up to |
| 1401 // 20 seconds to respond. Note that this needs to be done before we attempt | 1361 // 20 seconds to respond. Note that this needs to be done before we attempt |
| 1402 // to read the profile. | 1362 // to read the profile. |
| 1403 switch (process_singleton.NotifyOtherProcessOrCreate()) { | 1363 switch (process_singleton_->NotifyOtherProcessOrCreate()) { |
| 1404 case ProcessSingleton::PROCESS_NONE: | 1364 case ProcessSingleton::PROCESS_NONE: |
| 1405 // No process already running, fall through to starting a new one. | 1365 // No process already running, fall through to starting a new one. |
| 1406 break; | 1366 break; |
| 1407 | 1367 |
| 1408 case ProcessSingleton::PROCESS_NOTIFIED: | 1368 case ProcessSingleton::PROCESS_NOTIFIED: |
| 1409 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 1369 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 1410 printf("%s\n", base::SysWideToNativeMB(UTF16ToWide( | 1370 printf("%s\n", base::SysWideToNativeMB(UTF16ToWide( |
| 1411 l10n_util::GetStringUTF16(IDS_USED_EXISTING_BROWSER))).c_str()); | 1371 l10n_util::GetStringUTF16(IDS_USED_EXISTING_BROWSER))).c_str()); |
| 1412 #endif | 1372 #endif |
| 1413 return content::RESULT_CODE_NORMAL_EXIT; | 1373 set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
| 1374 return; | |
| 1414 | 1375 |
| 1415 case ProcessSingleton::PROFILE_IN_USE: | 1376 case ProcessSingleton::PROFILE_IN_USE: |
| 1416 return chrome::RESULT_CODE_PROFILE_IN_USE; | 1377 set_result_code(chrome::RESULT_CODE_PROFILE_IN_USE); |
| 1378 return; | |
| 1417 | 1379 |
| 1418 case ProcessSingleton::LOCK_ERROR: | 1380 case ProcessSingleton::LOCK_ERROR: |
| 1419 LOG(ERROR) << "Failed to create a ProcessSingleton for your profile " | 1381 LOG(ERROR) << "Failed to create a ProcessSingleton for your profile " |
| 1420 "directory. This means that running multiple instances " | 1382 "directory. This means that running multiple instances " |
| 1421 "would start multiple browser processes rather than " | 1383 "would start multiple browser processes rather than " |
| 1422 "opening a new window in the existing process. Aborting " | 1384 "opening a new window in the existing process. Aborting " |
| 1423 "now to avoid profile corruption."; | 1385 "now to avoid profile corruption."; |
| 1424 return chrome::RESULT_CODE_PROFILE_IN_USE; | 1386 set_result_code(chrome::RESULT_CODE_PROFILE_IN_USE); |
| 1387 return; | |
| 1425 | 1388 |
| 1426 default: | 1389 default: |
| 1427 NOTREACHED(); | 1390 NOTREACHED(); |
| 1428 } | 1391 } |
| 1429 #if !defined(OS_MACOSX) // closing brace for if | 1392 #if !defined(OS_MACOSX) // closing brace for if |
| 1430 } | 1393 } |
| 1431 #endif | 1394 #endif |
| 1432 | 1395 |
| 1433 #if defined(USE_X11) | 1396 #if defined(USE_X11) |
| 1434 SetBrowserX11ErrorHandlers(); | 1397 SetBrowserX11ErrorHandlers(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1471 username); | 1434 username); |
| 1472 } | 1435 } |
| 1473 #endif | 1436 #endif |
| 1474 | 1437 |
| 1475 if (is_first_run) { | 1438 if (is_first_run) { |
| 1476 // Warn the ProfileManager that an import process will run, possibly | 1439 // Warn the ProfileManager that an import process will run, possibly |
| 1477 // locking the WebDataService directory of the next Profile created. | 1440 // locking the WebDataService directory of the next Profile created. |
| 1478 g_browser_process->profile_manager()->SetWillImport(); | 1441 g_browser_process->profile_manager()->SetWillImport(); |
| 1479 } | 1442 } |
| 1480 | 1443 |
| 1481 Profile* profile = CreateProfile(parameters(), user_data_dir, | 1444 profile_ = CreateProfile(parameters(), user_data_dir, parsed_command_line()); |
| 1482 parsed_command_line()); | 1445 if (!profile_) { |
| 1483 if (!profile) | 1446 set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
| 1484 return content::RESULT_CODE_NORMAL_EXIT; | 1447 return; |
| 1448 } | |
| 1485 | 1449 |
| 1486 // Post-profile init --------------------------------------------------------- | 1450 // Post-profile init --------------------------------------------------------- |
| 1487 | 1451 |
| 1488 #if defined(OS_CHROMEOS) | 1452 #if defined(OS_CHROMEOS) |
| 1489 // Pass the TokenService pointer to the policy connector so user policy can | 1453 // Pass the TokenService pointer to the policy connector so user policy can |
| 1490 // grab a token and register with the policy server. | 1454 // grab a token and register with the policy server. |
| 1491 // TODO(mnissler): Remove once OAuth is the only authentication mechanism. | 1455 // TODO(mnissler): Remove once OAuth is the only authentication mechanism. |
| 1492 if (parsed_command_line().HasSwitch(switches::kLoginUser) && | 1456 if (parsed_command_line().HasSwitch(switches::kLoginUser) && |
| 1493 !parsed_command_line().HasSwitch(switches::kLoginPassword)) { | 1457 !parsed_command_line().HasSwitch(switches::kLoginPassword)) { |
| 1494 g_browser_process->browser_policy_connector()->SetUserPolicyTokenService( | 1458 g_browser_process->browser_policy_connector()->SetUserPolicyTokenService( |
| 1495 profile->GetTokenService()); | 1459 profile_->GetTokenService()); |
| 1496 } | 1460 } |
| 1497 #endif | 1461 #endif |
| 1498 | 1462 |
| 1499 PrefService* user_prefs = profile->GetPrefs(); | 1463 PrefService* user_prefs = profile_->GetPrefs(); |
| 1500 DCHECK(user_prefs); | 1464 DCHECK(user_prefs); |
| 1501 | 1465 |
| 1502 // Tests should be able to tune login manager before showing it. | 1466 // Tests should be able to tune login manager before showing it. |
| 1503 // Thus only show login manager in normal (non-testing) mode. | 1467 // Thus only show login manager in normal (non-testing) mode. |
| 1504 if (!parameters().ui_task) { | 1468 if (!parameters().ui_task) { |
| 1505 OptionallyRunChromeOSLoginManager(parsed_command_line(), profile); | 1469 OptionallyRunChromeOSLoginManager(parsed_command_line(), profile_); |
| 1506 } | 1470 } |
| 1507 | 1471 |
| 1508 #if !defined(OS_MACOSX) | 1472 #if !defined(OS_MACOSX) |
| 1509 // Importing other browser settings is done in a browser-like process | 1473 // Importing other browser settings is done in a browser-like process |
| 1510 // that exits when this task has finished. | 1474 // that exits when this task has finished. |
| 1511 // TODO(port): Port the Mac's IPC-based implementation to other platforms to | 1475 // TODO(port): Port the Mac's IPC-based implementation to other platforms to |
| 1512 // replace this implementation. http://crbug.com/22142 | 1476 // replace this implementation. http://crbug.com/22142 |
| 1513 if (parsed_command_line().HasSwitch(switches::kImport) || | 1477 if (parsed_command_line().HasSwitch(switches::kImport) || |
| 1514 parsed_command_line().HasSwitch(switches::kImportFromFile)) { | 1478 parsed_command_line().HasSwitch(switches::kImportFromFile)) { |
| 1515 return FirstRun::ImportNow(profile, parsed_command_line()); | 1479 set_result_code(FirstRun::ImportNow(profile_, parsed_command_line())); |
| 1480 return; | |
| 1516 } | 1481 } |
| 1517 #endif | 1482 #endif |
| 1518 | 1483 |
| 1519 #if defined(OS_WIN) | 1484 #if defined(OS_WIN) |
| 1520 // Do the tasks if chrome has been upgraded while it was last running. | 1485 // Do the tasks if chrome has been upgraded while it was last running. |
| 1521 if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line())) | 1486 if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line())) { |
| 1522 return content::RESULT_CODE_NORMAL_EXIT; | 1487 set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
| 1488 return; | |
| 1489 } | |
| 1523 #endif | 1490 #endif |
| 1524 | 1491 |
| 1525 // Check if there is any machine level Chrome installed on the current | 1492 // Check if there is any machine level Chrome installed on the current |
| 1526 // machine. If yes and the current Chrome process is user level, we do not | 1493 // machine. If yes and the current Chrome process is user level, we do not |
| 1527 // allow the user level Chrome to run. So we notify the user and uninstall | 1494 // allow the user level Chrome to run. So we notify the user and uninstall |
| 1528 // user level Chrome. | 1495 // user level Chrome. |
| 1529 // Note this check should only happen here, after all the checks above | 1496 // Note this check should only happen here, after all the checks above |
| 1530 // (uninstall, resource bundle initialization, other chrome browser | 1497 // (uninstall, resource bundle initialization, other chrome browser |
| 1531 // processes etc). | 1498 // processes etc). |
| 1532 // Do not allow this to occur for Chrome Frame user-to-system handoffs. | 1499 // Do not allow this to occur for Chrome Frame user-to-system handoffs. |
| 1533 if (!parsed_command_line().HasSwitch(switches::kChromeFrame) && | 1500 if (!parsed_command_line().HasSwitch(switches::kChromeFrame) && |
| 1534 CheckMachineLevelInstall()) | 1501 CheckMachineLevelInstall()) { |
| 1535 return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS; | 1502 set_result_code(chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS); |
| 1503 return; | |
| 1504 } | |
| 1536 | 1505 |
| 1537 // Create the TranslateManager singleton. | 1506 // Create the TranslateManager singleton. |
| 1538 TranslateManager* translate_manager = TranslateManager::GetInstance(); | 1507 translate_manager_ = TranslateManager::GetInstance(); |
| 1539 DCHECK(translate_manager != NULL); | 1508 DCHECK(translate_manager_ != NULL); |
| 1540 | 1509 |
| 1541 #if defined(OS_MACOSX) | 1510 #if defined(OS_MACOSX) |
| 1542 if (!parsed_command_line().HasSwitch(switches::kNoFirstRun)) { | 1511 if (!parsed_command_line().HasSwitch(switches::kNoFirstRun)) { |
| 1543 // Disk image installation is sort of a first-run task, so it shares the | 1512 // Disk image installation is sort of a first-run task, so it shares the |
| 1544 // kNoFirstRun switch. | 1513 // kNoFirstRun switch. |
| 1545 if (MaybeInstallFromDiskImage()) { | 1514 if (MaybeInstallFromDiskImage()) { |
| 1546 // The application was installed and the installed copy has been | 1515 // The application was installed and the installed copy has been |
| 1547 // launched. This process is now obsolete. Exit. | 1516 // launched. This process is now obsolete. Exit. |
| 1548 return content::RESULT_CODE_NORMAL_EXIT; | 1517 set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
| 1518 return; | |
| 1549 } | 1519 } |
| 1550 } | 1520 } |
| 1551 #endif | 1521 #endif |
| 1552 | 1522 |
| 1553 // Show the First Run UI if this is the first time Chrome has been run on | 1523 // Show the First Run UI if this is the first time Chrome has been run on |
| 1554 // this computer, or we're being compelled to do so by a command line flag. | 1524 // this computer, or we're being compelled to do so by a command line flag. |
| 1555 // Note that this be done _after_ the PrefService is initialized and all | 1525 // Note that this be done _after_ the PrefService is initialized and all |
| 1556 // preferences are registered, since some of the code that the importer | 1526 // preferences are registered, since some of the code that the importer |
| 1557 // touches reads preferences. | 1527 // touches reads preferences. |
| 1558 if (is_first_run) { | 1528 if (is_first_run) { |
| 1559 if (!first_run_ui_bypass) { | 1529 if (!first_run_ui_bypass) { |
| 1560 FirstRun::AutoImport(profile, | 1530 FirstRun::AutoImport(profile_, |
| 1561 master_prefs.homepage_defined, | 1531 master_prefs_->homepage_defined, |
| 1562 master_prefs.do_import_items, | 1532 master_prefs_->do_import_items, |
| 1563 master_prefs.dont_import_items, | 1533 master_prefs_->dont_import_items, |
| 1564 master_prefs.run_search_engine_experiment, | 1534 master_prefs_->run_search_engine_experiment, |
| 1565 master_prefs.randomize_search_engine_experiment, | 1535 master_prefs_->randomize_search_engine_experiment, |
| 1566 master_prefs.make_chrome_default, | 1536 master_prefs_->make_chrome_default, |
| 1567 &process_singleton); | 1537 process_singleton_.get()); |
| 1568 #if defined(OS_POSIX) | 1538 #if defined(OS_POSIX) |
| 1569 // On Windows, the download is tagged with enable/disable stats so there | 1539 // On Windows, the download is tagged with enable/disable stats so there |
| 1570 // is no need for this code. | 1540 // is no need for this code. |
| 1571 | 1541 |
| 1572 // If stats reporting was turned on by the first run dialog then toggle | 1542 // If stats reporting was turned on by the first run dialog then toggle |
| 1573 // the pref. | 1543 // the pref. |
| 1574 if (GoogleUpdateSettings::GetCollectStatsConsent()) | 1544 if (GoogleUpdateSettings::GetCollectStatsConsent()) |
| 1575 local_state->SetBoolean(prefs::kMetricsReportingEnabled, true); | 1545 local_state->SetBoolean(prefs::kMetricsReportingEnabled, true); |
| 1576 #endif // OS_POSIX | 1546 #endif // OS_POSIX |
| 1577 } // if (!first_run_ui_bypass) | 1547 } // if (!first_run_ui_bypass) |
| 1578 | 1548 |
| 1579 Browser::SetNewHomePagePrefs(user_prefs); | 1549 Browser::SetNewHomePagePrefs(user_prefs); |
| 1580 g_browser_process->profile_manager()->OnImportFinished(profile); | 1550 g_browser_process->profile_manager()->OnImportFinished(profile_); |
| 1581 } // if (is_first_run) | 1551 } // if (is_first_run) |
| 1582 | 1552 |
| 1583 // Sets things up so that if we crash from this point on, a dialog will | 1553 // Sets things up so that if we crash from this point on, a dialog will |
| 1584 // popup asking the user to restart chrome. It is done this late to avoid | 1554 // popup asking the user to restart chrome. It is done this late to avoid |
| 1585 // testing against a bunch of special cases that are taken care early on. | 1555 // testing against a bunch of special cases that are taken care early on. |
| 1586 PrepareRestartOnCrashEnviroment(parsed_command_line()); | 1556 PrepareRestartOnCrashEnviroment(parsed_command_line()); |
| 1587 | 1557 |
| 1588 #if defined(OS_WIN) | 1558 #if defined(OS_WIN) |
| 1589 // Registers Chrome with the Windows Restart Manager, which will restore the | 1559 // Registers Chrome with the Windows Restart Manager, which will restore the |
| 1590 // Chrome session when the computer is restarted after a system update. | 1560 // Chrome session when the computer is restarted after a system update. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1602 bool preconnect_enabled = true; // Default status (easy to change!). | 1572 bool preconnect_enabled = true; // Default status (easy to change!). |
| 1603 if (parsed_command_line().HasSwitch(switches::kDisablePreconnect)) | 1573 if (parsed_command_line().HasSwitch(switches::kDisablePreconnect)) |
| 1604 preconnect_enabled = false; | 1574 preconnect_enabled = false; |
| 1605 else if (parsed_command_line().HasSwitch(switches::kEnablePreconnect)) | 1575 else if (parsed_command_line().HasSwitch(switches::kEnablePreconnect)) |
| 1606 preconnect_enabled = true; | 1576 preconnect_enabled = true; |
| 1607 chrome_browser_net::PredictorInit dns_prefetch( | 1577 chrome_browser_net::PredictorInit dns_prefetch( |
| 1608 user_prefs, | 1578 user_prefs, |
| 1609 local_state, | 1579 local_state, |
| 1610 preconnect_enabled); | 1580 preconnect_enabled); |
| 1611 | 1581 |
| 1612 #if defined(OS_WIN) | 1582 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
| 1613 base::win::ScopedCOMInitializer com_initializer; | |
| 1614 | |
| 1615 #if defined(GOOGLE_CHROME_BUILD) | |
| 1616 // Init the RLZ library. This just binds the dll and schedules a task on the | 1583 // Init the RLZ library. This just binds the dll and schedules a task on the |
| 1617 // file thread to be run sometime later. If this is the first run we record | 1584 // file thread to be run sometime later. If this is the first run we record |
| 1618 // the installation event. | 1585 // the installation event. |
| 1619 bool google_search_default = false; | 1586 bool google_search_default = false; |
| 1620 TemplateURLService* template_url_service = | 1587 TemplateURLService* template_url_service = |
| 1621 TemplateURLServiceFactory::GetForProfile(profile); | 1588 TemplateURLServiceFactory::GetForProfile(profile_); |
| 1622 if (template_url_service) { | 1589 if (template_url_service) { |
| 1623 const TemplateURL* url_template = | 1590 const TemplateURL* url_template = |
| 1624 template_url_service->GetDefaultSearchProvider(); | 1591 template_url_service->GetDefaultSearchProvider(); |
| 1625 if (url_template) { | 1592 if (url_template) { |
| 1626 const TemplateURLRef* urlref = url_template->url(); | 1593 const TemplateURLRef* urlref = url_template->url(); |
| 1627 if (urlref) { | 1594 if (urlref) { |
| 1628 google_search_default = urlref->HasGoogleBaseURLs(); | 1595 google_search_default = urlref->HasGoogleBaseURLs(); |
| 1629 } | 1596 } |
| 1630 } | 1597 } |
| 1631 } | 1598 } |
| 1632 | 1599 |
| 1633 bool google_search_homepage = false; | 1600 bool google_search_homepage = false; |
| 1634 PrefService* pref_service = profile->GetPrefs(); | 1601 PrefService* pref_service = profile_->GetPrefs(); |
| 1635 if (pref_service) { | 1602 if (pref_service) { |
| 1636 std::string homepage = pref_service->GetString(prefs::kHomePage); | 1603 std::string homepage = pref_service->GetString(prefs::kHomePage); |
| 1637 google_search_homepage = | 1604 google_search_homepage = |
| 1638 homepage == GoogleURLTracker::kDefaultGoogleHomepage; | 1605 homepage == GoogleURLTracker::kDefaultGoogleHomepage; |
| 1639 } | 1606 } |
| 1640 | 1607 |
| 1641 RLZTracker::InitRlzDelayed(is_first_run, master_prefs.ping_delay, | 1608 RLZTracker::InitRlzDelayed(is_first_run, master_prefs_->ping_delay, |
| 1642 google_search_default, google_search_homepage); | 1609 google_search_default, google_search_homepage); |
| 1643 | 1610 |
| 1644 // Prime the RLZ cache for the home page access point so that its avaiable | 1611 // Prime the RLZ cache for the home page access point so that its avaiable |
| 1645 // for the startup page if needed (i.e., when the startup page is set to | 1612 // for the startup page if needed (i.e., when the startup page is set to |
| 1646 // the home page). | 1613 // the home page). |
| 1647 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, NULL); | 1614 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, NULL); |
| 1648 | 1615 #endif // GOOGLE_CHROME_BUILD && OS_WIN |
| 1649 #endif // GOOGLE_CHROME_BUILD | |
| 1650 #endif // OS_WIN | |
| 1651 | 1616 |
| 1652 // Configure modules that need access to resources. | 1617 // Configure modules that need access to resources. |
| 1653 net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider); | 1618 net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider); |
| 1654 | 1619 |
| 1655 // In unittest mode, this will do nothing. In normal mode, this will create | 1620 // In unittest mode, this will do nothing. In normal mode, this will create |
| 1656 // the global GoogleURLTracker and IntranetRedirectDetector instances, which | 1621 // the global GoogleURLTracker and IntranetRedirectDetector instances, which |
| 1657 // will promptly go to sleep for five and seven seconds, respectively (to | 1622 // will promptly go to sleep for five and seven seconds, respectively (to |
| 1658 // avoid slowing startup), and wake up afterwards to see if they should do | 1623 // avoid slowing startup), and wake up afterwards to see if they should do |
| 1659 // anything else. | 1624 // anything else. |
| 1660 // | 1625 // |
| 1661 // A simpler way of doing all this would be to have some function which could | 1626 // A simpler way of doing all this would be to have some function which could |
| 1662 // give the time elapsed since startup, and simply have these objects check | 1627 // give the time elapsed since startup, and simply have these objects check |
| 1663 // that when asked to initialize themselves, but this doesn't seem to exist. | 1628 // that when asked to initialize themselves, but this doesn't seem to exist. |
| 1664 // | 1629 // |
| 1665 // These can't be created in the BrowserProcessImpl constructor because they | 1630 // These can't be created in the BrowserProcessImpl constructor because they |
| 1666 // need to read prefs that get set after that runs. | 1631 // need to read prefs that get set after that runs. |
| 1667 browser_process->google_url_tracker(); | 1632 browser_process_->google_url_tracker(); |
| 1668 browser_process->intranet_redirect_detector(); | 1633 browser_process_->intranet_redirect_detector(); |
| 1669 | 1634 |
| 1670 // Prepare for memory caching of SDCH dictionaries. | 1635 // Prepare for memory caching of SDCH dictionaries. |
| 1671 // Perform A/B test to measure global impact of SDCH support. | 1636 // Perform A/B test to measure global impact of SDCH support. |
| 1672 // Set up a field trial to see what disabling SDCH does to latency of page | 1637 // Set up a field trial to see what disabling SDCH does to latency of page |
| 1673 // layout globally. | 1638 // layout globally. |
| 1674 base::FieldTrial::Probability kSDCH_DIVISOR = 1000; | 1639 base::FieldTrial::Probability kSDCH_DIVISOR = 1000; |
| 1675 base::FieldTrial::Probability kSDCH_DISABLE_PROBABILITY = 1; // 0.1% prob. | 1640 base::FieldTrial::Probability kSDCH_DISABLE_PROBABILITY = 1; // 0.1% prob. |
| 1676 // After June 30, 2011 builds, it will always be in default group. | 1641 // After June 30, 2011 builds, it will always be in default group. |
| 1677 scoped_refptr<base::FieldTrial> sdch_trial( | 1642 scoped_refptr<base::FieldTrial> sdch_trial( |
| 1678 new base::FieldTrial("GlobalSdch", kSDCH_DIVISOR, "global_enable_sdch", | 1643 new base::FieldTrial("GlobalSdch", kSDCH_DIVISOR, "global_enable_sdch", |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1704 printing::PrintedDocument::set_debug_dump_path(path); | 1669 printing::PrintedDocument::set_debug_dump_path(path); |
| 1705 } | 1670 } |
| 1706 #endif | 1671 #endif |
| 1707 | 1672 |
| 1708 #if defined(TOUCH_UI) | 1673 #if defined(TOUCH_UI) |
| 1709 views::TouchFactory::GetInstance()->set_keep_mouse_cursor( | 1674 views::TouchFactory::GetInstance()->set_keep_mouse_cursor( |
| 1710 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepMouseCursor)); | 1675 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepMouseCursor)); |
| 1711 #endif | 1676 #endif |
| 1712 | 1677 |
| 1713 HandleTestParameters(parsed_command_line()); | 1678 HandleTestParameters(parsed_command_line()); |
| 1714 RecordBreakpadStatusUMA(metrics); | 1679 RecordBreakpadStatusUMA(metrics_); |
| 1715 about_flags::RecordUMAStatistics(local_state); | 1680 about_flags::RecordUMAStatistics(local_state); |
| 1716 LanguageUsageMetrics::RecordAcceptLanguages( | 1681 LanguageUsageMetrics::RecordAcceptLanguages( |
| 1717 profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 1682 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
| 1718 LanguageUsageMetrics::RecordApplicationLanguage( | 1683 LanguageUsageMetrics::RecordApplicationLanguage( |
| 1719 g_browser_process->GetApplicationLocale()); | 1684 g_browser_process->GetApplicationLocale()); |
| 1720 | 1685 |
| 1721 #if defined(OS_CHROMEOS) | 1686 #if defined(OS_CHROMEOS) |
| 1722 metrics->StartExternalMetrics(); | 1687 metrics_->StartExternalMetrics(); |
| 1723 | 1688 |
| 1724 // Initialize the brightness observer so that we'll display an onscreen | 1689 // Initialize the brightness observer so that we'll display an onscreen |
| 1725 // indication of brightness changes during login. | 1690 // indication of brightness changes during login. |
| 1726 static chromeos::BrightnessObserver* brightness_observer = | 1691 static chromeos::BrightnessObserver* brightness_observer = |
| 1727 new chromeos::BrightnessObserver(); | 1692 new chromeos::BrightnessObserver(); |
| 1728 chromeos::CrosLibrary::Get()->GetBrightnessLibrary()->AddObserver( | 1693 chromeos::CrosLibrary::Get()->GetBrightnessLibrary()->AddObserver( |
| 1729 brightness_observer); | 1694 brightness_observer); |
| 1730 | 1695 |
| 1731 // Listen for system key events so that the user will be able to adjust the | 1696 // Listen for system key events so that the user will be able to adjust the |
| 1732 // volume on the login screen. | 1697 // volume on the login screen. |
| 1733 chromeos::SystemKeyEventListener::GetInstance(); | 1698 chromeos::SystemKeyEventListener::GetInstance(); |
| 1734 | 1699 |
| 1735 // Listen for XI_HierarchyChanged events. | 1700 // Listen for XI_HierarchyChanged events. |
| 1736 chromeos::XInputHierarchyChangedEventListener::GetInstance(); | 1701 chromeos::XInputHierarchyChangedEventListener::GetInstance(); |
| 1737 #endif | 1702 #endif |
| 1738 | 1703 |
| 1739 // The extension service may be available at this point. If the command line | 1704 // The extension service may be available at this point. If the command line |
| 1740 // specifies --uninstall-extension, attempt the uninstall extension startup | 1705 // specifies --uninstall-extension, attempt the uninstall extension startup |
| 1741 // action. | 1706 // action. |
| 1742 if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) { | 1707 if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) { |
| 1743 ExtensionsStartupUtil ext_startup_util; | 1708 ExtensionsStartupUtil ext_startup_util; |
| 1744 if (ext_startup_util.UninstallExtension(parsed_command_line(), profile)) { | 1709 if (ext_startup_util.UninstallExtension(parsed_command_line(), profile_)) { |
| 1745 return content::RESULT_CODE_NORMAL_EXIT; | 1710 set_result_code(content::RESULT_CODE_NORMAL_EXIT); |
| 1746 } else { | 1711 } else { |
| 1747 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; | 1712 set_result_code(chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR); |
| 1748 } | 1713 } |
| 1714 return; | |
| 1749 } | 1715 } |
| 1750 | 1716 |
| 1751 #if defined(OS_WIN) | 1717 #if defined(OS_WIN) |
| 1752 // We check this here because if the profile is OTR (chromeos possibility) | 1718 // We check this here because if the profile is OTR (chromeos possibility) |
| 1753 // it won't still be accessible after browser is destroyed. | 1719 // it won't still be accessible after browser is destroyed. |
| 1754 bool record_search_engine = is_first_run && !profile->IsOffTheRecord(); | 1720 record_search_engine_ = is_first_run && !profile_->IsOffTheRecord(); |
| 1755 #endif | 1721 #endif |
| 1756 | 1722 |
| 1757 // ChildProcess:: is a misnomer unless you consider context. Use | 1723 // ChildProcess:: is a misnomer unless you consider context. Use |
| 1758 // of --wait-for-debugger only makes sense when Chrome itself is a | 1724 // of --wait-for-debugger only makes sense when Chrome itself is a |
| 1759 // child process (e.g. when launched by PyAuto). | 1725 // child process (e.g. when launched by PyAuto). |
| 1760 if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) { | 1726 if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) { |
| 1761 ChildProcess::WaitForDebugger("Browser"); | 1727 ChildProcess::WaitForDebugger("Browser"); |
| 1762 } | 1728 } |
| 1763 | 1729 |
| 1764 #if defined(OS_CHROMEOS) | 1730 #if defined(OS_CHROMEOS) |
| 1765 // Run the Out of Memory priority manager while in this scope. Wait | 1731 // Run the Out of Memory priority manager while in this scope. Wait |
| 1766 // until here to start so that we give the most amount of time for | 1732 // until here to start so that we give the most amount of time for |
| 1767 // the other services to start up before we start adjusting the oom | 1733 // the other services to start up before we start adjusting the oom |
| 1768 // priority. In reality, it doesn't matter much where in this scope | 1734 // priority. In reality, it doesn't matter much where in this scope |
| 1769 // this is started, but it must be started in this scope so it will | 1735 // this is started, but it must be started in this scope so it will |
| 1770 // also be terminated when this scope exits. | 1736 // also be terminated when this scope exits. |
| 1771 scoped_ptr<browser::OomPriorityManager> oom_priority_manager( | 1737 scoped_ptr<browser::OomPriorityManager> oom_priority_manager( |
| 1772 new browser::OomPriorityManager); | 1738 new browser::OomPriorityManager); |
| 1773 #endif | 1739 #endif |
| 1774 | 1740 |
| 1775 // Create the instance of the cloud print proxy service so that it can launch | 1741 // Create the instance of the cloud print proxy service so that it can launch |
| 1776 // the service process if needed. This is needed because the service process | 1742 // the service process if needed. This is needed because the service process |
| 1777 // might have shutdown because an update was available. | 1743 // might have shutdown because an update was available. |
| 1778 // TODO(torne): this should maybe be done with | 1744 // TODO(torne): this should maybe be done with |
| 1779 // ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead? | 1745 // ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead? |
| 1780 CloudPrintProxyServiceFactory::GetForProfile(profile); | 1746 CloudPrintProxyServiceFactory::GetForProfile(profile_); |
| 1781 | 1747 |
| 1782 // Initialize GpuDataManager and collect preliminary gpu info on FILE thread. | 1748 // Initialize GpuDataManager and collect preliminary gpu info on FILE thread. |
| 1783 // Upon completion, it posts GpuBlacklist auto update task on UI thread. | 1749 // Upon completion, it posts GpuBlacklist auto update task on UI thread. |
| 1784 BrowserThread::PostTask( | 1750 BrowserThread::PostTask( |
| 1785 BrowserThread::FILE, FROM_HERE, | 1751 BrowserThread::FILE, FROM_HERE, |
| 1786 NewRunnableFunction(&GpuBlacklistUpdater::SetupOnFileThread)); | 1752 NewRunnableFunction(&GpuBlacklistUpdater::SetupOnFileThread)); |
| 1787 | 1753 |
| 1788 // Start watching all browser threads for responsiveness. | 1754 // Start watching all browser threads for responsiveness. |
| 1789 ThreadWatcherList::StartWatchingAll(parsed_command_line()); | 1755 ThreadWatcherList::StartWatchingAll(parsed_command_line()); |
| 1790 | 1756 |
|
jam
2011/09/08 16:21:06
fixed this spacing and also 1766
| |
| 1757 | |
| 1791 int result_code = content::RESULT_CODE_NORMAL_EXIT; | 1758 int result_code = content::RESULT_CODE_NORMAL_EXIT; |
| 1792 base::mac::ScopedNSAutoreleasePool* pool = parameters().autorelease_pool_; | 1759 base::mac::ScopedNSAutoreleasePool* pool = parameters().autorelease_pool_; |
| 1793 if (parameters().ui_task) { | 1760 if (parameters().ui_task) { |
| 1794 // We are in test mode. Run one task and enter the main message loop. | 1761 // We are in test mode. Run one task and enter the main message loop. |
| 1795 if (pool) | 1762 if (pool) |
| 1796 pool->Recycle(); | 1763 pool->Recycle(); |
| 1797 parameters().ui_task->Run(); | 1764 parameters().ui_task->Run(); |
| 1798 delete parameters().ui_task; | 1765 delete parameters().ui_task; |
| 1799 } else { | 1766 } else { |
| 1800 // Most general initialization is behind us, but opening a | 1767 // Most general initialization is behind us, but opening a |
| 1801 // tab and/or session restore and such is still to be done. | 1768 // tab and/or session restore and such is still to be done. |
| 1802 base::TimeTicks browser_open_start = base::TimeTicks::Now(); | 1769 base::TimeTicks browser_open_start = base::TimeTicks::Now(); |
| 1803 | 1770 |
| 1804 // We are in regular browser boot sequence. Open initial tabs and enter the | 1771 // We are in regular browser boot sequence. Open initial tabs and enter the |
| 1805 // main message loop. | 1772 // main message loop. |
| 1806 if (browser_init.Start(parsed_command_line(), FilePath(), profile, | 1773 if (browser_init.Start(parsed_command_line(), FilePath(), profile_, |
| 1807 &result_code)) { | 1774 &result_code)) { |
| 1808 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 1775 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| 1809 // Initialize autoupdate timer. Timer callback costs basically nothing | 1776 // Initialize autoupdate timer. Timer callback costs basically nothing |
| 1810 // when browser is not in persistent mode, so it's OK to let it ride on | 1777 // when browser is not in persistent mode, so it's OK to let it ride on |
| 1811 // the main thread. This needs to be done here because we don't want | 1778 // the main thread. This needs to be done here because we don't want |
| 1812 // to start the timer when Chrome is run inside a test harness. | 1779 // to start the timer when Chrome is run inside a test harness. |
| 1813 g_browser_process->StartAutoupdateTimer(); | 1780 g_browser_process->StartAutoupdateTimer(); |
| 1814 #endif | 1781 #endif |
| 1815 | 1782 |
| 1816 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 1783 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1829 pool->Recycle(); | 1796 pool->Recycle(); |
| 1830 | 1797 |
| 1831 RecordPreReadExperimentTime("Startup.BrowserOpenTabs", | 1798 RecordPreReadExperimentTime("Startup.BrowserOpenTabs", |
| 1832 base::TimeTicks::Now() - browser_open_start); | 1799 base::TimeTicks::Now() - browser_open_start); |
| 1833 | 1800 |
| 1834 // TODO(mad): Move this call in a proper place on CrOS. | 1801 // TODO(mad): Move this call in a proper place on CrOS. |
| 1835 // http://crosbug.com/17687 | 1802 // http://crosbug.com/17687 |
| 1836 #if !defined(OS_CHROMEOS) | 1803 #if !defined(OS_CHROMEOS) |
| 1837 // If we're running tests (ui_task is non-null), then we don't want to | 1804 // If we're running tests (ui_task is non-null), then we don't want to |
| 1838 // call FetchLanguageListFromTranslateServer | 1805 // call FetchLanguageListFromTranslateServer |
| 1839 if (parameters().ui_task == NULL && translate_manager != NULL) { | 1806 if (parameters().ui_task == NULL && translate_manager_ != NULL) { |
| 1840 // TODO(willchan): Get rid of this after TranslateManager doesn't use | 1807 // TODO(willchan): Get rid of this after TranslateManager doesn't use |
| 1841 // the default request context. http://crbug.com/89396. | 1808 // the default request context. http://crbug.com/89396. |
| 1842 // This is necessary to force |default_request_context_| to be | 1809 // This is necessary to force |default_request_context_| to be |
| 1843 // initialized. | 1810 // initialized. |
| 1844 profile->GetRequestContext(); | 1811 profile_->GetRequestContext(); |
| 1845 translate_manager->FetchLanguageListFromTranslateServer(user_prefs); | 1812 translate_manager_->FetchLanguageListFromTranslateServer(user_prefs); |
| 1846 } | 1813 } |
| 1847 #endif | 1814 #endif |
| 1848 | 1815 |
| 1849 RunUIMessageLoop(browser_process.get()); | 1816 run_message_loop_ = true; |
| 1850 } | 1817 } |
| 1851 } | 1818 } |
| 1819 } | |
| 1852 | 1820 |
| 1821 void ChromeBrowserMainParts::MainMessageLoopRun() { | |
| 1822 if (!run_message_loop_) | |
| 1823 return; | |
| 1824 | |
| 1825 // This should be invoked as close to the start of the browser's | |
| 1826 // UI thread message loop as possible to get a stable measurement | |
| 1827 // across versions. | |
| 1828 RecordBrowserStartupTime(); | |
| 1829 | |
| 1830 #if defined(TOOLKIT_VIEWS) | |
| 1831 views::AcceleratorHandler accelerator_handler; | |
| 1832 MessageLoopForUI::current()->Run(&accelerator_handler); | |
| 1833 #elif defined(USE_X11) | |
| 1834 MessageLoopForUI::current()->Run(NULL); | |
| 1835 #elif defined(OS_POSIX) | |
| 1836 MessageLoopForUI::current()->Run(); | |
| 1837 #endif | |
| 1838 #if defined(OS_CHROMEOS) | |
| 1839 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("UIMessageLoopEnded", | |
| 1840 true); | |
| 1841 #endif | |
| 1842 } | |
| 1843 | |
| 1844 void ChromeBrowserMainParts::PostMainMessageLoopRun() { | |
| 1853 // Start watching for jank during shutdown. It gets disarmed when | 1845 // Start watching for jank during shutdown. It gets disarmed when |
| 1854 // |shutdown_watcher_| object is destructed. | 1846 // |shutdown_watcher_| object is destructed. |
| 1855 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(45)); | 1847 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(45)); |
| 1856 | 1848 |
| 1857 #if defined(OS_WIN) | 1849 #if defined(OS_WIN) |
| 1858 // If it's the first run, log the search engine chosen. We wait until | 1850 // If it's the first run, log the search engine chosen. We wait until |
| 1859 // shutdown because otherwise we can't be sure the user has finished | 1851 // shutdown because otherwise we can't be sure the user has finished |
| 1860 // selecting a search engine through the dialog reached from the first run | 1852 // selecting a search engine through the dialog reached from the first run |
| 1861 // bubble link. | 1853 // bubble link. |
| 1862 if (record_search_engine) { | 1854 if (record_search_engine_) { |
| 1863 TemplateURLService* url_service = | 1855 TemplateURLService* url_service = |
| 1864 TemplateURLServiceFactory::GetForProfile(profile); | 1856 TemplateURLServiceFactory::GetForProfile(profile_); |
| 1865 const TemplateURL* default_search_engine = | 1857 const TemplateURL* default_search_engine = |
| 1866 url_service->GetDefaultSearchProvider(); | 1858 url_service->GetDefaultSearchProvider(); |
| 1867 // The default engine can be NULL if the administrator has disabled | 1859 // The default engine can be NULL if the administrator has disabled |
| 1868 // default search. | 1860 // default search. |
| 1869 SearchEngineType search_engine_type = | 1861 SearchEngineType search_engine_type = |
| 1870 default_search_engine ? default_search_engine->search_engine_type() : | 1862 default_search_engine ? default_search_engine->search_engine_type() : |
| 1871 SEARCH_ENGINE_OTHER; | 1863 SEARCH_ENGINE_OTHER; |
| 1872 // Record the search engine chosen. | 1864 // Record the search engine chosen. |
| 1873 if (master_prefs.run_search_engine_experiment) { | 1865 if (master_prefs_->run_search_engine_experiment) { |
| 1874 UMA_HISTOGRAM_ENUMERATION( | 1866 UMA_HISTOGRAM_ENUMERATION( |
| 1875 "Chrome.SearchSelectExperiment", | 1867 "Chrome.SearchSelectExperiment", |
| 1876 search_engine_type, | 1868 search_engine_type, |
| 1877 SEARCH_ENGINE_MAX); | 1869 SEARCH_ENGINE_MAX); |
| 1878 // If the selection has been randomized, also record the winner by slot. | 1870 // If the selection has been randomized, also record the winner by slot. |
| 1879 if (master_prefs.randomize_search_engine_experiment) { | 1871 if (master_prefs_->randomize_search_engine_experiment) { |
| 1880 size_t engine_pos = url_service->GetSearchEngineDialogSlot(); | 1872 size_t engine_pos = url_service->GetSearchEngineDialogSlot(); |
| 1881 if (engine_pos < 4) { | 1873 if (engine_pos < 4) { |
| 1882 std::string experiment_type = "Chrome.SearchSelectExperimentSlot"; | 1874 std::string experiment_type = "Chrome.SearchSelectExperimentSlot"; |
| 1883 // Nicer in UMA if slots are 1-based. | 1875 // Nicer in UMA if slots are 1-based. |
| 1884 experiment_type.push_back('1' + engine_pos); | 1876 experiment_type.push_back('1' + engine_pos); |
| 1885 UMA_HISTOGRAM_ENUMERATION( | 1877 UMA_HISTOGRAM_ENUMERATION( |
| 1886 experiment_type, | 1878 experiment_type, |
| 1887 search_engine_type, | 1879 search_engine_type, |
| 1888 SEARCH_ENGINE_MAX); | 1880 SEARCH_ENGINE_MAX); |
| 1889 } else { | 1881 } else { |
| 1890 NOTREACHED() << "Invalid search engine selection slot."; | 1882 NOTREACHED() << "Invalid search engine selection slot."; |
| 1891 } | 1883 } |
| 1892 } | 1884 } |
| 1893 } else { | 1885 } else { |
| 1894 UMA_HISTOGRAM_ENUMERATION( | 1886 UMA_HISTOGRAM_ENUMERATION( |
| 1895 "Chrome.SearchSelectExempt", | 1887 "Chrome.SearchSelectExempt", |
| 1896 search_engine_type, | 1888 search_engine_type, |
| 1897 SEARCH_ENGINE_MAX); | 1889 SEARCH_ENGINE_MAX); |
| 1898 } | 1890 } |
| 1899 } | 1891 } |
| 1900 #endif | 1892 #endif |
| 1901 | 1893 |
| 1902 // Some tests don't set parameters.ui_task, so they started translate | 1894 // Some tests don't set parameters.ui_task, so they started translate |
| 1903 // language fetch that was never completed so we need to cleanup here | 1895 // language fetch that was never completed so we need to cleanup here |
| 1904 // otherwise it will be done by the destructor in a wrong thread. | 1896 // otherwise it will be done by the destructor in a wrong thread. |
| 1905 if (parameters().ui_task == NULL && translate_manager != NULL) | 1897 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
| |
| 1906 translate_manager->CleanupPendingUlrFetcher(); | 1898 translate_manager_->CleanupPendingUlrFetcher(); |
| 1907 | 1899 |
| 1908 | 1900 process_singleton_->Cleanup(); |
| 1909 process_singleton.Cleanup(); | |
| 1910 | 1901 |
| 1911 // Stop all tasks that might run on WatchDogThread. | 1902 // Stop all tasks that might run on WatchDogThread. |
| 1912 ThreadWatcherList::StopWatchingAll(); | 1903 ThreadWatcherList::StopWatchingAll(); |
| 1913 | 1904 |
| 1914 metrics->Stop(); | 1905 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.
| |
| 1915 | 1906 |
| 1916 // browser_shutdown takes care of deleting browser_process, so we need to | 1907 // browser_shutdown takes care of deleting browser_process, so we need to |
| 1917 // release it. | 1908 // release it. |
| 1918 ignore_result(browser_process.release()); | 1909 ignore_result(browser_process_.release()); |
| 1919 browser_shutdown::Shutdown(); | 1910 browser_shutdown::Shutdown(); |
| 1911 master_prefs_.reset(); | |
| 1912 process_singleton_.reset(); | |
| 1913 } | |
| 1920 | 1914 |
| 1921 return result_code; | 1915 void ChromeBrowserMainParts::ToolkitInitialized() { |
| 1916 #if defined(TOOLKIT_VIEWS) | |
| 1917 // The delegate needs to be set before any UI is created so that windows | |
| 1918 // display the correct icon. | |
| 1919 if (!views::ViewsDelegate::views_delegate) | |
| 1920 views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; | |
| 1921 | |
| 1922 // TODO(beng): Move to WidgetImpl and implement on Windows too! | |
| 1923 if (parameters().command_line_.HasSwitch(switches::kDebugViewsPaint)) | |
| 1924 views::Widget::SetDebugPaintEnabled(true); | |
| 1925 #endif | |
| 1926 | |
| 1927 #if defined(OS_WIN) | |
| 1928 gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; | |
| 1929 gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; | |
| 1930 #endif | |
| 1922 } | 1931 } |
| 1923 | 1932 |
| 1924 // This code is specific to the Windows-only PreReadExperiment field-trial. | 1933 // This code is specific to the Windows-only PreReadExperiment field-trial. |
| 1925 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) { | 1934 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) { |
| 1926 DCHECK(name != NULL); | 1935 DCHECK(name != NULL); |
| 1927 | 1936 |
| 1928 // This gets called with different histogram names, so we don't want to use | 1937 // This gets called with different histogram names, so we don't want to use |
| 1929 // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the | 1938 // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the |
| 1930 // first call wins. | 1939 // first call wins. |
| 1931 AddPreReadHistogramTime(name, time); | 1940 AddPreReadHistogramTime(name, time); |
| 1932 | 1941 |
| 1933 #if defined(OS_WIN) | 1942 #if defined(OS_WIN) |
| 1934 #if defined(GOOGLE_CHROME_BUILD) | 1943 #if defined(GOOGLE_CHROME_BUILD) |
| 1935 // The pre-read experiment is Windows and Google Chrome specific. | 1944 // The pre-read experiment is Windows and Google Chrome specific. |
| 1936 scoped_ptr<base::Environment> env(base::Environment::Create()); | 1945 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 1937 | 1946 |
| 1938 // Only record the sub-histogram result if the experiment is running | 1947 // Only record the sub-histogram result if the experiment is running |
| 1939 // (environment variable is set, and valid). | 1948 // (environment variable is set, and valid). |
| 1940 std::string pre_read; | 1949 std::string pre_read; |
| 1941 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && | 1950 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && |
| 1942 (pre_read == "0" || pre_read == "1")) { | 1951 (pre_read == "0" || pre_read == "1")) { |
| 1943 std::string uma_name(name); | 1952 std::string uma_name(name); |
| 1944 uma_name += "_PreRead"; | 1953 uma_name += "_PreRead"; |
| 1945 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; | 1954 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; |
| 1946 AddPreReadHistogramTime(uma_name.c_str(), time); | 1955 AddPreReadHistogramTime(uma_name.c_str(), time); |
| 1947 } | 1956 } |
| 1948 #endif | 1957 #endif |
| 1949 #endif | 1958 #endif |
| 1950 } | 1959 } |
| OLD | NEW |