blob: 6f36b651ebb6c7ffa0cf6478f2a18ecdbdce85b7 [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]58580352010-10-26 04:07:5017#include "base/debug/trace_event.h"
[email protected]1bcdb532009-01-16 17:47:5718#include "base/file_util.h"
[email protected]57999812013-02-24 05:40:5219#include "base/files/file_path.h"
[email protected]835d7c82010-10-14 04:38:3820#include "base/metrics/field_trial.h"
21#include "base/metrics/histogram.h"
[email protected]1bcdb532009-01-16 17:47:5722#include "base/path_service.h"
[email protected]03b9b4e2012-10-22 20:01:5223#include "base/prefs/json_pref_store.h"
[email protected]3853a4c2013-02-11 17:15:5724#include "base/prefs/pref_registry_simple.h"
25#include "base/prefs/pref_service.h"
26#include "base/prefs/pref_value_store.h"
[email protected]843bc462012-06-19 17:43:3127#include "base/process_info.h"
[email protected]1bcdb532009-01-16 17:47:5728#include "base/process_util.h"
[email protected]8e937c1e2012-06-28 22:57:3029#include "base/run_loop.h"
[email protected]3ea1b182013-02-08 22:38:4130#include "base/strings/string_number_conversions.h"
[email protected]4570a252013-03-31 00:35:4331#include "base/strings/string_piece.h"
[email protected]1988e1c2013-02-28 20:27:4232#include "base/strings/string_split.h"
[email protected]3268d7b72013-03-28 17:41:4333#include "base/strings/sys_string_conversions.h"
[email protected]135cb802013-06-09 16:44:2034#include "base/strings/utf_string_conversions.h"
[email protected]0f24e53e2012-10-29 01:04:0935#include "base/sys_info.h"
[email protected]93270d002011-01-19 22:32:5936#include "base/threading/platform_thread.h"
[email protected]6b5f21d2009-04-13 17:01:3537#include "base/time.h"
[email protected]1bcdb532009-01-16 17:47:5738#include "base/values.h"
[email protected]01109dcf2010-03-27 00:56:4339#include "build/build_config.h"
[email protected]4bc5050c2010-11-18 17:55:5440#include "chrome/browser/about_flags.h"
[email protected]5d364542012-04-05 07:15:3941#include "chrome/browser/browser_process.h"
[email protected]b112a4c2009-02-01 20:24:0142#include "chrome/browser/browser_process_impl.h"
[email protected]f2068f92013-05-20 05:30:1743#include "chrome/browser/browser_process_platform_part.h"
[email protected]7f0ebc92009-02-05 18:34:2144#include "chrome/browser/browser_shutdown.h"
[email protected]50462bf02011-11-21 19:13:3145#include "chrome/browser/chrome_browser_main_extra_parts.h"
[email protected]8cebc942013-01-31 01:28:4246#include "chrome/browser/component_updater/component_updater_service.h"
47#include "chrome/browser/component_updater/flash_component_installer.h"
48#include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
49#include "chrome/browser/component_updater/recovery_component_installer.h"
50#include "chrome/browser/component_updater/swiftshader_component_installer.h"
[email protected]649e9b22013-05-04 06:36:5751#include "chrome/browser/component_updater/widevine_cdm_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]af7ba1e2013-04-12 17:09:4555#include "chrome/browser/extensions/message_handler.h"
[email protected]d9ede582012-08-14 19:21:3856#include "chrome/browser/extensions/startup_helper.h"
[email protected]1a905b72012-12-20 00:22:1357#include "chrome/browser/first_run/first_run.h"
[email protected]815856722011-04-13 17:19:1958#include "chrome/browser/first_run/upgrade_util.h"
[email protected]ed666562012-03-21 19:49:5259#include "chrome/browser/google/google_search_counter.h"
[email protected]7a336d6ec2011-10-07 14:17:5860#include "chrome/browser/google/google_util.h"
[email protected]c3da80c2012-12-07 20:57:2461#include "chrome/browser/gpu/chrome_gpu_util.h"
[email protected]a9830b52012-12-17 23:30:3662#include "chrome/browser/gpu/gl_string_manager.h"
[email protected]86230b92009-11-23 20:38:3863#include "chrome/browser/jankometer.h"
[email protected]46690b72012-10-26 19:33:3264#include "chrome/browser/managed_mode/managed_mode.h"
[email protected]4cb3c1fc2012-04-05 07:23:4865#include "chrome/browser/metrics/field_trial_synchronizer.h"
[email protected]679082052010-07-21 21:30:1366#include "chrome/browser/metrics/metrics_log.h"
[email protected]dc6f4962009-02-13 01:25:5067#include "chrome/browser/metrics/metrics_service.h"
[email protected]0b565182011-03-02 18:11:1568#include "chrome/browser/metrics/thread_watcher.h"
[email protected]10fe40c2011-11-05 03:27:4669#include "chrome/browser/metrics/tracking_synchronizer.h"
[email protected]cf265dc02012-08-15 01:01:1670#include "chrome/browser/metrics/variations/variations_service.h"
[email protected]773ebb92011-11-15 19:06:5271#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]82c71ba2011-05-27 18:51:5372#include "chrome/browser/net/chrome_net_log.h"
[email protected]8cebc942013-01-31 01:28:4273#include "chrome/browser/net/crl_set_fetcher.h"
[email protected]59368d9d2012-01-31 01:02:5474#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]aa84a7e2012-03-15 21:29:0675#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]684dace42012-07-01 14:30:4176#include "chrome/browser/page_cycler/page_cycler.h"
[email protected]d378f192012-08-14 18:42:0377#include "chrome/browser/performance_monitor/performance_monitor.h"
[email protected]0c1c4752012-08-09 20:30:2478#include "chrome/browser/performance_monitor/startup_timer.h"
[email protected]0f5e57f52012-09-20 20:53:1879#include "chrome/browser/plugins/plugin_prefs.h"
[email protected]e6d1c4f2013-06-12 17:37:4080#include "chrome/browser/pref_service_flags_storage.h"
[email protected]5b199522012-12-22 17:24:4481#include "chrome/browser/prefs/chrome_pref_service_factory.h"
82#include "chrome/browser/prefs/command_line_pref_store.h"
[email protected]1583def2012-01-25 11:26:3283#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]59368d9d2012-01-31 01:02:5484#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
[email protected]aa84a7e2012-03-15 21:29:0685#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
[email protected]e3db4fab2009-04-21 21:47:4086#include "chrome/browser/process_singleton.h"
[email protected]8ecad5e2010-12-02 21:18:3387#include "chrome/browser/profiles/profile.h"
88#include "chrome/browser/profiles/profile_manager.h"
[email protected]af7ba1e2013-04-12 17:09:4589#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]23872902010-10-26 03:43:5990#include "chrome/browser/search_engines/search_engine_type.h"
[email protected]8b62334b2010-08-31 22:37:1191#include "chrome/browser/search_engines/template_url.h"
[email protected]b37bdfe2012-03-16 20:53:2792#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
[email protected]59368d9d2012-01-31 01:02:5493#include "chrome/browser/search_engines/template_url_service.h"
[email protected]aa84a7e2012-03-15 21:29:0694#include "chrome/browser/search_engines/template_url_service_factory.h"
[email protected]e96bf0c52010-08-23 23:20:5795#include "chrome/browser/service/service_process_control.h"
[email protected]1bcdb532009-01-16 17:47:5796#include "chrome/browser/shell_integration.h"
[email protected]44327692013-02-26 21:21:2297#include "chrome/browser/three_d_api_observer.h"
[email protected]509acb8e2010-07-01 20:35:3198#include "chrome/browser/translate/translate_manager.h"
[email protected]f0ee7912013-02-27 06:02:5599#include "chrome/browser/ui/app_list/app_list_service.h"
[email protected]f46be6e2010-11-16 03:52:32100#include "chrome/browser/ui/browser.h"
[email protected]278a34d2012-06-07 00:34:58101#include "chrome/browser/ui/browser_finder.h"
[email protected]55d342402013-02-22 11:28:06102#include "chrome/browser/ui/host_desktop.h"
[email protected]eed73252012-08-03 18:47:44103#include "chrome/browser/ui/startup/default_browser_prompt.h"
[email protected]fe7c4872012-05-10 20:06:03104#include "chrome/browser/ui/startup/startup_browser_creator.h"
[email protected]3770c242012-07-12 22:58:17105#include "chrome/browser/ui/uma_browsing_activity_observer.h"
[email protected]eea4c6d2012-05-15 18:10:56106#include "chrome/browser/ui/user_data_dir_dialog.h"
[email protected]d5656f1c2013-01-29 01:31:26107#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]16951ead2013-03-27 06:44:44108#include "chrome/browser/user_data_dir_extractor.h"
[email protected]783f06f2011-09-14 01:36:11109#include "chrome/common/child_process_logging.h"
[email protected]1bcdb532009-01-16 17:47:57110#include "chrome/common/chrome_constants.h"
111#include "chrome/common/chrome_paths.h"
[email protected]1fcfb202011-07-19 19:53:14112#include "chrome/common/chrome_result_codes.h"
[email protected]1bcdb532009-01-16 17:47:57113#include "chrome/common/chrome_switches.h"
[email protected]1b084b5e2010-08-03 07:58:19114#include "chrome/common/env_vars.h"
[email protected]30f547c2010-08-04 01:00:01115#include "chrome/common/logging_chrome.h"
[email protected]64d50ed2009-09-22 21:05:47116#include "chrome/common/net/net_resource_provider.h"
[email protected]1bcdb532009-01-16 17:47:57117#include "chrome/common/pref_names.h"
[email protected]7664ab32011-02-01 23:35:25118#include "chrome/common/profiling.h"
[email protected]54676d0e2012-10-24 10:28:30119#include "chrome/common/startup_metric_utils.h"
[email protected]1e7377d2009-05-28 20:23:06120#include "chrome/installer/util/google_update_settings.h"
[email protected]c38831a12011-10-28 12:44:49121#include "content/public/browser/browser_thread.h"
[email protected]e327c752013-01-30 11:38:16122#include "content/public/browser/notification_observer.h"
123#include "content/public/browser/notification_registrar.h"
124#include "content/public/browser/notification_service.h"
125#include "content/public/browser/notification_types.h"
[email protected]af7ba1e2013-04-12 17:09:45126#include "content/public/browser/site_instance.h"
[email protected]5d1fa242011-10-18 23:35:38127#include "content/public/common/content_client.h"
[email protected]86d3aca2012-12-04 21:36:09128#include "content/public/common/content_switches.h"
[email protected]4573fbd2011-10-31 20:25:18129#include "content/public/common/main_function_params.h"
[email protected]ea500fc62010-03-22 21:34:29130#include "grit/app_locale_settings.h"
[email protected]4e039f242011-12-03 07:29:38131#include "grit/browser_resources.h"
[email protected]34ac8f32009-02-22 23:03:27132#include "grit/chromium_strings.h"
133#include "grit/generated_resources.h"
[email protected]61c6f412011-03-23 20:47:54134#include "grit/platform_locale_settings.h"
[email protected]698cccb12009-03-11 18:47:24135#include "net/base/net_module.h"
[email protected]3b543ab2011-09-17 21:47:00136#include "net/base/sdch_manager.h"
[email protected]aa84a7e2012-03-15 21:29:06137#include "net/cookies/cookie_monster.h"
[email protected]e0345002012-09-01 03:06:12138#include "net/http/http_network_layer.h"
[email protected]8e6441ca2010-08-19 05:56:38139#include "net/http/http_stream_factory.h"
[email protected]abb26092010-11-11 22:19:00140#include "net/url_request/url_request.h"
[email protected]e39027a2011-01-24 21:41:54141#include "ui/base/l10n/l10n_util.h"
[email protected]6bae7352012-06-15 15:46:46142#include "ui/base/layout.h"
[email protected]42ce29d2011-01-20 23:19:46143#include "ui/base/resource/resource_bundle.h"
[email protected]1bcdb532009-01-16 17:47:57144
[email protected]2f2f72b2013-03-08 22:37:31145#if !defined(OS_ANDROID)
146#include "chrome/browser/ui/active_tab_tracker.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]931d1042013-04-05 17:50:44157#include "chromeos/chromeos_switches.h"
[email protected]d4fe1fbc2010-05-19 17:36:06158#endif
159
[email protected]022614ef92008-12-30 20:50:01160// TODO(port): several win-only methods have been pulled out of this, but
[email protected]5c9587c2008-12-09 21:20:16161// BrowserMain() as a whole needs to be broken apart so that it's usable by
[email protected]022614ef92008-12-30 20:50:01162// other platforms. For now, it's just a stub. This is a serious work in
[email protected]5c9587c2008-12-09 21:20:16163// progress and should not be taken as an indication of a real refactoring.
164
165#if defined(OS_WIN)
[email protected]28f576f2011-08-26 20:46:55166#include "base/environment.h" // For PreRead experiment.
[email protected]0fd23af2011-02-20 06:33:04167#include "base/win/windows_version.h"
[email protected]a3abd5572011-04-15 02:09:33168#include "chrome/browser/browser_util_win.h"
[email protected]b48c9182011-10-26 18:03:30169#include "chrome/browser/chrome_browser_main_win.h"
[email protected]118b4a92011-04-14 01:15:13170#include "chrome/browser/first_run/try_chrome_dialog_view.h"
[email protected]3e087992011-04-14 22:28:12171#include "chrome/browser/first_run/upgrade_util_win.h"
[email protected]f870a322009-01-16 21:47:27172#include "chrome/browser/net/url_fixer_upper.h"
[email protected]297fb7c22012-06-26 12:37:49173#include "chrome/browser/ui/network_profile_bubble.h"
[email protected]68c921f2008-10-15 21:37:46174#include "chrome/installer/util/helper.h"
175#include "chrome/installer/util/install_util.h"
[email protected]67da235a2008-10-24 16:18:27176#include "chrome/installer/util/shell_util.h"
initial.commit09911bf2008-07-26 23:55:29177#include "net/base/net_util.h"
[email protected]8ff1d422009-07-07 21:31:39178#include "printing/printed_document.h"
[email protected]c051a1b2011-01-21 23:30:17179#include "ui/base/l10n/l10n_util_win.h"
[email protected]6bae7352012-06-15 15:46:46180#include "ui/base/win/dpi.h"
[email protected]7f0ebc92009-02-05 18:34:21181#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29182
[email protected]0a357e632010-04-02 21:26:58183#if defined(OS_MACOSX)
[email protected]a1e1d4902010-04-02 22:02:30184#include <Security/Security.h>
[email protected]10189862011-04-15 21:42:03185
[email protected]badf5cf2011-10-29 03:44:44186#include "base/mac/scoped_nsautorelease_pool.h"
[email protected]51a7a9d2011-09-27 17:21:41187#include "chrome/browser/mac/keystone_glue.h"
[email protected]3dd6f5e2010-06-01 20:28:03188#endif
189
[email protected]703369a2012-11-05 20:40:31190#if defined(ENABLE_LANGUAGE_DETECTION)
191#include "chrome/browser/language_usage_metrics.h"
192#endif
193
[email protected]81d9b72d2012-03-26 22:29:17194#if defined(ENABLE_RLZ)
195#include "chrome/browser/rlz/rlz.h"
196#endif
197
[email protected]fc9c69bf2009-08-27 01:10:44198#if defined(TOOLKIT_VIEWS)
[email protected]477ae052011-11-18 23:53:57199#include "ui/views/focus/accelerator_handler.h"
[email protected]dd092152009-05-18 21:20:33200#endif
201
[email protected]b48c9182011-10-26 18:03:30202#if defined(USE_X11)
203#include "chrome/browser/chrome_browser_main_x11.h"
204#endif
205
[email protected]631bb742011-11-02 11:29:39206using content::BrowserThread;
207
[email protected]3aada4602011-08-11 22:25:55208namespace {
initial.commit09911bf2008-07-26 23:55:29209
210// This function provides some ways to test crash and assertion handling
211// behavior of the program.
[email protected]9bade092009-11-13 17:04:42212void HandleTestParameters(const CommandLine& command_line) {
initial.commit09911bf2008-07-26 23:55:29213 // This parameter causes an assertion.
214 if (command_line.HasSwitch(switches::kBrowserAssertTest)) {
215 DCHECK(false);
216 }
217
218 // This parameter causes a null pointer crash (crash reporter trigger).
219 if (command_line.HasSwitch(switches::kBrowserCrashTest)) {
220 int* bad_pointer = NULL;
221 *bad_pointer = 0;
222 }
223}
224
[email protected]fe7c4872012-05-10 20:06:03225void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator,
[email protected]f9886382010-03-10 04:45:54226 const std::vector<GURL>& new_tabs) {
227 for (std::vector<GURL>::const_iterator it = new_tabs.begin();
[email protected]201028d2010-02-12 21:28:01228 it != new_tabs.end(); ++it) {
[email protected]f9886382010-03-10 04:45:54229 if (it->is_valid())
[email protected]fe7c4872012-05-10 20:06:03230 browser_creator->AddFirstRunTab(*it);
[email protected]1188a6c2009-05-09 00:27:42231 }
232}
[email protected]1188a6c2009-05-09 00:27:42233
[email protected]7e59cff2010-03-23 16:12:40234// Returns the new local state object, guaranteed non-NULL.
[email protected]0de615a2012-11-08 04:40:59235// |local_state_task_runner| must be a shutdown-blocking task runner.
236PrefService* InitializeLocalState(
237 base::SequencedTaskRunner* local_state_task_runner,
238 const CommandLine& parsed_command_line,
239 bool is_first_run) {
[email protected]aa328c72013-05-03 10:55:43240 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState")
[email protected]650b2d52013-02-10 03:41:45241 base::FilePath local_state_path;
[email protected]7e59cff2010-03-23 16:12:40242 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
243 bool local_state_file_exists = file_util::PathExists(local_state_path);
244
245 // Load local state. This includes the application locale so we know which
[email protected]b1de2c72013-02-06 02:45:47246 // locale dll to load. This also causes local state prefs to be registered.
247 PrefService* local_state = g_browser_process->local_state();
[email protected]7e59cff2010-03-23 16:12:40248 DCHECK(local_state);
249
[email protected]7e59cff2010-03-23 16:12:40250 if (is_first_run) {
251#if defined(OS_WIN)
252 // During first run we read the google_update registry key to find what
253 // language the user selected when downloading the installer. This
254 // becomes our default language in the prefs.
255 // Other platforms obey the system locale.
256 std::wstring install_lang;
[email protected]ddd231e2010-06-29 20:35:19257 if (GoogleUpdateSettings::GetLanguage(&install_lang)) {
258 local_state->SetString(prefs::kApplicationLocale,
[email protected]47e870b2013-02-24 21:14:53259 WideToASCII(install_lang));
[email protected]ddd231e2010-06-29 20:35:19260 }
[email protected]7e59cff2010-03-23 16:12:40261#endif // defined(OS_WIN)
262 }
263
264 // If the local state file for the current profile doesn't exist and the
265 // parent profile command line flag is present, then we should inherit some
266 // local state from the parent profile.
267 // Checking that the local state file for the current profile doesn't exist
268 // is the most robust way to determine whether we need to inherit or not
269 // since the parent profile command line flag can be present even when the
270 // current profile is not a new one, and in that case we do not want to
271 // inherit and reset the user's setting.
[email protected]08b035b92012-12-19 11:35:17272 //
273 // TODO(mnissler): We should probably just instantiate a
[email protected]b1de2c72013-02-06 02:45:47274 // JSONPrefStore here instead of an entire PrefService. Once this is
275 // addressed, the call to browser_prefs::RegisterLocalState can move
276 // to chrome_prefs::CreateLocalState.
[email protected]7e59cff2010-03-23 16:12:40277 if (!local_state_file_exists &&
278 parsed_command_line.HasSwitch(switches::kParentProfile)) {
[email protected]650b2d52013-02-10 03:41:45279 base::FilePath parent_profile =
[email protected]7e59cff2010-03-23 16:12:40280 parsed_command_line.GetSwitchValuePath(switches::kParentProfile);
[email protected]b1de2c72013-02-06 02:45:47281 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple();
282 scoped_ptr<PrefService> parent_local_state(
[email protected]5b199522012-12-22 17:24:44283 chrome_prefs::CreateLocalState(
[email protected]70a317a2012-12-19 20:59:33284 parent_profile,
285 local_state_task_runner,
286 g_browser_process->policy_service(),
[email protected]b1de2c72013-02-06 02:45:47287 NULL,
288 registry,
289 false));
290 registry->RegisterStringPref(prefs::kApplicationLocale, std::string());
[email protected]7e59cff2010-03-23 16:12:40291 // Right now, we only inherit the locale setting from the parent profile.
292 local_state->SetString(
293 prefs::kApplicationLocale,
[email protected]d8b08c92010-06-07 13:13:28294 parent_local_state->GetString(prefs::kApplicationLocale));
[email protected]7e59cff2010-03-23 16:12:40295 }
296
[email protected]fab807e2011-04-14 12:24:19297#if defined(OS_CHROMEOS)
[email protected]931d1042013-04-05 17:50:44298 if (parsed_command_line.HasSwitch(chromeos::switches::kLoginManager)) {
[email protected]fab807e2011-04-14 12:24:19299 std::string owner_locale = local_state->GetString(prefs::kOwnerLocale);
300 // Ensure that we start with owner's locale.
301 if (!owner_locale.empty() &&
302 local_state->GetString(prefs::kApplicationLocale) != owner_locale &&
303 !local_state->IsManagedPreference(prefs::kApplicationLocale)) {
304 local_state->SetString(prefs::kApplicationLocale, owner_locale);
[email protected]fab807e2011-04-14 12:24:19305 }
306 }
307#endif
308
[email protected]7e59cff2010-03-23 16:12:40309 return local_state;
310}
311
[email protected]e0203c02013-02-04 11:55:53312// Returns the path that contains the profile that should be loaded
313// on process startup.
[email protected]650b2d52013-02-10 03:41:45314base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir,
315 const CommandLine& command_line) {
[email protected]e0203c02013-02-04 11:55:53316 if (command_line.HasSwitch(switches::kProfileDirectory)) {
317 return user_data_dir.Append(
318 command_line.GetSwitchValuePath(switches::kProfileDirectory));
319 }
320
[email protected]e0203c02013-02-04 11:55:53321 // If we are showing the app list then chrome isn't shown so load the app
322 // list's profile rather than chrome's.
323 if (command_line.HasSwitch(switches::kShowAppList))
[email protected]71b71a92013-05-20 04:35:04324 return AppListService::Get()->GetProfilePath(user_data_dir);
[email protected]e0203c02013-02-04 11:55:53325
326 return g_browser_process->profile_manager()->GetLastUsedProfileDir(
327 user_data_dir);
328}
329
[email protected]20271f32010-03-26 03:04:51330// Initializes the profile, possibly doing some user prompting to pick a
331// fallback profile. Returns the newly created profile, or NULL if startup
332// should not continue.
[email protected]4573fbd2011-10-31 20:25:18333Profile* CreateProfile(const content::MainFunctionParams& parameters,
[email protected]650b2d52013-02-10 03:41:45334 const base::FilePath& user_data_dir,
[email protected]506a87c2011-07-21 16:01:54335 const CommandLine& parsed_command_line) {
[email protected]aa328c72013-05-03 10:55:43336 TRACE_EVENT0("startup", "ChromeBrowserMainParts::CreateProfile")
[email protected]7802309d2011-10-20 15:43:09337 if (ProfileManager::IsMultipleProfilesEnabled() &&
338 parsed_command_line.HasSwitch(switches::kProfileDirectory)) {
339 g_browser_process->local_state()->SetString(prefs::kProfileLastUsed,
[email protected]a5e8c6d42012-04-09 20:22:01340 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory));
[email protected]1583def2012-01-25 11:26:32341 // Clear kProfilesLastActive since the user only wants to launch a specific
342 // profile.
343 ListPrefUpdate update(g_browser_process->local_state(),
344 prefs::kProfilesLastActive);
345 ListValue* profile_list = update.Get();
346 profile_list->Clear();
[email protected]506a87c2011-07-21 16:01:54347 }
[email protected]e0203c02013-02-04 11:55:53348
349 Profile* profile = NULL;
[email protected]484262f2011-10-31 19:42:00350#if defined(OS_CHROMEOS)
351 // TODO(ivankr): http://crbug.com/83792
352 profile = g_browser_process->profile_manager()->GetDefaultProfile(
353 user_data_dir);
354#else
[email protected]650b2d52013-02-10 03:41:45355 base::FilePath profile_path =
[email protected]e0203c02013-02-04 11:55:53356 GetStartupProfilePath(user_data_dir, parsed_command_line);
357 profile = g_browser_process->profile_manager()->GetProfile(
358 profile_path);
[email protected]484262f2011-10-31 19:42:00359#endif
[email protected]20271f32010-03-26 03:04:51360 if (profile)
361 return profile;
362
[email protected]47dd8342013-04-12 20:40:59363#if !defined(OS_WIN)
[email protected]20271f32010-03-26 03:04:51364 // TODO(port): fix this. See comments near the definition of
365 // user_data_dir. It is better to CHECK-fail here than it is to
366 // silently exit because of missing code in the above test.
367 CHECK(profile) << "Cannot get default profile.";
[email protected]47dd8342013-04-12 20:40:59368#endif
[email protected]20271f32010-03-26 03:04:51369
370 return NULL;
371}
372
[email protected]e457f742010-04-02 17:25:43373#if defined(OS_MACOSX)
374OSStatus KeychainCallback(SecKeychainEvent keychain_event,
[email protected]d3b05ea2012-01-24 22:57:05375 SecKeychainCallbackInfo* info, void* context) {
[email protected]e457f742010-04-02 17:25:43376 return noErr;
377}
378#endif
379
[email protected]28f576f2011-08-26 20:46:55380// This code is specific to the Windows-only PreReadExperiment field-trial.
381void AddPreReadHistogramTime(const char* name, base::TimeDelta time) {
382 const base::TimeDelta kMin(base::TimeDelta::FromMilliseconds(1));
383 const base::TimeDelta kMax(base::TimeDelta::FromHours(1));
384 static const size_t kBuckets(100);
385
386 // FactoryTimeGet will always return a pointer to the same histogram object,
387 // keyed on its name. There's no need for us to store it explicitly anywhere.
[email protected]de415552013-01-23 04:12:17388 base::HistogramBase* counter = base::Histogram::FactoryTimeGet(
[email protected]28f576f2011-08-26 20:46:55389 name, kMin, kMax, kBuckets, base::Histogram::kUmaTargetedHistogramFlag);
390
391 counter->AddTime(time);
392}
393
[email protected]8cebc942013-01-31 01:28:42394void RegisterComponentsForUpdate(const CommandLine& command_line) {
395 ComponentUpdateService* cus = g_browser_process->component_updater();
[email protected]9f108f22013-04-09 00:39:56396
397 // Registration can be before or after cus->Start() so it is ok to post
[email protected]8cebc942013-01-31 01:28:42398 // a task to the UI thread to do registration once you done the necessary
399 // file IO to know you existing component version.
[email protected]9f108f22013-04-09 00:39:56400#if !defined(OS_CHROMEOS)
[email protected]8cebc942013-01-31 01:28:42401 RegisterRecoveryComponent(cus, g_browser_process->local_state());
402 RegisterPepperFlashComponent(cus);
403 RegisterSwiftShaderComponent(cus);
[email protected]649e9b22013-05-04 06:36:57404 RegisterWidevineCdmComponent(cus);
[email protected]8cebc942013-01-31 01:28:42405
406 // CRLSetFetcher attempts to load a CRL set from either the local disk or
407 // network.
408 if (!command_line.HasSwitch(switches::kDisableCRLSets))
409 g_browser_process->crl_set_fetcher()->StartInitialLoad(cus);
[email protected]9f108f22013-04-09 00:39:56410#endif
[email protected]8cebc942013-01-31 01:28:42411
[email protected]9f108f22013-04-09 00:39:56412 g_browser_process->pnacl_component_installer()->RegisterPnaclComponent(
413 cus, command_line);
[email protected]8cebc942013-01-31 01:28:42414
415 cus->Start();
416}
417
[email protected]650b2d52013-02-10 03:41:45418bool ProcessSingletonNotificationCallback(
419 const CommandLine& command_line,
420 const base::FilePath& current_directory) {
[email protected]5d364542012-04-05 07:15:39421 // Drop the request if the browser process is already in shutdown path.
422 if (!g_browser_process || g_browser_process->IsShuttingDown())
423 return false;
424
[email protected]84c584462013-05-13 05:05:00425 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) {
426 std::string start_time_string =
427 command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime);
428 int64 remote_start_time;
[email protected]5324b652013-05-24 09:42:40429 if (base::StringToInt64(start_time_string, &remote_start_time)) {
430 UMA_HISTOGRAM_LONG_TIMES(
431 "Startup.WarmStartTimeFromRemoteProcessStart",
432 base::Time::Now() - base::Time::FromInternalValue(remote_start_time));
433 }
[email protected]84c584462013-05-13 05:05:00434 }
435
[email protected]99106ba2013-05-17 23:36:35436 g_browser_process->platform_part()->PlatformSpecificCommandLineProcessing(
437 command_line);
[email protected]e9613b52012-11-27 22:35:13438
[email protected]5d364542012-04-05 07:15:39439 // TODO(erikwright): Consider removing this - AFAIK it is no longer used.
[email protected]dd85d452013-03-28 12:39:59440 // Handle the --uninstall-extension startup action. This needs to done here in
441 // the process that is running with the target profile, otherwise the
[email protected]5d364542012-04-05 07:15:39442 // uninstall will fail to unload and remove all components.
443 if (command_line.HasSwitch(switches::kUninstallExtension)) {
444 // The uninstall extension switch can't be combined with the profile
445 // directory switch.
446 DCHECK(!command_line.HasSwitch(switches::kProfileDirectory));
447
448 Profile* profile = ProfileManager::GetLastUsedProfile();
449 if (!profile) {
450 // We should never be called before the profile has been created.
451 NOTREACHED();
452 return true;
453 }
454
[email protected]d9ede582012-08-14 19:21:38455 extensions::StartupHelper extension_startup_helper;
456 extension_startup_helper.UninstallExtension(command_line, profile);
[email protected]5d364542012-04-05 07:15:39457 return true;
458 }
459
[email protected]650b2d52013-02-10 03:41:45460 base::FilePath user_data_dir =
[email protected]e0203c02013-02-04 11:55:53461 g_browser_process->profile_manager()->user_data_dir();
[email protected]650b2d52013-02-10 03:41:45462 base::FilePath startup_profile_dir =
[email protected]e0203c02013-02-04 11:55:53463 GetStartupProfilePath(user_data_dir, command_line);
464
[email protected]fe7c4872012-05-10 20:06:03465 StartupBrowserCreator::ProcessCommandLineAlreadyRunning(
[email protected]e0203c02013-02-04 11:55:53466 command_line, current_directory, startup_profile_dir);
[email protected]5d364542012-04-05 07:15:39467 return true;
468}
469
[email protected]cc5110ade2013-05-25 00:13:15470void LaunchDevToolsHandlerIfNeeded(const CommandLine& command_line) {
[email protected]86d3aca2012-12-04 21:36:09471 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) {
472 std::string port_str =
473 command_line.GetSwitchValueASCII(::switches::kRemoteDebuggingPort);
474 int port;
475 if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) {
476 std::string frontend_str;
477 if (command_line.HasSwitch(::switches::kRemoteDebuggingFrontend)) {
478 frontend_str = command_line.GetSwitchValueASCII(
479 ::switches::kRemoteDebuggingFrontend);
480 }
481 g_browser_process->CreateDevToolsHttpProtocolHandler(
[email protected]55d342402013-02-22 11:28:06482 chrome::HOST_DESKTOP_TYPE_NATIVE,
[email protected]86d3aca2012-12-04 21:36:09483 "127.0.0.1",
484 port,
485 frontend_str);
486 } else {
487 DLOG(WARNING) << "Invalid http debugger port number " << port;
488 }
489 }
490}
491
[email protected]e327c752013-01-30 11:38:16492// Heap allocated class that listens for first page load, kicks off stat
493// recording and then deletes itself.
494class LoadCompleteListener : public content::NotificationObserver {
495 public:
[email protected]95132f52013-04-12 02:19:04496 LoadCompleteListener() {
497 registrar_.Add(this,
498 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
499 content::NotificationService::AllSources());
500 }
501 virtual ~LoadCompleteListener() {}
[email protected]e327c752013-01-30 11:38:16502
[email protected]95132f52013-04-12 02:19:04503 // content::NotificationObserver implementation.
504 virtual void Observe(int type,
505 const content::NotificationSource& source,
506 const content::NotificationDetails& details) OVERRIDE {
507 DCHECK_EQ(content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, type);
508 startup_metric_utils::OnInitialPageLoadComplete();
509 delete this;
510 }
[email protected]e327c752013-01-30 11:38:16511
512 private:
513 content::NotificationRegistrar registrar_;
514 DISALLOW_COPY_AND_ASSIGN(LoadCompleteListener);
515};
516
[email protected]af7ba1e2013-04-12 17:09:45517void RenderViewHostCreated(content::RenderViewHost* render_view_host) {
518 content::SiteInstance* site_instance = render_view_host->GetSiteInstance();
519 Profile* profile = Profile::FromBrowserContext(
520 site_instance->GetBrowserContext());
521
522 new ChromeRenderViewHostObserver(render_view_host,
523 profile->GetNetworkPredictor());
524 new extensions::MessageHandler(render_view_host);
525}
526
527
[email protected]3aada4602011-08-11 22:25:55528} // namespace
529
[email protected]cbce47242011-08-12 21:40:59530namespace chrome_browser {
531// This error message is not localized because we failed to load the
532// localization data files.
533const char kMissingLocaleDataTitle[] = "Missing File Error";
534const char kMissingLocaleDataMessage[] =
535 "Unable to find locale data files. Please reinstall.";
536} // namespace chrome_browser
537
[email protected]4bb76022011-08-12 03:05:53538// BrowserMainParts ------------------------------------------------------------
539
[email protected]1948a4782012-04-30 13:45:44540// static
541bool ChromeBrowserMainParts::disable_enforcing_cookie_policies_for_tests_ =
542 false;
543
[email protected]f967b722011-09-07 00:58:04544ChromeBrowserMainParts::ChromeBrowserMainParts(
[email protected]4573fbd2011-10-31 20:25:18545 const content::MainFunctionParams& parameters)
[email protected]b48c9182011-10-26 18:03:30546 : parameters_(parameters),
[email protected]badf5cf2011-10-29 03:44:44547 parsed_command_line_(parameters.command_line),
[email protected]b48c9182011-10-26 18:03:30548 result_code_(content::RESULT_CODE_NORMAL_EXIT),
[email protected]08f1c5e2011-12-01 01:54:34549 startup_watcher_(new StartupTimeBomb()),
[email protected]c1702d712011-09-08 19:41:43550 shutdown_watcher_(new ShutdownWatcherHelper()),
[email protected]0c1c4752012-08-09 20:30:24551 startup_timer_(new performance_monitor::StartupTimer()),
[email protected]ae9e12a2012-07-31 17:48:12552 browser_field_trials_(parameters.command_line),
[email protected]af7ba1e2013-04-12 17:09:45553 rvh_callback_(base::Bind(&RenderViewHostCreated)),
[email protected]c1702d712011-09-08 19:41:43554 record_search_engine_(false),
555 translate_manager_(NULL),
556 profile_(NULL),
[email protected]66013922011-09-13 18:53:42557 run_message_loop_(true),
[email protected]2e5b60a22011-11-28 15:56:41558 notify_result_(ProcessSingleton::PROCESS_NONE),
[email protected]3f002a32013-01-02 17:52:38559 do_first_run_tasks_(false),
[email protected]2e5b60a22011-11-28 15:56:41560 local_state_(NULL),
561 restart_last_session_(false) {
[email protected]f967b722011-09-07 00:58:04562 // If we're running tests (ui_task is non-null).
[email protected]099b890c2013-04-25 19:16:26563 if (parameters.ui_task)
[email protected]b228ecf12011-09-08 17:06:59564 browser_defaults::enable_help_app = false;
[email protected]1948a4782012-04-30 13:45:44565
566 // Chrome disallows cookies by default. All code paths that want to use
567 // cookies need to go through one of Chrome's URLRequestContexts which have
568 // a ChromeNetworkDelegate attached that selectively allows cookies again.
569 if (!disable_enforcing_cookie_policies_for_tests_)
570 net::URLRequest::SetDefaultCookiePolicyToBlock();
[email protected]af7ba1e2013-04-12 17:09:45571
572 content::RenderViewHost::AddCreatedCallback(rvh_callback_);
[email protected]4bb76022011-08-12 03:05:53573}
574
[email protected]f967b722011-09-07 00:58:04575ChromeBrowserMainParts::~ChromeBrowserMainParts() {
[email protected]af7ba1e2013-04-12 17:09:45576 content::RenderViewHost::RemoveCreatedCallback(rvh_callback_);
577
[email protected]50462bf02011-11-21 19:13:31578 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i)
579 delete chrome_extra_parts_[i];
580 chrome_extra_parts_.clear();
[email protected]4bb76022011-08-12 03:05:53581}
582
[email protected]069cd9952011-10-01 16:34:45583// This will be called after the command-line has been mutated by about:flags
[email protected]5281db1d2012-01-11 22:51:54584void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
[email protected]aa328c72013-05-03 10:55:43585 TRACE_EVENT0("startup", "ChromeBrowserMainParts::SetupMetricsAndFieldTrials");
[email protected]069cd9952011-10-01 16:34:45586 // Must initialize metrics after labs have been converted into switches,
587 // but before field trials are set up (so that client ID is available for
588 // one-time randomized field trials).
[email protected]5281db1d2012-01-11 22:51:54589#if defined(OS_WIN)
590 if (parsed_command_line_.HasSwitch(switches::kChromeFrame))
591 MetricsLog::set_version_extension("-F");
592#elif defined(ARCH_CPU_64_BITS)
593 MetricsLog::set_version_extension("-64");
594#endif // defined(OS_WIN)
[email protected]069cd9952011-10-01 16:34:45595
596 // Initialize FieldTrialList to support FieldTrials that use one-time
[email protected]e61003a2012-05-24 17:03:19597 // randomization.
[email protected]5281db1d2012-01-11 22:51:54598 MetricsService* metrics = browser_process_->metrics_service();
[email protected]e5354322012-08-09 23:07:37599 bool metrics_reporting_enabled = IsMetricsReportingEnabled();
600 if (metrics_reporting_enabled)
[email protected]5cbeeef72012-02-08 02:05:18601 metrics->ForceClientIdCreation(); // Needed below.
[email protected]e61003a2012-05-24 17:03:19602 field_trial_list_.reset(
[email protected]e5354322012-08-09 23:07:37603 new base::FieldTrialList(
[email protected]20f999b52012-08-24 22:32:59604 metrics->CreateEntropyProvider(metrics_reporting_enabled).release()));
[email protected]4bb76022011-08-12 03:05:53605
[email protected]46323ac2013-04-04 10:56:24606 const CommandLine* command_line = CommandLine::ForCurrentProcess();
607 if (command_line->HasSwitch(switches::kEnableBenchmarking))
608 base::FieldTrial::EnableBenchmarking();
609
[email protected]2d4729582012-04-12 07:08:07610 // Ensure any field trials specified on the command line are initialized.
611 // Also stop the metrics service so that we don't pollute UMA.
[email protected]2d4729582012-04-12 07:08:07612 if (command_line->HasSwitch(switches::kForceFieldTrials)) {
613 std::string persistent = command_line->GetSwitchValueASCII(
614 switches::kForceFieldTrials);
615 bool ret = base::FieldTrialList::CreateTrialsFromString(persistent);
616 CHECK(ret) << "Invalid --" << switches::kForceFieldTrials <<
617 " list specified.";
618 }
[email protected]2d4729582012-04-12 07:08:07619
[email protected]04811242012-07-06 18:04:29620 chrome_variations::VariationsService* variations_service =
[email protected]54e26c122012-05-17 15:36:21621 browser_process_->variations_service();
[email protected]58c63cb2012-11-26 19:22:11622 if (variations_service)
[email protected]7e6b753f2013-02-15 16:21:38623 variations_service->CreateTrialsFromSeed();
[email protected]54e26c122012-05-17 15:36:21624
[email protected]a7c94bc2013-03-26 21:38:15625 // This must be called after the local state is initialized.
626 browser_field_trials_.SetupFieldTrials(local_state_);
[email protected]4bb76022011-08-12 03:05:53627
[email protected]b98def82012-06-28 23:42:45628 SetupPlatformFieldTrials();
629
[email protected]4bb76022011-08-12 03:05:53630 // Initialize FieldTrialSynchronizer system. This is a singleton and is used
[email protected]716476c2011-12-29 00:07:03631 // for posting tasks via base::Bind. Its deleted when it goes out of scope.
632 // Even though base::Bind does AddRef and Release, the object will not be
633 // deleted after the Task is executed.
[email protected]4bb76022011-08-12 03:05:53634 field_trial_synchronizer_ = new FieldTrialSynchronizer();
[email protected]4bb76022011-08-12 03:05:53635}
636
[email protected]069cd9952011-10-01 16:34:45637// ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related --------------
638
[email protected]5281db1d2012-01-11 22:51:54639void ChromeBrowserMainParts::StartMetricsRecording() {
[email protected]aa328c72013-05-03 10:55:43640 TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording");
[email protected]5281db1d2012-01-11 22:51:54641 MetricsService* metrics = g_browser_process->metrics_service();
[email protected]c0aa875b2012-11-06 22:09:13642
[email protected]e50163382013-03-02 01:08:27643 // TODO(miu): Metrics reporting is disabled in DEBUG builds until ill-fired
644 // DCHECKs are fixed, and/or we reconsider whether metrics reporting should
645 // really ever be enabled for debug builds. http://crbug.com/156979
646#if defined(NDEBUG)
[email protected]e3ac866b2013-04-09 16:43:53647 const bool only_do_metrics_recording =
648 parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) ||
649 parsed_command_line_.HasSwitch(switches::kEnableBenchmarking);
[email protected]e50163382013-03-02 01:08:27650#else
651 const bool only_do_metrics_recording = true;
652#endif
653 if (only_do_metrics_recording) {
[email protected]5281db1d2012-01-11 22:51:54654 // If we're testing then we don't care what the user preference is, we turn
655 // on recording, but not reporting, otherwise tests fail.
[email protected]410938e02012-10-24 16:33:59656 metrics->StartRecordingForTests();
[email protected]5281db1d2012-01-11 22:51:54657 return;
658 }
659
[email protected]5cbeeef72012-02-08 02:05:18660 if (IsMetricsReportingEnabled())
661 metrics->Start();
662}
663
664bool ChromeBrowserMainParts::IsMetricsReportingEnabled() {
[email protected]5281db1d2012-01-11 22:51:54665 // If the user permits metrics reporting with the checkbox in the
666 // prefs, we turn on recording. We disable metrics completely for
[email protected]e5354322012-08-09 23:07:37667 // non-official builds. This can be forced with a flag.
668 const CommandLine* command_line = CommandLine::ForCurrentProcess();
669 if (command_line->HasSwitch(switches::kEnableMetricsReportingForTesting))
670 return true;
671
[email protected]5cbeeef72012-02-08 02:05:18672 bool enabled = false;
[email protected]9f4dd172012-05-11 02:29:56673 // The debug build doesn't send UMA logs when FieldTrials are forced.
[email protected]2d4729582012-04-12 07:08:07674 if (command_line->HasSwitch(switches::kForceFieldTrials))
675 return false;
[email protected]2d4729582012-04-12 07:08:07676
[email protected]5281db1d2012-01-11 22:51:54677#if defined(GOOGLE_CHROME_BUILD)
678#if defined(OS_CHROMEOS)
[email protected]5281db1d2012-01-11 22:51:54679 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref,
680 &enabled);
681#else
[email protected]5cbeeef72012-02-08 02:05:18682 enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled);
[email protected]5281db1d2012-01-11 22:51:54683#endif // #if defined(OS_CHROMEOS)
[email protected]5281db1d2012-01-11 22:51:54684#endif // defined(GOOGLE_CHROME_BUILD)
[email protected]5cbeeef72012-02-08 02:05:18685 return enabled;
[email protected]5281db1d2012-01-11 22:51:54686}
687
[email protected]4bb76022011-08-12 03:05:53688// -----------------------------------------------------------------------------
689// TODO(viettrungluu): move more/rest of BrowserMain() into BrowserMainParts.
690
[email protected]3aada4602011-08-11 22:25:55691#if defined(OS_WIN)
692#define DLLEXPORT __declspec(dllexport)
693
694// We use extern C for the prototype DLLEXPORT to avoid C++ name mangling.
695extern "C" {
696DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded();
697}
698
699DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
700 // Need an instance of AtExitManager to handle singleton creations and
701 // deletions. We need this new instance because, the old instance created
702 // in ChromeMain() got destructed when the function returned.
703 base::AtExitManager exit_manager;
704 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded();
705}
706#endif
707
[email protected]50462bf02011-11-21 19:13:31708// content::BrowserMainParts implementation ------------------------------------
709
[email protected]c7480942011-11-08 19:18:27710void ChromeBrowserMainParts::PreEarlyInitialization() {
[email protected]aa328c72013-05-03 10:55:43711 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreEarlyInitialization");
[email protected]50462bf02011-11-21 19:13:31712 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
713 chrome_extra_parts_[i]->PreEarlyInitialization();
[email protected]c7480942011-11-08 19:18:27714}
715
716void ChromeBrowserMainParts::PostEarlyInitialization() {
[email protected]aa328c72013-05-03 10:55:43717 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostEarlyInitialization");
[email protected]50462bf02011-11-21 19:13:31718 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
719 chrome_extra_parts_[i]->PostEarlyInitialization();
[email protected]c7480942011-11-08 19:18:27720}
721
722void ChromeBrowserMainParts::ToolkitInitialized() {
[email protected]aa328c72013-05-03 10:55:43723 TRACE_EVENT0("startup", "ChromeBrowserMainParts::ToolkitInitialized");
[email protected]50462bf02011-11-21 19:13:31724 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
725 chrome_extra_parts_[i]->ToolkitInitialized();
[email protected]c7480942011-11-08 19:18:27726}
727
728void ChromeBrowserMainParts::PreMainMessageLoopStart() {
[email protected]aa328c72013-05-03 10:55:43729 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopStart");
[email protected]50462bf02011-11-21 19:13:31730 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
731 chrome_extra_parts_[i]->PreMainMessageLoopStart();
[email protected]c7480942011-11-08 19:18:27732}
733
734void ChromeBrowserMainParts::PostMainMessageLoopStart() {
[email protected]aa328c72013-05-03 10:55:43735 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostMainMessageLoopStart");
[email protected]50462bf02011-11-21 19:13:31736 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
737 chrome_extra_parts_[i]->PostMainMessageLoopStart();
[email protected]c7480942011-11-08 19:18:27738}
739
[email protected]69479b922012-02-02 09:56:20740int ChromeBrowserMainParts::PreCreateThreads() {
[email protected]aa328c72013-05-03 10:55:43741 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreCreateThreads");
[email protected]2e5b60a22011-11-28 15:56:41742 result_code_ = PreCreateThreadsImpl();
[email protected]7defb4f02012-02-07 18:25:46743 // These members must be initialized before returning from this function.
744 DCHECK(master_prefs_.get());
[email protected]81054f812012-08-30 00:47:09745#if !defined(OS_ANDROID)
[email protected]fe7c4872012-05-10 20:06:03746 DCHECK(browser_creator_.get());
[email protected]81054f812012-08-30 00:47:09747#endif
[email protected]045c7e12013-03-27 07:30:55748
749 if (result_code_ == 0) {
750 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
751 chrome_extra_parts_[i]->PreCreateThreads();
752 }
753
[email protected]69479b922012-02-02 09:56:20754 return result_code_;
[email protected]2e5b60a22011-11-28 15:56:41755}
756
757int ChromeBrowserMainParts::PreCreateThreadsImpl() {
[email protected]aa328c72013-05-03 10:55:43758 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreCreateThreadsImpl")
[email protected]c1702d712011-09-08 19:41:43759 run_message_loop_ = false;
[email protected]aa328c72013-05-03 10:55:43760 {
761 TRACE_EVENT0("startup",
762 "ChromeBrowserMainParts::PreCreateThreadsImpl:GetUserDataDir");
763 user_data_dir_ = chrome::GetUserDataDir(parameters());
764 }
[email protected]0c298a52009-09-25 21:33:52765
[email protected]3f002a32013-01-02 17:52:38766 // Whether this is First Run. |do_first_run_tasks_| should be prefered to this
767 // unless the desire is actually to know whether this is really First Run
768 // (i.e., even if --no-first-run is passed).
769 bool is_first_run = false;
[email protected]81054f812012-08-30 00:47:09770 // Android's first run is done in Java instead of native.
771#if !defined(OS_ANDROID)
[email protected]9a47c432013-04-19 20:33:55772 process_singleton_.reset(new ChromeProcessSingleton(
[email protected]dd85d452013-03-28 12:39:59773 user_data_dir_, base::Bind(&ProcessSingletonNotificationCallback)));
initial.commit09911bf2008-07-26 23:55:29774
[email protected]3f002a32013-01-02 17:52:38775 bool force_first_run =
776 parsed_command_line().HasSwitch(switches::kForceFirstRun);
777 bool force_skip_first_run_tasks =
778 (!force_first_run &&
779 parsed_command_line().HasSwitch(switches::kNoFirstRun));
780
[email protected]8c61902f2013-05-24 06:14:41781 is_first_run = force_first_run || first_run::IsChromeFirstRun();
[email protected]81054f812012-08-30 00:47:09782#endif
[email protected]0de615a2012-11-08 04:40:59783
[email protected]0de615a2012-11-08 04:40:59784 scoped_refptr<base::SequencedTaskRunner> local_state_task_runner =
[email protected]9bcdc202013-03-07 20:51:43785 JsonPrefStore::GetTaskRunnerForFile(
786 base::FilePath(chrome::kLocalStorePoolName),
787 BrowserThread::GetBlockingPool());
[email protected]aa328c72013-05-03 10:55:43788
789 {
790 TRACE_EVENT0("startup",
791 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitBrowswerProcessImpl");
[email protected]dc24976f2013-06-02 21:15:09792 browser_process_.reset(new BrowserProcessImpl(local_state_task_runner.get(),
[email protected]aa328c72013-05-03 10:55:43793 parsed_command_line()));
794 }
initial.commit09911bf2008-07-26 23:55:29795
[email protected]9b53dab2011-11-14 05:26:05796 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) {
[email protected]aa328c72013-05-03 10:55:43797 TRACE_EVENT0("startup",
798 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitProfiling");
[email protected]b2a9bbd2011-10-31 22:36:21799 // User wants to override default tracking status.
800 std::string flag =
[email protected]9b53dab2011-11-14 05:26:05801 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling);
[email protected]702a12d2012-02-10 19:43:42802 // Default to basic profiling (no parent child support).
803 tracked_objects::ThreadData::Status status =
804 tracked_objects::ThreadData::PROFILING_ACTIVE;
805 if (flag.compare("0") != 0)
806 status = tracked_objects::ThreadData::DEACTIVATED;
807 else if (flag.compare("child") != 0)
808 status = tracked_objects::ThreadData::PROFILING_CHILDREN_ACTIVE;
809 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(status);
[email protected]b2a9bbd2011-10-31 22:36:21810 }
811
[email protected]61b53f972012-02-10 20:39:23812 if (parsed_command_line().HasSwitch(switches::kProfilingOutputFile)) {
813 tracking_objects_.set_output_file_path(
814 parsed_command_line().GetSwitchValuePath(
815 switches::kProfilingOutputFile));
816 }
817
[email protected]dc24976f2013-06-02 21:15:09818 local_state_ = InitializeLocalState(
819 local_state_task_runner.get(), parsed_command_line(), is_first_run);
[email protected]1b084b5e2010-08-03 07:58:19820
[email protected]7defb4f02012-02-07 18:25:46821 // These members must be initialized before returning from this function.
822 master_prefs_.reset(new first_run::MasterPrefs);
[email protected]81054f812012-08-30 00:47:09823
824#if !defined(OS_ANDROID)
825 // Android doesn't use StartupBrowserCreator.
[email protected]fe7c4872012-05-10 20:06:03826 browser_creator_.reset(new StartupBrowserCreator);
[email protected]81054f812012-08-30 00:47:09827 // TODO(yfriedman): Refactor Android to re-use UMABrowsingActivityObserver
[email protected]3770c242012-07-12 22:58:17828 chrome::UMABrowsingActivityObserver::Init();
[email protected]81054f812012-08-30 00:47:09829#endif
[email protected]7defb4f02012-02-07 18:25:46830
[email protected]6346d152012-05-04 04:02:33831 // Convert active labs into switches. This needs to be done before
832 // ResourceBundle::InitSharedInstanceWithLocale as some loaded resources are
833 // affected by experiment flags (--touch-optimized-ui in particular). Not
834 // needed on Android as there aren't experimental flags.
[email protected]aa328c72013-05-03 10:55:43835 {
836 TRACE_EVENT0("startup",
837 "ChromeBrowserMainParts::PreCreateThreadsImpl:ConvertFlags");
[email protected]e6d1c4f2013-06-12 17:37:40838 about_flags::PrefServiceFlagsStorage flags_storage_(
839 g_browser_process->local_state());
840 about_flags::ConvertFlagsToSwitches(&flags_storage_,
[email protected]aa328c72013-05-03 10:55:43841 CommandLine::ForCurrentProcess());
842 }
843
[email protected]5b199522012-12-22 17:24:44844 local_state_->UpdateCommandLinePrefStore(
845 new CommandLinePrefStore(CommandLine::ForCurrentProcess()));
[email protected]6346d152012-05-04 04:02:33846
847 // Reset the command line in the crash report details, since we may have
848 // just changed it to include experiments.
849 child_process_logging::SetCommandLine(CommandLine::ForCurrentProcess());
850
[email protected]d4515eb2009-01-30 00:40:43851 // If we're running tests (ui_task is non-null), then the ResourceBundle
852 // has already been initialized.
[email protected]f900367b22012-09-11 16:08:36853 if (parameters().ui_task &&
854 !local_state_->IsManagedPreference(prefs::kApplicationLocale)) {
[email protected]17e6cde52012-01-05 00:16:57855 browser_process_->SetApplicationLocale("en-US");
[email protected]ce4b6a92009-12-10 00:04:48856 } else {
[email protected]1fec64352010-07-27 13:55:21857 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is
858 // needed when loading the MainMenu.nib and the language doesn't depend on
859 // anything since it comes from Cocoa.
[email protected]ce4b6a92009-12-10 00:04:48860#if defined(OS_MACOSX)
[email protected]17e6cde52012-01-05 00:16:57861 browser_process_->SetApplicationLocale(l10n_util::GetLocaleOverride());
[email protected]ce4b6a92009-12-10 00:04:48862#else
[email protected]455ee192010-12-22 16:05:57863 const std::string locale =
[email protected]2e5b60a22011-11-28 15:56:41864 local_state_->GetString(prefs::kApplicationLocale);
[email protected]aa328c72013-05-03 10:55:43865
[email protected]cd87be132011-02-04 13:07:38866 // On a POSIX OS other than ChromeOS, the parameter that is passed to the
867 // method InitSharedInstance is ignored.
[email protected]aa328c72013-05-03 10:55:43868
869 TRACE_EVENT_BEGIN0("startup",
870 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle");
[email protected]455ee192010-12-22 16:05:57871 const std::string loaded_locale =
[email protected]fb317a52012-05-09 15:57:47872 ResourceBundle::InitSharedInstanceWithLocale(locale, NULL);
[email protected]aa328c72013-05-03 10:55:43873 TRACE_EVENT_END0("startup",
874 "ChromeBrowserMainParts::PreCreateThreadsImpl:InitResourceBundle");
875
[email protected]cbce47242011-08-12 21:40:59876 if (loaded_locale.empty() &&
[email protected]f967b722011-09-07 00:58:04877 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) {
[email protected]cbce47242011-08-12 21:40:59878 ShowMissingLocaleMessageBox();
879 return chrome::RESULT_CODE_MISSING_DATA;
880 }
[email protected]455ee192010-12-22 16:05:57881 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
[email protected]17e6cde52012-01-05 00:16:57882 browser_process_->SetApplicationLocale(loaded_locale);
[email protected]e1cb0e92010-06-15 07:23:59883
[email protected]650b2d52013-02-10 03:41:45884 base::FilePath resources_pack_path;
[email protected]e1cb0e92010-06-15 07:23:59885 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
[email protected]aa328c72013-05-03 10:55:43886 {
887 TRACE_EVENT0("startup",
888 "ChromeBrowserMainParts::PreCreateThreadsImpl:AddDataPack");
889 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
890 resources_pack_path, ui::SCALE_FACTOR_NONE);
891 }
[email protected]cd87be132011-02-04 13:07:38892#endif // defined(OS_MACOSX)
[email protected]ce4b6a92009-12-10 00:04:48893 }
initial.commit09911bf2008-07-26 23:55:29894
[email protected]d9edd312011-02-16 20:52:28895#if defined(TOOLKIT_GTK)
896 g_set_application_name(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str());
[email protected]d0646f32009-08-27 00:58:46897#endif
898
[email protected]81054f812012-08-30 00:47:09899 // Android does first run in Java instead of native.
900#if !defined(OS_ANDROID)
[email protected]74be069e82010-06-25 00:12:49901 // On first run, we need to process the predictor preferences before the
[email protected]34f73fb2010-03-24 20:50:34902 // browser's profile_manager object is created, but after ResourceBundle
903 // is initialized.
[email protected]3f002a32013-01-02 17:52:38904 if (is_first_run) {
[email protected]786799692012-09-26 14:16:48905 first_run::ProcessMasterPreferencesResult pmp_result =
906 first_run::ProcessMasterPreferences(user_data_dir_,
907 master_prefs_.get());
908 if (pmp_result == first_run::EULA_EXIT_NOW)
909 return chrome::RESULT_CODE_EULA_REFUSED;
910
[email protected]3f002a32013-01-02 17:52:38911 // Do first run tasks unless:
912 // - Explicitly forced not to by |force_skip_first_run_tasks| or
913 // |pmp_result|.
[email protected]749dc3db2013-02-11 22:52:31914 // - Running in App (or App Launcher) mode, where showing the importer
915 // (first run) UI is undesired.
916 do_first_run_tasks_ = (
917 !force_skip_first_run_tasks &&
918 pmp_result != first_run::SKIP_FIRST_RUN_TASKS &&
919 !parsed_command_line().HasSwitch(switches::kApp) &&
920 !parsed_command_line().HasSwitch(switches::kAppId) &&
921 !parsed_command_line().HasSwitch(switches::kShowAppList));
[email protected]786799692012-09-26 14:16:48922
[email protected]3f002a32013-01-02 17:52:38923 if (do_first_run_tasks_) {
924 AddFirstRunNewTabs(browser_creator_.get(), master_prefs_->new_tabs);
[email protected]a723f0af2013-02-15 06:36:03925
[email protected]abaca602013-03-29 01:31:29926 // TODO(macourteau): refactor preferences that are copied from
927 // master_preferences into local_state, as a "local_state" section in
928 // master preferences. If possible, a generic solution would be prefered
929 // over a copy one-by-one of specific preferences. Also see related TODO
930 // in first_run.h.
931
[email protected]a723f0af2013-02-15 06:36:03932 // Store the initial VariationsService seed in local state, if it exists
933 // in master prefs.
934 if (!master_prefs_->variations_seed.empty()) {
935 local_state_->SetString(prefs::kVariationsSeed,
936 master_prefs_->variations_seed);
937 // Set the variation seed date to the current system time. If the user's
938 // clock is incorrect, this may cause some field trial expiry checks to
939 // not do the right thing until the next seed update from the server,
940 // when this value will be updated.
941 local_state_->SetInt64(prefs::kVariationsSeedDate,
942 base::Time::Now().ToInternalValue());
943 }
[email protected]abaca602013-03-29 01:31:29944
945 if (!master_prefs_->suppress_default_browser_prompt_for_version.empty()) {
946 local_state_->SetString(
947 prefs::kBrowserSuppressDefaultBrowserPrompt,
948 master_prefs_->suppress_default_browser_prompt_for_version);
949 }
[email protected]c9719e252013-04-25 04:55:17950 }
951
952 if (do_first_run_tasks_ ||
953 parsed_command_line().HasSwitch(switches::kNoFirstRun)) {
954 // Create the First Run sentinel whether first run tasks are executed
955 // or not.
[email protected]dfa08b042011-12-28 23:07:21956 first_run::CreateSentinel();
[email protected]3f002a32013-01-02 17:52:38957 }
[email protected]fe247ac2009-03-19 00:10:48958 }
[email protected]81054f812012-08-30 00:47:09959#endif
[email protected]fe247ac2009-03-19 00:10:48960
[email protected]f8abf722010-07-07 19:46:24961 // TODO(viettrungluu): why don't we run this earlier?
[email protected]f967b722011-09-07 00:58:04962 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs))
[email protected]34f73fb2010-03-24 20:50:34963 WarnAboutMinimumSystemRequirements();
initial.commit09911bf2008-07-26 23:55:29964
[email protected]2ec5a482012-02-22 00:01:18965#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_MACOSX)
[email protected]e643e57c2012-01-28 02:26:09966 // Set the product channel for crash reports.
967 child_process_logging::SetChannel(
968 chrome::VersionInfo::GetVersionStringModifier());
969#endif
970
[email protected]83ab4a282012-07-12 18:19:45971 // Initialize tracking synchronizer system.
[email protected]10fe40c2011-11-05 03:27:46972 tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer();
[email protected]332749032011-10-22 00:32:46973
[email protected]6b5f21d2009-04-13 17:01:35974 // Now that all preferences have been registered, set the install date
975 // for the uninstall metrics if this is our first run. This only actually
976 // gets used if the user has metrics reporting enabled at uninstall time.
[email protected]5c181552013-02-07 09:12:52977 int64 install_date = local_state_->GetInt64(prefs::kInstallDate);
978 if (install_date == 0)
979 local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT());
[email protected]6b5f21d2009-04-13 17:01:35980
[email protected]e457f742010-04-02 17:25:43981#if defined(OS_MACOSX)
982 // Get the Keychain API to register for distributed notifications on the main
983 // thread, which has a proper CFRunloop, instead of later on the I/O thread,
984 // which doesn't. This ensures those notifications will get delivered
985 // properly. See issue 37766.
986 // (Note that the callback mask here is empty. I don't want to register for
987 // any callbacks, I just want to initialize the mechanism.)
988 SecKeychainAddCallback(&KeychainCallback, 0, NULL);
989#endif
990
[email protected]427042b2013-04-17 23:03:17991#if defined(OS_CHROMEOS)
992 // Must be done after g_browser_process is constructed, before
993 // SetupMetricsAndFieldTrials().
994 chromeos::CrosSettings::Initialize();
995#endif
996
[email protected]69479b922012-02-02 09:56:20997 // Now the command line has been mutated based on about:flags, we can setup
998 // metrics and initialize field trials. The field trials are needed by
999 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads.
1000 SetupMetricsAndFieldTrials();
1001
1002 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this.
1003 browser_process_->PreCreateThreads();
1004
[email protected]2e5b60a22011-11-28 15:56:411005 return content::RESULT_CODE_NORMAL_EXIT;
1006}
1007
[email protected]2167cd62011-11-30 21:20:211008void ChromeBrowserMainParts::PreMainMessageLoopRun() {
[email protected]aa328c72013-05-03 10:55:431009 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRun");
[email protected]2167cd62011-11-30 21:20:211010 result_code_ = PreMainMessageLoopRunImpl();
1011
1012 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1013 chrome_extra_parts_[i]->PreMainMessageLoopRun();
1014}
1015
[email protected]97ef83f2011-12-19 19:26:361016// PreMainMessageLoopRun calls these extra stages in the following order:
1017// PreMainMessageLoopRunImpl()
1018// ... initial setup, including browser_process_ setup.
1019// PreProfileInit()
1020// ... additional setup, including CreateProfile()
1021// PostProfileInit()
1022// ... additional setup
1023// PreBrowserStart()
[email protected]fe7c4872012-05-10 20:06:031024// ... browser_creator_->Start (OR parameters().ui_task->Run())
[email protected]97ef83f2011-12-19 19:26:361025// PostBrowserStart()
1026
1027void ChromeBrowserMainParts::PreProfileInit() {
[email protected]aa328c72013-05-03 10:55:431028 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreProfileInit");
[email protected]97ef83f2011-12-19 19:26:361029 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1030 chrome_extra_parts_[i]->PreProfileInit();
1031}
1032
1033void ChromeBrowserMainParts::PostProfileInit() {
[email protected]aa328c72013-05-03 10:55:431034 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostProfileInit");
[email protected]cc5110ade2013-05-25 00:13:151035 LaunchDevToolsHandlerIfNeeded(parsed_command_line());
[email protected]97ef83f2011-12-19 19:26:361036 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1037 chrome_extra_parts_[i]->PostProfileInit();
1038}
1039
1040void ChromeBrowserMainParts::PreBrowserStart() {
[email protected]aa328c72013-05-03 10:55:431041 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreBrowserStart");
[email protected]97ef83f2011-12-19 19:26:361042 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1043 chrome_extra_parts_[i]->PreBrowserStart();
[email protected]44327692013-02-26 21:21:221044
1045 three_d_observer_.reset(new ThreeDAPIObserver());
[email protected]97ef83f2011-12-19 19:26:361046}
1047
1048void ChromeBrowserMainParts::PostBrowserStart() {
[email protected]aa328c72013-05-03 10:55:431049 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostBrowserStart");
[email protected]81054f812012-08-30 00:47:091050#if !defined(OS_ANDROID)
[email protected]278a34d2012-06-07 00:34:581051 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kVisitURLs))
1052 RunPageCycler();
[email protected]81054f812012-08-30 00:47:091053#endif
[email protected]278a34d2012-06-07 00:34:581054
[email protected]97ef83f2011-12-19 19:26:361055 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1056 chrome_extra_parts_[i]->PostBrowserStart();
[email protected]81054f812012-08-30 00:47:091057#if !defined(OS_ANDROID)
[email protected]edf04b512012-02-23 09:47:431058 // Allow ProcessSingleton to process messages.
1059 process_singleton_->Unlock();
[email protected]81054f812012-08-30 00:47:091060#endif
[email protected]97ef83f2011-12-19 19:26:361061}
1062
[email protected]81054f812012-08-30 00:47:091063#if !defined(OS_ANDROID)
[email protected]278a34d2012-06-07 00:34:581064void ChromeBrowserMainParts::RunPageCycler() {
1065 CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]323fd7122012-08-24 14:45:111066 // We assume a native desktop for tests, but we will need to find a way to
1067 // get the proper host desktop type once we start running these tests in ASH.
[email protected]3c6a0952012-12-17 11:56:091068 Browser* browser = chrome::FindBrowserWithProfile(
[email protected]323fd7122012-08-24 14:45:111069 profile_, chrome::HOST_DESKTOP_TYPE_NATIVE);
[email protected]278a34d2012-06-07 00:34:581070 DCHECK(browser);
1071 PageCycler* page_cycler = NULL;
[email protected]650b2d52013-02-10 03:41:451072 base::FilePath input_file =
[email protected]278a34d2012-06-07 00:34:581073 command_line->GetSwitchValuePath(switches::kVisitURLs);
1074 page_cycler = new PageCycler(browser, input_file);
1075 page_cycler->set_errors_file(
1076 input_file.AddExtension(FILE_PATH_LITERAL(".errors")));
1077 if (command_line->HasSwitch(switches::kRecordStats)) {
1078 page_cycler->set_stats_file(
1079 command_line->GetSwitchValuePath(switches::kRecordStats));
1080 }
[email protected]165b0562012-06-20 00:41:221081 page_cycler->Run();
[email protected]278a34d2012-06-07 00:34:581082}
[email protected]81054f812012-08-30 00:47:091083#endif // !defined(OS_ANDROID)
[email protected]278a34d2012-06-07 00:34:581084
[email protected]b98def82012-06-28 23:42:451085void ChromeBrowserMainParts::SetupPlatformFieldTrials() {
1086 // Base class implementation of this does nothing.
1087}
1088
[email protected]2e5b60a22011-11-28 15:56:411089int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
[email protected]aa328c72013-05-03 10:55:431090 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl");
[email protected]2f2f72b2013-03-08 22:37:311091#if !defined(OS_ANDROID)
1092 if (CommandLine::ForCurrentProcess()->HasSwitch(
1093 switches::kTrackActiveVisitTime)) {
1094 active_tab_tracker_.reset(new ActiveTabTracker());
1095 // TODO(sky): nuke this when all ports support ActiveTabTracker.
1096 if (!active_tab_tracker_->is_valid())
1097 active_tab_tracker_.reset();
1098 }
1099#endif
1100
[email protected]81054f812012-08-30 00:47:091101 // Android updates the metrics service dynamically depending on whether the
1102 // application is in the foreground or not. Do not start here.
1103#if !defined(OS_ANDROID)
[email protected]5281db1d2012-01-11 22:51:541104 // Now that the file thread has been started, start recording.
1105 StartMetricsRecording();
[email protected]81054f812012-08-30 00:47:091106#endif
[email protected]99907362012-01-11 05:41:401107
[email protected]2e5b60a22011-11-28 15:56:411108 // Create watchdog thread after creating all other threads because it will
1109 // watch the other threads and they must be running.
1110 browser_process_->watchdog_thread();
[email protected]61e95722009-11-25 06:54:111111
[email protected]d2caaa22011-12-12 03:04:151112 // Do any initializating in the browser process that requires all threads
1113 // running.
1114 browser_process_->PreMainMessageLoopRun();
1115
initial.commit09911bf2008-07-26 23:55:291116 // Record last shutdown time into a histogram.
1117 browser_shutdown::ReadLastShutdownInfo();
[email protected]04999e62009-09-25 01:27:311118
[email protected]01109dcf2010-03-27 00:56:431119#if defined(OS_WIN)
[email protected]04999e62009-09-25 01:27:311120 // On Windows, we use our startup as an opportunity to do upgrade/uninstall
1121 // tasks. Those care whether the browser is already running. On Linux/Mac,
1122 // upgrade/uninstall happen separately.
[email protected]a3abd5572011-04-15 02:09:331123 bool already_running = browser_util::IsBrowserAlreadyRunning();
initial.commit09911bf2008-07-26 23:55:291124
1125 // If the command line specifies 'uninstall' then we need to work here
1126 // unless we detect another chrome browser running.
[email protected]c1702d712011-09-08 19:41:431127 if (parsed_command_line().HasSwitch(switches::kUninstall)) {
[email protected]53c38d232009-02-13 20:52:181128 return DoUninstallTasks(already_running);
[email protected]c1702d712011-09-08 19:41:431129 }
initial.commit09911bf2008-07-26 23:55:291130
[email protected]f967b722011-09-07 00:58:041131 if (parsed_command_line().HasSwitch(switches::kHideIcons) ||
[email protected]c1702d712011-09-08 19:41:431132 parsed_command_line().HasSwitch(switches::kShowIcons)) {
[email protected]b48c9182011-10-26 18:03:301133 return ChromeBrowserMainPartsWin::HandleIconsCommands(
1134 parsed_command_line_);
[email protected]c1702d712011-09-08 19:41:431135 }
[email protected]b48c9182011-10-26 18:03:301136#endif
1137
[email protected]f967b722011-09-07 00:58:041138 if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) {
[email protected]201028d2010-02-12 21:28:011139 return ShellIntegration::SetAsDefaultBrowser() ?
[email protected]1fcfb202011-07-19 19:53:141140 static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) :
1141 static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED);
initial.commit09911bf2008-07-26 23:55:291142 }
1143
[email protected]81054f812012-08-30 00:47:091144 // Android doesn't support extensions and doesn't implement ProcessSingleton.
1145#if !defined(OS_ANDROID)
[email protected]6aeac8342010-10-01 20:21:181146 // If the command line specifies --pack-extension, attempt the pack extension
1147 // startup action and exit.
[email protected]f967b722011-09-07 00:58:041148 if (parsed_command_line().HasSwitch(switches::kPackExtension)) {
[email protected]d9ede582012-08-14 19:21:381149 extensions::StartupHelper extension_startup_helper;
1150 if (extension_startup_helper.PackExtension(parsed_command_line()))
[email protected]1fcfb202011-07-19 19:53:141151 return content::RESULT_CODE_NORMAL_EXIT;
[email protected]c1702d712011-09-08 19:41:431152 return chrome::RESULT_CODE_PACK_EXTENSION_ERROR;
[email protected]6aeac8342010-10-01 20:21:181153 }
1154
[email protected]ed8ce0b2012-07-28 02:18:101155 // If we're being launched just to check the connector policy, we are
1156 // short-lived and don't want to be passing that switch off.
[email protected]8c61902f2013-05-24 06:14:411157 bool pass_command_line = !parsed_command_line().HasSwitch(
[email protected]ed8ce0b2012-07-28 02:18:101158 switches::kCheckCloudPrintConnectorPolicy);
1159
1160 if (pass_command_line) {
[email protected]5425d062010-04-11 23:16:021161 // When another process is running, use that process instead of starting a
1162 // new one. NotifyOtherProcess will currently give the other process up to
1163 // 20 seconds to respond. Note that this needs to be done before we attempt
1164 // to read the profile.
[email protected]dd85d452013-03-28 12:39:591165 notify_result_ = process_singleton_->NotifyOtherProcessOrCreate();
[email protected]7bb9ddc12012-12-12 00:00:561166 UMA_HISTOGRAM_ENUMERATION("NotifyOtherProcessOrCreate.Result",
1167 notify_result_,
1168 ProcessSingleton::NUM_NOTIFY_RESULTS);
[email protected]66013922011-09-13 18:53:421169 switch (notify_result_) {
[email protected]5425d062010-04-11 23:16:021170 case ProcessSingleton::PROCESS_NONE:
1171 // No process already running, fall through to starting a new one.
1172 break;
[email protected]bd48c2b02010-04-09 20:32:421173
[email protected]5425d062010-04-11 23:16:021174 case ProcessSingleton::PROCESS_NOTIFIED:
1175#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]47e870b2013-02-24 21:14:531176 printf("%s\n", base::SysWideToNativeMB(UTF16ToWide(
[email protected]d5c45b72011-01-04 18:38:511177 l10n_util::GetStringUTF16(IDS_USED_EXISTING_BROWSER))).c_str());
[email protected]5425d062010-04-11 23:16:021178#endif
[email protected]68296502012-09-07 19:45:061179 // Having a differentiated return type for testing allows for tests to
1180 // verify proper handling of some switches. When not testing, stick to
1181 // the standard Unix convention of returning zero when things went as
1182 // expected.
1183 if (parsed_command_line().HasSwitch(switches::kTestType))
1184 return chrome::RESULT_CODE_NORMAL_EXIT_PROCESS_NOTIFIED;
1185 return content::RESULT_CODE_NORMAL_EXIT;
[email protected]bd48c2b02010-04-09 20:32:421186
[email protected]5425d062010-04-11 23:16:021187 case ProcessSingleton::PROFILE_IN_USE:
[email protected]1fcfb202011-07-19 19:53:141188 return chrome::RESULT_CODE_PROFILE_IN_USE;
[email protected]5425d062010-04-11 23:16:021189
[email protected]4a44bc32010-05-28 22:22:441190 case ProcessSingleton::LOCK_ERROR:
1191 LOG(ERROR) << "Failed to create a ProcessSingleton for your profile "
1192 "directory. This means that running multiple instances "
1193 "would start multiple browser processes rather than "
1194 "opening a new window in the existing process. Aborting "
1195 "now to avoid profile corruption.";
[email protected]1fcfb202011-07-19 19:53:141196 return chrome::RESULT_CODE_PROFILE_IN_USE;
[email protected]4a44bc32010-05-28 22:22:441197
[email protected]5425d062010-04-11 23:16:021198 default:
1199 NOTREACHED();
1200 }
[email protected]bd48c2b02010-04-09 20:32:421201 }
[email protected]81054f812012-08-30 00:47:091202#endif // !defined(OS_ANDROID)
[email protected]bd48c2b02010-04-09 20:32:421203
[email protected]2989d7342010-10-27 02:00:091204#if defined(USE_X11)
1205 SetBrowserX11ErrorHandlers();
1206#endif
1207
[email protected]50462bf02011-11-21 19:13:311208 // Desktop construction occurs here, (required before profile creation).
[email protected]97ef83f2011-12-19 19:26:361209 PreProfileInit();
[email protected]50462bf02011-11-21 19:13:311210
[email protected]ec79ca62012-11-16 01:16:511211 std::string try_chrome =
1212 parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain);
1213 if (!try_chrome.empty()) {
1214#if defined(OS_WIN)
1215 // Setup.exe has determined that we need to run a retention experiment
[email protected]622b764c2012-12-04 15:24:001216 // and has lauched chrome to show the experiment UI. It is guaranteed that
1217 // no other Chrome is currently running as the process singleton was
1218 // sucessfully grabbed above.
[email protected]ec79ca62012-11-16 01:16:511219 int try_chrome_int;
1220 base::StringToInt(try_chrome, &try_chrome_int);
[email protected]9a47c432013-04-19 20:33:551221 TryChromeDialogView::Result answer = TryChromeDialogView::Show(
1222 try_chrome_int,
1223 base::Bind(&ChromeProcessSingleton::SetActiveModalDialog,
1224 base::Unretained(process_singleton_.get())));
[email protected]ec79ca62012-11-16 01:16:511225 if (answer == TryChromeDialogView::NOT_NOW)
1226 return chrome::RESULT_CODE_NORMAL_EXIT_CANCEL;
1227 if (answer == TryChromeDialogView::UNINSTALL_CHROME)
1228 return chrome::RESULT_CODE_NORMAL_EXIT_EXP2;
1229 // At this point the user is willing to try chrome again.
1230 if (answer == TryChromeDialogView::TRY_CHROME_AS_DEFAULT) {
1231 // Only set in the unattended case, the interactive case is Windows 8.
1232 if (ShellIntegration::CanSetAsDefaultBrowser() ==
1233 ShellIntegration::SET_DEFAULT_UNATTENDED)
1234 ShellIntegration::SetAsDefaultBrowser();
1235 }
1236#else
1237 // We don't support retention experiments on Mac or Linux.
1238 return content::RESULT_CODE_NORMAL_EXIT;
1239#endif // defined(OS_WIN)
1240 }
1241
[email protected]20271f32010-03-26 03:04:511242 // Profile creation ----------------------------------------------------------
[email protected]08e6f6d2009-12-14 17:42:121243
[email protected]3f002a32013-01-02 17:52:381244 if (do_first_run_tasks_) {
[email protected]d91268022011-08-26 13:17:371245 // Warn the ProfileManager that an import process will run, possibly
1246 // locking the WebDataService directory of the next Profile created.
[email protected]17e6cde52012-01-05 00:16:571247 browser_process_->profile_manager()->SetWillImport();
[email protected]d91268022011-08-26 13:17:371248 }
1249
[email protected]dd8fc7762013-05-24 20:59:231250 // Called before CreateProfile because creating the profile can trigger
1251 // calls to GetDefaultProfile().
1252 ProfileManager::AllowGetDefaultProfile();
1253
[email protected]2e5b60a22011-11-28 15:56:411254 profile_ = CreateProfile(parameters(), user_data_dir_, parsed_command_line());
[email protected]c1702d712011-09-08 19:41:431255 if (!profile_)
[email protected]1fcfb202011-07-19 19:53:141256 return content::RESULT_CODE_NORMAL_EXIT;
[email protected]20271f32010-03-26 03:04:511257
[email protected]81054f812012-08-30 00:47:091258#if defined(ENABLE_BACKGROUND)
[email protected]279170832011-10-12 23:38:031259 // Autoload any profiles which are running background apps.
1260 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075.
[email protected]d6bbd2932012-03-19 17:10:071261 browser_process_->profile_manager()->AutoloadProfiles();
[email protected]81054f812012-08-30 00:47:091262#endif
[email protected]20271f32010-03-26 03:04:511263 // Post-profile init ---------------------------------------------------------
[email protected]9acc48602009-11-30 21:18:511264
[email protected]04999e62009-09-25 01:27:311265#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291266 // Do the tasks if chrome has been upgraded while it was last running.
[email protected]f967b722011-09-07 00:58:041267 if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line()))
[email protected]1fcfb202011-07-19 19:53:141268 return content::RESULT_CODE_NORMAL_EXIT;
initial.commit09911bf2008-07-26 23:55:291269
[email protected]68c921f2008-10-15 21:37:461270 // Check if there is any machine level Chrome installed on the current
1271 // machine. If yes and the current Chrome process is user level, we do not
1272 // allow the user level Chrome to run. So we notify the user and uninstall
1273 // user level Chrome.
1274 // Note this check should only happen here, after all the checks above
1275 // (uninstall, resource bundle initialization, other chrome browser
1276 // processes etc).
[email protected]6a7748e2011-05-27 16:44:311277 // Do not allow this to occur for Chrome Frame user-to-system handoffs.
[email protected]f967b722011-09-07 00:58:041278 if (!parsed_command_line().HasSwitch(switches::kChromeFrame) &&
[email protected]b48c9182011-10-26 18:03:301279 ChromeBrowserMainPartsWin::CheckMachineLevelInstall()) {
[email protected]1fcfb202011-07-19 19:53:141280 return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS;
[email protected]c1702d712011-09-08 19:41:431281 }
[email protected]b48c9182011-10-26 18:03:301282#endif
[email protected]68c921f2008-10-15 21:37:461283
[email protected]7e0831b2010-02-01 08:45:151284 // Create the TranslateManager singleton.
[email protected]c1702d712011-09-08 19:41:431285 translate_manager_ = TranslateManager::GetInstance();
1286 DCHECK(translate_manager_ != NULL);
[email protected]7e0831b2010-02-01 08:45:151287
[email protected]b16cc212013-02-06 21:09:511288#if !defined(OS_ANDROID)
[email protected]a6c7a8252012-06-25 18:28:241289 // Initialize Managed Mode.
1290 ManagedMode::Init(profile_);
[email protected]81054f812012-08-30 00:47:091291#endif
[email protected]a6c7a8252012-06-25 18:28:241292
[email protected]d5656f1c2013-01-29 01:31:261293 // Needs to be done before PostProfileInit, since login manager on CrOS is
1294 // called inside PostProfileInit.
1295 content::WebUIControllerFactory::RegisterFactory(
1296 ChromeWebUIControllerFactory::GetInstance());
1297
[email protected]a6c7a8252012-06-25 18:28:241298 // TODO(stevenjb): Move WIN and MACOSX specific code to appropriate Parts.
[email protected]97ef83f2011-12-19 19:26:361299 // (requires supporting early exit).
1300 PostProfileInit();
[email protected]50462bf02011-11-21 19:13:311301
[email protected]a9830b52012-12-17 23:30:361302 // Retrieve cached GL strings from local state and use them for GPU
1303 // blacklist decisions.
1304 if (g_browser_process->gl_string_manager())
1305 g_browser_process->gl_string_manager()->Initialize();
1306
[email protected]8bbe3a92013-05-12 00:58:351307 // Create an instance of GpuModeManager to watch gpu mode pref change.
1308 g_browser_process->gpu_mode_manager();
1309
[email protected]81054f812012-08-30 00:47:091310#if !defined(OS_ANDROID)
initial.commit09911bf2008-07-26 23:55:291311 // Show the First Run UI if this is the first time Chrome has been run on
1312 // this computer, or we're being compelled to do so by a command line flag.
1313 // Note that this be done _after_ the PrefService is initialized and all
1314 // preferences are registered, since some of the code that the importer
1315 // touches reads preferences.
[email protected]3f002a32013-01-02 17:52:381316 if (do_first_run_tasks_) {
1317 first_run::AutoImport(profile_,
1318 master_prefs_->homepage_defined,
1319 master_prefs_->do_import_items,
[email protected]8c61902f2013-05-24 06:14:411320 master_prefs_->dont_import_items,
1321 master_prefs_->import_bookmarks_path);
1322
[email protected]3f002a32013-01-02 17:52:381323 // Note: this can pop the first run consent dialog on linux.
1324 first_run::DoPostImportTasks(profile_, master_prefs_->make_chrome_default);
[email protected]96fe2e22012-03-07 22:54:191325
[email protected]17e6cde52012-01-05 00:16:571326 browser_process_->profile_manager()->OnImportFinished(profile_);
[email protected]eed73252012-08-03 18:47:441327
[email protected]820a1402012-08-09 23:13:511328 if (!master_prefs_->suppress_first_run_default_browser_prompt) {
1329 browser_creator_->set_show_main_browser_window(
1330 !chrome::ShowFirstRunDefaultBrowserPrompt(profile_));
1331 } else {
[email protected]eed73252012-08-03 18:47:441332 browser_creator_->set_is_default_browser_dialog_suppressed(true);
[email protected]820a1402012-08-09 23:13:511333 }
[email protected]3f002a32013-01-02 17:52:381334 } // if (do_first_run_tasks_)
[email protected]81054f812012-08-30 00:47:091335#endif // !defined(OS_ANDROID)
initial.commit09911bf2008-07-26 23:55:291336
[email protected]b48c9182011-10-26 18:03:301337#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:291338 // Sets things up so that if we crash from this point on, a dialog will
1339 // popup asking the user to restart chrome. It is done this late to avoid
1340 // testing against a bunch of special cases that are taken care early on.
[email protected]b48c9182011-10-26 18:03:301341 ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment(
1342 parsed_command_line());
initial.commit09911bf2008-07-26 23:55:291343
[email protected]0fd23af2011-02-20 06:33:041344 // Registers Chrome with the Windows Restart Manager, which will restore the
1345 // Chrome session when the computer is restarted after a system update.
1346 // This could be run as late as WM_QUERYENDSESSION for system update reboots,
1347 // but should run on startup if extended to handle crashes/hangs/patches.
1348 // Also, better to run once here than once for each HWND's WM_QUERYENDSESSION.
[email protected]b48c9182011-10-26 18:03:301349 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
1350 ChromeBrowserMainPartsWin::RegisterApplicationRestart(
1351 parsed_command_line());
1352 }
[email protected]a4422802012-05-03 09:19:151353
1354 // Verify that the profile is not on a network share and if so prepare to show
1355 // notification to the user.
[email protected]297fb7c22012-06-26 12:37:491356 if (NetworkProfileBubble::ShouldCheckNetworkProfile(profile_)) {
[email protected]4d0f1732012-06-25 17:55:201357 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
[email protected]115dcfe2012-11-01 22:32:501358 base::Bind(&NetworkProfileBubble::CheckNetworkProfile,
1359 profile_->GetPath()));
[email protected]a4422802012-05-03 09:19:151360 }
[email protected]81d9b72d2012-03-26 22:29:171361#endif // OS_WIN
[email protected]0fd23af2011-02-20 06:33:041362
[email protected]e625c3b22012-11-16 14:55:391363#if defined(ENABLE_RLZ) && !defined(OS_CHROMEOS)
initial.commit09911bf2008-07-26 23:55:291364 // Init the RLZ library. This just binds the dll and schedules a task on the
1365 // file thread to be run sometime later. If this is the first run we record
1366 // the installation event.
[email protected]c1702d712011-09-08 19:41:431367 PrefService* pref_service = profile_->GetPrefs();
[email protected]3f002a32013-01-02 17:52:381368 int ping_delay = do_first_run_tasks_ ? master_prefs_->ping_delay :
[email protected]1b3588d2012-10-10 21:17:251369 pref_service->GetInteger(first_run::GetPingDelayPrefName().c_str());
[email protected]99de6a52012-12-25 13:08:411370 // Negative ping delay means to send ping immediately after a first search is
1371 // recorded.
1372 RLZTracker::InitRlzFromProfileDelayed(
[email protected]3f002a32013-01-02 17:52:381373 profile_, do_first_run_tasks_, ping_delay < 0,
[email protected]99de6a52012-12-25 13:08:411374 base::TimeDelta::FromMilliseconds(abs(ping_delay)));
[email protected]e625c3b22012-11-16 14:55:391375#endif // defined(ENABLE_RLZ) && !defined(OS_CHROMEOS)
[email protected]b48c9182011-10-26 18:03:301376
[email protected]a12f7fb2011-01-20 18:21:081377 // Configure modules that need access to resources.
[email protected]64d50ed2009-09-22 21:05:471378 net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider);
initial.commit09911bf2008-07-26 23:55:291379
[email protected]3dd1f6d52008-09-15 18:28:091380 // In unittest mode, this will do nothing. In normal mode, this will create
[email protected]665fa012012-05-09 00:24:381381 // the global IntranetRedirectDetector instance, which will promptly go to
1382 // sleep for seven seconds (to avoid slowing startup), and wake up afterwards
1383 // to see if it should do anything else.
[email protected]3dd1f6d52008-09-15 18:28:091384 //
1385 // A simpler way of doing all this would be to have some function which could
[email protected]665fa012012-05-09 00:24:381386 // give the time elapsed since startup, and simply have this object check that
1387 // when asked to initialize itself, but this doesn't seem to exist.
[email protected]3dd1f6d52008-09-15 18:28:091388 //
[email protected]665fa012012-05-09 00:24:381389 // This can't be created in the BrowserProcessImpl constructor because it
1390 // needs to read prefs that get set after that runs.
[email protected]c1702d712011-09-08 19:41:431391 browser_process_->intranet_redirect_detector();
[email protected]ed666562012-03-21 19:49:521392 GoogleSearchCounter::RegisterForNotifications();
initial.commit09911bf2008-07-26 23:55:291393
[email protected]3b543ab2011-09-17 21:47:001394 // Disable SDCH filtering if switches::kEnableSdch is 0.
1395 int sdch_enabled = 1;
1396 if (parsed_command_line().HasSwitch(switches::kEnableSdch)) {
1397 base::StringToInt(parsed_command_line().GetSwitchValueASCII(
1398 switches::kEnableSdch), &sdch_enabled);
1399 if (!sdch_enabled)
1400 net::SdchManager::EnableSdchSupport(false);
1401 }
[email protected]e695fbd62009-06-30 16:31:541402
[email protected]b7672d12011-11-06 03:19:001403 if (parsed_command_line().HasSwitch(switches::kEnableWatchdog))
1404 InstallJankometer(parsed_command_line());
initial.commit09911bf2008-07-26 23:55:291405
[email protected]e1504d82009-07-03 15:27:151406#if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD)
[email protected]f967b722011-09-07 00:58:041407 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) {
[email protected]650b2d52013-02-10 03:41:451408 base::FilePath path =
[email protected]f967b722011-09-07 00:58:041409 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint);
[email protected]d9d42992010-09-13 19:39:191410 printing::PrintedDocument::set_debug_dump_path(path);
initial.commit09911bf2008-07-26 23:55:291411 }
[email protected]1bcdb532009-01-16 17:47:571412#endif
initial.commit09911bf2008-07-26 23:55:291413
[email protected]f967b722011-09-07 00:58:041414 HandleTestParameters(parsed_command_line());
[email protected]5281db1d2012-01-11 22:51:541415 RecordBreakpadStatusUMA(browser_process_->metrics_service());
[email protected]703369a2012-11-05 20:40:311416#if defined(ENABLE_LANGUAGE_DETECTION)
[email protected]04261032011-07-21 08:42:081417 LanguageUsageMetrics::RecordAcceptLanguages(
[email protected]c1702d712011-09-08 19:41:431418 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]04261032011-07-21 08:42:081419 LanguageUsageMetrics::RecordApplicationLanguage(
[email protected]17e6cde52012-01-05 00:16:571420 browser_process_->GetApplicationLocale());
[email protected]703369a2012-11-05 20:40:311421#endif
[email protected]3cf4f0992009-02-03 23:00:301422
[email protected]6aeac8342010-10-01 20:21:181423 // The extension service may be available at this point. If the command line
1424 // specifies --uninstall-extension, attempt the uninstall extension startup
1425 // action.
[email protected]f967b722011-09-07 00:58:041426 if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) {
[email protected]d9ede582012-08-14 19:21:381427 extensions::StartupHelper extension_startup_helper;
1428 if (extension_startup_helper.UninstallExtension(
1429 parsed_command_line(), profile_))
[email protected]1fcfb202011-07-19 19:53:141430 return content::RESULT_CODE_NORMAL_EXIT;
[email protected]c1702d712011-09-08 19:41:431431 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR;
[email protected]6aeac8342010-10-01 20:21:181432 }
1433
[email protected]08f1c5e2011-12-01 01:54:341434 // Start watching for hangs during startup. We disarm this hang detector when
1435 // ThreadWatcher takes over or when browser is shutdown or when
1436 // startup_watcher_ is deleted.
1437 startup_watcher_->Arm(base::TimeDelta::FromSeconds(300));
1438
[email protected]84c384e2013-03-01 23:20:191439 // On mobile, need for clean shutdown arises only when the application comes
1440 // to foreground (i.e. MetricsService::OnAppEnterForeground is called).
1441 // http://crbug.com/179143
1442#if !defined(OS_ANDROID)
[email protected]c0c55e92011-09-10 18:47:301443 // Start watching for a hang.
1444 MetricsService::LogNeedForCleanShutdown();
[email protected]84c384e2013-03-01 23:20:191445#endif
[email protected]c0c55e92011-09-10 18:47:301446
[email protected]15406b6a2010-04-21 00:35:011447#if defined(OS_WIN)
[email protected]8a9c63e2010-04-19 21:27:551448 // We check this here because if the profile is OTR (chromeos possibility)
1449 // it won't still be accessible after browser is destroyed.
[email protected]3f002a32013-01-02 17:52:381450 record_search_engine_ = do_first_run_tasks_ && !profile_->IsOffTheRecord();
[email protected]15406b6a2010-04-21 00:35:011451#endif
[email protected]8a9c63e2010-04-19 21:27:551452
[email protected]17543d62010-10-07 22:37:381453 // Create the instance of the cloud print proxy service so that it can launch
1454 // the service process if needed. This is needed because the service process
1455 // might have shutdown because an update was available.
[email protected]17cefaaf2011-08-02 14:42:581456 // TODO(torne): this should maybe be done with
[email protected]f1484c52013-05-22 23:25:441457 // BrowserContextKeyedServiceFactory::ServiceIsCreatedWithBrowserContext()
1458 // instead?
[email protected]058e5732012-03-01 22:48:031459#if !defined(OS_ANDROID)
[email protected]c1702d712011-09-08 19:41:431460 CloudPrintProxyServiceFactory::GetForProfile(profile_);
[email protected]058e5732012-03-01 22:48:031461#endif
[email protected]17543d62010-10-07 22:37:381462
[email protected]dedfabae2011-03-04 04:00:401463 // Start watching all browser threads for responsiveness.
[email protected]f967b722011-09-07 00:58:041464 ThreadWatcherList::StartWatchingAll(parsed_command_line());
[email protected]dedfabae2011-03-04 04:00:401465
[email protected]773ebb92011-11-15 19:06:521466#if !defined(DISABLE_NACL)
[email protected]b1511ab02012-07-02 23:45:511467 if (parsed_command_line().HasSwitch(switches::kPnaclDir)) {
1468 PathService::Override(chrome::DIR_PNACL_BASE,
1469 parsed_command_line().GetSwitchValuePath(
1470 switches::kPnaclDir));
1471 }
[email protected]773ebb92011-11-15 19:06:521472 NaClProcessHost::EarlyStartup();
1473#endif
1474
[email protected]97ef83f2011-12-19 19:26:361475 PreBrowserStart();
1476
[email protected]087453292011-11-22 00:43:121477 // Instantiate the notification UI manager, as this triggers a perf timer
1478 // used to measure startup time. TODO(stevenjb): Figure out what is actually
1479 // triggering the timer and call that explicitly in the approprate place.
1480 // http://crbug.com/105065.
[email protected]17e6cde52012-01-05 00:16:571481 browser_process_->notification_ui_manager();
[email protected]087453292011-11-22 00:43:121482
[email protected]ebc60b72013-04-21 06:15:401483#if defined(OS_ANDROID)
1484 chrome_variations::VariationsService* variations_service =
1485 browser_process_->variations_service();
1486 if (variations_service)
1487 variations_service->StartRepeatedVariationsSeedFetch();
1488#else
[email protected]5b027af2012-06-21 18:32:531489 // Most general initialization is behind us, but opening a
1490 // tab and/or session restore and such is still to be done.
1491 base::TimeTicks browser_open_start = base::TimeTicks::Now();
[email protected]45d72762011-04-15 18:58:201492
[email protected]5b027af2012-06-21 18:32:531493 // We are in regular browser boot sequence. Open initial tabs and enter the
1494 // main message loop.
1495 int result_code;
[email protected]a64ad242012-01-18 15:17:361496#if defined(OS_CHROMEOS)
[email protected]5b027af2012-06-21 18:32:531497 // On ChromeOS multiple profiles doesn't apply, and will break if we load
1498 // them this early as the cryptohome hasn't yet been mounted (which happens
1499 // only once we log in.
1500 std::vector<Profile*> last_opened_profiles;
[email protected]a64ad242012-01-18 15:17:361501#else
[email protected]5b027af2012-06-21 18:32:531502 std::vector<Profile*> last_opened_profiles =
1503 g_browser_process->profile_manager()->GetLastOpenedProfiles();
[email protected]a64ad242012-01-18 15:17:361504#endif
[email protected]aec25bc2012-10-04 18:45:261505
[email protected]8cebc942013-01-31 01:28:421506 if (!parsed_command_line().HasSwitch(switches::kDisableComponentUpdate))
1507 RegisterComponentsForUpdate(parsed_command_line());
1508
[email protected]650b2d52013-02-10 03:41:451509 if (browser_creator_->Start(parsed_command_line(), base::FilePath(),
[email protected]5b027af2012-06-21 18:32:531510 profile_, last_opened_profiles, &result_code)) {
[email protected]c7480942011-11-08 19:18:271511#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
[email protected]5b027af2012-06-21 18:32:531512 // Initialize autoupdate timer. Timer callback costs basically nothing
1513 // when browser is not in persistent mode, so it's OK to let it ride on
1514 // the main thread. This needs to be done here because we don't want
1515 // to start the timer when Chrome is run inside a test harness.
1516 browser_process_->StartAutoupdateTimer();
[email protected]bd48c2b02010-04-09 20:32:421517#endif
1518
[email protected]3cdacd42010-04-30 18:55:531519#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]5b027af2012-06-21 18:32:531520 // On Linux, the running exe will be updated if an upgrade becomes
1521 // available while the browser is running. We need to save the last
1522 // modified time of the exe, so we can compare to determine if there is
1523 // an upgrade while the browser is kept alive by a persistent extension.
1524 upgrade_util::SaveLastModifiedTimeOfExe();
[email protected]3cdacd42010-04-30 18:55:531525#endif
1526
[email protected]5b027af2012-06-21 18:32:531527 // Record now as the last successful chrome start.
1528 GoogleUpdateSettings::SetLastRunTime();
[email protected]badf5cf2011-10-29 03:44:441529
1530#if defined(OS_MACOSX)
[email protected]5b027af2012-06-21 18:32:531531 // Call Recycle() here as late as possible, before going into the loop
1532 // because Start() will add things to it while creating the main window.
1533 if (parameters().autorelease_pool)
1534 parameters().autorelease_pool->Recycle();
[email protected]badf5cf2011-10-29 03:44:441535#endif
[email protected]45d72762011-04-15 18:58:201536
[email protected]5b027af2012-06-21 18:32:531537 RecordPreReadExperimentTime("Startup.BrowserOpenTabs",
1538 base::TimeTicks::Now() - browser_open_start);
[email protected]45d72762011-04-15 18:58:201539
[email protected]5b027af2012-06-21 18:32:531540 // If we're running tests (ui_task is non-null), then we don't want to
1541 // call FetchLanguageListFromTranslateServer or
[email protected]88bac3f2012-07-22 21:22:571542 // StartRepeatedVariationsSeedFetch.
[email protected]5b027af2012-06-21 18:32:531543 if (parameters().ui_task == NULL) {
1544 // Request new variations seed information from server.
[email protected]58c63cb2012-11-26 19:22:111545 chrome_variations::VariationsService* variations_service =
1546 browser_process_->variations_service();
[email protected]92e669c2013-01-30 00:30:021547 if (variations_service) {
[email protected]58c63cb2012-11-26 19:22:111548 variations_service->StartRepeatedVariationsSeedFetch();
1549
[email protected]92e669c2013-01-30 00:30:021550#if defined(OS_WIN)
1551 variations_service->StartGoogleUpdateRegistrySync();
1552#endif
1553 }
1554
[email protected]d06ba1242012-09-25 20:51:391555#if !defined(OS_CHROMEOS)
1556 // TODO(mad): Move this call in a proper place on CrOS.
1557 // http://crosbug.com/17687
[email protected]5b027af2012-06-21 18:32:531558 if (translate_manager_ != NULL) {
1559 translate_manager_->FetchLanguageListFromTranslateServer(
1560 profile_->GetPrefs());
[email protected]63e26822011-07-16 19:07:351561 }
[email protected]bafa00e42011-07-18 14:47:261562#endif
[email protected]d06ba1242012-09-25 20:51:391563 }
[email protected]fa436972011-06-23 05:58:011564
[email protected]5b027af2012-06-21 18:32:531565 run_message_loop_ = true;
1566 } else {
1567 run_message_loop_ = false;
1568 }
[email protected]fe7c4872012-05-10 20:06:031569 browser_creator_.reset();
[email protected]81054f812012-08-30 00:47:091570#endif // !defined(OS_ANDROID)
[email protected]97ef83f2011-12-19 19:26:361571
1572 PostBrowserStart();
1573
[email protected]886f1142012-05-03 20:00:161574 if (parameters().ui_task) {
[email protected]0c1c4752012-08-09 20:30:241575 // We end the startup timer here if we have parameters to run, because we
1576 // never start to run the main loop (where we normally stop the timer).
1577 startup_timer_->SignalStartupComplete(
1578 performance_monitor::StartupTimer::STARTUP_TEST);
[email protected]886f1142012-05-03 20:00:161579 parameters().ui_task->Run();
1580 delete parameters().ui_task;
1581 run_message_loop_ = false;
1582 }
1583
[email protected]50462bf02011-11-21 19:13:311584 return result_code_;
[email protected]c1702d712011-09-08 19:41:431585}
1586
[email protected]b48c9182011-10-26 18:03:301587bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) {
[email protected]aa328c72013-05-03 10:55:431588 TRACE_EVENT0("startup", "ChromeBrowserMainParts::MainMessageLoopRun");
[email protected]82d2c332012-08-07 22:46:311589#if defined(OS_ANDROID)
1590 // Chrome on Android does not use default MessageLoop. It has its own
1591 // Android specific MessageLoop
1592 NOTREACHED();
1593 return true;
1594#else
[email protected]c7480942011-11-08 19:18:271595 // Set the result code set in PreMainMessageLoopRun or set above.
[email protected]b48c9182011-10-26 18:03:301596 *result_code = result_code_;
[email protected]c1702d712011-09-08 19:41:431597 if (!run_message_loop_)
[email protected]b48c9182011-10-26 18:03:301598 return true; // Don't run the default message loop.
[email protected]c1702d712011-09-08 19:41:431599
[email protected]0c1c4752012-08-09 20:30:241600 // These should be invoked as close to the start of the browser's
[email protected]c1702d712011-09-08 19:41:431601 // UI thread message loop as possible to get a stable measurement
1602 // across versions.
[email protected]d2a39f02013-05-07 13:14:461603 RecordBrowserStartupTime(do_first_run_tasks_);
[email protected]0c1c4752012-08-09 20:30:241604 startup_timer_->SignalStartupComplete(
1605 performance_monitor::StartupTimer::STARTUP_NORMAL);
1606
[email protected]b3a25092013-05-28 22:08:161607 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type());
[email protected]8e937c1e2012-06-28 22:57:301608#if !defined(USE_AURA) && defined(TOOLKIT_VIEWS)
[email protected]c1702d712011-09-08 19:41:431609 views::AcceleratorHandler accelerator_handler;
[email protected]8e937c1e2012-06-28 22:57:301610 base::RunLoop run_loop(&accelerator_handler);
1611#else
1612 base::RunLoop run_loop;
[email protected]c1702d712011-09-08 19:41:431613#endif
[email protected]d378f192012-08-14 18:42:031614
1615 if (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]7fae42952012-09-05 21:25:271616 switches::kPerformanceMonitorGathering)) {
[email protected]d378f192012-08-14 18:42:031617 performance_monitor::PerformanceMonitor::GetInstance()->Start();
1618 }
1619
[email protected]8e937c1e2012-06-28 22:57:301620 run_loop.Run();
[email protected]b48c9182011-10-26 18:03:301621
1622 return true;
[email protected]82d2c332012-08-07 22:46:311623#endif
[email protected]c1702d712011-09-08 19:41:431624}
1625
1626void ChromeBrowserMainParts::PostMainMessageLoopRun() {
[email protected]aa328c72013-05-03 10:55:431627 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PostMainMessageLoopRun");
[email protected]82d2c332012-08-07 22:46:311628#if defined(OS_ANDROID)
1629 // Chrome on Android does not use default MessageLoop. It has its own
1630 // Android specific MessageLoop
1631 NOTREACHED();
1632#else
[email protected]1dd7a8e2012-09-16 18:49:291633
1634#if defined(USE_X11)
1635 // Unset the X11 error handlers. The X11 error handlers log the errors using a
1636 // |PostTask()| on the message-loop. But since the message-loop is in the
1637 // process of terminating, this can cause errors.
1638 UnsetBrowserX11ErrorHandlers();
1639#endif
1640
[email protected]6d823b42011-09-05 02:54:021641 // Start watching for jank during shutdown. It gets disarmed when
[email protected]f967b722011-09-07 00:58:041642 // |shutdown_watcher_| object is destructed.
[email protected]56bdb712012-01-27 00:35:591643 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(300));
[email protected]6d823b42011-09-05 02:54:021644
[email protected]b69941522011-10-08 03:17:371645 // Disarm the startup hang detector time bomb if it is still Arm'ed.
[email protected]08f1c5e2011-12-01 01:54:341646 startup_watcher_->Disarm();
[email protected]b69941522011-10-08 03:17:371647
[email protected]ef589af2011-12-03 01:07:151648 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1649 chrome_extra_parts_[i]->PostMainMessageLoopRun();
1650
[email protected]15406b6a2010-04-21 00:35:011651#if defined(OS_WIN)
[email protected]2381ed22012-01-26 04:05:291652 // Log the search engine chosen on first run. Do this at shutdown, after any
1653 // changes are made from the first run bubble link, etc.
[email protected]c1702d712011-09-08 19:41:431654 if (record_search_engine_) {
[email protected]8e5c89a2011-06-07 18:13:331655 TemplateURLService* url_service =
[email protected]c1702d712011-09-08 19:41:431656 TemplateURLServiceFactory::GetForProfile(profile_);
[email protected]96b3c5c2010-04-16 20:30:141657 const TemplateURL* default_search_engine =
[email protected]8e5c89a2011-06-07 18:13:331658 url_service->GetDefaultSearchProvider();
[email protected]32cba2b2010-10-19 06:19:481659 // The default engine can be NULL if the administrator has disabled
1660 // default search.
[email protected]23872902010-10-26 03:43:591661 SearchEngineType search_engine_type =
[email protected]360ba052012-04-04 17:26:131662 TemplateURLPrepopulateData::GetEngineType(default_search_engine ?
1663 default_search_engine->url() : std::string());
[email protected]bf7eb2f92010-06-28 22:55:551664 // Record the search engine chosen.
[email protected]b37bdfe2012-03-16 20:53:271665 UMA_HISTOGRAM_ENUMERATION("Chrome.SearchSelectExempt", search_engine_type,
[email protected]2381ed22012-01-26 04:05:291666 SEARCH_ENGINE_MAX);
[email protected]96b3c5c2010-04-16 20:30:141667 }
[email protected]15406b6a2010-04-21 00:35:011668#endif
[email protected]96b3c5c2010-04-16 20:30:141669
[email protected]a6e9dce22011-06-25 00:19:221670 // Some tests don't set parameters.ui_task, so they started translate
1671 // language fetch that was never completed so we need to cleanup here
1672 // otherwise it will be done by the destructor in a wrong thread.
[email protected]716476c2011-12-29 00:07:031673 if (parameters().ui_task == NULL && translate_manager_ != NULL)
[email protected]c1702d712011-09-08 19:41:431674 translate_manager_->CleanupPendingUlrFetcher();
[email protected]a6e9dce22011-06-25 00:19:221675
[email protected]66013922011-09-13 18:53:421676 if (notify_result_ == ProcessSingleton::PROCESS_NONE)
1677 process_singleton_->Cleanup();
[email protected]9f20a6d02009-08-21 01:18:371678
[email protected]0b565182011-03-02 18:11:151679 // Stop all tasks that might run on WatchDogThread.
1680 ThreadWatcherList::StopWatchingAll();
1681
[email protected]17e6cde52012-01-05 00:16:571682 browser_process_->metrics_service()->Stop();
initial.commit09911bf2008-07-26 23:55:291683
[email protected]2e5b60a22011-11-28 15:56:411684 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop();
1685 browser_process_->StartTearDown();
[email protected]82d2c332012-08-07 22:46:311686#endif
[email protected]2e5b60a22011-11-28 15:56:411687}
1688
[email protected]2e5b60a22011-11-28 15:56:411689void ChromeBrowserMainParts::PostDestroyThreads() {
[email protected]81054f812012-08-30 00:47:091690#if defined(OS_ANDROID)
1691 // On Android, there is no quit/exit. So the browser's main message loop will
1692 // not finish.
1693 NOTREACHED();
1694#else
[email protected]99907362012-01-11 05:41:401695 browser_process_->PostDestroyThreads();
initial.commit09911bf2008-07-26 23:55:291696 // browser_shutdown takes care of deleting browser_process, so we need to
1697 // release it.
[email protected]c1702d712011-09-08 19:41:431698 ignore_result(browser_process_.release());
[email protected]2e5b60a22011-11-28 15:56:411699 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_);
[email protected]c1702d712011-09-08 19:41:431700 master_prefs_.reset();
1701 process_singleton_.reset();
[email protected]c0c55e92011-09-10 18:47:301702
1703 // We need to do this check as late as possible, but due to modularity, this
1704 // may be the last point in Chrome. This would be more effective if done at
1705 // a higher level on the stack, so that it is impossible for an early return
1706 // to bypass this code. Perhaps we need a *final* hook that is called on all
1707 // paths from content/browser/browser_main.
1708 CHECK(MetricsService::UmaMetricsProperlyShutdown());
[email protected]427042b2013-04-17 23:03:171709
1710#if defined(OS_CHROMEOS)
1711 chromeos::CrosSettings::Shutdown();
1712#endif
[email protected]81054f812012-08-30 00:47:091713#endif
[email protected]c1702d712011-09-08 19:41:431714}
initial.commit09911bf2008-07-26 23:55:291715
[email protected]50462bf02011-11-21 19:13:311716// Public members:
1717
1718void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
1719 chrome_extra_parts_.push_back(parts);
1720}
1721
1722// Misc ------------------------------------------------------------------------
1723
[email protected]d2a39f02013-05-07 13:14:461724void RecordBrowserStartupTime(bool is_first_run) {
[email protected]54676d0e2012-10-24 10:28:301725 // Don't record any metrics if UI was displayed before this point e.g.
1726 // warning dialogs.
1727 if (startup_metric_utils::WasNonBrowserUIDisplayed())
1728 return;
1729
[email protected]843bc462012-06-19 17:43:311730// CurrentProcessInfo::CreationTime() is currently only implemented on Mac and
1731// Windows.
1732#if defined(OS_MACOSX) || defined(OS_WIN)
[email protected]95132f52013-04-12 02:19:041733 const base::Time* process_creation_time =
[email protected]843bc462012-06-19 17:43:311734 base::CurrentProcessInfo::CreationTime();
1735
[email protected]d2a39f02013-05-07 13:14:461736 if (!is_first_run && process_creation_time) {
[email protected]843bc462012-06-19 17:43:311737 RecordPreReadExperimentTime("Startup.BrowserMessageLoopStartTime",
1738 base::Time::Now() - *process_creation_time);
[email protected]d2a39f02013-05-07 13:14:461739 }
[email protected]95132f52013-04-12 02:19:041740#endif // defined(OS_MACOSX) || defined(OS_WIN)
[email protected]54676d0e2012-10-24 10:28:301741
[email protected]40c4f412013-01-15 06:35:571742 // Record collected startup metrics.
[email protected]d2a39f02013-05-07 13:14:461743 startup_metric_utils::OnBrowserStartupComplete(is_first_run);
[email protected]e327c752013-01-30 11:38:161744
1745 // Deletes self.
1746 new LoadCompleteListener();
[email protected]843bc462012-06-19 17:43:311747}
1748
[email protected]28f576f2011-08-26 20:46:551749// This code is specific to the Windows-only PreReadExperiment field-trial.
1750void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) {
1751 DCHECK(name != NULL);
1752
1753 // This gets called with different histogram names, so we don't want to use
1754 // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the
1755 // first call wins.
1756 AddPreReadHistogramTime(name, time);
1757
1758#if defined(OS_WIN)
[email protected]5bca9ee2011-09-03 00:18:421759#if defined(GOOGLE_CHROME_BUILD)
1760 // The pre-read experiment is Windows and Google Chrome specific.
[email protected]28f576f2011-08-26 20:46:551761 scoped_ptr<base::Environment> env(base::Environment::Create());
1762
1763 // Only record the sub-histogram result if the experiment is running
1764 // (environment variable is set, and valid).
[email protected]48078e52012-02-09 00:02:261765 std::string pre_read_percentage;
1766 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read_percentage)) {
[email protected]28f576f2011-08-26 20:46:551767 std::string uma_name(name);
[email protected]ff5ce2372011-12-21 02:00:591768
1769 // We want XP to record a separate histogram, as the loader on XP
1770 // is very different from the Vista and Win7 loaders.
1771 if (base::win::GetVersion() <= base::win::VERSION_XP)
1772 uma_name += "_XP";
1773
[email protected]48078e52012-02-09 00:02:261774 uma_name += "_PreRead_";
1775 uma_name += pre_read_percentage;
[email protected]28f576f2011-08-26 20:46:551776 AddPreReadHistogramTime(uma_name.c_str(), time);
1777 }
1778#endif
[email protected]5bca9ee2011-09-03 00:18:421779#endif
[email protected]28f576f2011-08-26 20:46:551780}