blob: 09ede3412fd5a4ff02156ba5abb0aa8681ad9fa1 [file] [log] [blame]
[email protected]c65aafcc2012-01-04 15:05:501// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]e6b5bc22011-09-08 22:01:565#include "chrome/browser/chrome_browser_main.h"
[email protected]5c9587c2008-12-09 21:20:166
[email protected]cbdb7a32012-11-13 16:36:047#if defined(TOOLKIT_GTK)
8#include <gtk/gtk.h>
9#endif
10
[email protected]01109dcf2010-03-27 00:56:4311#include <string>
12#include <vector>
[email protected]a1a130f7d2009-01-09 20:28:4413
[email protected]e2cc2e62010-08-28 00:26:3714#include "base/at_exit.h"
[email protected]97f3ac632011-10-19 20:09:5615#include "base/bind.h"
[email protected]1bcdb532009-01-16 17:47:5716#include "base/command_line.h"
[email protected]5016a9dd2013-02-02 01:10:0217#include "base/cpu.h"
[email protected]58580352010-10-26 04:07:5018#include "base/debug/trace_event.h"
[email protected]1bcdb532009-01-16 17:47:5719#include "base/file_util.h"
[email protected]57999812013-02-24 05:40:5220#include "base/files/file_path.h"
[email protected]835d7c82010-10-14 04:38:3821#include "base/metrics/field_trial.h"
22#include "base/metrics/histogram.h"
[email protected]1bcdb532009-01-16 17:47:5723#include "base/path_service.h"
[email protected]03b9b4e2012-10-22 20:01:5224#include "base/prefs/json_pref_store.h"
[email protected]3853a4c2013-02-11 17:15:5725#include "base/prefs/pref_registry_simple.h"
26#include "base/prefs/pref_service.h"
27#include "base/prefs/pref_value_store.h"
[email protected]843bc462012-06-19 17:43:3128#include "base/process_info.h"
[email protected]1bcdb532009-01-16 17:47:5729#include "base/process_util.h"
[email protected]8e937c1e2012-06-28 22:57:3030#include "base/run_loop.h"
[email protected]1bcdb532009-01-16 17:47:5731#include "base/string_piece.h"
[email protected]3ea1b182013-02-08 22:38:4132#include "base/strings/string_number_conversions.h"
[email protected]1988e1c2013-02-28 20:27:4233#include "base/strings/string_split.h"
[email protected]0f24e53e2012-10-29 01:04:0934#include "base/sys_info.h"
[email protected]4efe77c2009-07-18 03:25:3235#include "base/sys_string_conversions.h"
[email protected]93270d002011-01-19 22:32:5936#include "base/threading/platform_thread.h"
[email protected]89886652012-12-11 18:09:0737#include "base/threading/sequenced_worker_pool.h"
[email protected]6b5f21d2009-04-13 17:01:3538#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2239#include "base/utf_string_conversions.h"
[email protected]1bcdb532009-01-16 17:47:5740#include "base/values.h"
[email protected]01109dcf2010-03-27 00:56:4341#include "build/build_config.h"
[email protected]4bc5050c2010-11-18 17:55:5442#include "chrome/browser/about_flags.h"
[email protected]5d364542012-04-05 07:15:3943#include "chrome/browser/browser_process.h"
[email protected]b112a4c2009-02-01 20:24:0144#include "chrome/browser/browser_process_impl.h"
[email protected]7f0ebc92009-02-05 18:34:2145#include "chrome/browser/browser_shutdown.h"
[email protected]50462bf02011-11-21 19:13:3146#include "chrome/browser/chrome_browser_main_extra_parts.h"
[email protected]8cebc942013-01-31 01:28:4247#include "chrome/browser/component_updater/component_updater_service.h"
48#include "chrome/browser/component_updater/flash_component_installer.h"
49#include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
50#include "chrome/browser/component_updater/recovery_component_installer.h"
51#include "chrome/browser/component_updater/swiftshader_component_installer.h"
[email protected]10189862011-04-15 21:42:0352#include "chrome/browser/defaults.h"
[email protected]f7e615a2009-06-26 19:50:5253#include "chrome/browser/extensions/extension_protocols.h"
[email protected]eaa7dd182010-12-14 11:09:0054#include "chrome/browser/extensions/extension_service.h"
[email protected]d9ede582012-08-14 19:21:3855#include "chrome/browser/extensions/startup_helper.h"
[email protected]1a905b72012-12-20 00:22:1356#include "chrome/browser/first_run/first_run.h"
[email protected]815856722011-04-13 17:19:1957#include "chrome/browser/first_run/upgrade_util.h"
[email protected]ed666562012-03-21 19:49:5258#include "chrome/browser/google/google_search_counter.h"
[email protected]7a336d6ec2011-10-07 14:17:5859#include "chrome/browser/google/google_util.h"
[email protected]c3da80c2012-12-07 20:57:2460#include "chrome/browser/gpu/chrome_gpu_util.h"
[email protected]a9830b52012-12-17 23:30:3661#include "chrome/browser/gpu/gl_string_manager.h"
[email protected]86230b92009-11-23 20:38:3862#include "chrome/browser/jankometer.h"
[email protected]46690b72012-10-26 19:33:3263#include "chrome/browser/managed_mode/managed_mode.h"
[email protected]4cb3c1fc2012-04-05 07:23:4864#include "chrome/browser/metrics/field_trial_synchronizer.h"
[email protected]679082052010-07-21 21:30:1365#include "chrome/browser/metrics/metrics_log.h"
[email protected]dc6f4962009-02-13 01:25:5066#include "chrome/browser/metrics/metrics_service.h"
[email protected]0b565182011-03-02 18:11:1567#include "chrome/browser/metrics/thread_watcher.h"
[email protected]10fe40c2011-11-05 03:27:4668#include "chrome/browser/metrics/tracking_synchronizer.h"
[email protected]cf265dc02012-08-15 01:01:1669#include "chrome/browser/metrics/variations/variations_service.h"
[email protected]773ebb92011-11-15 19:06:5270#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]82c71ba2011-05-27 18:51:5371#include "chrome/browser/net/chrome_net_log.h"
[email protected]8cebc942013-01-31 01:28:4272#include "chrome/browser/net/crl_set_fetcher.h"
[email protected]59368d9d2012-01-31 01:02:5473#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]aa84a7e2012-03-15 21:29:0674#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]684dace42012-07-01 14:30:4175#include "chrome/browser/page_cycler/page_cycler.h"
[email protected]d378f192012-08-14 18:42:0376#include "chrome/browser/performance_monitor/performance_monitor.h"
[email protected]0c1c4752012-08-09 20:30:2477#include "chrome/browser/performance_monitor/startup_timer.h"
[email protected]0f5e57f52012-09-20 20:53:1878#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]c83399d1f2012-09-19 01:50:5479#include "chrome/browser/policy/policy_service.h"
[email protected]5b199522012-12-22 17:24:4480#include "chrome/browser/prefs/chrome_pref_service_factory.h"
81#include "chrome/browser/prefs/command_line_pref_store.h"
[email protected]1583def2012-01-25 11:26:3282#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]59368d9d2012-01-31 01:02:5483#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
[email protected]aa84a7e2012-03-15 21:29:0684#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
[email protected]e3db4fab2009-04-21 21:47:4085#include "chrome/browser/process_singleton.h"
[email protected]8ecad5e2010-12-02 21:18:3386#include "chrome/browser/profiles/profile.h"
87#include "chrome/browser/profiles/profile_manager.h"
[email protected]23872902010-10-26 03:43:5988#include "chrome/browser/search_engines/search_engine_type.h"
[email protected]8b62334b2010-08-31 22:37:1189#include "chrome/browser/search_engines/template_url.h"
[email protected]b37bdfe2012-03-16 20:53:2790#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
[email protected]59368d9d2012-01-31 01:02:5491#include "chrome/browser/search_engines/template_url_service.h"
[email protected]aa84a7e2012-03-15 21:29:0692#include "chrome/browser/search_engines/template_url_service_factory.h"
[email protected]e96bf0c52010-08-23 23:20:5793#include "chrome/browser/service/service_process_control.h"
[email protected]1bcdb532009-01-16 17:47:5794#include "chrome/browser/shell_integration.h"
[email protected]44327692013-02-26 21:21:2295#include "chrome/browser/three_d_api_observer.h"
[email protected]509acb8e2010-07-01 20:35:3196#include "chrome/browser/translate/translate_manager.h"
[email protected]f0ee7912013-02-27 06:02:5597#include "chrome/browser/ui/app_list/app_list_service.h"
[email protected]f46be6e2010-11-16 03:52:3298#include "chrome/browser/ui/browser.h"
[email protected]278a34d2012-06-07 00:34:5899#include "chrome/browser/ui/browser_finder.h"
[email protected]55d342402013-02-22 11:28:06100#include "chrome/browser/ui/host_desktop.h"
[email protected]eed73252012-08-03 18:47:44101#include "chrome/browser/ui/startup/default_browser_prompt.h"
[email protected]fe7c4872012-05-10 20:06:03102#include "chrome/browser/ui/startup/startup_browser_creator.h"
[email protected]3770c242012-07-12 22:58:17103#include "chrome/browser/ui/uma_browsing_activity_observer.h"
[email protected]eea4c6d2012-05-15 18:10:56104#include "chrome/browser/ui/user_data_dir_dialog.h"
[email protected]d5656f1c2013-01-29 01:31:26105#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]783f06f2011-09-14 01:36:11106#include "chrome/common/child_process_logging.h"
[email protected]1bcdb532009-01-16 17:47:57107#include "chrome/common/chrome_constants.h"
108#include "chrome/common/chrome_paths.h"
[email protected]1fcfb202011-07-19 19:53:14109#include "chrome/common/chrome_result_codes.h"
[email protected]1bcdb532009-01-16 17:47:57110#include "chrome/common/chrome_switches.h"
[email protected]1b084b5e2010-08-03 07:58:19111#include "chrome/common/env_vars.h"
[email protected]30f547c2010-08-04 01:00:01112#include "chrome/common/logging_chrome.h"
[email protected]cf265dc02012-08-15 01:01:16113#include "chrome/common/metrics/variations/variations_util.h"
[email protected]64d50ed2009-09-22 21:05:47114#include "chrome/common/net/net_resource_provider.h"
[email protected]1bcdb532009-01-16 17:47:57115#include "chrome/common/pref_names.h"
[email protected]7664ab32011-02-01 23:35:25116#include "chrome/common/profiling.h"
[email protected]54676d0e2012-10-24 10:28:30117#include "chrome/common/startup_metric_utils.h"
[email protected]1e7377d2009-05-28 20:23:06118#include "chrome/installer/util/google_update_settings.h"
[email protected]c38831a12011-10-28 12:44:49119#include "content/public/browser/browser_thread.h"
[email protected]e327c752013-01-30 11:38:16120#include "content/public/browser/notification_observer.h"
121#include "content/public/browser/notification_registrar.h"
122#include "content/public/browser/notification_service.h"
123#include "content/public/browser/notification_types.h"
[email protected]5d1fa242011-10-18 23:35:38124#include "content/public/common/content_client.h"
[email protected]86d3aca2012-12-04 21:36:09125#include "content/public/common/content_switches.h"
[email protected]4573fbd2011-10-31 20:25:18126#include "content/public/common/main_function_params.h"
[email protected]ea500fc62010-03-22 21:34:29127#include "grit/app_locale_settings.h"
[email protected]4e039f242011-12-03 07:29:38128#include "grit/browser_resources.h"
[email protected]34ac8f32009-02-22 23:03:27129#include "grit/chromium_strings.h"
130#include "grit/generated_resources.h"
[email protected]61c6f412011-03-23 20:47:54131#include "grit/platform_locale_settings.h"
[email protected]698cccb12009-03-11 18:47:24132#include "net/base/net_module.h"
[email protected]3b543ab2011-09-17 21:47:00133#include "net/base/sdch_manager.h"
[email protected]aa84a7e2012-03-15 21:29:06134#include "net/cookies/cookie_monster.h"
[email protected]e0345002012-09-01 03:06:12135#include "net/http/http_network_layer.h"
[email protected]8e6441ca2010-08-19 05:56:38136#include "net/http/http_stream_factory.h"
[email protected]abb26092010-11-11 22:19:00137#include "net/url_request/url_request.h"
[email protected]e39027a2011-01-24 21:41:54138#include "ui/base/l10n/l10n_util.h"
[email protected]6bae7352012-06-15 15:46:46139#include "ui/base/layout.h"
[email protected]42ce29d2011-01-20 23:19:46140#include "ui/base/resource/resource_bundle.h"
[email protected]63942f22012-05-01 06:11:52141#include "ui/base/resource/resource_handle.h"
[email protected]b19e0e2e2013-02-06 18:15:51142#include "ui/base/touch/touch_device.h"
143#include "ui/base/ui_base_switches.h"
[email protected]1bcdb532009-01-16 17:47:57144
[email protected]000bed62012-10-20 01:35:36145#if defined(OS_ANDROID)
146#include "base/android/build_info.h"
147#endif
148
[email protected]3e087992011-04-14 22:28:12149#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
150#include "chrome/browser/first_run/upgrade_util_linux.h"
151#endif
152
[email protected]d4fe1fbc2010-05-19 17:36:06153#if defined(OS_CHROMEOS)
[email protected]3e087992011-04-14 22:28:12154#include "chrome/browser/chromeos/cros/cros_library.h"
[email protected]edaf5962012-08-01 11:31:31155#include "chrome/browser/chromeos/settings/cros_settings.h"
156#include "chrome/browser/chromeos/settings/cros_settings_names.h"
[email protected]d4fe1fbc2010-05-19 17:36:06157#endif
158
[email protected]022614ef92008-12-30 20:50:01159// TODO(port): several win-only methods have been pulled out of this, but
[email protected]5c9587c2008-12-09 21:20:16160// BrowserMain() as a whole needs to be broken apart so that it's usable by
[email protected]022614ef92008-12-30 20:50:01161// other platforms. For now, it's just a stub. This is a serious work in
[email protected]5c9587c2008-12-09 21:20:16162// progress and should not be taken as an indication of a real refactoring.
163
164#if defined(OS_WIN)
[email protected]28f576f2011-08-26 20:46:55165#include "base/environment.h" // For PreRead experiment.
[email protected]0fd23af2011-02-20 06:33:04166#include "base/win/windows_version.h"
[email protected]a3abd5572011-04-15 02:09:33167#include "chrome/browser/browser_util_win.h"
[email protected]b48c9182011-10-26 18:03:30168#include "chrome/browser/chrome_browser_main_win.h"
[email protected]118b4a92011-04-14 01:15:13169#include "chrome/browser/first_run/try_chrome_dialog_view.h"
[email protected]3e087992011-04-14 22:28:12170#include "chrome/browser/first_run/upgrade_util_win.h"
[email protected]f870a322009-01-16 21:47:27171#include "chrome/browser/net/url_fixer_upper.h"
[email protected]297fb7c22012-06-26 12:37:49172#include "chrome/browser/ui/network_profile_bubble.h"
[email protected]68c921f2008-10-15 21:37:46173#include "chrome/installer/util/helper.h"
174#include "chrome/installer/util/install_util.h"
[email protected]67da235a2008-10-24 16:18:27175#include "chrome/installer/util/shell_util.h"
initial.commit09911bf2008-07-26 23:55:29176#include "net/base/net_util.h"
[email protected]8ff1d422009-07-07 21:31:39177#include "printing/printed_document.h"
[email protected]c051a1b2011-01-21 23:30:17178#include "ui/base/l10n/l10n_util_win.h"
[email protected]6bae7352012-06-15 15:46:46179#include "ui/base/win/dpi.h"
[email protected]7f0ebc92009-02-05 18:34:21180#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29181
[email protected]0a357e632010-04-02 21:26:58182#if defined(OS_MACOSX)
[email protected]a1e1d4902010-04-02 22:02:30183#include <Security/Security.h>
[email protected]10189862011-04-15 21:42:03184
[email protected]badf5cf2011-10-29 03:44:44185#include "base/mac/scoped_nsautorelease_pool.h"
[email protected]51a7a9d2011-09-27 17:21:41186#include "chrome/browser/mac/keystone_glue.h"
[email protected]3dd6f5e2010-06-01 20:28:03187#endif
188
[email protected]c83399d1f2012-09-19 01:50:54189#if defined(ENABLE_CONFIGURATION_POLICY)
190#include "policy/policy_constants.h"
191#endif
192
[email protected]6ee43a72012-12-07 22:44:40193#if defined(ENABLE_GOOGLE_NOW)
194#include "chrome/browser/ui/google_now/google_now_service_factory.h"
195#endif
196
[email protected]703369a2012-11-05 20:40:31197#if defined(ENABLE_LANGUAGE_DETECTION)
198#include "chrome/browser/language_usage_metrics.h"
199#endif
200
[email protected]81d9b72d2012-03-26 22:29:17201#if defined(ENABLE_RLZ)
202#include "chrome/browser/rlz/rlz.h"
203#endif
204
[email protected]fc9c69bf2009-08-27 01:10:44205#if defined(TOOLKIT_VIEWS)
[email protected]477ae052011-11-18 23:53:57206#include "ui/views/focus/accelerator_handler.h"
[email protected]dd092152009-05-18 21:20:33207#endif
208
[email protected]b48c9182011-10-26 18:03:30209#if defined(USE_X11)
210#include "chrome/browser/chrome_browser_main_x11.h"
211#endif
212
[email protected]631bb742011-11-02 11:29:39213using content::BrowserThread;
214
[email protected]3aada4602011-08-11 22:25:55215namespace {
initial.commit09911bf2008-07-26 23:55:29216
[email protected]b19e0e2e2013-02-06 18:15:51217enum UMATouchEventsState {
218 UMA_TOUCH_EVENTS_ENABLED,
219 UMA_TOUCH_EVENTS_AUTO_ENABLED,
220 UMA_TOUCH_EVENTS_AUTO_DISABLED,
221 UMA_TOUCH_EVENTS_DISABLED,
222 // NOTE: Add states only immediately above this line. Make sure to
223 // update the enum list in tools/histogram/histograms.xml accordingly.
224 UMA_TOUCH_EVENTS_STATE_COUNT
225};
226
[email protected]5016a9dd2013-02-02 01:10:02227void LogIntelMicroArchitecture() {
228 base::CPU cpu;
229 base::CPU::IntelMicroArchitecture arch = cpu.GetIntelMicroArchitecture();
230 UMA_HISTOGRAM_ENUMERATION("Platform.IntelMaxMicroArchitecture", arch,
231 base::CPU::MAX_INTEL_MICRO_ARCHITECTURE);
232}
233
initial.commit09911bf2008-07-26 23:55:29234// This function provides some ways to test crash and assertion handling
235// behavior of the program.
[email protected]9bade092009-11-13 17:04:42236void HandleTestParameters(const CommandLine& command_line) {
initial.commit09911bf2008-07-26 23:55:29237 // This parameter causes an assertion.
238 if (command_line.HasSwitch(switches::kBrowserAssertTest)) {
239 DCHECK(false);
240 }
241
242 // This parameter causes a null pointer crash (crash reporter trigger).
243 if (command_line.HasSwitch(switches::kBrowserCrashTest)) {
244 int* bad_pointer = NULL;
245 *bad_pointer = 0;
246 }
247}
248
[email protected]fe7c4872012-05-10 20:06:03249void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator,
[email protected]f9886382010-03-10 04:45:54250 const std::vector<GURL>& new_tabs) {
251 for (std::vector<GURL>::const_iterator it = new_tabs.begin();
[email protected]201028d2010-02-12 21:28:01252 it != new_tabs.end(); ++it) {
[email protected]f9886382010-03-10 04:45:54253 if (it->is_valid())
[email protected]fe7c4872012-05-10 20:06:03254 browser_creator->AddFirstRunTab(*it);
[email protected]1188a6c2009-05-09 00:27:42255 }
256}
[email protected]1188a6c2009-05-09 00:27:42257
[email protected]7e59cff2010-03-23 16:12:40258// Returns the new local state object, guaranteed non-NULL.
[email protected]0de615a2012-11-08 04:40:59259// |local_state_task_runner| must be a shutdown-blocking task runner.
260PrefService* InitializeLocalState(
261 base::SequencedTaskRunner* local_state_task_runner,
262 const CommandLine& parsed_command_line,
263 bool is_first_run) {
[email protected]650b2d52013-02-10 03:41:45264 base::FilePath local_state_path;
[email protected]7e59cff2010-03-23 16:12:40265 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
266 bool local_state_file_exists = file_util::PathExists(local_state_path);
267
268 // Load local state. This includes the application locale so we know which
[email protected]b1de2c72013-02-06 02:45:47269 // locale dll to load. This also causes local state prefs to be registered.
270 PrefService* local_state = g_browser_process->local_state();
[email protected]7e59cff2010-03-23 16:12:40271 DCHECK(local_state);
272
[email protected]7e59cff2010-03-23 16:12:40273 if (is_first_run) {
274#if defined(OS_WIN)
275 // During first run we read the google_update registry key to find what
276 // language the user selected when downloading the installer. This
277 // becomes our default language in the prefs.
278 // Other platforms obey the system locale.
279 std::wstring install_lang;
[email protected]ddd231e2010-06-29 20:35:19280 if (GoogleUpdateSettings::GetLanguage(&install_lang)) {
281 local_state->SetString(prefs::kApplicationLocale,
[email protected]47e870b2013-02-24 21:14:53282 WideToASCII(install_lang));
[email protected]ddd231e2010-06-29 20:35:19283 }
[email protected]7e59cff2010-03-23 16:12:40284#endif // defined(OS_WIN)
285 }
286
287 // If the local state file for the current profile doesn't exist and the
288 // parent profile command line flag is present, then we should inherit some
289 // local state from the parent profile.
290 // Checking that the local state file for the current profile doesn't exist
291 // is the most robust way to determine whether we need to inherit or not
292 // since the parent profile command line flag can be present even when the
293 // current profile is not a new one, and in that case we do not want to
294 // inherit and reset the user's setting.
[email protected]08b035b92012-12-19 11:35:17295 //
296 // TODO(mnissler): We should probably just instantiate a
[email protected]b1de2c72013-02-06 02:45:47297 // JSONPrefStore here instead of an entire PrefService. Once this is
298 // addressed, the call to browser_prefs::RegisterLocalState can move
299 // to chrome_prefs::CreateLocalState.
[email protected]7e59cff2010-03-23 16:12:40300 if (!local_state_file_exists &&
301 parsed_command_line.HasSwitch(switches::kParentProfile)) {
[email protected]650b2d52013-02-10 03:41:45302 base::FilePath parent_profile =
[email protected]7e59cff2010-03-23 16:12:40303 parsed_command_line.GetSwitchValuePath(switches::kParentProfile);
[email protected]b1de2c72013-02-06 02:45:47304 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple();
305 scoped_ptr<PrefService> parent_local_state(
[email protected]5b199522012-12-22 17:24:44306 chrome_prefs::CreateLocalState(
[email protected]70a317a2012-12-19 20:59:33307 parent_profile,
308 local_state_task_runner,
309 g_browser_process->policy_service(),
[email protected]b1de2c72013-02-06 02:45:47310 NULL,
311 registry,
312 false));
313 registry->RegisterStringPref(prefs::kApplicationLocale, std::string());
[email protected]7e59cff2010-03-23 16:12:40314 // Right now, we only inherit the locale setting from the parent profile.
315 local_state->SetString(
316 prefs::kApplicationLocale,
[email protected]d8b08c92010-06-07 13:13:28317 parent_local_state->GetString(prefs::kApplicationLocale));
[email protected]7e59cff2010-03-23 16:12:40318 }
319
[email protected]fab807e2011-04-14 12:24:19320#if defined(OS_CHROMEOS)
321 if (parsed_command_line.HasSwitch(switches::kLoginManager)) {
322 std::string owner_locale = local_state->GetString(prefs::kOwnerLocale);
323 // Ensure that we start with owner's locale.
324 if (!owner_locale.empty() &&
325 local_state->GetString(prefs::kApplicationLocale) != owner_locale &&
326 !local_state->IsManagedPreference(prefs::kApplicationLocale)) {
327 local_state->SetString(prefs::kApplicationLocale, owner_locale);
[email protected]fab807e2011-04-14 12:24:19328 }
329 }
330#endif
331
[email protected]7e59cff2010-03-23 16:12:40332 return local_state;
333}
334
[email protected]e0203c02013-02-04 11:55:53335// Returns the path that contains the profile that should be loaded
336// on process startup.
[email protected]650b2d52013-02-10 03:41:45337base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir,
338 const CommandLine& command_line) {
[email protected]e0203c02013-02-04 11:55:53339 if (command_line.HasSwitch(switches::kProfileDirectory)) {
340 return user_data_dir.Append(
341 command_line.GetSwitchValuePath(switches::kProfileDirectory));
342 }
343
[email protected]e0203c02013-02-04 11:55:53344 // If we are showing the app list then chrome isn't shown so load the app
345 // list's profile rather than chrome's.
346 if (command_line.HasSwitch(switches::kShowAppList))
[email protected]f0ee7912013-02-27 06:02:55347 return AppListService::Get()->GetAppListProfilePath(user_data_dir);
[email protected]e0203c02013-02-04 11:55:53348
349 return g_browser_process->profile_manager()->GetLastUsedProfileDir(
350 user_data_dir);
351}
352
[email protected]20271f32010-03-26 03:04:51353// Initializes the profile, possibly doing some user prompting to pick a
354// fallback profile. Returns the newly created profile, or NULL if startup
355// should not continue.
[email protected]4573fbd2011-10-31 20:25:18356Profile* CreateProfile(const content::MainFunctionParams& parameters,
[email protected]650b2d52013-02-10 03:41:45357 const base::FilePath& user_data_dir,
[email protected]506a87c2011-07-21 16:01:54358 const CommandLine& parsed_command_line) {
[email protected]7802309d2011-10-20 15:43:09359 if (ProfileManager::IsMultipleProfilesEnabled() &&
360 parsed_command_line.HasSwitch(switches::kProfileDirectory)) {
361 g_browser_process->local_state()->SetString(prefs::kProfileLastUsed,
[email protected]a5e8c6d42012-04-09 20:22:01362 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory));
[email protected]1583def2012-01-25 11:26:32363 // Clear kProfilesLastActive since the user only wants to launch a specific
364 // profile.
365 ListPrefUpdate update(g_browser_process->local_state(),
366 prefs::kProfilesLastActive);
367 ListValue* profile_list = update.Get();
368 profile_list->Clear();
[email protected]506a87c2011-07-21 16:01:54369 }
[email protected]e0203c02013-02-04 11:55:53370
371 Profile* profile = NULL;
[email protected]484262f2011-10-31 19:42:00372#if defined(OS_CHROMEOS)
373 // TODO(ivankr): http://crbug.com/83792
374 profile = g_browser_process->profile_manager()->GetDefaultProfile(
375 user_data_dir);
376#else
[email protected]650b2d52013-02-10 03:41:45377 base::FilePath profile_path =
[email protected]e0203c02013-02-04 11:55:53378 GetStartupProfilePath(user_data_dir, parsed_command_line);
379 profile = g_browser_process->profile_manager()->GetProfile(
380 profile_path);
[email protected]484262f2011-10-31 19:42:00381#endif
[email protected]20271f32010-03-26 03:04:51382 if (profile)
383 return profile;
384
385#if defined(OS_WIN)
[email protected]94fbaa42011-09-07 20:09:54386#if defined(USE_AURA)
387 // TODO(beng):
388 NOTIMPLEMENTED();
389#else
[email protected]20271f32010-03-26 03:04:51390 // Ideally, we should be able to run w/o access to disk. For now, we
391 // prompt the user to pick a different user-data-dir and restart chrome
392 // with the new dir.
393 // http://code.google.com/p/chromium/issues/detail?id=11510
[email protected]650b2d52013-02-10 03:41:45394 base::FilePath new_user_data_dir =
395 chrome::ShowUserDataDirDialog(user_data_dir);
[email protected]20271f32010-03-26 03:04:51396
397 if (!new_user_data_dir.empty()) {
398 // Because of the way CommandLine parses, it's sufficient to append a new
399 // --user-data-dir switch. The last flag of the same name wins.
400 // TODO(tc): It would be nice to remove the flag we don't want, but that
401 // sounds risky if we parse differently than CommandLineToArgvW.
[email protected]badf5cf2011-10-29 03:44:44402 CommandLine new_command_line = parameters.command_line;
[email protected]4f08c83f2010-07-29 23:02:34403 new_command_line.AppendSwitchPath(switches::kUserDataDir,
404 new_user_data_dir);
[email protected]e5992182011-07-15 16:47:02405 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL);
[email protected]20271f32010-03-26 03:04:51406 }
[email protected]94fbaa42011-09-07 20:09:54407#endif
[email protected]20271f32010-03-26 03:04:51408#else
409 // TODO(port): fix this. See comments near the definition of
410 // user_data_dir. It is better to CHECK-fail here than it is to
411 // silently exit because of missing code in the above test.
412 CHECK(profile) << "Cannot get default profile.";
413#endif
414
415 return NULL;
416}
417
[email protected]e457f742010-04-02 17:25:43418#if defined(OS_MACOSX)
419OSStatus KeychainCallback(SecKeychainEvent keychain_event,
[email protected]d3b05ea2012-01-24 22:57:05420 SecKeychainCallbackInfo* info, void* context) {
[email protected]e457f742010-04-02 17:25:43421 return noErr;
422}
423#endif
424
[email protected]28f576f2011-08-26 20:46:55425// This code is specific to the Windows-only PreReadExperiment field-trial.
426void AddPreReadHistogramTime(const char* name, base::TimeDelta time) {
427 const base::TimeDelta kMin(base::TimeDelta::FromMilliseconds(1));
428 const base::TimeDelta kMax(base::TimeDelta::FromHours(1));
429 static const size_t kBuckets(100);
430
431 // FactoryTimeGet will always return a pointer to the same histogram object,
432 // keyed on its name. There's no need for us to store it explicitly anywhere.
[email protected]de415552013-01-23 04:12:17433 base::HistogramBase* counter = base::Histogram::FactoryTimeGet(
[email protected]28f576f2011-08-26 20:46:55434 name, kMin, kMax, kBuckets, base::Histogram::kUmaTargetedHistogramFlag);
435
436 counter->AddTime(time);
437}
438
[email protected]89886652012-12-11 18:09:07439void RecordDefaultBrowserUMAStat() {
440 // Record whether Chrome is the default browser or not.
441 ShellIntegration::DefaultWebClientState default_state =
442 ShellIntegration::GetDefaultBrowser();
443 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.State", default_state,
444 ShellIntegration::NUM_DEFAULT_STATES);
445}
446
[email protected]b19e0e2e2013-02-06 18:15:51447void RecordTouchEventState(const CommandLine& command_line) {
448 const std::string touch_enabled_switch =
449 command_line.HasSwitch(switches::kTouchEvents) ?
450 command_line.GetSwitchValueASCII(switches::kTouchEvents) :
451 switches::kTouchEventsAuto;
452
453 if (touch_enabled_switch.empty() ||
454 touch_enabled_switch == switches::kTouchEventsEnabled) {
455 UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled",
456 UMA_TOUCH_EVENTS_ENABLED,
457 UMA_TOUCH_EVENTS_STATE_COUNT);
458 } else if (touch_enabled_switch == switches::kTouchEventsAuto) {
459 bool touch_device_present = ui::IsTouchDevicePresent();
460 UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled",
461 touch_device_present ?
462 UMA_TOUCH_EVENTS_AUTO_ENABLED :
463 UMA_TOUCH_EVENTS_AUTO_DISABLED,
464 UMA_TOUCH_EVENTS_STATE_COUNT);
465 } else if (touch_enabled_switch == switches::kTouchEventsDisabled) {
466 UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled",
467 UMA_TOUCH_EVENTS_DISABLED,
468 UMA_TOUCH_EVENTS_STATE_COUNT);
469 }
470}
471
[email protected]8cebc942013-01-31 01:28:42472void RegisterComponentsForUpdate(const CommandLine& command_line) {
473 ComponentUpdateService* cus = g_browser_process->component_updater();
474 if (!cus)
475 return;
476 // Registration can be before of after cus->Start() so it is ok to post
477 // a task to the UI thread to do registration once you done the necessary
478 // file IO to know you existing component version.
479 RegisterRecoveryComponent(cus, g_browser_process->local_state());
480 RegisterPepperFlashComponent(cus);
481 RegisterSwiftShaderComponent(cus);
482
483 // CRLSetFetcher attempts to load a CRL set from either the local disk or
484 // network.
485 if (!command_line.HasSwitch(switches::kDisableCRLSets))
486 g_browser_process->crl_set_fetcher()->StartInitialLoad(cus);
487
[email protected]ccb4feef2013-02-14 06:16:47488 RegisterPnaclComponent(cus, command_line);
[email protected]8cebc942013-01-31 01:28:42489
490 cus->Start();
491}
492
[email protected]650b2d52013-02-10 03:41:45493bool ProcessSingletonNotificationCallback(
494 const CommandLine& command_line,
495 const base::FilePath& current_directory) {
[email protected]5d364542012-04-05 07:15:39496 // Drop the request if the browser process is already in shutdown path.
497 if (!g_browser_process || g_browser_process->IsShuttingDown())
498 return false;
499
[email protected]e9613b52012-11-27 22:35:13500 g_browser_process->PlatformSpecificCommandLineProcessing(command_line);
501
[email protected]5d364542012-04-05 07:15:39502 // TODO(erikwright): Consider removing this - AFAIK it is no longer used.
503 // Handle the --uninstall-extension startup action. This needs to done here
504 // in the process that is running with the target profile, otherwise the
505 // uninstall will fail to unload and remove all components.
506 if (command_line.HasSwitch(switches::kUninstallExtension)) {
507 // The uninstall extension switch can't be combined with the profile
508 // directory switch.
509 DCHECK(!command_line.HasSwitch(switches::kProfileDirectory));
510
511 Profile* profile = ProfileManager::GetLastUsedProfile();
512 if (!profile) {
513 // We should never be called before the profile has been created.
514 NOTREACHED();
515 return true;
516 }
517
[email protected]d9ede582012-08-14 19:21:38518 extensions::StartupHelper extension_startup_helper;
519 extension_startup_helper.UninstallExtension(command_line, profile);
[email protected]5d364542012-04-05 07:15:39520 return true;
521 }
522
[email protected]650b2d52013-02-10 03:41:45523 base::FilePath user_data_dir =
[email protected]e0203c02013-02-04 11:55:53524 g_browser_process->profile_manager()->user_data_dir();
[email protected]650b2d52013-02-10 03:41:45525 base::FilePath startup_profile_dir =
[email protected]e0203c02013-02-04 11:55:53526 GetStartupProfilePath(user_data_dir, command_line);
527
[email protected]fe7c4872012-05-10 20:06:03528 StartupBrowserCreator::ProcessCommandLineAlreadyRunning(
[email protected]e0203c02013-02-04 11:55:53529 command_line, current_directory, startup_profile_dir);
[email protected]5d364542012-04-05 07:15:39530 return true;
531}
532
[email protected]86d3aca2012-12-04 21:36:09533void LaunchDevToolsHandlerIfNeeded(Profile* profile,
534 const CommandLine& command_line) {
535 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) {
536 std::string port_str =
537 command_line.GetSwitchValueASCII(::switches::kRemoteDebuggingPort);
538 int port;
539 if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) {
540 std::string frontend_str;
541 if (command_line.HasSwitch(::switches::kRemoteDebuggingFrontend)) {
542 frontend_str = command_line.GetSwitchValueASCII(
543 ::switches::kRemoteDebuggingFrontend);
544 }
545 g_browser_process->CreateDevToolsHttpProtocolHandler(
546 profile,
[email protected]55d342402013-02-22 11:28:06547 chrome::HOST_DESKTOP_TYPE_NATIVE,
[email protected]86d3aca2012-12-04 21:36:09548 "127.0.0.1",
549 port,
550 frontend_str);
551 } else {
552 DLOG(WARNING) << "Invalid http debugger port number " << port;
553 }
554 }
555}
556
[email protected]e327c752013-01-30 11:38:16557// Heap allocated class that listens for first page load, kicks off stat
558// recording and then deletes itself.
559class LoadCompleteListener : public content::NotificationObserver {
560 public:
561 LoadCompleteListener() {
562 registrar_.Add(this,
563 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
564 content::NotificationService::AllSources());
565 }
566 virtual ~LoadCompleteListener() {}
567
568 // content::NotificationObserver implementation.
569 virtual void Observe(int type,
570 const content::NotificationSource& source,
[email protected]b94584a2013-02-07 03:02:08571 const content::NotificationDetails& details) OVERRIDE {
[email protected]e327c752013-01-30 11:38:16572 DCHECK(type == content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
573 startup_metric_utils::OnInitialPageLoadComplete();
574 delete this;
575 }
576
577 private:
578 content::NotificationRegistrar registrar_;
579 DISALLOW_COPY_AND_ASSIGN(LoadCompleteListener);
580};
581
[email protected]3aada4602011-08-11 22:25:55582} // namespace
583
[email protected]cbce47242011-08-12 21:40:59584namespace chrome_browser {
585// This error message is not localized because we failed to load the
586// localization data files.
587const char kMissingLocaleDataTitle[] = "Missing File Error";
588const char kMissingLocaleDataMessage[] =
589 "Unable to find locale data files. Please reinstall.";
590} // namespace chrome_browser
591
[email protected]4bb76022011-08-12 03:05:53592// BrowserMainParts ------------------------------------------------------------
593
[email protected]1948a4782012-04-30 13:45:44594// static
595bool ChromeBrowserMainParts::disable_enforcing_cookie_policies_for_tests_ =
596 false;
597
[email protected]f967b722011-09-07 00:58:04598ChromeBrowserMainParts::ChromeBrowserMainParts(
[email protected]4573fbd2011-10-31 20:25:18599 const content::MainFunctionParams& parameters)
[email protected]b48c9182011-10-26 18:03:30600 : parameters_(parameters),
[email protected]badf5cf2011-10-29 03:44:44601 parsed_command_line_(parameters.command_line),
[email protected]b48c9182011-10-26 18:03:30602 result_code_(content::RESULT_CODE_NORMAL_EXIT),
[email protected]08f1c5e2011-12-01 01:54:34603 startup_watcher_(new StartupTimeBomb()),
[email protected]c1702d712011-09-08 19:41:43604 shutdown_watcher_(new ShutdownWatcherHelper()),
[email protected]0c1c4752012-08-09 20:30:24605 startup_timer_(new performance_monitor::StartupTimer()),
[email protected]ae9e12a2012-07-31 17:48:12606 browser_field_trials_(parameters.command_line),
[email protected]c1702d712011-09-08 19:41:43607 record_search_engine_(false),
608 translate_manager_(NULL),
609 profile_(NULL),
[email protected]66013922011-09-13 18:53:42610 run_message_loop_(true),
[email protected]2e5b60a22011-11-28 15:56:41611 notify_result_(ProcessSingleton::PROCESS_NONE),
[email protected]3f002a32013-01-02 17:52:38612 do_first_run_tasks_(false),
[email protected]2e5b60a22011-11-28 15:56:41613 local_state_(NULL),
614 restart_last_session_(false) {
[email protected]f967b722011-09-07 00:58:04615 // If we're running tests (ui_task is non-null).
[email protected]716476c2011-12-29 00:07:03616 if (parameters.ui_task)
[email protected]b228ecf12011-09-08 17:06:59617 browser_defaults::enable_help_app = false;
[email protected]1948a4782012-04-30 13:45:44618
619 // Chrome disallows cookies by default. All code paths that want to use
620 // cookies need to go through one of Chrome's URLRequestContexts which have
621 // a ChromeNetworkDelegate attached that selectively allows cookies again.
622 if (!disable_enforcing_cookie_policies_for_tests_)
623 net::URLRequest::SetDefaultCookiePolicyToBlock();
[email protected]4bb76022011-08-12 03:05:53624}
625
[email protected]f967b722011-09-07 00:58:04626ChromeBrowserMainParts::~ChromeBrowserMainParts() {
[email protected]50462bf02011-11-21 19:13:31627 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i)
628 delete chrome_extra_parts_[i];
629 chrome_extra_parts_.clear();
[email protected]4bb76022011-08-12 03:05:53630}
631
[email protected]069cd9952011-10-01 16:34:45632// This will be called after the command-line has been mutated by about:flags
[email protected]5281db1d2012-01-11 22:51:54633void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
[email protected]069cd9952011-10-01 16:34:45634 // Must initialize metrics after labs have been converted into switches,
635 // but before field trials are set up (so that client ID is available for
636 // one-time randomized field trials).
[email protected]5281db1d2012-01-11 22:51:54637#if defined(OS_WIN)
638 if (parsed_command_line_.HasSwitch(switches::kChromeFrame))
639 MetricsLog::set_version_extension("-F");
640#elif defined(ARCH_CPU_64_BITS)
641 MetricsLog::set_version_extension("-64");
[email protected]000bed62012-10-20 01:35:36642#elif defined(OS_ANDROID)
643 // Set version extension to identify Android releases.
644 // Example: 16.0.912.61-K88
645 std::string version_extension = "-K";
646 version_extension.append(
647 base::android::BuildInfo::GetInstance()->package_version_code());
648 MetricsLog::set_version_extension(version_extension);
[email protected]5281db1d2012-01-11 22:51:54649#endif // defined(OS_WIN)
[email protected]069cd9952011-10-01 16:34:45650
651 // Initialize FieldTrialList to support FieldTrials that use one-time
[email protected]e61003a2012-05-24 17:03:19652 // randomization.
[email protected]5281db1d2012-01-11 22:51:54653 MetricsService* metrics = browser_process_->metrics_service();
[email protected]e5354322012-08-09 23:07:37654 bool metrics_reporting_enabled = IsMetricsReportingEnabled();
655 if (metrics_reporting_enabled)
[email protected]5cbeeef72012-02-08 02:05:18656 metrics->ForceClientIdCreation(); // Needed below.
[email protected]e61003a2012-05-24 17:03:19657 field_trial_list_.reset(
[email protected]e5354322012-08-09 23:07:37658 new base::FieldTrialList(
[email protected]20f999b52012-08-24 22:32:59659 metrics->CreateEntropyProvider(metrics_reporting_enabled).release()));
[email protected]4bb76022011-08-12 03:05:53660
[email protected]2d4729582012-04-12 07:08:07661 // Ensure any field trials specified on the command line are initialized.
662 // Also stop the metrics service so that we don't pollute UMA.
[email protected]2d4729582012-04-12 07:08:07663 const CommandLine* command_line = CommandLine::ForCurrentProcess();
664 if (command_line->HasSwitch(switches::kForceFieldTrials)) {
665 std::string persistent = command_line->GetSwitchValueASCII(
666 switches::kForceFieldTrials);
667 bool ret = base::FieldTrialList::CreateTrialsFromString(persistent);
668 CHECK(ret) << "Invalid --" << switches::kForceFieldTrials <<
669 " list specified.";
670 }
[email protected]2d4729582012-04-12 07:08:07671
[email protected]04811242012-07-06 18:04:29672 chrome_variations::VariationsService* variations_service =
[email protected]54e26c122012-05-17 15:36:21673 browser_process_->variations_service();
[email protected]58c63cb2012-11-26 19:22:11674 if (variations_service)
[email protected]7e6b753f2013-02-15 16:21:38675 variations_service->CreateTrialsFromSeed();
[email protected]54e26c122012-05-17 15:36:21676
[email protected]5c181552013-02-07 09:12:52677 const int64 install_date = local_state_->GetInt64(prefs::kInstallDate);
[email protected]bc381c02012-11-05 21:36:42678 // This must be called after the pref is initialized.
679 DCHECK(install_date);
680 browser_field_trials_.SetupFieldTrials(base::Time::FromTimeT(install_date));
[email protected]4bb76022011-08-12 03:05:53681
[email protected]b98def82012-06-28 23:42:45682 SetupPlatformFieldTrials();
683
[email protected]4bb76022011-08-12 03:05:53684 // Initialize FieldTrialSynchronizer system. This is a singleton and is used
[email protected]716476c2011-12-29 00:07:03685 // for posting tasks via base::Bind. Its deleted when it goes out of scope.
686 // Even though base::Bind does AddRef and Release, the object will not be
687 // deleted after the Task is executed.
[email protected]4bb76022011-08-12 03:05:53688 field_trial_synchronizer_ = new FieldTrialSynchronizer();
[email protected]4bb76022011-08-12 03:05:53689}
690
[email protected]069cd9952011-10-01 16:34:45691// ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related --------------
692
[email protected]5281db1d2012-01-11 22:51:54693void ChromeBrowserMainParts::StartMetricsRecording() {
694 MetricsService* metrics = g_browser_process->metrics_service();
[email protected]c0aa875b2012-11-06 22:09:13695
[email protected]e50163382013-03-02 01:08:27696 const bool enable_benchmarking =
[email protected]c0aa875b2012-11-06 22:09:13697 parsed_command_line_.HasSwitch(switches::kEnableBenchmarking);
698 // TODO(stevet): This is a temporary histogram used to investigate an issue
699 // with logging. Remove this when investigations are complete.
700 UMA_HISTOGRAM_BOOLEAN("UMA.FieldTrialsEnabledBenchmarking",
701 enable_benchmarking);
[email protected]e50163382013-03-02 01:08:27702 // TODO(miu): Metrics reporting is disabled in DEBUG builds until ill-fired
703 // DCHECKs are fixed, and/or we reconsider whether metrics reporting should
704 // really ever be enabled for debug builds. http://crbug.com/156979
705#if defined(NDEBUG)
706 const bool only_do_metrics_recording = enable_benchmarking ||
707 parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly);
708#else
709 const bool only_do_metrics_recording = true;
710#endif
711 if (only_do_metrics_recording) {
[email protected]5281db1d2012-01-11 22:51:54712 // If we're testing then we don't care what the user preference is, we turn
713 // on recording, but not reporting, otherwise tests fail.
[email protected]410938e02012-10-24 16:33:59714 metrics->StartRecordingForTests();
[email protected]5281db1d2012-01-11 22:51:54715 return;
716 }
717
[email protected]5cbeeef72012-02-08 02:05:18718 if (IsMetricsReportingEnabled())
719 metrics->Start();
720}
721
722bool ChromeBrowserMainParts::IsMetricsReportingEnabled() {
[email protected]5281db1d2012-01-11 22:51:54723 // If the user permits metrics reporting with the checkbox in the
724 // prefs, we turn on recording. We disable metrics completely for
[email protected]e5354322012-08-09 23:07:37725 // non-official builds. This can be forced with a flag.
726 const CommandLine* command_line = CommandLine::ForCurrentProcess();
727 if (command_line->HasSwitch(switches::kEnableMetricsReportingForTesting))
728 return true;
729
[email protected]5cbeeef72012-02-08 02:05:18730 bool enabled = false;
[email protected]9f4dd172012-05-11 02:29:56731 // The debug build doesn't send UMA logs when FieldTrials are forced.
[email protected]2d4729582012-04-12 07:08:07732 if (command_line->HasSwitch(switches::kForceFieldTrials))
733 return false;
[email protected]2d4729582012-04-12 07:08:07734
[email protected]5281db1d2012-01-11 22:51:54735#if defined(GOOGLE_CHROME_BUILD)
736#if defined(OS_CHROMEOS)
[email protected]5281db1d2012-01-11 22:51:54737 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
738 &enabled);
739#else
[email protected]5cbeeef72012-02-08 02:05:18740 enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled);
[email protected]5281db1d2012-01-11 22:51:54741#endif // #if defined(OS_CHROMEOS)
[email protected]5281db1d2012-01-11 22:51:54742#endif // defined(GOOGLE_CHROME_BUILD)
[email protected]5cbeeef72012-02-08 02:05:18743 return enabled;
[email protected]5281db1d2012-01-11 22:51:54744}
745
[email protected]4bb76022011-08-12 03:05:53746// -----------------------------------------------------------------------------
747// TODO(viettrungluu): move more/rest of BrowserMain() into BrowserMainParts.
748
[email protected]3aada4602011-08-11 22:25:55749#if defined(OS_WIN)
750#define DLLEXPORT __declspec(dllexport)
751
752// We use extern C for the prototype DLLEXPORT to avoid C++ name mangling.
753extern "C" {
754DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded();
755}
756
757DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
758 // Need an instance of AtExitManager to handle singleton creations and
759 // deletions. We need this new instance because, the old instance created
760 // in ChromeMain() got destructed when the function returned.
761 base::AtExitManager exit_manager;
762 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded();
763}
764#endif
765
[email protected]50462bf02011-11-21 19:13:31766// content::BrowserMainParts implementation ------------------------------------
767
[email protected]c7480942011-11-08 19:18:27768void ChromeBrowserMainParts::PreEarlyInitialization() {
[email protected]50462bf02011-11-21 19:13:31769 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
770 chrome_extra_parts_[i]->PreEarlyInitialization();
[email protected]c7480942011-11-08 19:18:27771}
772
773void ChromeBrowserMainParts::PostEarlyInitialization() {
[email protected]50462bf02011-11-21 19:13:31774 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
775 chrome_extra_parts_[i]->PostEarlyInitialization();
[email protected]c7480942011-11-08 19:18:27776}
777
778void ChromeBrowserMainParts::ToolkitInitialized() {
[email protected]50462bf02011-11-21 19:13:31779 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
780 chrome_extra_parts_[i]->ToolkitInitialized();
[email protected]c7480942011-11-08 19:18:27781}
782
783void ChromeBrowserMainParts::PreMainMessageLoopStart() {
[email protected]50462bf02011-11-21 19:13:31784 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
785 chrome_extra_parts_[i]->PreMainMessageLoopStart();
[email protected]c7480942011-11-08 19:18:27786}
787
788void ChromeBrowserMainParts::PostMainMessageLoopStart() {
[email protected]50462bf02011-11-21 19:13:31789 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
790 chrome_extra_parts_[i]->PostMainMessageLoopStart();
[email protected]c7480942011-11-08 19:18:27791}
792
[email protected]69479b922012-02-02 09:56:20793int ChromeBrowserMainParts::PreCreateThreads() {
[email protected]2e5b60a22011-11-28 15:56:41794 result_code_ = PreCreateThreadsImpl();
[email protected]7defb4f02012-02-07 18:25:46795 // These members must be initialized before returning from this function.
796 DCHECK(master_prefs_.get());
[email protected]81054f812012-08-30 00:47:09797#if !defined(OS_ANDROID)
[email protected]fe7c4872012-05-10 20:06:03798 DCHECK(browser_creator_.get());
[email protected]81054f812012-08-30 00:47:09799#endif
[email protected]69479b922012-02-02 09:56:20800 return result_code_;
[email protected]2e5b60a22011-11-28 15:56:41801}
802
803int ChromeBrowserMainParts::PreCreateThreadsImpl() {
[email protected]c1702d712011-09-08 19:41:43804 run_message_loop_ = false;
[email protected]0c298a52009-09-25 21:33:52805#if defined(OS_WIN)
[email protected]2e5b60a22011-11-28 15:56:41806 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_);
[email protected]0c298a52009-09-25 21:33:52807#else
808 // Getting the user data dir can fail if the directory isn't
809 // creatable, for example; on Windows in code below we bring up a
810 // dialog prompting the user to pick a different directory.
811 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux,
812 // so it's better to fail here than fail mysteriously elsewhere.
[email protected]2e5b60a22011-11-28 15:56:41813 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
[email protected]0c298a52009-09-25 21:33:52814 << "Must be able to get user data directory!";
815#endif
816
[email protected]3f002a32013-01-02 17:52:38817 // Whether this is First Run. |do_first_run_tasks_| should be prefered to this
818 // unless the desire is actually to know whether this is really First Run
819 // (i.e., even if --no-first-run is passed).
820 bool is_first_run = false;
[email protected]81054f812012-08-30 00:47:09821 // Android's first run is done in Java instead of native.
822#if !defined(OS_ANDROID)
[email protected]3f002a32013-01-02 17:52:38823
[email protected]2e5b60a22011-11-28 15:56:41824 process_singleton_.reset(new ProcessSingleton(user_data_dir_));
[email protected]edf04b512012-02-23 09:47:43825 // Ensure ProcessSingleton won't process messages too early. It will be
826 // unlocked in PostBrowserStart().
827 process_singleton_->Lock(NULL);
initial.commit09911bf2008-07-26 23:55:29828
[email protected]3f002a32013-01-02 17:52:38829 bool force_first_run =
830 parsed_command_line().HasSwitch(switches::kForceFirstRun);
831 bool force_skip_first_run_tasks =
832 (!force_first_run &&
833 parsed_command_line().HasSwitch(switches::kNoFirstRun));
834
835 is_first_run =
836 (force_first_run || first_run::IsChromeFirstRun()) &&
[email protected]ae4c37e2012-12-21 01:16:25837 !ProfileManager::IsImportProcess(parsed_command_line());
[email protected]81054f812012-08-30 00:47:09838#endif
[email protected]0de615a2012-11-08 04:40:59839
[email protected]0de615a2012-11-08 04:40:59840 scoped_refptr<base::SequencedTaskRunner> local_state_task_runner =
[email protected]9bcdc202013-03-07 20:51:43841 JsonPrefStore::GetTaskRunnerForFile(
842 base::FilePath(chrome::kLocalStorePoolName),
843 BrowserThread::GetBlockingPool());
[email protected]0de615a2012-11-08 04:40:59844 browser_process_.reset(new BrowserProcessImpl(local_state_task_runner,
845 parsed_command_line()));
initial.commit09911bf2008-07-26 23:55:29846
[email protected]9b53dab2011-11-14 05:26:05847 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) {
[email protected]b2a9bbd2011-10-31 22:36:21848 // User wants to override default tracking status.
849 std::string flag =
[email protected]9b53dab2011-11-14 05:26:05850 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling);
[email protected]702a12d2012-02-10 19:43:42851 // Default to basic profiling (no parent child support).
852 tracked_objects::ThreadData::Status status =
853 tracked_objects::ThreadData::PROFILING_ACTIVE;
854 if (flag.compare("0") != 0)
855 status = tracked_objects::ThreadData::DEACTIVATED;
856 else if (flag.compare("child") != 0)
857 status = tracked_objects::ThreadData::PROFILING_CHILDREN_ACTIVE;
858 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(status);
[email protected]b2a9bbd2011-10-31 22:36:21859 }
860
[email protected]61b53f972012-02-10 20:39:23861 if (parsed_command_line().HasSwitch(switches::kProfilingOutputFile)) {
862 tracking_objects_.set_output_file_path(
863 parsed_command_line().GetSwitchValuePath(
864 switches::kProfilingOutputFile));
865 }
866
[email protected]0de615a2012-11-08 04:40:59867 local_state_ = InitializeLocalState(local_state_task_runner,
868 parsed_command_line(),
[email protected]3f002a32013-01-02 17:52:38869 is_first_run);
[email protected]1b084b5e2010-08-03 07:58:19870
[email protected]7defb4f02012-02-07 18:25:46871 // These members must be initialized before returning from this function.
872 master_prefs_.reset(new first_run::MasterPrefs);
[email protected]81054f812012-08-30 00:47:09873
874#if !defined(OS_ANDROID)
875 // Android doesn't use StartupBrowserCreator.
[email protected]fe7c4872012-05-10 20:06:03876 browser_creator_.reset(new StartupBrowserCreator);
[email protected]81054f812012-08-30 00:47:09877 // TODO(yfriedman): Refactor Android to re-use UMABrowsingActivityObserver
[email protected]3770c242012-07-12 22:58:17878 chrome::UMABrowsingActivityObserver::Init();
[email protected]81054f812012-08-30 00:47:09879#endif
[email protected]7defb4f02012-02-07 18:25:46880
[email protected]6346d152012-05-04 04:02:33881 // Convert active labs into switches. This needs to be done before
882 // ResourceBundle::InitSharedInstanceWithLocale as some loaded resources are
883 // affected by experiment flags (--touch-optimized-ui in particular). Not
884 // needed on Android as there aren't experimental flags.
885 about_flags::ConvertFlagsToSwitches(local_state_,
886 CommandLine::ForCurrentProcess());
[email protected]5b199522012-12-22 17:24:44887 local_state_->UpdateCommandLinePrefStore(
888 new CommandLinePrefStore(CommandLine::ForCurrentProcess()));
[email protected]6346d152012-05-04 04:02:33889
890 // Reset the command line in the crash report details, since we may have
891 // just changed it to include experiments.
892 child_process_logging::SetCommandLine(CommandLine::ForCurrentProcess());
893
[email protected]d4515eb2009-01-30 00:40:43894 // If we're running tests (ui_task is non-null), then the ResourceBundle
895 // has already been initialized.
[email protected]f900367b22012-09-11 16:08:36896 if (parameters().ui_task &&
897 !local_state_->IsManagedPreference(prefs::kApplicationLocale)) {
[email protected]17e6cde52012-01-05 00:16:57898 browser_process_->SetApplicationLocale("en-US");
[email protected]ce4b6a92009-12-10 00:04:48899 } else {
[email protected]1fec64352010-07-27 13:55:21900 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is
901 // needed when loading the MainMenu.nib and the language doesn't depend on
902 // anything since it comes from Cocoa.
[email protected]ce4b6a92009-12-10 00:04:48903#if defined(OS_MACOSX)
[email protected]17e6cde52012-01-05 00:16:57904 browser_process_->SetApplicationLocale(l10n_util::GetLocaleOverride());
[email protected]ce4b6a92009-12-10 00:04:48905#else
[email protected]455ee192010-12-22 16:05:57906 const std::string locale =
[email protected]2e5b60a22011-11-28 15:56:41907 local_state_->GetString(prefs::kApplicationLocale);
[email protected]cd87be132011-02-04 13:07:38908 // On a POSIX OS other than ChromeOS, the parameter that is passed to the
909 // method InitSharedInstance is ignored.
[email protected]455ee192010-12-22 16:05:57910 const std::string loaded_locale =
[email protected]fb317a52012-05-09 15:57:47911 ResourceBundle::InitSharedInstanceWithLocale(locale, NULL);
[email protected]cbce47242011-08-12 21:40:59912 if (loaded_locale.empty() &&
[email protected]f967b722011-09-07 00:58:04913 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) {
[email protected]cbce47242011-08-12 21:40:59914 ShowMissingLocaleMessageBox();
915 return chrome::RESULT_CODE_MISSING_DATA;
916 }
[email protected]455ee192010-12-22 16:05:57917 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
[email protected]17e6cde52012-01-05 00:16:57918 browser_process_->SetApplicationLocale(loaded_locale);
[email protected]e1cb0e92010-06-15 07:23:59919
[email protected]650b2d52013-02-10 03:41:45920 base::FilePath resources_pack_path;
[email protected]e1cb0e92010-06-15 07:23:59921 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
[email protected]6c26d9c2012-07-10 19:18:04922 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
[email protected]bf44c132012-11-15 19:41:42923 resources_pack_path, ui::SCALE_FACTOR_NONE);
[email protected]cd87be132011-02-04 13:07:38924#endif // defined(OS_MACOSX)
[email protected]ce4b6a92009-12-10 00:04:48925 }
initial.commit09911bf2008-07-26 23:55:29926
[email protected]d9edd312011-02-16 20:52:28927#if defined(TOOLKIT_GTK)
928 g_set_application_name(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str());
[email protected]d0646f32009-08-27 00:58:46929#endif
930
[email protected]81054f812012-08-30 00:47:09931 // Android does first run in Java instead of native.
932#if !defined(OS_ANDROID)
[email protected]74be069e82010-06-25 00:12:49933 // On first run, we need to process the predictor preferences before the
[email protected]34f73fb2010-03-24 20:50:34934 // browser's profile_manager object is created, but after ResourceBundle
935 // is initialized.
[email protected]3f002a32013-01-02 17:52:38936 if (is_first_run) {
[email protected]786799692012-09-26 14:16:48937 first_run::ProcessMasterPreferencesResult pmp_result =
938 first_run::ProcessMasterPreferences(user_data_dir_,
939 master_prefs_.get());
940 if (pmp_result == first_run::EULA_EXIT_NOW)
941 return chrome::RESULT_CODE_EULA_REFUSED;
942
[email protected]3f002a32013-01-02 17:52:38943 // Do first run tasks unless:
944 // - Explicitly forced not to by |force_skip_first_run_tasks| or
945 // |pmp_result|.
[email protected]749dc3db2013-02-11 22:52:31946 // - Running in App (or App Launcher) mode, where showing the importer
947 // (first run) UI is undesired.
948 do_first_run_tasks_ = (
949 !force_skip_first_run_tasks &&
950 pmp_result != first_run::SKIP_FIRST_RUN_TASKS &&
951 !parsed_command_line().HasSwitch(switches::kApp) &&
952 !parsed_command_line().HasSwitch(switches::kAppId) &&
953 !parsed_command_line().HasSwitch(switches::kShowAppList));
[email protected]786799692012-09-26 14:16:48954
[email protected]3f002a32013-01-02 17:52:38955 if (do_first_run_tasks_) {
956 AddFirstRunNewTabs(browser_creator_.get(), master_prefs_->new_tabs);
[email protected]a723f0af2013-02-15 06:36:03957
958 // Store the initial VariationsService seed in local state, if it exists
959 // in master prefs.
960 if (!master_prefs_->variations_seed.empty()) {
961 local_state_->SetString(prefs::kVariationsSeed,
962 master_prefs_->variations_seed);
963 // Set the variation seed date to the current system time. If the user's
964 // clock is incorrect, this may cause some field trial expiry checks to
965 // not do the right thing until the next seed update from the server,
966 // when this value will be updated.
967 local_state_->SetInt64(prefs::kVariationsSeedDate,
968 base::Time::Now().ToInternalValue());
969 }
[email protected]3f002a32013-01-02 17:52:38970 } else if (parsed_command_line().HasSwitch(switches::kNoFirstRun)) {
971 // Create the First Run beacon anyways if --no-first-run was passed on the
972 // command line.
[email protected]dfa08b042011-12-28 23:07:21973 first_run::CreateSentinel();
[email protected]3f002a32013-01-02 17:52:38974 }
[email protected]fe247ac2009-03-19 00:10:48975 }
[email protected]81054f812012-08-30 00:47:09976#endif
[email protected]fe247ac2009-03-19 00:10:48977
[email protected]f8abf722010-07-07 19:46:24978 // TODO(viettrungluu): why don't we run this earlier?
[email protected]f967b722011-09-07 00:58:04979 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs))
[email protected]34f73fb2010-03-24 20:50:34980 WarnAboutMinimumSystemRequirements();
initial.commit09911bf2008-07-26 23:55:29981
[email protected]2ec5a482012-02-22 00:01:18982#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_MACOSX)
[email protected]e643e57c2012-01-28 02:26:09983 // Set the product channel for crash reports.
984 child_process_logging::SetChannel(
985 chrome::VersionInfo::GetVersionStringModifier());
986#endif
987
[email protected]83ab4a282012-07-12 18:19:45988 // Initialize tracking synchronizer system.
[email protected]10fe40c2011-11-05 03:27:46989 tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer();
[email protected]332749032011-10-22 00:32:46990
[email protected]6b5f21d2009-04-13 17:01:35991 // Now that all preferences have been registered, set the install date
992 // for the uninstall metrics if this is our first run. This only actually
993 // gets used if the user has metrics reporting enabled at uninstall time.
[email protected]5c181552013-02-07 09:12:52994 int64 install_date = local_state_->GetInt64(prefs::kInstallDate);
995 if (install_date == 0)
996 local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT());
[email protected]6b5f21d2009-04-13 17:01:35997
[email protected]e457f742010-04-02 17:25:43998#if defined(OS_MACOSX)
999 // Get the Keychain API to register for distributed notifications on the main
1000 // thread, which has a proper CFRunloop, instead of later on the I/O thread,
1001 // which doesn't. This ensures those notifications will get delivered
1002 // properly. See issue 37766.
1003 // (Note that the callback mask here is empty. I don't want to register for
1004 // any callbacks, I just want to initialize the mechanism.)
1005 SecKeychainAddCallback(&KeychainCallback, 0, NULL);
1006#endif
1007
[email protected]69479b922012-02-02 09:56:201008 // Now the command line has been mutated based on about:flags, we can setup
1009 // metrics and initialize field trials. The field trials are needed by
1010 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads.
1011 SetupMetricsAndFieldTrials();
1012
1013 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this.
1014 browser_process_->PreCreateThreads();
1015
[email protected]2e5b60a22011-11-28 15:56:411016 return content::RESULT_CODE_NORMAL_EXIT;
1017}
1018
[email protected]2167cd62011-11-30 21:20:211019void ChromeBrowserMainParts::PreMainMessageLoopRun() {
1020 result_code_ = PreMainMessageLoopRunImpl();
1021
1022 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1023 chrome_extra_parts_[i]->PreMainMessageLoopRun();
1024}
1025
[email protected]97ef83f2011-12-19 19:26:361026// PreMainMessageLoopRun calls these extra stages in the following order:
1027// PreMainMessageLoopRunImpl()
1028// ... initial setup, including browser_process_ setup.
1029// PreProfileInit()
1030// ... additional setup, including CreateProfile()
1031// PostProfileInit()
1032// ... additional setup
1033// PreBrowserStart()
[email protected]fe7c4872012-05-10 20:06:031034// ... browser_creator_->Start (OR parameters().ui_task->Run())
[email protected]97ef83f2011-12-19 19:26:361035// PostBrowserStart()
1036
1037void ChromeBrowserMainParts::PreProfileInit() {
1038 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1039 chrome_extra_parts_[i]->PreProfileInit();
1040}
1041
1042void ChromeBrowserMainParts::PostProfileInit() {
[email protected]86d3aca2012-12-04 21:36:091043 LaunchDevToolsHandlerIfNeeded(profile(), parsed_command_line());
[email protected]97ef83f2011-12-19 19:26:361044 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1045 chrome_extra_parts_[i]->PostProfileInit();
1046}
1047
1048void ChromeBrowserMainParts::PreBrowserStart() {
1049 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1050 chrome_extra_parts_[i]->PreBrowserStart();
[email protected]aec25bc2012-10-04 18:45:261051#if !defined(OS_ANDROID)
1052 gpu_util::InstallBrowserMonitor();
1053#endif
[email protected]44327692013-02-26 21:21:221054
1055 three_d_observer_.reset(new ThreeDAPIObserver());
[email protected]97ef83f2011-12-19 19:26:361056}
1057
1058void ChromeBrowserMainParts::PostBrowserStart() {
[email protected]81054f812012-08-30 00:47:091059#if !defined(OS_ANDROID)
[email protected]278a34d2012-06-07 00:34:581060 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kVisitURLs))
1061 RunPageCycler();
[email protected]81054f812012-08-30 00:47:091062#endif
[email protected]278a34d2012-06-07 00:34:581063
[email protected]6ee43a72012-12-07 22:44:401064 // Create the instance of the Google Now service.
1065#if defined(ENABLE_GOOGLE_NOW)
1066 if (CommandLine::ForCurrentProcess()->HasSwitch(
1067 switches::kEnableGoogleNowIntegration)) {
1068 GoogleNowServiceFactory::GetForProfile(profile_);
1069 }
1070#endif
1071
[email protected]97ef83f2011-12-19 19:26:361072 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1073 chrome_extra_parts_[i]->PostBrowserStart();
[email protected]81054f812012-08-30 00:47:091074#if !defined(OS_ANDROID)
[email protected]edf04b512012-02-23 09:47:431075 // Allow ProcessSingleton to process messages.
1076 process_singleton_->Unlock();
[email protected]81054f812012-08-30 00:47:091077#endif
[email protected]97ef83f2011-12-19 19:26:361078}
1079
[email protected]81054f812012-08-30 00:47:091080#if !defined(OS_ANDROID)
[email protected]278a34d2012-06-07 00:34:581081void ChromeBrowserMainParts::RunPageCycler() {
1082 CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]323fd7122012-08-24 14:45:111083 // We assume a native desktop for tests, but we will need to find a way to
1084 // get the proper host desktop type once we start running these tests in ASH.
[email protected]3c6a0952012-12-17 11:56:091085 Browser* browser = chrome::FindBrowserWithProfile(
[email protected]323fd7122012-08-24 14:45:111086 profile_, chrome::HOST_DESKTOP_TYPE_NATIVE);
[email protected]278a34d2012-06-07 00:34:581087 DCHECK(browser);
1088 PageCycler* page_cycler = NULL;
[email protected]650b2d52013-02-10 03:41:451089 base::FilePath input_file =
[email protected]278a34d2012-06-07 00:34:581090 command_line->GetSwitchValuePath(switches::kVisitURLs);
1091 page_cycler = new PageCycler(browser, input_file);
1092 page_cycler->set_errors_file(
1093 input_file.AddExtension(FILE_PATH_LITERAL(".errors")));
1094 if (command_line->HasSwitch(switches::kRecordStats)) {
1095 page_cycler->set_stats_file(
1096 command_line->GetSwitchValuePath(switches::kRecordStats));
1097 }
[email protected]165b0562012-06-20 00:41:221098 page_cycler->Run();
[email protected]278a34d2012-06-07 00:34:581099}
[email protected]81054f812012-08-30 00:47:091100#endif // !defined(OS_ANDROID)
[email protected]278a34d2012-06-07 00:34:581101
[email protected]b98def82012-06-28 23:42:451102void ChromeBrowserMainParts::SetupPlatformFieldTrials() {
1103 // Base class implementation of this does nothing.
1104}
1105
[email protected]2e5b60a22011-11-28 15:56:411106int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
[email protected]81054f812012-08-30 00:47:091107 // Android updates the metrics service dynamically depending on whether the
1108 // application is in the foreground or not. Do not start here.
1109#if !defined(OS_ANDROID)
[email protected]5281db1d2012-01-11 22:51:541110 // Now that the file thread has been started, start recording.
1111 StartMetricsRecording();
[email protected]81054f812012-08-30 00:47:091112#endif
[email protected]99907362012-01-11 05:41:401113
[email protected]5016a9dd2013-02-02 01:10:021114#if defined(ARCH_CPU_X86_FAMILY)
1115 LogIntelMicroArchitecture();
1116#endif // defined(ARCH_CPU_X86_FAMILY)
1117
[email protected]2e5b60a22011-11-28 15:56:411118 // Create watchdog thread after creating all other threads because it will
1119 // watch the other threads and they must be running.
1120 browser_process_->watchdog_thread();
[email protected]61e95722009-11-25 06:54:111121
[email protected]d2caaa22011-12-12 03:04:151122 // Do any initializating in the browser process that requires all threads
1123 // running.
1124 browser_process_->PreMainMessageLoopRun();
1125
initial.commit09911bf2008-07-26 23:55:291126 // Record last shutdown time into a histogram.
1127 browser_shutdown::ReadLastShutdownInfo();
[email protected]04999e62009-09-25 01:27:311128
[email protected]01109dcf2010-03-27 00:56:431129#if defined(OS_WIN)
[email protected]04999e62009-09-25 01:27:311130 // On Windows, we use our startup as an opportunity to do upgrade/uninstall
1131 // tasks. Those care whether the browser is already running. On Linux/Mac,
1132 // upgrade/uninstall happen separately.
[email protected]a3abd5572011-04-15 02:09:331133 bool already_running = browser_util::IsBrowserAlreadyRunning();
initial.commit09911bf2008-07-26 23:55:291134
1135 // If the command line specifies 'uninstall' then we need to work here
1136 // unless we detect another chrome browser running.
[email protected]c1702d712011-09-08 19:41:431137 if (parsed_command_line().HasSwitch(switches::kUninstall)) {
[email protected]53c38d232009-02-13 20:52:181138 return DoUninstallTasks(already_running);
[email protected]c1702d712011-09-08 19:41:431139 }
initial.commit09911bf2008-07-26 23:55:291140
[email protected]f967b722011-09-07 00:58:041141 if (parsed_command_line().HasSwitch(switches::kHideIcons) ||
[email protected]c1702d712011-09-08 19:41:431142 parsed_command_line().HasSwitch(switches::kShowIcons)) {
[email protected]b48c9182011-10-26 18:03:301143 return ChromeBrowserMainPartsWin::HandleIconsCommands(
1144 parsed_command_line_);
[email protected]c1702d712011-09-08 19:41:431145 }
[email protected]b48c9182011-10-26 18:03:301146#endif
1147
[email protected]f967b722011-09-07 00:58:041148 if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) {
[email protected]201028d2010-02-12 21:28:011149 return ShellIntegration::SetAsDefaultBrowser() ?
[email protected]1fcfb202011-07-19 19:53:141150 static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) :
1151 static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED);
initial.commit09911bf2008-07-26 23:55:291152 }
1153
[email protected]81054f812012-08-30 00:47:091154 // Android doesn't support extensions and doesn't implement ProcessSingleton.
1155#if !defined(OS_ANDROID)
[email protected]6aeac8342010-10-01 20:21:181156 // If the command line specifies --pack-extension, attempt the pack extension
1157 // startup action and exit.
[email protected]f967b722011-09-07 00:58:041158 if (parsed_command_line().HasSwitch(switches::kPackExtension)) {
[email protected]d9ede582012-08-14 19:21:381159 extensions::StartupHelper extension_startup_helper;
1160 if (extension_startup_helper.PackExtension(parsed_command_line()))
[email protected]1fcfb202011-07-19 19:53:141161 return content::RESULT_CODE_NORMAL_EXIT;
[email protected]c1702d712011-09-08 19:41:431162 return chrome::RESULT_CODE_PACK_EXTENSION_ERROR;
[email protected]6aeac8342010-10-01 20:21:181163 }
1164
[email protected]ed8ce0b2012-07-28 02:18:101165 bool pass_command_line = true;
1166
[email protected]5425d062010-04-11 23:16:021167#if !defined(OS_MACOSX)
1168 // In environments other than Mac OS X we support import of settings
1169 // from other browsers. In case this process is a short-lived "import"
1170 // process that another browser runs just to import the settings, we
1171 // don't want to be checking for another browser process, by design.
[email protected]ae4c37e2012-12-21 01:16:251172 pass_command_line = !ProfileManager::IsImportProcess(parsed_command_line());
[email protected]bd48c2b02010-04-09 20:32:421173#endif
[email protected]ed8ce0b2012-07-28 02:18:101174
1175 // If we're being launched just to check the connector policy, we are
1176 // short-lived and don't want to be passing that switch off.
1177 pass_command_line = pass_command_line && !parsed_command_line().HasSwitch(
1178 switches::kCheckCloudPrintConnectorPolicy);
1179
1180 if (pass_command_line) {
[email protected]5425d062010-04-11 23:16:021181 // When another process is running, use that process instead of starting a
1182 // new one. NotifyOtherProcess will currently give the other process up to
1183 // 20 seconds to respond. Note that this needs to be done before we attempt
1184 // to read the profile.
[email protected]5d364542012-04-05 07:15:391185 notify_result_ = process_singleton_->NotifyOtherProcessOrCreate(
1186 base::Bind(&ProcessSingletonNotificationCallback));
[email protected]7bb9ddc12012-12-12 00:00:561187 UMA_HISTOGRAM_ENUMERATION("NotifyOtherProcessOrCreate.Result",
1188 notify_result_,
1189 ProcessSingleton::NUM_NOTIFY_RESULTS);
[email protected]66013922011-09-13 18:53:421190 switch (notify_result_) {
[email protected]5425d062010-04-11 23:16:021191 case ProcessSingleton::PROCESS_NONE:
1192 // No process already running, fall through to starting a new one.
1193 break;
[email protected]bd48c2b02010-04-09 20:32:421194
[email protected]5425d062010-04-11 23:16:021195 case ProcessSingleton::PROCESS_NOTIFIED:
1196#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]47e870b2013-02-24 21:14:531197 printf("%s\n", base::SysWideToNativeMB(UTF16ToWide(
[email protected]d5c45b72011-01-04 18:38:511198 l10n_util::GetStringUTF16(IDS_USED_EXISTING_BROWSER))).c_str());
[email protected]5425d062010-04-11 23:16:021199#endif
[email protected]68296502012-09-07 19:45:061200 // Having a differentiated return type for testing allows for tests to
1201 // verify proper handling of some switches. When not testing, stick to
1202 // the standard Unix convention of returning zero when things went as
1203 // expected.
1204 if (parsed_command_line().HasSwitch(switches::kTestType))
1205 return chrome::RESULT_CODE_NORMAL_EXIT_PROCESS_NOTIFIED;
1206 return content::RESULT_CODE_NORMAL_EXIT;
[email protected]bd48c2b02010-04-09 20:32:421207
[email protected]5425d062010-04-11 23:16:021208 case ProcessSingleton::PROFILE_IN_USE:
[email protected]1fcfb202011-07-19 19:53:141209 return chrome::RESULT_CODE_PROFILE_IN_USE;
[email protected]5425d062010-04-11 23:16:021210
[email protected]4a44bc32010-05-28 22:22:441211 case ProcessSingleton::LOCK_ERROR:
1212 LOG(ERROR) << "Failed to create a ProcessSingleton for your profile "
1213 "directory. This means that running multiple instances "
1214 "would start multiple browser processes rather than "
1215 "opening a new window in the existing process. Aborting "
1216 "now to avoid profile corruption.";
[email protected]1fcfb202011-07-19 19:53:141217 return chrome::RESULT_CODE_PROFILE_IN_USE;
[email protected]4a44bc32010-05-28 22:22:441218
[email protected]5425d062010-04-11 23:16:021219 default:
1220 NOTREACHED();
1221 }
[email protected]bd48c2b02010-04-09 20:32:421222 }
[email protected]81054f812012-08-30 00:47:091223#endif // !defined(OS_ANDROID)
[email protected]bd48c2b02010-04-09 20:32:421224
[email protected]2989d7342010-10-27 02:00:091225#if defined(USE_X11)
1226 SetBrowserX11ErrorHandlers();
1227#endif
1228
[email protected]50462bf02011-11-21 19:13:311229 // Desktop construction occurs here, (required before profile creation).
[email protected]97ef83f2011-12-19 19:26:361230 PreProfileInit();
[email protected]50462bf02011-11-21 19:13:311231
[email protected]ec79ca62012-11-16 01:16:511232 std::string try_chrome =
1233 parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain);
1234 if (!try_chrome.empty()) {
1235#if defined(OS_WIN)
1236 // Setup.exe has determined that we need to run a retention experiment
[email protected]622b764c2012-12-04 15:24:001237 // and has lauched chrome to show the experiment UI. It is guaranteed that
1238 // no other Chrome is currently running as the process singleton was
1239 // sucessfully grabbed above.
[email protected]ec79ca62012-11-16 01:16:511240 int try_chrome_int;
1241 base::StringToInt(try_chrome, &try_chrome_int);
1242 TryChromeDialogView::Result answer =
1243 TryChromeDialogView::Show(try_chrome_int, process_singleton_.get());
1244 if (answer == TryChromeDialogView::NOT_NOW)
1245 return chrome::RESULT_CODE_NORMAL_EXIT_CANCEL;
1246 if (answer == TryChromeDialogView::UNINSTALL_CHROME)
1247 return chrome::RESULT_CODE_NORMAL_EXIT_EXP2;
1248 // At this point the user is willing to try chrome again.
1249 if (answer == TryChromeDialogView::TRY_CHROME_AS_DEFAULT) {
1250 // Only set in the unattended case, the interactive case is Windows 8.
1251 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1252 ShellIntegration::SET_DEFAULT_UNATTENDED)
1253 ShellIntegration::SetAsDefaultBrowser();
1254 }
1255#else
1256 // We don't support retention experiments on Mac or Linux.
1257 return content::RESULT_CODE_NORMAL_EXIT;
1258#endif // defined(OS_WIN)
1259 }
1260
[email protected]20271f32010-03-26 03:04:511261 // Profile creation ----------------------------------------------------------
[email protected]08e6f6d2009-12-14 17:42:121262
[email protected]3f002a32013-01-02 17:52:381263 if (do_first_run_tasks_) {
[email protected]d91268022011-08-26 13:17:371264 // Warn the ProfileManager that an import process will run, possibly
1265 // locking the WebDataService directory of the next Profile created.
[email protected]17e6cde52012-01-05 00:16:571266 browser_process_->profile_manager()->SetWillImport();
[email protected]d91268022011-08-26 13:17:371267 }
1268
[email protected]2e5b60a22011-11-28 15:56:411269 profile_ = CreateProfile(parameters(), user_data_dir_, parsed_command_line());
[email protected]c1702d712011-09-08 19:41:431270 if (!profile_)
[email protected]1fcfb202011-07-19 19:53:141271 return content::RESULT_CODE_NORMAL_EXIT;
[email protected]20271f32010-03-26 03:04:511272
[email protected]81054f812012-08-30 00:47:091273#if defined(ENABLE_BACKGROUND)
[email protected]279170832011-10-12 23:38:031274 // Autoload any profiles which are running background apps.
1275 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075.
[email protected]d6bbd2932012-03-19 17:10:071276 browser_process_->profile_manager()->AutoloadProfiles();
[email protected]81054f812012-08-30 00:47:091277#endif
[email protected]20271f32010-03-26 03:04:511278 // Post-profile init ---------------------------------------------------------
[email protected]9acc48602009-11-30 21:18:511279
[email protected]81054f812012-08-30 00:47:091280#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
initial.commit09911bf2008-07-26 23:55:291281 // Importing other browser settings is done in a browser-like process
1282 // that exits when this task has finished.
[email protected]3ef4755e2010-09-27 20:25:041283 // TODO(port): Port the Mac's IPC-based implementation to other platforms to
1284 // replace this implementation. http://crbug.com/22142
[email protected]ae4c37e2012-12-21 01:16:251285 if (ProfileManager::IsImportProcess(parsed_command_line())) {
[email protected]4b516152012-01-07 03:09:151286 return first_run::ImportNow(profile_, parsed_command_line());
[email protected]272709ca2010-04-01 00:24:471287 }
[email protected]7da7f3432009-10-28 20:12:081288#endif
initial.commit09911bf2008-07-26 23:55:291289
[email protected]04999e62009-09-25 01:27:311290#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291291 // Do the tasks if chrome has been upgraded while it was last running.
[email protected]f967b722011-09-07 00:58:041292 if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line()))
[email protected]1fcfb202011-07-19 19:53:141293 return content::RESULT_CODE_NORMAL_EXIT;
initial.commit09911bf2008-07-26 23:55:291294
[email protected]68c921f2008-10-15 21:37:461295 // Check if there is any machine level Chrome installed on the current
1296 // machine. If yes and the current Chrome process is user level, we do not
1297 // allow the user level Chrome to run. So we notify the user and uninstall
1298 // user level Chrome.
1299 // Note this check should only happen here, after all the checks above
1300 // (uninstall, resource bundle initialization, other chrome browser
1301 // processes etc).
[email protected]6a7748e2011-05-27 16:44:311302 // Do not allow this to occur for Chrome Frame user-to-system handoffs.
[email protected]f967b722011-09-07 00:58:041303 if (!parsed_command_line().HasSwitch(switches::kChromeFrame) &&
[email protected]b48c9182011-10-26 18:03:301304 ChromeBrowserMainPartsWin::CheckMachineLevelInstall()) {
[email protected]1fcfb202011-07-19 19:53:141305 return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS;
[email protected]c1702d712011-09-08 19:41:431306 }
[email protected]b48c9182011-10-26 18:03:301307#endif
[email protected]68c921f2008-10-15 21:37:461308
[email protected]7e0831b2010-02-01 08:45:151309 // Create the TranslateManager singleton.
[email protected]c1702d712011-09-08 19:41:431310 translate_manager_ = TranslateManager::GetInstance();
1311 DCHECK(translate_manager_ != NULL);
[email protected]7e0831b2010-02-01 08:45:151312
[email protected]b16cc212013-02-06 21:09:511313#if !defined(OS_ANDROID)
[email protected]a6c7a8252012-06-25 18:28:241314 // Initialize Managed Mode.
1315 ManagedMode::Init(profile_);
[email protected]81054f812012-08-30 00:47:091316#endif
[email protected]a6c7a8252012-06-25 18:28:241317
[email protected]d5656f1c2013-01-29 01:31:261318 // Needs to be done before PostProfileInit, since login manager on CrOS is
1319 // called inside PostProfileInit.
1320 content::WebUIControllerFactory::RegisterFactory(
1321 ChromeWebUIControllerFactory::GetInstance());
1322
[email protected]a6c7a8252012-06-25 18:28:241323 // TODO(stevenjb): Move WIN and MACOSX specific code to appropriate Parts.
[email protected]97ef83f2011-12-19 19:26:361324 // (requires supporting early exit).
1325 PostProfileInit();
[email protected]50462bf02011-11-21 19:13:311326
[email protected]a9830b52012-12-17 23:30:361327 // Retrieve cached GL strings from local state and use them for GPU
1328 // blacklist decisions.
1329 if (g_browser_process->gl_string_manager())
1330 g_browser_process->gl_string_manager()->Initialize();
1331
[email protected]81054f812012-08-30 00:47:091332#if !defined(OS_ANDROID)
initial.commit09911bf2008-07-26 23:55:291333 // Show the First Run UI if this is the first time Chrome has been run on
1334 // this computer, or we're being compelled to do so by a command line flag.
1335 // Note that this be done _after_ the PrefService is initialized and all
1336 // preferences are registered, since some of the code that the importer
1337 // touches reads preferences.
[email protected]3f002a32013-01-02 17:52:381338 if (do_first_run_tasks_) {
1339 first_run::AutoImport(profile_,
1340 master_prefs_->homepage_defined,
1341 master_prefs_->do_import_items,
1342 master_prefs_->dont_import_items,
1343 process_singleton_.get());
1344 // Note: this can pop the first run consent dialog on linux.
1345 first_run::DoPostImportTasks(profile_, master_prefs_->make_chrome_default);
[email protected]96fe2e22012-03-07 22:54:191346
[email protected]17e6cde52012-01-05 00:16:571347 browser_process_->profile_manager()->OnImportFinished(profile_);
[email protected]eed73252012-08-03 18:47:441348
[email protected]820a1402012-08-09 23:13:511349 if (!master_prefs_->suppress_first_run_default_browser_prompt) {
1350 browser_creator_->set_show_main_browser_window(
1351 !chrome::ShowFirstRunDefaultBrowserPrompt(profile_));
1352 } else {
[email protected]eed73252012-08-03 18:47:441353 browser_creator_->set_is_default_browser_dialog_suppressed(true);
[email protected]820a1402012-08-09 23:13:511354 }
[email protected]3f002a32013-01-02 17:52:381355 } // if (do_first_run_tasks_)
[email protected]81054f812012-08-30 00:47:091356#endif // !defined(OS_ANDROID)
initial.commit09911bf2008-07-26 23:55:291357
[email protected]b48c9182011-10-26 18:03:301358#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291359 // Sets things up so that if we crash from this point on, a dialog will
1360 // popup asking the user to restart chrome. It is done this late to avoid
1361 // testing against a bunch of special cases that are taken care early on.
[email protected]b48c9182011-10-26 18:03:301362 ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment(
1363 parsed_command_line());
initial.commit09911bf2008-07-26 23:55:291364
[email protected]0fd23af2011-02-20 06:33:041365 // Registers Chrome with the Windows Restart Manager, which will restore the
1366 // Chrome session when the computer is restarted after a system update.
1367 // This could be run as late as WM_QUERYENDSESSION for system update reboots,
1368 // but should run on startup if extended to handle crashes/hangs/patches.
1369 // Also, better to run once here than once for each HWND's WM_QUERYENDSESSION.
[email protected]b48c9182011-10-26 18:03:301370 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
1371 ChromeBrowserMainPartsWin::RegisterApplicationRestart(
1372 parsed_command_line());
1373 }
[email protected]a4422802012-05-03 09:19:151374
1375 // Verify that the profile is not on a network share and if so prepare to show
1376 // notification to the user.
[email protected]297fb7c22012-06-26 12:37:491377 if (NetworkProfileBubble::ShouldCheckNetworkProfile(profile_)) {
[email protected]4d0f1732012-06-25 17:55:201378 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
[email protected]115dcfe2012-11-01 22:32:501379 base::Bind(&NetworkProfileBubble::CheckNetworkProfile,
1380 profile_->GetPath()));
[email protected]a4422802012-05-03 09:19:151381 }
[email protected]81d9b72d2012-03-26 22:29:171382#endif // OS_WIN
[email protected]0fd23af2011-02-20 06:33:041383
[email protected]e625c3b22012-11-16 14:55:391384#if defined(ENABLE_RLZ) && !defined(OS_CHROMEOS)
initial.commit09911bf2008-07-26 23:55:291385 // Init the RLZ library. This just binds the dll and schedules a task on the
1386 // file thread to be run sometime later. If this is the first run we record
1387 // the installation event.
[email protected]c1702d712011-09-08 19:41:431388 PrefService* pref_service = profile_->GetPrefs();
[email protected]3f002a32013-01-02 17:52:381389 int ping_delay = do_first_run_tasks_ ? master_prefs_->ping_delay :
[email protected]1b3588d2012-10-10 21:17:251390 pref_service->GetInteger(first_run::GetPingDelayPrefName().c_str());
[email protected]99de6a52012-12-25 13:08:411391 // Negative ping delay means to send ping immediately after a first search is
1392 // recorded.
1393 RLZTracker::InitRlzFromProfileDelayed(
[email protected]3f002a32013-01-02 17:52:381394 profile_, do_first_run_tasks_, ping_delay < 0,
[email protected]99de6a52012-12-25 13:08:411395 base::TimeDelta::FromMilliseconds(abs(ping_delay)));
[email protected]e625c3b22012-11-16 14:55:391396#endif // defined(ENABLE_RLZ) && !defined(OS_CHROMEOS)
[email protected]b48c9182011-10-26 18:03:301397
[email protected]a12f7fb2011-01-20 18:21:081398 // Configure modules that need access to resources.
[email protected]64d50ed2009-09-22 21:05:471399 net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider);
initial.commit09911bf2008-07-26 23:55:291400
[email protected]3dd1f6d52008-09-15 18:28:091401 // In unittest mode, this will do nothing. In normal mode, this will create
[email protected]665fa012012-05-09 00:24:381402 // the global IntranetRedirectDetector instance, which will promptly go to
1403 // sleep for seven seconds (to avoid slowing startup), and wake up afterwards
1404 // to see if it should do anything else.
[email protected]3dd1f6d52008-09-15 18:28:091405 //
1406 // A simpler way of doing all this would be to have some function which could
[email protected]665fa012012-05-09 00:24:381407 // give the time elapsed since startup, and simply have this object check that
1408 // when asked to initialize itself, but this doesn't seem to exist.
[email protected]3dd1f6d52008-09-15 18:28:091409 //
[email protected]665fa012012-05-09 00:24:381410 // This can't be created in the BrowserProcessImpl constructor because it
1411 // needs to read prefs that get set after that runs.
[email protected]c1702d712011-09-08 19:41:431412 browser_process_->intranet_redirect_detector();
[email protected]ed666562012-03-21 19:49:521413 GoogleSearchCounter::RegisterForNotifications();
initial.commit09911bf2008-07-26 23:55:291414
[email protected]3b543ab2011-09-17 21:47:001415 // Disable SDCH filtering if switches::kEnableSdch is 0.
1416 int sdch_enabled = 1;
1417 if (parsed_command_line().HasSwitch(switches::kEnableSdch)) {
1418 base::StringToInt(parsed_command_line().GetSwitchValueASCII(
1419 switches::kEnableSdch), &sdch_enabled);
1420 if (!sdch_enabled)
1421 net::SdchManager::EnableSdchSupport(false);
1422 }
1423 if (sdch_enabled) {
1424 // Perform A/B test to measure global impact of SDCH support.
1425 // Set up a field trial to see what disabling SDCH does to latency of page
1426 // layout globally.
1427 base::FieldTrial::Probability kSDCH_DIVISOR = 1000;
1428 base::FieldTrial::Probability kSDCH_DISABLE_PROBABILITY = 1; // 0.1% prob.
1429 // After March 31, 2012 builds, it will always be in default group.
[email protected]2d4729582012-04-12 07:08:071430 int sdch_enabled_group = -1;
[email protected]3b543ab2011-09-17 21:47:001431 scoped_refptr<base::FieldTrial> sdch_trial(
[email protected]2d4729582012-04-12 07:08:071432 base::FieldTrialList::FactoryGetFieldTrial(
1433 "GlobalSdch", kSDCH_DIVISOR, "global_enable_sdch", 2012, 3, 31,
1434 &sdch_enabled_group));
[email protected]e695fbd62009-06-30 16:31:541435
[email protected]58d2d2d2010-08-05 22:46:331436 sdch_trial->AppendGroup("global_disable_sdch",
[email protected]e12d50592010-01-06 17:35:191437 kSDCH_DISABLE_PROBABILITY);
[email protected]3b543ab2011-09-17 21:47:001438 if (sdch_enabled_group != sdch_trial->group())
1439 net::SdchManager::EnableSdchSupport(false);
[email protected]60889422008-09-23 01:18:161440 }
[email protected]e695fbd62009-06-30 16:31:541441
[email protected]b7672d12011-11-06 03:19:001442 if (parsed_command_line().HasSwitch(switches::kEnableWatchdog))
1443 InstallJankometer(parsed_command_line());
initial.commit09911bf2008-07-26 23:55:291444
[email protected]e1504d82009-07-03 15:27:151445#if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD)
[email protected]f967b722011-09-07 00:58:041446 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) {
[email protected]650b2d52013-02-10 03:41:451447 base::FilePath path =
[email protected]f967b722011-09-07 00:58:041448 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint);
[email protected]d9d42992010-09-13 19:39:191449 printing::PrintedDocument::set_debug_dump_path(path);
initial.commit09911bf2008-07-26 23:55:291450 }
[email protected]1bcdb532009-01-16 17:47:571451#endif
initial.commit09911bf2008-07-26 23:55:291452
[email protected]f967b722011-09-07 00:58:041453 HandleTestParameters(parsed_command_line());
[email protected]5281db1d2012-01-11 22:51:541454 RecordBreakpadStatusUMA(browser_process_->metrics_service());
[email protected]2e5b60a22011-11-28 15:56:411455 about_flags::RecordUMAStatistics(local_state_);
[email protected]703369a2012-11-05 20:40:311456#if defined(ENABLE_LANGUAGE_DETECTION)
[email protected]04261032011-07-21 08:42:081457 LanguageUsageMetrics::RecordAcceptLanguages(
[email protected]c1702d712011-09-08 19:41:431458 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]04261032011-07-21 08:42:081459 LanguageUsageMetrics::RecordApplicationLanguage(
[email protected]17e6cde52012-01-05 00:16:571460 browser_process_->GetApplicationLocale());
[email protected]703369a2012-11-05 20:40:311461#endif
[email protected]3cf4f0992009-02-03 23:00:301462
[email protected]89886652012-12-11 18:09:071463 // Querying the default browser state can be slow, do it in the background.
1464 BrowserThread::GetBlockingPool()->PostDelayedTask(
1465 FROM_HERE,
1466 base::Bind(&RecordDefaultBrowserUMAStat),
1467 base::TimeDelta::FromSeconds(5));
1468
[email protected]6aeac8342010-10-01 20:21:181469 // The extension service may be available at this point. If the command line
1470 // specifies --uninstall-extension, attempt the uninstall extension startup
1471 // action.
[email protected]f967b722011-09-07 00:58:041472 if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) {
[email protected]d9ede582012-08-14 19:21:381473 extensions::StartupHelper extension_startup_helper;
1474 if (extension_startup_helper.UninstallExtension(
1475 parsed_command_line(), profile_))
[email protected]1fcfb202011-07-19 19:53:141476 return content::RESULT_CODE_NORMAL_EXIT;
[email protected]c1702d712011-09-08 19:41:431477 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR;
[email protected]6aeac8342010-10-01 20:21:181478 }
1479
[email protected]08f1c5e2011-12-01 01:54:341480 // Start watching for hangs during startup. We disarm this hang detector when
1481 // ThreadWatcher takes over or when browser is shutdown or when
1482 // startup_watcher_ is deleted.
1483 startup_watcher_->Arm(base::TimeDelta::FromSeconds(300));
1484
[email protected]84c384e2013-03-01 23:20:191485 // On mobile, need for clean shutdown arises only when the application comes
1486 // to foreground (i.e. MetricsService::OnAppEnterForeground is called).
1487 // http://crbug.com/179143
1488#if !defined(OS_ANDROID)
[email protected]c0c55e92011-09-10 18:47:301489 // Start watching for a hang.
1490 MetricsService::LogNeedForCleanShutdown();
[email protected]84c384e2013-03-01 23:20:191491#endif
[email protected]c0c55e92011-09-10 18:47:301492
[email protected]15406b6a2010-04-21 00:35:011493#if defined(OS_WIN)
[email protected]8a9c63e2010-04-19 21:27:551494 // We check this here because if the profile is OTR (chromeos possibility)
1495 // it won't still be accessible after browser is destroyed.
[email protected]3f002a32013-01-02 17:52:381496 record_search_engine_ = do_first_run_tasks_ && !profile_->IsOffTheRecord();
[email protected]15406b6a2010-04-21 00:35:011497#endif
[email protected]8a9c63e2010-04-19 21:27:551498
[email protected]17543d62010-10-07 22:37:381499 // Create the instance of the cloud print proxy service so that it can launch
1500 // the service process if needed. This is needed because the service process
1501 // might have shutdown because an update was available.
[email protected]17cefaaf2011-08-02 14:42:581502 // TODO(torne): this should maybe be done with
1503 // ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead?
[email protected]058e5732012-03-01 22:48:031504#if !defined(OS_ANDROID)
[email protected]c1702d712011-09-08 19:41:431505 CloudPrintProxyServiceFactory::GetForProfile(profile_);
[email protected]058e5732012-03-01 22:48:031506#endif
[email protected]17543d62010-10-07 22:37:381507
[email protected]dedfabae2011-03-04 04:00:401508 // Start watching all browser threads for responsiveness.
[email protected]f967b722011-09-07 00:58:041509 ThreadWatcherList::StartWatchingAll(parsed_command_line());
[email protected]dedfabae2011-03-04 04:00:401510
[email protected]773ebb92011-11-15 19:06:521511#if !defined(DISABLE_NACL)
[email protected]b1511ab02012-07-02 23:45:511512 if (parsed_command_line().HasSwitch(switches::kPnaclDir)) {
1513 PathService::Override(chrome::DIR_PNACL_BASE,
1514 parsed_command_line().GetSwitchValuePath(
1515 switches::kPnaclDir));
1516 }
[email protected]773ebb92011-11-15 19:06:521517 NaClProcessHost::EarlyStartup();
1518#endif
1519
[email protected]97ef83f2011-12-19 19:26:361520 PreBrowserStart();
1521
[email protected]087453292011-11-22 00:43:121522 // Instantiate the notification UI manager, as this triggers a perf timer
1523 // used to measure startup time. TODO(stevenjb): Figure out what is actually
1524 // triggering the timer and call that explicitly in the approprate place.
1525 // http://crbug.com/105065.
[email protected]17e6cde52012-01-05 00:16:571526 browser_process_->notification_ui_manager();
[email protected]087453292011-11-22 00:43:121527
[email protected]81054f812012-08-30 00:47:091528#if !defined(OS_ANDROID)
[email protected]5b027af2012-06-21 18:32:531529 // Most general initialization is behind us, but opening a
1530 // tab and/or session restore and such is still to be done.
1531 base::TimeTicks browser_open_start = base::TimeTicks::Now();
[email protected]45d72762011-04-15 18:58:201532
[email protected]5b027af2012-06-21 18:32:531533 // We are in regular browser boot sequence. Open initial tabs and enter the
1534 // main message loop.
1535 int result_code;
[email protected]a64ad242012-01-18 15:17:361536#if defined(OS_CHROMEOS)
[email protected]5b027af2012-06-21 18:32:531537 // On ChromeOS multiple profiles doesn't apply, and will break if we load
1538 // them this early as the cryptohome hasn't yet been mounted (which happens
1539 // only once we log in.
1540 std::vector<Profile*> last_opened_profiles;
[email protected]a64ad242012-01-18 15:17:361541#else
[email protected]5b027af2012-06-21 18:32:531542 std::vector<Profile*> last_opened_profiles =
1543 g_browser_process->profile_manager()->GetLastOpenedProfiles();
[email protected]a64ad242012-01-18 15:17:361544#endif
[email protected]aec25bc2012-10-04 18:45:261545
[email protected]8cebc942013-01-31 01:28:421546 if (!parsed_command_line().HasSwitch(switches::kDisableComponentUpdate))
1547 RegisterComponentsForUpdate(parsed_command_line());
1548
[email protected]650b2d52013-02-10 03:41:451549 if (browser_creator_->Start(parsed_command_line(), base::FilePath(),
[email protected]5b027af2012-06-21 18:32:531550 profile_, last_opened_profiles, &result_code)) {
[email protected]c7480942011-11-08 19:18:271551#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
[email protected]5b027af2012-06-21 18:32:531552 // Initialize autoupdate timer. Timer callback costs basically nothing
1553 // when browser is not in persistent mode, so it's OK to let it ride on
1554 // the main thread. This needs to be done here because we don't want
1555 // to start the timer when Chrome is run inside a test harness.
1556 browser_process_->StartAutoupdateTimer();
[email protected]bd48c2b02010-04-09 20:32:421557#endif
1558
[email protected]3cdacd42010-04-30 18:55:531559#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]5b027af2012-06-21 18:32:531560 // On Linux, the running exe will be updated if an upgrade becomes
1561 // available while the browser is running. We need to save the last
1562 // modified time of the exe, so we can compare to determine if there is
1563 // an upgrade while the browser is kept alive by a persistent extension.
1564 upgrade_util::SaveLastModifiedTimeOfExe();
[email protected]3cdacd42010-04-30 18:55:531565#endif
1566
[email protected]5b027af2012-06-21 18:32:531567 // Record now as the last successful chrome start.
1568 GoogleUpdateSettings::SetLastRunTime();
[email protected]badf5cf2011-10-29 03:44:441569
1570#if defined(OS_MACOSX)
[email protected]5b027af2012-06-21 18:32:531571 // Call Recycle() here as late as possible, before going into the loop
1572 // because Start() will add things to it while creating the main window.
1573 if (parameters().autorelease_pool)
1574 parameters().autorelease_pool->Recycle();
[email protected]badf5cf2011-10-29 03:44:441575#endif
[email protected]45d72762011-04-15 18:58:201576
[email protected]5b027af2012-06-21 18:32:531577 RecordPreReadExperimentTime("Startup.BrowserOpenTabs",
1578 base::TimeTicks::Now() - browser_open_start);
[email protected]45d72762011-04-15 18:58:201579
[email protected]5b027af2012-06-21 18:32:531580 // If we're running tests (ui_task is non-null), then we don't want to
1581 // call FetchLanguageListFromTranslateServer or
[email protected]88bac3f2012-07-22 21:22:571582 // StartRepeatedVariationsSeedFetch.
[email protected]5b027af2012-06-21 18:32:531583 if (parameters().ui_task == NULL) {
1584 // Request new variations seed information from server.
[email protected]58c63cb2012-11-26 19:22:111585 chrome_variations::VariationsService* variations_service =
1586 browser_process_->variations_service();
[email protected]92e669c2013-01-30 00:30:021587 if (variations_service) {
[email protected]58c63cb2012-11-26 19:22:111588 variations_service->StartRepeatedVariationsSeedFetch();
1589
[email protected]92e669c2013-01-30 00:30:021590#if defined(OS_WIN)
1591 variations_service->StartGoogleUpdateRegistrySync();
1592#endif
1593 }
1594
[email protected]d06ba1242012-09-25 20:51:391595#if !defined(OS_CHROMEOS)
1596 // TODO(mad): Move this call in a proper place on CrOS.
1597 // http://crosbug.com/17687
[email protected]5b027af2012-06-21 18:32:531598 if (translate_manager_ != NULL) {
1599 translate_manager_->FetchLanguageListFromTranslateServer(
1600 profile_->GetPrefs());
[email protected]63e26822011-07-16 19:07:351601 }
[email protected]bafa00e42011-07-18 14:47:261602#endif
[email protected]d06ba1242012-09-25 20:51:391603 }
[email protected]fa436972011-06-23 05:58:011604
[email protected]5b027af2012-06-21 18:32:531605 run_message_loop_ = true;
1606 } else {
1607 run_message_loop_ = false;
1608 }
[email protected]fe7c4872012-05-10 20:06:031609 browser_creator_.reset();
[email protected]81054f812012-08-30 00:47:091610#endif // !defined(OS_ANDROID)
[email protected]97ef83f2011-12-19 19:26:361611
[email protected]b19e0e2e2013-02-06 18:15:511612 RecordTouchEventState(parsed_command_line());
1613
[email protected]97ef83f2011-12-19 19:26:361614 PostBrowserStart();
1615
[email protected]886f1142012-05-03 20:00:161616 if (parameters().ui_task) {
[email protected]0c1c4752012-08-09 20:30:241617 // We end the startup timer here if we have parameters to run, because we
1618 // never start to run the main loop (where we normally stop the timer).
1619 startup_timer_->SignalStartupComplete(
1620 performance_monitor::StartupTimer::STARTUP_TEST);
[email protected]886f1142012-05-03 20:00:161621 parameters().ui_task->Run();
1622 delete parameters().ui_task;
1623 run_message_loop_ = false;
1624 }
1625
[email protected]50462bf02011-11-21 19:13:311626 return result_code_;
[email protected]c1702d712011-09-08 19:41:431627}
1628
[email protected]b48c9182011-10-26 18:03:301629bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) {
[email protected]82d2c332012-08-07 22:46:311630#if defined(OS_ANDROID)
1631 // Chrome on Android does not use default MessageLoop. It has its own
1632 // Android specific MessageLoop
1633 NOTREACHED();
1634 return true;
1635#else
[email protected]c7480942011-11-08 19:18:271636 // Set the result code set in PreMainMessageLoopRun or set above.
[email protected]b48c9182011-10-26 18:03:301637 *result_code = result_code_;
[email protected]c1702d712011-09-08 19:41:431638 if (!run_message_loop_)
[email protected]b48c9182011-10-26 18:03:301639 return true; // Don't run the default message loop.
[email protected]c1702d712011-09-08 19:41:431640
[email protected]0c1c4752012-08-09 20:30:241641 // These should be invoked as close to the start of the browser's
[email protected]c1702d712011-09-08 19:41:431642 // UI thread message loop as possible to get a stable measurement
1643 // across versions.
1644 RecordBrowserStartupTime();
[email protected]0c1c4752012-08-09 20:30:241645 startup_timer_->SignalStartupComplete(
1646 performance_monitor::StartupTimer::STARTUP_NORMAL);
1647
[email protected]8e937c1e2012-06-28 22:57:301648 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type());
1649#if !defined(USE_AURA) && defined(TOOLKIT_VIEWS)
[email protected]c1702d712011-09-08 19:41:431650 views::AcceleratorHandler accelerator_handler;
[email protected]8e937c1e2012-06-28 22:57:301651 base::RunLoop run_loop(&accelerator_handler);
1652#else
1653 base::RunLoop run_loop;
[email protected]c1702d712011-09-08 19:41:431654#endif
[email protected]d378f192012-08-14 18:42:031655
1656 if (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]7fae42952012-09-05 21:25:271657 switches::kPerformanceMonitorGathering)) {
[email protected]d378f192012-08-14 18:42:031658 performance_monitor::PerformanceMonitor::GetInstance()->Start();
1659 }
1660
[email protected]8e937c1e2012-06-28 22:57:301661 run_loop.Run();
[email protected]b48c9182011-10-26 18:03:301662
1663 return true;
[email protected]82d2c332012-08-07 22:46:311664#endif
[email protected]c1702d712011-09-08 19:41:431665}
1666
1667void ChromeBrowserMainParts::PostMainMessageLoopRun() {
[email protected]82d2c332012-08-07 22:46:311668#if defined(OS_ANDROID)
1669 // Chrome on Android does not use default MessageLoop. It has its own
1670 // Android specific MessageLoop
1671 NOTREACHED();
1672#else
[email protected]1dd7a8e2012-09-16 18:49:291673
1674#if defined(USE_X11)
1675 // Unset the X11 error handlers. The X11 error handlers log the errors using a
1676 // |PostTask()| on the message-loop. But since the message-loop is in the
1677 // process of terminating, this can cause errors.
1678 UnsetBrowserX11ErrorHandlers();
1679#endif
1680
[email protected]6d823b42011-09-05 02:54:021681 // Start watching for jank during shutdown. It gets disarmed when
[email protected]f967b722011-09-07 00:58:041682 // |shutdown_watcher_| object is destructed.
[email protected]56bdb712012-01-27 00:35:591683 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(300));
[email protected]6d823b42011-09-05 02:54:021684
[email protected]b69941522011-10-08 03:17:371685 // Disarm the startup hang detector time bomb if it is still Arm'ed.
[email protected]08f1c5e2011-12-01 01:54:341686 startup_watcher_->Disarm();
[email protected]b69941522011-10-08 03:17:371687
[email protected]ef589af2011-12-03 01:07:151688 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1689 chrome_extra_parts_[i]->PostMainMessageLoopRun();
1690
[email protected]aec25bc2012-10-04 18:45:261691#if !defined(OS_ANDROID)
1692 gpu_util::UninstallBrowserMonitor();
1693#endif
1694
[email protected]15406b6a2010-04-21 00:35:011695#if defined(OS_WIN)
[email protected]2381ed22012-01-26 04:05:291696 // Log the search engine chosen on first run. Do this at shutdown, after any
1697 // changes are made from the first run bubble link, etc.
[email protected]c1702d712011-09-08 19:41:431698 if (record_search_engine_) {
[email protected]8e5c89a2011-06-07 18:13:331699 TemplateURLService* url_service =
[email protected]c1702d712011-09-08 19:41:431700 TemplateURLServiceFactory::GetForProfile(profile_);
[email protected]96b3c5c2010-04-16 20:30:141701 const TemplateURL* default_search_engine =
[email protected]8e5c89a2011-06-07 18:13:331702 url_service->GetDefaultSearchProvider();
[email protected]32cba2b2010-10-19 06:19:481703 // The default engine can be NULL if the administrator has disabled
1704 // default search.
[email protected]23872902010-10-26 03:43:591705 SearchEngineType search_engine_type =
[email protected]360ba052012-04-04 17:26:131706 TemplateURLPrepopulateData::GetEngineType(default_search_engine ?
1707 default_search_engine->url() : std::string());
[email protected]bf7eb2f92010-06-28 22:55:551708 // Record the search engine chosen.
[email protected]b37bdfe2012-03-16 20:53:271709 UMA_HISTOGRAM_ENUMERATION("Chrome.SearchSelectExempt", search_engine_type,
[email protected]2381ed22012-01-26 04:05:291710 SEARCH_ENGINE_MAX);
[email protected]96b3c5c2010-04-16 20:30:141711 }
[email protected]15406b6a2010-04-21 00:35:011712#endif
[email protected]96b3c5c2010-04-16 20:30:141713
[email protected]a6e9dce22011-06-25 00:19:221714 // Some tests don't set parameters.ui_task, so they started translate
1715 // language fetch that was never completed so we need to cleanup here
1716 // otherwise it will be done by the destructor in a wrong thread.
[email protected]716476c2011-12-29 00:07:031717 if (parameters().ui_task == NULL && translate_manager_ != NULL)
[email protected]c1702d712011-09-08 19:41:431718 translate_manager_->CleanupPendingUlrFetcher();
[email protected]a6e9dce22011-06-25 00:19:221719
[email protected]66013922011-09-13 18:53:421720 if (notify_result_ == ProcessSingleton::PROCESS_NONE)
1721 process_singleton_->Cleanup();
[email protected]9f20a6d02009-08-21 01:18:371722
[email protected]0b565182011-03-02 18:11:151723 // Stop all tasks that might run on WatchDogThread.
1724 ThreadWatcherList::StopWatchingAll();
1725
[email protected]17e6cde52012-01-05 00:16:571726 browser_process_->metrics_service()->Stop();
initial.commit09911bf2008-07-26 23:55:291727
[email protected]2e5b60a22011-11-28 15:56:411728 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop();
1729 browser_process_->StartTearDown();
[email protected]82d2c332012-08-07 22:46:311730#endif
[email protected]2e5b60a22011-11-28 15:56:411731}
1732
[email protected]2e5b60a22011-11-28 15:56:411733void ChromeBrowserMainParts::PostDestroyThreads() {
[email protected]81054f812012-08-30 00:47:091734#if defined(OS_ANDROID)
1735 // On Android, there is no quit/exit. So the browser's main message loop will
1736 // not finish.
1737 NOTREACHED();
1738#else
[email protected]99907362012-01-11 05:41:401739 browser_process_->PostDestroyThreads();
initial.commit09911bf2008-07-26 23:55:291740 // browser_shutdown takes care of deleting browser_process, so we need to
1741 // release it.
[email protected]c1702d712011-09-08 19:41:431742 ignore_result(browser_process_.release());
[email protected]2e5b60a22011-11-28 15:56:411743 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_);
[email protected]c1702d712011-09-08 19:41:431744 master_prefs_.reset();
1745 process_singleton_.reset();
[email protected]c0c55e92011-09-10 18:47:301746
1747 // We need to do this check as late as possible, but due to modularity, this
1748 // may be the last point in Chrome. This would be more effective if done at
1749 // a higher level on the stack, so that it is impossible for an early return
1750 // to bypass this code. Perhaps we need a *final* hook that is called on all
1751 // paths from content/browser/browser_main.
1752 CHECK(MetricsService::UmaMetricsProperlyShutdown());
[email protected]81054f812012-08-30 00:47:091753#endif
[email protected]c1702d712011-09-08 19:41:431754}
initial.commit09911bf2008-07-26 23:55:291755
[email protected]50462bf02011-11-21 19:13:311756// Public members:
1757
1758void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
1759 chrome_extra_parts_.push_back(parts);
1760}
1761
1762// Misc ------------------------------------------------------------------------
1763
[email protected]843bc462012-06-19 17:43:311764void RecordBrowserStartupTime() {
[email protected]54676d0e2012-10-24 10:28:301765 // Don't record any metrics if UI was displayed before this point e.g.
1766 // warning dialogs.
1767 if (startup_metric_utils::WasNonBrowserUIDisplayed())
1768 return;
1769
[email protected]843bc462012-06-19 17:43:311770// CurrentProcessInfo::CreationTime() is currently only implemented on Mac and
1771// Windows.
1772#if defined(OS_MACOSX) || defined(OS_WIN)
1773 const base::Time *process_creation_time =
1774 base::CurrentProcessInfo::CreationTime();
1775
1776 if (process_creation_time)
1777 RecordPreReadExperimentTime("Startup.BrowserMessageLoopStartTime",
1778 base::Time::Now() - *process_creation_time);
1779#endif // OS_MACOSX || OS_WIN
[email protected]54676d0e2012-10-24 10:28:301780
[email protected]40c4f412013-01-15 06:35:571781 // Record collected startup metrics.
1782 startup_metric_utils::OnBrowserStartupComplete();
[email protected]e327c752013-01-30 11:38:161783
1784 // Deletes self.
1785 new LoadCompleteListener();
[email protected]843bc462012-06-19 17:43:311786}
1787
[email protected]28f576f2011-08-26 20:46:551788// This code is specific to the Windows-only PreReadExperiment field-trial.
1789void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) {
1790 DCHECK(name != NULL);
1791
1792 // This gets called with different histogram names, so we don't want to use
1793 // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the
1794 // first call wins.
1795 AddPreReadHistogramTime(name, time);
1796
1797#if defined(OS_WIN)
[email protected]5bca9ee2011-09-03 00:18:421798#if defined(GOOGLE_CHROME_BUILD)
1799 // The pre-read experiment is Windows and Google Chrome specific.
[email protected]28f576f2011-08-26 20:46:551800 scoped_ptr<base::Environment> env(base::Environment::Create());
1801
1802 // Only record the sub-histogram result if the experiment is running
1803 // (environment variable is set, and valid).
[email protected]48078e52012-02-09 00:02:261804 std::string pre_read_percentage;
1805 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read_percentage)) {
[email protected]28f576f2011-08-26 20:46:551806 std::string uma_name(name);
[email protected]ff5ce2372011-12-21 02:00:591807
1808 // We want XP to record a separate histogram, as the loader on XP
1809 // is very different from the Vista and Win7 loaders.
1810 if (base::win::GetVersion() <= base::win::VERSION_XP)
1811 uma_name += "_XP";
1812
[email protected]48078e52012-02-09 00:02:261813 uma_name += "_PreRead_";
1814 uma_name += pre_read_percentage;
[email protected]28f576f2011-08-26 20:46:551815 AddPreReadHistogramTime(uma_name.c_str(), time);
1816 }
1817#endif
[email protected]5bca9ee2011-09-03 00:18:421818#endif
[email protected]28f576f2011-08-26 20:46:551819}