[email protected] | c65aafcc | 2012-01-04 15:05:50 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 5 | #include "chrome/browser/chrome_browser_main.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 6 | |
[email protected] | cbdb7a3 | 2012-11-13 16:36:04 | [diff] [blame] | 7 | #if defined(TOOLKIT_GTK) |
| 8 | #include <gtk/gtk.h> |
| 9 | #endif |
| 10 | |
[email protected] | 01109dcf | 2010-03-27 00:56:43 | [diff] [blame] | 11 | #include <string> |
| 12 | #include <vector> |
[email protected] | a1a130f7d | 2009-01-09 20:28:44 | [diff] [blame] | 13 | |
[email protected] | e2cc2e6 | 2010-08-28 00:26:37 | [diff] [blame] | 14 | #include "base/at_exit.h" |
[email protected] | 97f3ac63 | 2011-10-19 20:09:56 | [diff] [blame] | 15 | #include "base/bind.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 16 | #include "base/command_line.h" |
[email protected] | 5016a9dd | 2013-02-02 01:10:02 | [diff] [blame] | 17 | #include "base/cpu.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 18 | #include "base/debug/trace_event.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 19 | #include "base/file_util.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 20 | #include "base/files/file_path.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 21 | #include "base/metrics/field_trial.h" |
| 22 | #include "base/metrics/histogram.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 23 | #include "base/path_service.h" |
[email protected] | 03b9b4e | 2012-10-22 20:01:52 | [diff] [blame] | 24 | #include "base/prefs/json_pref_store.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 25 | #include "base/prefs/pref_registry_simple.h" |
| 26 | #include "base/prefs/pref_service.h" |
| 27 | #include "base/prefs/pref_value_store.h" |
[email protected] | 843bc46 | 2012-06-19 17:43:31 | [diff] [blame] | 28 | #include "base/process_info.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 29 | #include "base/process_util.h" |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 30 | #include "base/run_loop.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 31 | #include "base/string_piece.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 32 | #include "base/strings/string_number_conversions.h" |
[email protected] | 1988e1c | 2013-02-28 20:27:42 | [diff] [blame] | 33 | #include "base/strings/string_split.h" |
[email protected] | 0f24e53e | 2012-10-29 01:04:09 | [diff] [blame] | 34 | #include "base/sys_info.h" |
[email protected] | 4efe77c | 2009-07-18 03:25:32 | [diff] [blame] | 35 | #include "base/sys_string_conversions.h" |
[email protected] | 93270d00 | 2011-01-19 22:32:59 | [diff] [blame] | 36 | #include "base/threading/platform_thread.h" |
[email protected] | 8988665 | 2012-12-11 18:09:07 | [diff] [blame] | 37 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | 6b5f21d | 2009-04-13 17:01:35 | [diff] [blame] | 38 | #include "base/time.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 39 | #include "base/utf_string_conversions.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 40 | #include "base/values.h" |
[email protected] | 01109dcf | 2010-03-27 00:56:43 | [diff] [blame] | 41 | #include "build/build_config.h" |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 42 | #include "chrome/browser/about_flags.h" |
[email protected] | 5d36454 | 2012-04-05 07:15:39 | [diff] [blame] | 43 | #include "chrome/browser/browser_process.h" |
[email protected] | b112a4c | 2009-02-01 20:24:01 | [diff] [blame] | 44 | #include "chrome/browser/browser_process_impl.h" |
[email protected] | 7f0ebc9 | 2009-02-05 18:34:21 | [diff] [blame] | 45 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 46 | #include "chrome/browser/chrome_browser_main_extra_parts.h" |
[email protected] | 8cebc94 | 2013-01-31 01:28:42 | [diff] [blame] | 47 | #include "chrome/browser/component_updater/component_updater_service.h" |
| 48 | #include "chrome/browser/component_updater/flash_component_installer.h" |
| 49 | #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" |
| 50 | #include "chrome/browser/component_updater/recovery_component_installer.h" |
| 51 | #include "chrome/browser/component_updater/swiftshader_component_installer.h" |
[email protected] | 1018986 | 2011-04-15 21:42:03 | [diff] [blame] | 52 | #include "chrome/browser/defaults.h" |
[email protected] | f7e615a | 2009-06-26 19:50:52 | [diff] [blame] | 53 | #include "chrome/browser/extensions/extension_protocols.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 54 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 55 | #include "chrome/browser/extensions/startup_helper.h" |
[email protected] | 1a905b7 | 2012-12-20 00:22:13 | [diff] [blame] | 56 | #include "chrome/browser/first_run/first_run.h" |
[email protected] | 81585672 | 2011-04-13 17:19:19 | [diff] [blame] | 57 | #include "chrome/browser/first_run/upgrade_util.h" |
[email protected] | ed66656 | 2012-03-21 19:49:52 | [diff] [blame] | 58 | #include "chrome/browser/google/google_search_counter.h" |
[email protected] | 7a336d6ec | 2011-10-07 14:17:58 | [diff] [blame] | 59 | #include "chrome/browser/google/google_util.h" |
[email protected] | c3da80c | 2012-12-07 20:57:24 | [diff] [blame] | 60 | #include "chrome/browser/gpu/chrome_gpu_util.h" |
[email protected] | a9830b5 | 2012-12-17 23:30:36 | [diff] [blame] | 61 | #include "chrome/browser/gpu/gl_string_manager.h" |
[email protected] | 86230b9 | 2009-11-23 20:38:38 | [diff] [blame] | 62 | #include "chrome/browser/jankometer.h" |
[email protected] | 46690b7 | 2012-10-26 19:33:32 | [diff] [blame] | 63 | #include "chrome/browser/managed_mode/managed_mode.h" |
[email protected] | 4cb3c1fc | 2012-04-05 07:23:48 | [diff] [blame] | 64 | #include "chrome/browser/metrics/field_trial_synchronizer.h" |
[email protected] | 67908205 | 2010-07-21 21:30:13 | [diff] [blame] | 65 | #include "chrome/browser/metrics/metrics_log.h" |
[email protected] | dc6f496 | 2009-02-13 01:25:50 | [diff] [blame] | 66 | #include "chrome/browser/metrics/metrics_service.h" |
[email protected] | 0b56518 | 2011-03-02 18:11:15 | [diff] [blame] | 67 | #include "chrome/browser/metrics/thread_watcher.h" |
[email protected] | 10fe40c | 2011-11-05 03:27:46 | [diff] [blame] | 68 | #include "chrome/browser/metrics/tracking_synchronizer.h" |
[email protected] | cf265dc0 | 2012-08-15 01:01:16 | [diff] [blame] | 69 | #include "chrome/browser/metrics/variations/variations_service.h" |
[email protected] | 773ebb9 | 2011-11-15 19:06:52 | [diff] [blame] | 70 | #include "chrome/browser/nacl_host/nacl_process_host.h" |
[email protected] | 82c71ba | 2011-05-27 18:51:53 | [diff] [blame] | 71 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | 8cebc94 | 2013-01-31 01:28:42 | [diff] [blame] | 72 | #include "chrome/browser/net/crl_set_fetcher.h" |
[email protected] | 59368d9d | 2012-01-31 01:02:54 | [diff] [blame] | 73 | #include "chrome/browser/notifications/desktop_notification_service.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 74 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
[email protected] | 684dace4 | 2012-07-01 14:30:41 | [diff] [blame] | 75 | #include "chrome/browser/page_cycler/page_cycler.h" |
[email protected] | d378f19 | 2012-08-14 18:42:03 | [diff] [blame] | 76 | #include "chrome/browser/performance_monitor/performance_monitor.h" |
[email protected] | 0c1c475 | 2012-08-09 20:30:24 | [diff] [blame] | 77 | #include "chrome/browser/performance_monitor/startup_timer.h" |
[email protected] | 0f5e57f5 | 2012-09-20 20:53:18 | [diff] [blame] | 78 | #include "chrome/browser/plugins/plugin_prefs.h" |
[email protected] | c83399d1f | 2012-09-19 01:50:54 | [diff] [blame] | 79 | #include "chrome/browser/policy/policy_service.h" |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 80 | #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
| 81 | #include "chrome/browser/prefs/command_line_pref_store.h" |
[email protected] | 1583def | 2012-01-25 11:26:32 | [diff] [blame] | 82 | #include "chrome/browser/prefs/scoped_user_pref_update.h" |
[email protected] | 59368d9d | 2012-01-31 01:02:54 | [diff] [blame] | 83 | #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 84 | #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h" |
[email protected] | e3db4fab | 2009-04-21 21:47:40 | [diff] [blame] | 85 | #include "chrome/browser/process_singleton.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 86 | #include "chrome/browser/profiles/profile.h" |
| 87 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 2387290 | 2010-10-26 03:43:59 | [diff] [blame] | 88 | #include "chrome/browser/search_engines/search_engine_type.h" |
[email protected] | 8b62334b | 2010-08-31 22:37:11 | [diff] [blame] | 89 | #include "chrome/browser/search_engines/template_url.h" |
[email protected] | b37bdfe | 2012-03-16 20:53:27 | [diff] [blame] | 90 | #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
[email protected] | 59368d9d | 2012-01-31 01:02:54 | [diff] [blame] | 91 | #include "chrome/browser/search_engines/template_url_service.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 92 | #include "chrome/browser/search_engines/template_url_service_factory.h" |
[email protected] | e96bf0c5 | 2010-08-23 23:20:57 | [diff] [blame] | 93 | #include "chrome/browser/service/service_process_control.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 94 | #include "chrome/browser/shell_integration.h" |
[email protected] | 4432769 | 2013-02-26 21:21:22 | [diff] [blame] | 95 | #include "chrome/browser/three_d_api_observer.h" |
[email protected] | 509acb8e | 2010-07-01 20:35:31 | [diff] [blame] | 96 | #include "chrome/browser/translate/translate_manager.h" |
[email protected] | f0ee791 | 2013-02-27 06:02:55 | [diff] [blame] | 97 | #include "chrome/browser/ui/app_list/app_list_service.h" |
[email protected] | f46be6e | 2010-11-16 03:52:32 | [diff] [blame] | 98 | #include "chrome/browser/ui/browser.h" |
[email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 99 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | 55d34240 | 2013-02-22 11:28:06 | [diff] [blame] | 100 | #include "chrome/browser/ui/host_desktop.h" |
[email protected] | eed7325 | 2012-08-03 18:47:44 | [diff] [blame] | 101 | #include "chrome/browser/ui/startup/default_browser_prompt.h" |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 102 | #include "chrome/browser/ui/startup/startup_browser_creator.h" |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 103 | #include "chrome/browser/ui/uma_browsing_activity_observer.h" |
[email protected] | eea4c6d | 2012-05-15 18:10:56 | [diff] [blame] | 104 | #include "chrome/browser/ui/user_data_dir_dialog.h" |
[email protected] | d5656f1c | 2013-01-29 01:31:26 | [diff] [blame] | 105 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
[email protected] | 783f06f | 2011-09-14 01:36:11 | [diff] [blame] | 106 | #include "chrome/common/child_process_logging.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 107 | #include "chrome/common/chrome_constants.h" |
| 108 | #include "chrome/common/chrome_paths.h" |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 109 | #include "chrome/common/chrome_result_codes.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 110 | #include "chrome/common/chrome_switches.h" |
[email protected] | 1b084b5e | 2010-08-03 07:58:19 | [diff] [blame] | 111 | #include "chrome/common/env_vars.h" |
[email protected] | 30f547c | 2010-08-04 01:00:01 | [diff] [blame] | 112 | #include "chrome/common/logging_chrome.h" |
[email protected] | cf265dc0 | 2012-08-15 01:01:16 | [diff] [blame] | 113 | #include "chrome/common/metrics/variations/variations_util.h" |
[email protected] | 64d50ed | 2009-09-22 21:05:47 | [diff] [blame] | 114 | #include "chrome/common/net/net_resource_provider.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 115 | #include "chrome/common/pref_names.h" |
[email protected] | 7664ab3 | 2011-02-01 23:35:25 | [diff] [blame] | 116 | #include "chrome/common/profiling.h" |
[email protected] | 54676d0e | 2012-10-24 10:28:30 | [diff] [blame] | 117 | #include "chrome/common/startup_metric_utils.h" |
[email protected] | 1e7377d | 2009-05-28 20:23:06 | [diff] [blame] | 118 | #include "chrome/installer/util/google_update_settings.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 119 | #include "content/public/browser/browser_thread.h" |
[email protected] | e327c75 | 2013-01-30 11:38:16 | [diff] [blame] | 120 | #include "content/public/browser/notification_observer.h" |
| 121 | #include "content/public/browser/notification_registrar.h" |
| 122 | #include "content/public/browser/notification_service.h" |
| 123 | #include "content/public/browser/notification_types.h" |
[email protected] | 5d1fa24 | 2011-10-18 23:35:38 | [diff] [blame] | 124 | #include "content/public/common/content_client.h" |
[email protected] | 86d3aca | 2012-12-04 21:36:09 | [diff] [blame] | 125 | #include "content/public/common/content_switches.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 126 | #include "content/public/common/main_function_params.h" |
[email protected] | ea500fc6 | 2010-03-22 21:34:29 | [diff] [blame] | 127 | #include "grit/app_locale_settings.h" |
[email protected] | 4e039f24 | 2011-12-03 07:29:38 | [diff] [blame] | 128 | #include "grit/browser_resources.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 129 | #include "grit/chromium_strings.h" |
| 130 | #include "grit/generated_resources.h" |
[email protected] | 61c6f41 | 2011-03-23 20:47:54 | [diff] [blame] | 131 | #include "grit/platform_locale_settings.h" |
[email protected] | 698cccb1 | 2009-03-11 18:47:24 | [diff] [blame] | 132 | #include "net/base/net_module.h" |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 133 | #include "net/base/sdch_manager.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 134 | #include "net/cookies/cookie_monster.h" |
[email protected] | e034500 | 2012-09-01 03:06:12 | [diff] [blame] | 135 | #include "net/http/http_network_layer.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 136 | #include "net/http/http_stream_factory.h" |
[email protected] | abb2609 | 2010-11-11 22:19:00 | [diff] [blame] | 137 | #include "net/url_request/url_request.h" |
[email protected] | e39027a | 2011-01-24 21:41:54 | [diff] [blame] | 138 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 6bae735 | 2012-06-15 15:46:46 | [diff] [blame] | 139 | #include "ui/base/layout.h" |
[email protected] | 42ce29d | 2011-01-20 23:19:46 | [diff] [blame] | 140 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 63942f2 | 2012-05-01 06:11:52 | [diff] [blame] | 141 | #include "ui/base/resource/resource_handle.h" |
[email protected] | b19e0e2e | 2013-02-06 18:15:51 | [diff] [blame] | 142 | #include "ui/base/touch/touch_device.h" |
| 143 | #include "ui/base/ui_base_switches.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 144 | |
[email protected] | 000bed6 | 2012-10-20 01:35:36 | [diff] [blame] | 145 | #if defined(OS_ANDROID) |
| 146 | #include "base/android/build_info.h" |
| 147 | #endif |
| 148 | |
[email protected] | 3e08799 | 2011-04-14 22:28:12 | [diff] [blame] | 149 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 150 | #include "chrome/browser/first_run/upgrade_util_linux.h" |
| 151 | #endif |
| 152 | |
[email protected] | d4fe1fbc | 2010-05-19 17:36:06 | [diff] [blame] | 153 | #if defined(OS_CHROMEOS) |
[email protected] | 3e08799 | 2011-04-14 22:28:12 | [diff] [blame] | 154 | #include "chrome/browser/chromeos/cros/cros_library.h" |
[email protected] | edaf596 | 2012-08-01 11:31:31 | [diff] [blame] | 155 | #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 156 | #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
[email protected] | d4fe1fbc | 2010-05-19 17:36:06 | [diff] [blame] | 157 | #endif |
| 158 | |
[email protected] | 022614ef9 | 2008-12-30 20:50:01 | [diff] [blame] | 159 | // TODO(port): several win-only methods have been pulled out of this, but |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 160 | // BrowserMain() as a whole needs to be broken apart so that it's usable by |
[email protected] | 022614ef9 | 2008-12-30 20:50:01 | [diff] [blame] | 161 | // other platforms. For now, it's just a stub. This is a serious work in |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 162 | // progress and should not be taken as an indication of a real refactoring. |
| 163 | |
| 164 | #if defined(OS_WIN) |
[email protected] | 28f576f | 2011-08-26 20:46:55 | [diff] [blame] | 165 | #include "base/environment.h" // For PreRead experiment. |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 166 | #include "base/win/windows_version.h" |
[email protected] | a3abd557 | 2011-04-15 02:09:33 | [diff] [blame] | 167 | #include "chrome/browser/browser_util_win.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 168 | #include "chrome/browser/chrome_browser_main_win.h" |
[email protected] | 118b4a9 | 2011-04-14 01:15:13 | [diff] [blame] | 169 | #include "chrome/browser/first_run/try_chrome_dialog_view.h" |
[email protected] | 3e08799 | 2011-04-14 22:28:12 | [diff] [blame] | 170 | #include "chrome/browser/first_run/upgrade_util_win.h" |
[email protected] | f870a32 | 2009-01-16 21:47:27 | [diff] [blame] | 171 | #include "chrome/browser/net/url_fixer_upper.h" |
[email protected] | 297fb7c2 | 2012-06-26 12:37:49 | [diff] [blame] | 172 | #include "chrome/browser/ui/network_profile_bubble.h" |
[email protected] | 68c921f | 2008-10-15 21:37:46 | [diff] [blame] | 173 | #include "chrome/installer/util/helper.h" |
| 174 | #include "chrome/installer/util/install_util.h" |
[email protected] | 67da235a | 2008-10-24 16:18:27 | [diff] [blame] | 175 | #include "chrome/installer/util/shell_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 176 | #include "net/base/net_util.h" |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 177 | #include "printing/printed_document.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 178 | #include "ui/base/l10n/l10n_util_win.h" |
[email protected] | 6bae735 | 2012-06-15 15:46:46 | [diff] [blame] | 179 | #include "ui/base/win/dpi.h" |
[email protected] | 7f0ebc9 | 2009-02-05 18:34:21 | [diff] [blame] | 180 | #endif // defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 181 | |
[email protected] | 0a357e63 | 2010-04-02 21:26:58 | [diff] [blame] | 182 | #if defined(OS_MACOSX) |
[email protected] | a1e1d490 | 2010-04-02 22:02:30 | [diff] [blame] | 183 | #include <Security/Security.h> |
[email protected] | 1018986 | 2011-04-15 21:42:03 | [diff] [blame] | 184 | |
[email protected] | badf5cf | 2011-10-29 03:44:44 | [diff] [blame] | 185 | #include "base/mac/scoped_nsautorelease_pool.h" |
[email protected] | 51a7a9d | 2011-09-27 17:21:41 | [diff] [blame] | 186 | #include "chrome/browser/mac/keystone_glue.h" |
[email protected] | 3dd6f5e | 2010-06-01 20:28:03 | [diff] [blame] | 187 | #endif |
| 188 | |
[email protected] | c83399d1f | 2012-09-19 01:50:54 | [diff] [blame] | 189 | #if defined(ENABLE_CONFIGURATION_POLICY) |
| 190 | #include "policy/policy_constants.h" |
| 191 | #endif |
| 192 | |
[email protected] | 6ee43a7 | 2012-12-07 22:44:40 | [diff] [blame] | 193 | #if defined(ENABLE_GOOGLE_NOW) |
| 194 | #include "chrome/browser/ui/google_now/google_now_service_factory.h" |
| 195 | #endif |
| 196 | |
[email protected] | 703369a | 2012-11-05 20:40:31 | [diff] [blame] | 197 | #if defined(ENABLE_LANGUAGE_DETECTION) |
| 198 | #include "chrome/browser/language_usage_metrics.h" |
| 199 | #endif |
| 200 | |
[email protected] | 81d9b72d | 2012-03-26 22:29:17 | [diff] [blame] | 201 | #if defined(ENABLE_RLZ) |
| 202 | #include "chrome/browser/rlz/rlz.h" |
| 203 | #endif |
| 204 | |
[email protected] | fc9c69bf | 2009-08-27 01:10:44 | [diff] [blame] | 205 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 477ae05 | 2011-11-18 23:53:57 | [diff] [blame] | 206 | #include "ui/views/focus/accelerator_handler.h" |
[email protected] | dd09215 | 2009-05-18 21:20:33 | [diff] [blame] | 207 | #endif |
| 208 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 209 | #if defined(USE_X11) |
| 210 | #include "chrome/browser/chrome_browser_main_x11.h" |
| 211 | #endif |
| 212 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 213 | using content::BrowserThread; |
| 214 | |
[email protected] | 3aada460 | 2011-08-11 22:25:55 | [diff] [blame] | 215 | namespace { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 216 | |
[email protected] | b19e0e2e | 2013-02-06 18:15:51 | [diff] [blame] | 217 | enum UMATouchEventsState { |
| 218 | UMA_TOUCH_EVENTS_ENABLED, |
| 219 | UMA_TOUCH_EVENTS_AUTO_ENABLED, |
| 220 | UMA_TOUCH_EVENTS_AUTO_DISABLED, |
| 221 | UMA_TOUCH_EVENTS_DISABLED, |
| 222 | // NOTE: Add states only immediately above this line. Make sure to |
| 223 | // update the enum list in tools/histogram/histograms.xml accordingly. |
| 224 | UMA_TOUCH_EVENTS_STATE_COUNT |
| 225 | }; |
| 226 | |
[email protected] | 5016a9dd | 2013-02-02 01:10:02 | [diff] [blame] | 227 | void LogIntelMicroArchitecture() { |
| 228 | base::CPU cpu; |
| 229 | base::CPU::IntelMicroArchitecture arch = cpu.GetIntelMicroArchitecture(); |
| 230 | UMA_HISTOGRAM_ENUMERATION("Platform.IntelMaxMicroArchitecture", arch, |
| 231 | base::CPU::MAX_INTEL_MICRO_ARCHITECTURE); |
| 232 | } |
| 233 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 234 | // This function provides some ways to test crash and assertion handling |
| 235 | // behavior of the program. |
[email protected] | 9bade09 | 2009-11-13 17:04:42 | [diff] [blame] | 236 | void HandleTestParameters(const CommandLine& command_line) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 237 | // This parameter causes an assertion. |
| 238 | if (command_line.HasSwitch(switches::kBrowserAssertTest)) { |
| 239 | DCHECK(false); |
| 240 | } |
| 241 | |
| 242 | // This parameter causes a null pointer crash (crash reporter trigger). |
| 243 | if (command_line.HasSwitch(switches::kBrowserCrashTest)) { |
| 244 | int* bad_pointer = NULL; |
| 245 | *bad_pointer = 0; |
| 246 | } |
| 247 | } |
| 248 | |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 249 | void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator, |
[email protected] | f988638 | 2010-03-10 04:45:54 | [diff] [blame] | 250 | const std::vector<GURL>& new_tabs) { |
| 251 | for (std::vector<GURL>::const_iterator it = new_tabs.begin(); |
[email protected] | 201028d | 2010-02-12 21:28:01 | [diff] [blame] | 252 | it != new_tabs.end(); ++it) { |
[email protected] | f988638 | 2010-03-10 04:45:54 | [diff] [blame] | 253 | if (it->is_valid()) |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 254 | browser_creator->AddFirstRunTab(*it); |
[email protected] | 1188a6c | 2009-05-09 00:27:42 | [diff] [blame] | 255 | } |
| 256 | } |
[email protected] | 1188a6c | 2009-05-09 00:27:42 | [diff] [blame] | 257 | |
[email protected] | 7e59cff | 2010-03-23 16:12:40 | [diff] [blame] | 258 | // Returns the new local state object, guaranteed non-NULL. |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 259 | // |local_state_task_runner| must be a shutdown-blocking task runner. |
| 260 | PrefService* InitializeLocalState( |
| 261 | base::SequencedTaskRunner* local_state_task_runner, |
| 262 | const CommandLine& parsed_command_line, |
| 263 | bool is_first_run) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 264 | base::FilePath local_state_path; |
[email protected] | 7e59cff | 2010-03-23 16:12:40 | [diff] [blame] | 265 | PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); |
| 266 | bool local_state_file_exists = file_util::PathExists(local_state_path); |
| 267 | |
| 268 | // Load local state. This includes the application locale so we know which |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 269 | // locale dll to load. This also causes local state prefs to be registered. |
| 270 | PrefService* local_state = g_browser_process->local_state(); |
[email protected] | 7e59cff | 2010-03-23 16:12:40 | [diff] [blame] | 271 | DCHECK(local_state); |
| 272 | |
[email protected] | 7e59cff | 2010-03-23 16:12:40 | [diff] [blame] | 273 | if (is_first_run) { |
| 274 | #if defined(OS_WIN) |
| 275 | // During first run we read the google_update registry key to find what |
| 276 | // language the user selected when downloading the installer. This |
| 277 | // becomes our default language in the prefs. |
| 278 | // Other platforms obey the system locale. |
| 279 | std::wstring install_lang; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 280 | if (GoogleUpdateSettings::GetLanguage(&install_lang)) { |
| 281 | local_state->SetString(prefs::kApplicationLocale, |
[email protected] | 47e870b | 2013-02-24 21:14:53 | [diff] [blame] | 282 | WideToASCII(install_lang)); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 283 | } |
[email protected] | 7e59cff | 2010-03-23 16:12:40 | [diff] [blame] | 284 | #endif // defined(OS_WIN) |
| 285 | } |
| 286 | |
| 287 | // If the local state file for the current profile doesn't exist and the |
| 288 | // parent profile command line flag is present, then we should inherit some |
| 289 | // local state from the parent profile. |
| 290 | // Checking that the local state file for the current profile doesn't exist |
| 291 | // is the most robust way to determine whether we need to inherit or not |
| 292 | // since the parent profile command line flag can be present even when the |
| 293 | // current profile is not a new one, and in that case we do not want to |
| 294 | // inherit and reset the user's setting. |
[email protected] | 08b035b9 | 2012-12-19 11:35:17 | [diff] [blame] | 295 | // |
| 296 | // TODO(mnissler): We should probably just instantiate a |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 297 | // JSONPrefStore here instead of an entire PrefService. Once this is |
| 298 | // addressed, the call to browser_prefs::RegisterLocalState can move |
| 299 | // to chrome_prefs::CreateLocalState. |
[email protected] | 7e59cff | 2010-03-23 16:12:40 | [diff] [blame] | 300 | if (!local_state_file_exists && |
| 301 | parsed_command_line.HasSwitch(switches::kParentProfile)) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 302 | base::FilePath parent_profile = |
[email protected] | 7e59cff | 2010-03-23 16:12:40 | [diff] [blame] | 303 | parsed_command_line.GetSwitchValuePath(switches::kParentProfile); |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 304 | scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple(); |
| 305 | scoped_ptr<PrefService> parent_local_state( |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 306 | chrome_prefs::CreateLocalState( |
[email protected] | 70a317a | 2012-12-19 20:59:33 | [diff] [blame] | 307 | parent_profile, |
| 308 | local_state_task_runner, |
| 309 | g_browser_process->policy_service(), |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 310 | NULL, |
| 311 | registry, |
| 312 | false)); |
| 313 | registry->RegisterStringPref(prefs::kApplicationLocale, std::string()); |
[email protected] | 7e59cff | 2010-03-23 16:12:40 | [diff] [blame] | 314 | // Right now, we only inherit the locale setting from the parent profile. |
| 315 | local_state->SetString( |
| 316 | prefs::kApplicationLocale, |
[email protected] | d8b08c9 | 2010-06-07 13:13:28 | [diff] [blame] | 317 | parent_local_state->GetString(prefs::kApplicationLocale)); |
[email protected] | 7e59cff | 2010-03-23 16:12:40 | [diff] [blame] | 318 | } |
| 319 | |
[email protected] | fab807e | 2011-04-14 12:24:19 | [diff] [blame] | 320 | #if defined(OS_CHROMEOS) |
| 321 | if (parsed_command_line.HasSwitch(switches::kLoginManager)) { |
| 322 | std::string owner_locale = local_state->GetString(prefs::kOwnerLocale); |
| 323 | // Ensure that we start with owner's locale. |
| 324 | if (!owner_locale.empty() && |
| 325 | local_state->GetString(prefs::kApplicationLocale) != owner_locale && |
| 326 | !local_state->IsManagedPreference(prefs::kApplicationLocale)) { |
| 327 | local_state->SetString(prefs::kApplicationLocale, owner_locale); |
[email protected] | fab807e | 2011-04-14 12:24:19 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | #endif |
| 331 | |
[email protected] | 7e59cff | 2010-03-23 16:12:40 | [diff] [blame] | 332 | return local_state; |
| 333 | } |
| 334 | |
[email protected] | e0203c0 | 2013-02-04 11:55:53 | [diff] [blame] | 335 | // Returns the path that contains the profile that should be loaded |
| 336 | // on process startup. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 337 | base::FilePath GetStartupProfilePath(const base::FilePath& user_data_dir, |
| 338 | const CommandLine& command_line) { |
[email protected] | e0203c0 | 2013-02-04 11:55:53 | [diff] [blame] | 339 | if (command_line.HasSwitch(switches::kProfileDirectory)) { |
| 340 | return user_data_dir.Append( |
| 341 | command_line.GetSwitchValuePath(switches::kProfileDirectory)); |
| 342 | } |
| 343 | |
[email protected] | e0203c0 | 2013-02-04 11:55:53 | [diff] [blame] | 344 | // If we are showing the app list then chrome isn't shown so load the app |
| 345 | // list's profile rather than chrome's. |
| 346 | if (command_line.HasSwitch(switches::kShowAppList)) |
[email protected] | f0ee791 | 2013-02-27 06:02:55 | [diff] [blame] | 347 | return AppListService::Get()->GetAppListProfilePath(user_data_dir); |
[email protected] | e0203c0 | 2013-02-04 11:55:53 | [diff] [blame] | 348 | |
| 349 | return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
| 350 | user_data_dir); |
| 351 | } |
| 352 | |
[email protected] | 20271f3 | 2010-03-26 03:04:51 | [diff] [blame] | 353 | // Initializes the profile, possibly doing some user prompting to pick a |
| 354 | // fallback profile. Returns the newly created profile, or NULL if startup |
| 355 | // should not continue. |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 356 | Profile* CreateProfile(const content::MainFunctionParams& parameters, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 357 | const base::FilePath& user_data_dir, |
[email protected] | 506a87c | 2011-07-21 16:01:54 | [diff] [blame] | 358 | const CommandLine& parsed_command_line) { |
[email protected] | 7802309d | 2011-10-20 15:43:09 | [diff] [blame] | 359 | if (ProfileManager::IsMultipleProfilesEnabled() && |
| 360 | parsed_command_line.HasSwitch(switches::kProfileDirectory)) { |
| 361 | g_browser_process->local_state()->SetString(prefs::kProfileLastUsed, |
[email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 362 | parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory)); |
[email protected] | 1583def | 2012-01-25 11:26:32 | [diff] [blame] | 363 | // Clear kProfilesLastActive since the user only wants to launch a specific |
| 364 | // profile. |
| 365 | ListPrefUpdate update(g_browser_process->local_state(), |
| 366 | prefs::kProfilesLastActive); |
| 367 | ListValue* profile_list = update.Get(); |
| 368 | profile_list->Clear(); |
[email protected] | 506a87c | 2011-07-21 16:01:54 | [diff] [blame] | 369 | } |
[email protected] | e0203c0 | 2013-02-04 11:55:53 | [diff] [blame] | 370 | |
| 371 | Profile* profile = NULL; |
[email protected] | 484262f | 2011-10-31 19:42:00 | [diff] [blame] | 372 | #if defined(OS_CHROMEOS) |
| 373 | // TODO(ivankr): http://crbug.com/83792 |
| 374 | profile = g_browser_process->profile_manager()->GetDefaultProfile( |
| 375 | user_data_dir); |
| 376 | #else |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 377 | base::FilePath profile_path = |
[email protected] | e0203c0 | 2013-02-04 11:55:53 | [diff] [blame] | 378 | GetStartupProfilePath(user_data_dir, parsed_command_line); |
| 379 | profile = g_browser_process->profile_manager()->GetProfile( |
| 380 | profile_path); |
[email protected] | 484262f | 2011-10-31 19:42:00 | [diff] [blame] | 381 | #endif |
[email protected] | 20271f3 | 2010-03-26 03:04:51 | [diff] [blame] | 382 | if (profile) |
| 383 | return profile; |
| 384 | |
| 385 | #if defined(OS_WIN) |
[email protected] | 94fbaa4 | 2011-09-07 20:09:54 | [diff] [blame] | 386 | #if defined(USE_AURA) |
| 387 | // TODO(beng): |
| 388 | NOTIMPLEMENTED(); |
| 389 | #else |
[email protected] | 20271f3 | 2010-03-26 03:04:51 | [diff] [blame] | 390 | // Ideally, we should be able to run w/o access to disk. For now, we |
| 391 | // prompt the user to pick a different user-data-dir and restart chrome |
| 392 | // with the new dir. |
| 393 | // http://code.google.com/p/chromium/issues/detail?id=11510 |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 394 | base::FilePath new_user_data_dir = |
| 395 | chrome::ShowUserDataDirDialog(user_data_dir); |
[email protected] | 20271f3 | 2010-03-26 03:04:51 | [diff] [blame] | 396 | |
| 397 | if (!new_user_data_dir.empty()) { |
| 398 | // Because of the way CommandLine parses, it's sufficient to append a new |
| 399 | // --user-data-dir switch. The last flag of the same name wins. |
| 400 | // TODO(tc): It would be nice to remove the flag we don't want, but that |
| 401 | // sounds risky if we parse differently than CommandLineToArgvW. |
[email protected] | badf5cf | 2011-10-29 03:44:44 | [diff] [blame] | 402 | CommandLine new_command_line = parameters.command_line; |
[email protected] | 4f08c83f | 2010-07-29 23:02:34 | [diff] [blame] | 403 | new_command_line.AppendSwitchPath(switches::kUserDataDir, |
| 404 | new_user_data_dir); |
[email protected] | e599218 | 2011-07-15 16:47:02 | [diff] [blame] | 405 | base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); |
[email protected] | 20271f3 | 2010-03-26 03:04:51 | [diff] [blame] | 406 | } |
[email protected] | 94fbaa4 | 2011-09-07 20:09:54 | [diff] [blame] | 407 | #endif |
[email protected] | 20271f3 | 2010-03-26 03:04:51 | [diff] [blame] | 408 | #else |
| 409 | // TODO(port): fix this. See comments near the definition of |
| 410 | // user_data_dir. It is better to CHECK-fail here than it is to |
| 411 | // silently exit because of missing code in the above test. |
| 412 | CHECK(profile) << "Cannot get default profile."; |
| 413 | #endif |
| 414 | |
| 415 | return NULL; |
| 416 | } |
| 417 | |
[email protected] | e457f74 | 2010-04-02 17:25:43 | [diff] [blame] | 418 | #if defined(OS_MACOSX) |
| 419 | OSStatus KeychainCallback(SecKeychainEvent keychain_event, |
[email protected] | d3b05ea | 2012-01-24 22:57:05 | [diff] [blame] | 420 | SecKeychainCallbackInfo* info, void* context) { |
[email protected] | e457f74 | 2010-04-02 17:25:43 | [diff] [blame] | 421 | return noErr; |
| 422 | } |
| 423 | #endif |
| 424 | |
[email protected] | 28f576f | 2011-08-26 20:46:55 | [diff] [blame] | 425 | // This code is specific to the Windows-only PreReadExperiment field-trial. |
| 426 | void AddPreReadHistogramTime(const char* name, base::TimeDelta time) { |
| 427 | const base::TimeDelta kMin(base::TimeDelta::FromMilliseconds(1)); |
| 428 | const base::TimeDelta kMax(base::TimeDelta::FromHours(1)); |
| 429 | static const size_t kBuckets(100); |
| 430 | |
| 431 | // FactoryTimeGet will always return a pointer to the same histogram object, |
| 432 | // keyed on its name. There's no need for us to store it explicitly anywhere. |
[email protected] | de41555 | 2013-01-23 04:12:17 | [diff] [blame] | 433 | base::HistogramBase* counter = base::Histogram::FactoryTimeGet( |
[email protected] | 28f576f | 2011-08-26 20:46:55 | [diff] [blame] | 434 | name, kMin, kMax, kBuckets, base::Histogram::kUmaTargetedHistogramFlag); |
| 435 | |
| 436 | counter->AddTime(time); |
| 437 | } |
| 438 | |
[email protected] | 8988665 | 2012-12-11 18:09:07 | [diff] [blame] | 439 | void RecordDefaultBrowserUMAStat() { |
| 440 | // Record whether Chrome is the default browser or not. |
| 441 | ShellIntegration::DefaultWebClientState default_state = |
| 442 | ShellIntegration::GetDefaultBrowser(); |
| 443 | UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.State", default_state, |
| 444 | ShellIntegration::NUM_DEFAULT_STATES); |
| 445 | } |
| 446 | |
[email protected] | b19e0e2e | 2013-02-06 18:15:51 | [diff] [blame] | 447 | void RecordTouchEventState(const CommandLine& command_line) { |
| 448 | const std::string touch_enabled_switch = |
| 449 | command_line.HasSwitch(switches::kTouchEvents) ? |
| 450 | command_line.GetSwitchValueASCII(switches::kTouchEvents) : |
| 451 | switches::kTouchEventsAuto; |
| 452 | |
| 453 | if (touch_enabled_switch.empty() || |
| 454 | touch_enabled_switch == switches::kTouchEventsEnabled) { |
| 455 | UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled", |
| 456 | UMA_TOUCH_EVENTS_ENABLED, |
| 457 | UMA_TOUCH_EVENTS_STATE_COUNT); |
| 458 | } else if (touch_enabled_switch == switches::kTouchEventsAuto) { |
| 459 | bool touch_device_present = ui::IsTouchDevicePresent(); |
| 460 | UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled", |
| 461 | touch_device_present ? |
| 462 | UMA_TOUCH_EVENTS_AUTO_ENABLED : |
| 463 | UMA_TOUCH_EVENTS_AUTO_DISABLED, |
| 464 | UMA_TOUCH_EVENTS_STATE_COUNT); |
| 465 | } else if (touch_enabled_switch == switches::kTouchEventsDisabled) { |
| 466 | UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled", |
| 467 | UMA_TOUCH_EVENTS_DISABLED, |
| 468 | UMA_TOUCH_EVENTS_STATE_COUNT); |
| 469 | } |
| 470 | } |
| 471 | |
[email protected] | 8cebc94 | 2013-01-31 01:28:42 | [diff] [blame] | 472 | void RegisterComponentsForUpdate(const CommandLine& command_line) { |
| 473 | ComponentUpdateService* cus = g_browser_process->component_updater(); |
| 474 | if (!cus) |
| 475 | return; |
| 476 | // Registration can be before of after cus->Start() so it is ok to post |
| 477 | // a task to the UI thread to do registration once you done the necessary |
| 478 | // file IO to know you existing component version. |
| 479 | RegisterRecoveryComponent(cus, g_browser_process->local_state()); |
| 480 | RegisterPepperFlashComponent(cus); |
| 481 | RegisterSwiftShaderComponent(cus); |
| 482 | |
| 483 | // CRLSetFetcher attempts to load a CRL set from either the local disk or |
| 484 | // network. |
| 485 | if (!command_line.HasSwitch(switches::kDisableCRLSets)) |
| 486 | g_browser_process->crl_set_fetcher()->StartInitialLoad(cus); |
| 487 | |
[email protected] | ccb4feef | 2013-02-14 06:16:47 | [diff] [blame] | 488 | RegisterPnaclComponent(cus, command_line); |
[email protected] | 8cebc94 | 2013-01-31 01:28:42 | [diff] [blame] | 489 | |
| 490 | cus->Start(); |
| 491 | } |
| 492 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 493 | bool ProcessSingletonNotificationCallback( |
| 494 | const CommandLine& command_line, |
| 495 | const base::FilePath& current_directory) { |
[email protected] | 5d36454 | 2012-04-05 07:15:39 | [diff] [blame] | 496 | // Drop the request if the browser process is already in shutdown path. |
| 497 | if (!g_browser_process || g_browser_process->IsShuttingDown()) |
| 498 | return false; |
| 499 | |
[email protected] | e9613b5 | 2012-11-27 22:35:13 | [diff] [blame] | 500 | g_browser_process->PlatformSpecificCommandLineProcessing(command_line); |
| 501 | |
[email protected] | 5d36454 | 2012-04-05 07:15:39 | [diff] [blame] | 502 | // TODO(erikwright): Consider removing this - AFAIK it is no longer used. |
| 503 | // Handle the --uninstall-extension startup action. This needs to done here |
| 504 | // in the process that is running with the target profile, otherwise the |
| 505 | // uninstall will fail to unload and remove all components. |
| 506 | if (command_line.HasSwitch(switches::kUninstallExtension)) { |
| 507 | // The uninstall extension switch can't be combined with the profile |
| 508 | // directory switch. |
| 509 | DCHECK(!command_line.HasSwitch(switches::kProfileDirectory)); |
| 510 | |
| 511 | Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 512 | if (!profile) { |
| 513 | // We should never be called before the profile has been created. |
| 514 | NOTREACHED(); |
| 515 | return true; |
| 516 | } |
| 517 | |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 518 | extensions::StartupHelper extension_startup_helper; |
| 519 | extension_startup_helper.UninstallExtension(command_line, profile); |
[email protected] | 5d36454 | 2012-04-05 07:15:39 | [diff] [blame] | 520 | return true; |
| 521 | } |
| 522 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 523 | base::FilePath user_data_dir = |
[email protected] | e0203c0 | 2013-02-04 11:55:53 | [diff] [blame] | 524 | g_browser_process->profile_manager()->user_data_dir(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 525 | base::FilePath startup_profile_dir = |
[email protected] | e0203c0 | 2013-02-04 11:55:53 | [diff] [blame] | 526 | GetStartupProfilePath(user_data_dir, command_line); |
| 527 | |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 528 | StartupBrowserCreator::ProcessCommandLineAlreadyRunning( |
[email protected] | e0203c0 | 2013-02-04 11:55:53 | [diff] [blame] | 529 | command_line, current_directory, startup_profile_dir); |
[email protected] | 5d36454 | 2012-04-05 07:15:39 | [diff] [blame] | 530 | return true; |
| 531 | } |
| 532 | |
[email protected] | 86d3aca | 2012-12-04 21:36:09 | [diff] [blame] | 533 | void LaunchDevToolsHandlerIfNeeded(Profile* profile, |
| 534 | const CommandLine& command_line) { |
| 535 | if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { |
| 536 | std::string port_str = |
| 537 | command_line.GetSwitchValueASCII(::switches::kRemoteDebuggingPort); |
| 538 | int port; |
| 539 | if (base::StringToInt(port_str, &port) && port > 0 && port < 65535) { |
| 540 | std::string frontend_str; |
| 541 | if (command_line.HasSwitch(::switches::kRemoteDebuggingFrontend)) { |
| 542 | frontend_str = command_line.GetSwitchValueASCII( |
| 543 | ::switches::kRemoteDebuggingFrontend); |
| 544 | } |
| 545 | g_browser_process->CreateDevToolsHttpProtocolHandler( |
| 546 | profile, |
[email protected] | 55d34240 | 2013-02-22 11:28:06 | [diff] [blame] | 547 | chrome::HOST_DESKTOP_TYPE_NATIVE, |
[email protected] | 86d3aca | 2012-12-04 21:36:09 | [diff] [blame] | 548 | "127.0.0.1", |
| 549 | port, |
| 550 | frontend_str); |
| 551 | } else { |
| 552 | DLOG(WARNING) << "Invalid http debugger port number " << port; |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | |
[email protected] | e327c75 | 2013-01-30 11:38:16 | [diff] [blame] | 557 | // Heap allocated class that listens for first page load, kicks off stat |
| 558 | // recording and then deletes itself. |
| 559 | class LoadCompleteListener : public content::NotificationObserver { |
| 560 | public: |
| 561 | LoadCompleteListener() { |
| 562 | registrar_.Add(this, |
| 563 | content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 564 | content::NotificationService::AllSources()); |
| 565 | } |
| 566 | virtual ~LoadCompleteListener() {} |
| 567 | |
| 568 | // content::NotificationObserver implementation. |
| 569 | virtual void Observe(int type, |
| 570 | const content::NotificationSource& source, |
[email protected] | b94584a | 2013-02-07 03:02:08 | [diff] [blame] | 571 | const content::NotificationDetails& details) OVERRIDE { |
[email protected] | e327c75 | 2013-01-30 11:38:16 | [diff] [blame] | 572 | DCHECK(type == content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME); |
| 573 | startup_metric_utils::OnInitialPageLoadComplete(); |
| 574 | delete this; |
| 575 | } |
| 576 | |
| 577 | private: |
| 578 | content::NotificationRegistrar registrar_; |
| 579 | DISALLOW_COPY_AND_ASSIGN(LoadCompleteListener); |
| 580 | }; |
| 581 | |
[email protected] | 3aada460 | 2011-08-11 22:25:55 | [diff] [blame] | 582 | } // namespace |
| 583 | |
[email protected] | cbce4724 | 2011-08-12 21:40:59 | [diff] [blame] | 584 | namespace chrome_browser { |
| 585 | // This error message is not localized because we failed to load the |
| 586 | // localization data files. |
| 587 | const char kMissingLocaleDataTitle[] = "Missing File Error"; |
| 588 | const char kMissingLocaleDataMessage[] = |
| 589 | "Unable to find locale data files. Please reinstall."; |
| 590 | } // namespace chrome_browser |
| 591 | |
[email protected] | 4bb7602 | 2011-08-12 03:05:53 | [diff] [blame] | 592 | // BrowserMainParts ------------------------------------------------------------ |
| 593 | |
[email protected] | 1948a478 | 2012-04-30 13:45:44 | [diff] [blame] | 594 | // static |
| 595 | bool ChromeBrowserMainParts::disable_enforcing_cookie_policies_for_tests_ = |
| 596 | false; |
| 597 | |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 598 | ChromeBrowserMainParts::ChromeBrowserMainParts( |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 599 | const content::MainFunctionParams& parameters) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 600 | : parameters_(parameters), |
[email protected] | badf5cf | 2011-10-29 03:44:44 | [diff] [blame] | 601 | parsed_command_line_(parameters.command_line), |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 602 | result_code_(content::RESULT_CODE_NORMAL_EXIT), |
[email protected] | 08f1c5e | 2011-12-01 01:54:34 | [diff] [blame] | 603 | startup_watcher_(new StartupTimeBomb()), |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 604 | shutdown_watcher_(new ShutdownWatcherHelper()), |
[email protected] | 0c1c475 | 2012-08-09 20:30:24 | [diff] [blame] | 605 | startup_timer_(new performance_monitor::StartupTimer()), |
[email protected] | ae9e12a | 2012-07-31 17:48:12 | [diff] [blame] | 606 | browser_field_trials_(parameters.command_line), |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 607 | record_search_engine_(false), |
| 608 | translate_manager_(NULL), |
| 609 | profile_(NULL), |
[email protected] | 6601392 | 2011-09-13 18:53:42 | [diff] [blame] | 610 | run_message_loop_(true), |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 611 | notify_result_(ProcessSingleton::PROCESS_NONE), |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 612 | do_first_run_tasks_(false), |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 613 | local_state_(NULL), |
| 614 | restart_last_session_(false) { |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 615 | // If we're running tests (ui_task is non-null). |
[email protected] | 716476c | 2011-12-29 00:07:03 | [diff] [blame] | 616 | if (parameters.ui_task) |
[email protected] | b228ecf1 | 2011-09-08 17:06:59 | [diff] [blame] | 617 | browser_defaults::enable_help_app = false; |
[email protected] | 1948a478 | 2012-04-30 13:45:44 | [diff] [blame] | 618 | |
| 619 | // Chrome disallows cookies by default. All code paths that want to use |
| 620 | // cookies need to go through one of Chrome's URLRequestContexts which have |
| 621 | // a ChromeNetworkDelegate attached that selectively allows cookies again. |
| 622 | if (!disable_enforcing_cookie_policies_for_tests_) |
| 623 | net::URLRequest::SetDefaultCookiePolicyToBlock(); |
[email protected] | 4bb7602 | 2011-08-12 03:05:53 | [diff] [blame] | 624 | } |
| 625 | |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 626 | ChromeBrowserMainParts::~ChromeBrowserMainParts() { |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 627 | for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) |
| 628 | delete chrome_extra_parts_[i]; |
| 629 | chrome_extra_parts_.clear(); |
[email protected] | 4bb7602 | 2011-08-12 03:05:53 | [diff] [blame] | 630 | } |
| 631 | |
[email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 632 | // This will be called after the command-line has been mutated by about:flags |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 633 | void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() { |
[email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 634 | // Must initialize metrics after labs have been converted into switches, |
| 635 | // but before field trials are set up (so that client ID is available for |
| 636 | // one-time randomized field trials). |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 637 | #if defined(OS_WIN) |
| 638 | if (parsed_command_line_.HasSwitch(switches::kChromeFrame)) |
| 639 | MetricsLog::set_version_extension("-F"); |
| 640 | #elif defined(ARCH_CPU_64_BITS) |
| 641 | MetricsLog::set_version_extension("-64"); |
[email protected] | 000bed6 | 2012-10-20 01:35:36 | [diff] [blame] | 642 | #elif defined(OS_ANDROID) |
| 643 | // Set version extension to identify Android releases. |
| 644 | // Example: 16.0.912.61-K88 |
| 645 | std::string version_extension = "-K"; |
| 646 | version_extension.append( |
| 647 | base::android::BuildInfo::GetInstance()->package_version_code()); |
| 648 | MetricsLog::set_version_extension(version_extension); |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 649 | #endif // defined(OS_WIN) |
[email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 650 | |
| 651 | // Initialize FieldTrialList to support FieldTrials that use one-time |
[email protected] | e61003a | 2012-05-24 17:03:19 | [diff] [blame] | 652 | // randomization. |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 653 | MetricsService* metrics = browser_process_->metrics_service(); |
[email protected] | e535432 | 2012-08-09 23:07:37 | [diff] [blame] | 654 | bool metrics_reporting_enabled = IsMetricsReportingEnabled(); |
| 655 | if (metrics_reporting_enabled) |
[email protected] | 5cbeeef7 | 2012-02-08 02:05:18 | [diff] [blame] | 656 | metrics->ForceClientIdCreation(); // Needed below. |
[email protected] | e61003a | 2012-05-24 17:03:19 | [diff] [blame] | 657 | field_trial_list_.reset( |
[email protected] | e535432 | 2012-08-09 23:07:37 | [diff] [blame] | 658 | new base::FieldTrialList( |
[email protected] | 20f999b5 | 2012-08-24 22:32:59 | [diff] [blame] | 659 | metrics->CreateEntropyProvider(metrics_reporting_enabled).release())); |
[email protected] | 4bb7602 | 2011-08-12 03:05:53 | [diff] [blame] | 660 | |
[email protected] | 2d472958 | 2012-04-12 07:08:07 | [diff] [blame] | 661 | // Ensure any field trials specified on the command line are initialized. |
| 662 | // Also stop the metrics service so that we don't pollute UMA. |
[email protected] | 2d472958 | 2012-04-12 07:08:07 | [diff] [blame] | 663 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 664 | if (command_line->HasSwitch(switches::kForceFieldTrials)) { |
| 665 | std::string persistent = command_line->GetSwitchValueASCII( |
| 666 | switches::kForceFieldTrials); |
| 667 | bool ret = base::FieldTrialList::CreateTrialsFromString(persistent); |
| 668 | CHECK(ret) << "Invalid --" << switches::kForceFieldTrials << |
| 669 | " list specified."; |
| 670 | } |
[email protected] | 2d472958 | 2012-04-12 07:08:07 | [diff] [blame] | 671 | |
[email protected] | 0481124 | 2012-07-06 18:04:29 | [diff] [blame] | 672 | chrome_variations::VariationsService* variations_service = |
[email protected] | 54e26c12 | 2012-05-17 15:36:21 | [diff] [blame] | 673 | browser_process_->variations_service(); |
[email protected] | 58c63cb | 2012-11-26 19:22:11 | [diff] [blame] | 674 | if (variations_service) |
[email protected] | 7e6b753f | 2013-02-15 16:21:38 | [diff] [blame] | 675 | variations_service->CreateTrialsFromSeed(); |
[email protected] | 54e26c12 | 2012-05-17 15:36:21 | [diff] [blame] | 676 | |
[email protected] | 5c18155 | 2013-02-07 09:12:52 | [diff] [blame] | 677 | const int64 install_date = local_state_->GetInt64(prefs::kInstallDate); |
[email protected] | bc381c0 | 2012-11-05 21:36:42 | [diff] [blame] | 678 | // This must be called after the pref is initialized. |
| 679 | DCHECK(install_date); |
| 680 | browser_field_trials_.SetupFieldTrials(base::Time::FromTimeT(install_date)); |
[email protected] | 4bb7602 | 2011-08-12 03:05:53 | [diff] [blame] | 681 | |
[email protected] | b98def8 | 2012-06-28 23:42:45 | [diff] [blame] | 682 | SetupPlatformFieldTrials(); |
| 683 | |
[email protected] | 4bb7602 | 2011-08-12 03:05:53 | [diff] [blame] | 684 | // Initialize FieldTrialSynchronizer system. This is a singleton and is used |
[email protected] | 716476c | 2011-12-29 00:07:03 | [diff] [blame] | 685 | // for posting tasks via base::Bind. Its deleted when it goes out of scope. |
| 686 | // Even though base::Bind does AddRef and Release, the object will not be |
| 687 | // deleted after the Task is executed. |
[email protected] | 4bb7602 | 2011-08-12 03:05:53 | [diff] [blame] | 688 | field_trial_synchronizer_ = new FieldTrialSynchronizer(); |
[email protected] | 4bb7602 | 2011-08-12 03:05:53 | [diff] [blame] | 689 | } |
| 690 | |
[email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 691 | // ChromeBrowserMainParts: |SetupMetricsAndFieldTrials()| related -------------- |
| 692 | |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 693 | void ChromeBrowserMainParts::StartMetricsRecording() { |
| 694 | MetricsService* metrics = g_browser_process->metrics_service(); |
[email protected] | c0aa875b | 2012-11-06 22:09:13 | [diff] [blame] | 695 | |
[email protected] | e5016338 | 2013-03-02 01:08:27 | [diff] [blame] | 696 | const bool enable_benchmarking = |
[email protected] | c0aa875b | 2012-11-06 22:09:13 | [diff] [blame] | 697 | parsed_command_line_.HasSwitch(switches::kEnableBenchmarking); |
| 698 | // TODO(stevet): This is a temporary histogram used to investigate an issue |
| 699 | // with logging. Remove this when investigations are complete. |
| 700 | UMA_HISTOGRAM_BOOLEAN("UMA.FieldTrialsEnabledBenchmarking", |
| 701 | enable_benchmarking); |
[email protected] | e5016338 | 2013-03-02 01:08:27 | [diff] [blame] | 702 | // TODO(miu): Metrics reporting is disabled in DEBUG builds until ill-fired |
| 703 | // DCHECKs are fixed, and/or we reconsider whether metrics reporting should |
| 704 | // really ever be enabled for debug builds. http://crbug.com/156979 |
| 705 | #if defined(NDEBUG) |
| 706 | const bool only_do_metrics_recording = enable_benchmarking || |
| 707 | parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly); |
| 708 | #else |
| 709 | const bool only_do_metrics_recording = true; |
| 710 | #endif |
| 711 | if (only_do_metrics_recording) { |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 712 | // If we're testing then we don't care what the user preference is, we turn |
| 713 | // on recording, but not reporting, otherwise tests fail. |
[email protected] | 410938e0 | 2012-10-24 16:33:59 | [diff] [blame] | 714 | metrics->StartRecordingForTests(); |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 715 | return; |
| 716 | } |
| 717 | |
[email protected] | 5cbeeef7 | 2012-02-08 02:05:18 | [diff] [blame] | 718 | if (IsMetricsReportingEnabled()) |
| 719 | metrics->Start(); |
| 720 | } |
| 721 | |
| 722 | bool ChromeBrowserMainParts::IsMetricsReportingEnabled() { |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 723 | // If the user permits metrics reporting with the checkbox in the |
| 724 | // prefs, we turn on recording. We disable metrics completely for |
[email protected] | e535432 | 2012-08-09 23:07:37 | [diff] [blame] | 725 | // non-official builds. This can be forced with a flag. |
| 726 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 727 | if (command_line->HasSwitch(switches::kEnableMetricsReportingForTesting)) |
| 728 | return true; |
| 729 | |
[email protected] | 5cbeeef7 | 2012-02-08 02:05:18 | [diff] [blame] | 730 | bool enabled = false; |
[email protected] | 9f4dd17 | 2012-05-11 02:29:56 | [diff] [blame] | 731 | // The debug build doesn't send UMA logs when FieldTrials are forced. |
[email protected] | 2d472958 | 2012-04-12 07:08:07 | [diff] [blame] | 732 | if (command_line->HasSwitch(switches::kForceFieldTrials)) |
| 733 | return false; |
[email protected] | 2d472958 | 2012-04-12 07:08:07 | [diff] [blame] | 734 | |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 735 | #if defined(GOOGLE_CHROME_BUILD) |
| 736 | #if defined(OS_CHROMEOS) |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 737 | chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, |
| 738 | &enabled); |
| 739 | #else |
[email protected] | 5cbeeef7 | 2012-02-08 02:05:18 | [diff] [blame] | 740 | enabled = local_state_->GetBoolean(prefs::kMetricsReportingEnabled); |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 741 | #endif // #if defined(OS_CHROMEOS) |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 742 | #endif // defined(GOOGLE_CHROME_BUILD) |
[email protected] | 5cbeeef7 | 2012-02-08 02:05:18 | [diff] [blame] | 743 | return enabled; |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 744 | } |
| 745 | |
[email protected] | 4bb7602 | 2011-08-12 03:05:53 | [diff] [blame] | 746 | // ----------------------------------------------------------------------------- |
| 747 | // TODO(viettrungluu): move more/rest of BrowserMain() into BrowserMainParts. |
| 748 | |
[email protected] | 3aada460 | 2011-08-11 22:25:55 | [diff] [blame] | 749 | #if defined(OS_WIN) |
| 750 | #define DLLEXPORT __declspec(dllexport) |
| 751 | |
| 752 | // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. |
| 753 | extern "C" { |
| 754 | DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
| 755 | } |
| 756 | |
| 757 | DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { |
| 758 | // Need an instance of AtExitManager to handle singleton creations and |
| 759 | // deletions. We need this new instance because, the old instance created |
| 760 | // in ChromeMain() got destructed when the function returned. |
| 761 | base::AtExitManager exit_manager; |
| 762 | upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
| 763 | } |
| 764 | #endif |
| 765 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 766 | // content::BrowserMainParts implementation ------------------------------------ |
| 767 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 768 | void ChromeBrowserMainParts::PreEarlyInitialization() { |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 769 | for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 770 | chrome_extra_parts_[i]->PreEarlyInitialization(); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | void ChromeBrowserMainParts::PostEarlyInitialization() { |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 774 | for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 775 | chrome_extra_parts_[i]->PostEarlyInitialization(); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | void ChromeBrowserMainParts::ToolkitInitialized() { |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 779 | for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 780 | chrome_extra_parts_[i]->ToolkitInitialized(); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | void ChromeBrowserMainParts::PreMainMessageLoopStart() { |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 784 | for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 785 | chrome_extra_parts_[i]->PreMainMessageLoopStart(); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | void ChromeBrowserMainParts::PostMainMessageLoopStart() { |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 789 | for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 790 | chrome_extra_parts_[i]->PostMainMessageLoopStart(); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 791 | } |
| 792 | |
[email protected] | 69479b92 | 2012-02-02 09:56:20 | [diff] [blame] | 793 | int ChromeBrowserMainParts::PreCreateThreads() { |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 794 | result_code_ = PreCreateThreadsImpl(); |
[email protected] | 7defb4f0 | 2012-02-07 18:25:46 | [diff] [blame] | 795 | // These members must be initialized before returning from this function. |
| 796 | DCHECK(master_prefs_.get()); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 797 | #if !defined(OS_ANDROID) |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 798 | DCHECK(browser_creator_.get()); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 799 | #endif |
[email protected] | 69479b92 | 2012-02-02 09:56:20 | [diff] [blame] | 800 | return result_code_; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | int ChromeBrowserMainParts::PreCreateThreadsImpl() { |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 804 | run_message_loop_ = false; |
[email protected] | 0c298a5 | 2009-09-25 21:33:52 | [diff] [blame] | 805 | #if defined(OS_WIN) |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 806 | PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_); |
[email protected] | 0c298a5 | 2009-09-25 21:33:52 | [diff] [blame] | 807 | #else |
| 808 | // Getting the user data dir can fail if the directory isn't |
| 809 | // creatable, for example; on Windows in code below we bring up a |
| 810 | // dialog prompting the user to pick a different directory. |
| 811 | // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, |
| 812 | // so it's better to fail here than fail mysteriously elsewhere. |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 813 | CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_)) |
[email protected] | 0c298a5 | 2009-09-25 21:33:52 | [diff] [blame] | 814 | << "Must be able to get user data directory!"; |
| 815 | #endif |
| 816 | |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 817 | // Whether this is First Run. |do_first_run_tasks_| should be prefered to this |
| 818 | // unless the desire is actually to know whether this is really First Run |
| 819 | // (i.e., even if --no-first-run is passed). |
| 820 | bool is_first_run = false; |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 821 | // Android's first run is done in Java instead of native. |
| 822 | #if !defined(OS_ANDROID) |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 823 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 824 | process_singleton_.reset(new ProcessSingleton(user_data_dir_)); |
[email protected] | edf04b51 | 2012-02-23 09:47:43 | [diff] [blame] | 825 | // Ensure ProcessSingleton won't process messages too early. It will be |
| 826 | // unlocked in PostBrowserStart(). |
| 827 | process_singleton_->Lock(NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 828 | |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 829 | bool force_first_run = |
| 830 | parsed_command_line().HasSwitch(switches::kForceFirstRun); |
| 831 | bool force_skip_first_run_tasks = |
| 832 | (!force_first_run && |
| 833 | parsed_command_line().HasSwitch(switches::kNoFirstRun)); |
| 834 | |
| 835 | is_first_run = |
| 836 | (force_first_run || first_run::IsChromeFirstRun()) && |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 837 | !ProfileManager::IsImportProcess(parsed_command_line()); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 838 | #endif |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 839 | |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 840 | scoped_refptr<base::SequencedTaskRunner> local_state_task_runner = |
[email protected] | 9bcdc20 | 2013-03-07 20:51:43 | [diff] [blame^] | 841 | JsonPrefStore::GetTaskRunnerForFile( |
| 842 | base::FilePath(chrome::kLocalStorePoolName), |
| 843 | BrowserThread::GetBlockingPool()); |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 844 | browser_process_.reset(new BrowserProcessImpl(local_state_task_runner, |
| 845 | parsed_command_line())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 846 | |
[email protected] | 9b53dab | 2011-11-14 05:26:05 | [diff] [blame] | 847 | if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) { |
[email protected] | b2a9bbd | 2011-10-31 22:36:21 | [diff] [blame] | 848 | // User wants to override default tracking status. |
| 849 | std::string flag = |
[email protected] | 9b53dab | 2011-11-14 05:26:05 | [diff] [blame] | 850 | parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling); |
[email protected] | 702a12d | 2012-02-10 19:43:42 | [diff] [blame] | 851 | // Default to basic profiling (no parent child support). |
| 852 | tracked_objects::ThreadData::Status status = |
| 853 | tracked_objects::ThreadData::PROFILING_ACTIVE; |
| 854 | if (flag.compare("0") != 0) |
| 855 | status = tracked_objects::ThreadData::DEACTIVATED; |
| 856 | else if (flag.compare("child") != 0) |
| 857 | status = tracked_objects::ThreadData::PROFILING_CHILDREN_ACTIVE; |
| 858 | tracked_objects::ThreadData::InitializeAndSetTrackingStatus(status); |
[email protected] | b2a9bbd | 2011-10-31 22:36:21 | [diff] [blame] | 859 | } |
| 860 | |
[email protected] | 61b53f97 | 2012-02-10 20:39:23 | [diff] [blame] | 861 | if (parsed_command_line().HasSwitch(switches::kProfilingOutputFile)) { |
| 862 | tracking_objects_.set_output_file_path( |
| 863 | parsed_command_line().GetSwitchValuePath( |
| 864 | switches::kProfilingOutputFile)); |
| 865 | } |
| 866 | |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 867 | local_state_ = InitializeLocalState(local_state_task_runner, |
| 868 | parsed_command_line(), |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 869 | is_first_run); |
[email protected] | 1b084b5e | 2010-08-03 07:58:19 | [diff] [blame] | 870 | |
[email protected] | 7defb4f0 | 2012-02-07 18:25:46 | [diff] [blame] | 871 | // These members must be initialized before returning from this function. |
| 872 | master_prefs_.reset(new first_run::MasterPrefs); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 873 | |
| 874 | #if !defined(OS_ANDROID) |
| 875 | // Android doesn't use StartupBrowserCreator. |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 876 | browser_creator_.reset(new StartupBrowserCreator); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 877 | // TODO(yfriedman): Refactor Android to re-use UMABrowsingActivityObserver |
[email protected] | 3770c24 | 2012-07-12 22:58:17 | [diff] [blame] | 878 | chrome::UMABrowsingActivityObserver::Init(); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 879 | #endif |
[email protected] | 7defb4f0 | 2012-02-07 18:25:46 | [diff] [blame] | 880 | |
[email protected] | 6346d15 | 2012-05-04 04:02:33 | [diff] [blame] | 881 | // Convert active labs into switches. This needs to be done before |
| 882 | // ResourceBundle::InitSharedInstanceWithLocale as some loaded resources are |
| 883 | // affected by experiment flags (--touch-optimized-ui in particular). Not |
| 884 | // needed on Android as there aren't experimental flags. |
| 885 | about_flags::ConvertFlagsToSwitches(local_state_, |
| 886 | CommandLine::ForCurrentProcess()); |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 887 | local_state_->UpdateCommandLinePrefStore( |
| 888 | new CommandLinePrefStore(CommandLine::ForCurrentProcess())); |
[email protected] | 6346d15 | 2012-05-04 04:02:33 | [diff] [blame] | 889 | |
| 890 | // Reset the command line in the crash report details, since we may have |
| 891 | // just changed it to include experiments. |
| 892 | child_process_logging::SetCommandLine(CommandLine::ForCurrentProcess()); |
| 893 | |
[email protected] | d4515eb | 2009-01-30 00:40:43 | [diff] [blame] | 894 | // If we're running tests (ui_task is non-null), then the ResourceBundle |
| 895 | // has already been initialized. |
[email protected] | f900367b2 | 2012-09-11 16:08:36 | [diff] [blame] | 896 | if (parameters().ui_task && |
| 897 | !local_state_->IsManagedPreference(prefs::kApplicationLocale)) { |
[email protected] | 17e6cde5 | 2012-01-05 00:16:57 | [diff] [blame] | 898 | browser_process_->SetApplicationLocale("en-US"); |
[email protected] | ce4b6a9 | 2009-12-10 00:04:48 | [diff] [blame] | 899 | } else { |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 900 | // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is |
| 901 | // needed when loading the MainMenu.nib and the language doesn't depend on |
| 902 | // anything since it comes from Cocoa. |
[email protected] | ce4b6a9 | 2009-12-10 00:04:48 | [diff] [blame] | 903 | #if defined(OS_MACOSX) |
[email protected] | 17e6cde5 | 2012-01-05 00:16:57 | [diff] [blame] | 904 | browser_process_->SetApplicationLocale(l10n_util::GetLocaleOverride()); |
[email protected] | ce4b6a9 | 2009-12-10 00:04:48 | [diff] [blame] | 905 | #else |
[email protected] | 455ee19 | 2010-12-22 16:05:57 | [diff] [blame] | 906 | const std::string locale = |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 907 | local_state_->GetString(prefs::kApplicationLocale); |
[email protected] | cd87be13 | 2011-02-04 13:07:38 | [diff] [blame] | 908 | // On a POSIX OS other than ChromeOS, the parameter that is passed to the |
| 909 | // method InitSharedInstance is ignored. |
[email protected] | 455ee19 | 2010-12-22 16:05:57 | [diff] [blame] | 910 | const std::string loaded_locale = |
[email protected] | fb317a5 | 2012-05-09 15:57:47 | [diff] [blame] | 911 | ResourceBundle::InitSharedInstanceWithLocale(locale, NULL); |
[email protected] | cbce4724 | 2011-08-12 21:40:59 | [diff] [blame] | 912 | if (loaded_locale.empty() && |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 913 | !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { |
[email protected] | cbce4724 | 2011-08-12 21:40:59 | [diff] [blame] | 914 | ShowMissingLocaleMessageBox(); |
| 915 | return chrome::RESULT_CODE_MISSING_DATA; |
| 916 | } |
[email protected] | 455ee19 | 2010-12-22 16:05:57 | [diff] [blame] | 917 | CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; |
[email protected] | 17e6cde5 | 2012-01-05 00:16:57 | [diff] [blame] | 918 | browser_process_->SetApplicationLocale(loaded_locale); |
[email protected] | e1cb0e9 | 2010-06-15 07:23:59 | [diff] [blame] | 919 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 920 | base::FilePath resources_pack_path; |
[email protected] | e1cb0e9 | 2010-06-15 07:23:59 | [diff] [blame] | 921 | PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
[email protected] | 6c26d9c | 2012-07-10 19:18:04 | [diff] [blame] | 922 | ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
[email protected] | bf44c13 | 2012-11-15 19:41:42 | [diff] [blame] | 923 | resources_pack_path, ui::SCALE_FACTOR_NONE); |
[email protected] | cd87be13 | 2011-02-04 13:07:38 | [diff] [blame] | 924 | #endif // defined(OS_MACOSX) |
[email protected] | ce4b6a9 | 2009-12-10 00:04:48 | [diff] [blame] | 925 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 926 | |
[email protected] | d9edd31 | 2011-02-16 20:52:28 | [diff] [blame] | 927 | #if defined(TOOLKIT_GTK) |
| 928 | g_set_application_name(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str()); |
[email protected] | d0646f3 | 2009-08-27 00:58:46 | [diff] [blame] | 929 | #endif |
| 930 | |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 931 | // Android does first run in Java instead of native. |
| 932 | #if !defined(OS_ANDROID) |
[email protected] | 74be069e8 | 2010-06-25 00:12:49 | [diff] [blame] | 933 | // On first run, we need to process the predictor preferences before the |
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 934 | // browser's profile_manager object is created, but after ResourceBundle |
| 935 | // is initialized. |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 936 | if (is_first_run) { |
[email protected] | 78679969 | 2012-09-26 14:16:48 | [diff] [blame] | 937 | first_run::ProcessMasterPreferencesResult pmp_result = |
| 938 | first_run::ProcessMasterPreferences(user_data_dir_, |
| 939 | master_prefs_.get()); |
| 940 | if (pmp_result == first_run::EULA_EXIT_NOW) |
| 941 | return chrome::RESULT_CODE_EULA_REFUSED; |
| 942 | |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 943 | // Do first run tasks unless: |
| 944 | // - Explicitly forced not to by |force_skip_first_run_tasks| or |
| 945 | // |pmp_result|. |
[email protected] | 749dc3db | 2013-02-11 22:52:31 | [diff] [blame] | 946 | // - Running in App (or App Launcher) mode, where showing the importer |
| 947 | // (first run) UI is undesired. |
| 948 | do_first_run_tasks_ = ( |
| 949 | !force_skip_first_run_tasks && |
| 950 | pmp_result != first_run::SKIP_FIRST_RUN_TASKS && |
| 951 | !parsed_command_line().HasSwitch(switches::kApp) && |
| 952 | !parsed_command_line().HasSwitch(switches::kAppId) && |
| 953 | !parsed_command_line().HasSwitch(switches::kShowAppList)); |
[email protected] | 78679969 | 2012-09-26 14:16:48 | [diff] [blame] | 954 | |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 955 | if (do_first_run_tasks_) { |
| 956 | AddFirstRunNewTabs(browser_creator_.get(), master_prefs_->new_tabs); |
[email protected] | a723f0af | 2013-02-15 06:36:03 | [diff] [blame] | 957 | |
| 958 | // Store the initial VariationsService seed in local state, if it exists |
| 959 | // in master prefs. |
| 960 | if (!master_prefs_->variations_seed.empty()) { |
| 961 | local_state_->SetString(prefs::kVariationsSeed, |
| 962 | master_prefs_->variations_seed); |
| 963 | // Set the variation seed date to the current system time. If the user's |
| 964 | // clock is incorrect, this may cause some field trial expiry checks to |
| 965 | // not do the right thing until the next seed update from the server, |
| 966 | // when this value will be updated. |
| 967 | local_state_->SetInt64(prefs::kVariationsSeedDate, |
| 968 | base::Time::Now().ToInternalValue()); |
| 969 | } |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 970 | } else if (parsed_command_line().HasSwitch(switches::kNoFirstRun)) { |
| 971 | // Create the First Run beacon anyways if --no-first-run was passed on the |
| 972 | // command line. |
[email protected] | dfa08b04 | 2011-12-28 23:07:21 | [diff] [blame] | 973 | first_run::CreateSentinel(); |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 974 | } |
[email protected] | fe247ac | 2009-03-19 00:10:48 | [diff] [blame] | 975 | } |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 976 | #endif |
[email protected] | fe247ac | 2009-03-19 00:10:48 | [diff] [blame] | 977 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 978 | // TODO(viettrungluu): why don't we run this earlier? |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 979 | if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) |
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 980 | WarnAboutMinimumSystemRequirements(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 981 | |
[email protected] | 2ec5a48 | 2012-02-22 00:01:18 | [diff] [blame] | 982 | #if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_MACOSX) |
[email protected] | e643e57c | 2012-01-28 02:26:09 | [diff] [blame] | 983 | // Set the product channel for crash reports. |
| 984 | child_process_logging::SetChannel( |
| 985 | chrome::VersionInfo::GetVersionStringModifier()); |
| 986 | #endif |
| 987 | |
[email protected] | 83ab4a28 | 2012-07-12 18:19:45 | [diff] [blame] | 988 | // Initialize tracking synchronizer system. |
[email protected] | 10fe40c | 2011-11-05 03:27:46 | [diff] [blame] | 989 | tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer(); |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 990 | |
[email protected] | 6b5f21d | 2009-04-13 17:01:35 | [diff] [blame] | 991 | // Now that all preferences have been registered, set the install date |
| 992 | // for the uninstall metrics if this is our first run. This only actually |
| 993 | // gets used if the user has metrics reporting enabled at uninstall time. |
[email protected] | 5c18155 | 2013-02-07 09:12:52 | [diff] [blame] | 994 | int64 install_date = local_state_->GetInt64(prefs::kInstallDate); |
| 995 | if (install_date == 0) |
| 996 | local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT()); |
[email protected] | 6b5f21d | 2009-04-13 17:01:35 | [diff] [blame] | 997 | |
[email protected] | e457f74 | 2010-04-02 17:25:43 | [diff] [blame] | 998 | #if defined(OS_MACOSX) |
| 999 | // Get the Keychain API to register for distributed notifications on the main |
| 1000 | // thread, which has a proper CFRunloop, instead of later on the I/O thread, |
| 1001 | // which doesn't. This ensures those notifications will get delivered |
| 1002 | // properly. See issue 37766. |
| 1003 | // (Note that the callback mask here is empty. I don't want to register for |
| 1004 | // any callbacks, I just want to initialize the mechanism.) |
| 1005 | SecKeychainAddCallback(&KeychainCallback, 0, NULL); |
| 1006 | #endif |
| 1007 | |
[email protected] | 69479b92 | 2012-02-02 09:56:20 | [diff] [blame] | 1008 | // Now the command line has been mutated based on about:flags, we can setup |
| 1009 | // metrics and initialize field trials. The field trials are needed by |
| 1010 | // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. |
| 1011 | SetupMetricsAndFieldTrials(); |
| 1012 | |
| 1013 | // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. |
| 1014 | browser_process_->PreCreateThreads(); |
| 1015 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 1016 | return content::RESULT_CODE_NORMAL_EXIT; |
| 1017 | } |
| 1018 | |
[email protected] | 2167cd6 | 2011-11-30 21:20:21 | [diff] [blame] | 1019 | void ChromeBrowserMainParts::PreMainMessageLoopRun() { |
| 1020 | result_code_ = PreMainMessageLoopRunImpl(); |
| 1021 | |
| 1022 | for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1023 | chrome_extra_parts_[i]->PreMainMessageLoopRun(); |
| 1024 | } |
| 1025 | |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 1026 | // PreMainMessageLoopRun calls these extra stages in the following order: |
| 1027 | // PreMainMessageLoopRunImpl() |
| 1028 | // ... initial setup, including browser_process_ setup. |
| 1029 | // PreProfileInit() |
| 1030 | // ... additional setup, including CreateProfile() |
| 1031 | // PostProfileInit() |
| 1032 | // ... additional setup |
| 1033 | // PreBrowserStart() |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 1034 | // ... browser_creator_->Start (OR parameters().ui_task->Run()) |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 1035 | // PostBrowserStart() |
| 1036 | |
| 1037 | void ChromeBrowserMainParts::PreProfileInit() { |
| 1038 | for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1039 | chrome_extra_parts_[i]->PreProfileInit(); |
| 1040 | } |
| 1041 | |
| 1042 | void ChromeBrowserMainParts::PostProfileInit() { |
[email protected] | 86d3aca | 2012-12-04 21:36:09 | [diff] [blame] | 1043 | LaunchDevToolsHandlerIfNeeded(profile(), parsed_command_line()); |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 1044 | for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1045 | chrome_extra_parts_[i]->PostProfileInit(); |
| 1046 | } |
| 1047 | |
| 1048 | void ChromeBrowserMainParts::PreBrowserStart() { |
| 1049 | for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1050 | chrome_extra_parts_[i]->PreBrowserStart(); |
[email protected] | aec25bc | 2012-10-04 18:45:26 | [diff] [blame] | 1051 | #if !defined(OS_ANDROID) |
| 1052 | gpu_util::InstallBrowserMonitor(); |
| 1053 | #endif |
[email protected] | 4432769 | 2013-02-26 21:21:22 | [diff] [blame] | 1054 | |
| 1055 | three_d_observer_.reset(new ThreeDAPIObserver()); |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | void ChromeBrowserMainParts::PostBrowserStart() { |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1059 | #if !defined(OS_ANDROID) |
[email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 1060 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kVisitURLs)) |
| 1061 | RunPageCycler(); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1062 | #endif |
[email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 1063 | |
[email protected] | 6ee43a7 | 2012-12-07 22:44:40 | [diff] [blame] | 1064 | // Create the instance of the Google Now service. |
| 1065 | #if defined(ENABLE_GOOGLE_NOW) |
| 1066 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1067 | switches::kEnableGoogleNowIntegration)) { |
| 1068 | GoogleNowServiceFactory::GetForProfile(profile_); |
| 1069 | } |
| 1070 | #endif |
| 1071 | |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 1072 | for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1073 | chrome_extra_parts_[i]->PostBrowserStart(); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1074 | #if !defined(OS_ANDROID) |
[email protected] | edf04b51 | 2012-02-23 09:47:43 | [diff] [blame] | 1075 | // Allow ProcessSingleton to process messages. |
| 1076 | process_singleton_->Unlock(); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1077 | #endif |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 1078 | } |
| 1079 | |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1080 | #if !defined(OS_ANDROID) |
[email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 1081 | void ChromeBrowserMainParts::RunPageCycler() { |
| 1082 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
[email protected] | 323fd712 | 2012-08-24 14:45:11 | [diff] [blame] | 1083 | // We assume a native desktop for tests, but we will need to find a way to |
| 1084 | // get the proper host desktop type once we start running these tests in ASH. |
[email protected] | 3c6a095 | 2012-12-17 11:56:09 | [diff] [blame] | 1085 | Browser* browser = chrome::FindBrowserWithProfile( |
[email protected] | 323fd712 | 2012-08-24 14:45:11 | [diff] [blame] | 1086 | profile_, chrome::HOST_DESKTOP_TYPE_NATIVE); |
[email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 1087 | DCHECK(browser); |
| 1088 | PageCycler* page_cycler = NULL; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1089 | base::FilePath input_file = |
[email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 1090 | command_line->GetSwitchValuePath(switches::kVisitURLs); |
| 1091 | page_cycler = new PageCycler(browser, input_file); |
| 1092 | page_cycler->set_errors_file( |
| 1093 | input_file.AddExtension(FILE_PATH_LITERAL(".errors"))); |
| 1094 | if (command_line->HasSwitch(switches::kRecordStats)) { |
| 1095 | page_cycler->set_stats_file( |
| 1096 | command_line->GetSwitchValuePath(switches::kRecordStats)); |
| 1097 | } |
[email protected] | 165b056 | 2012-06-20 00:41:22 | [diff] [blame] | 1098 | page_cycler->Run(); |
[email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 1099 | } |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1100 | #endif // !defined(OS_ANDROID) |
[email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 1101 | |
[email protected] | b98def8 | 2012-06-28 23:42:45 | [diff] [blame] | 1102 | void ChromeBrowserMainParts::SetupPlatformFieldTrials() { |
| 1103 | // Base class implementation of this does nothing. |
| 1104 | } |
| 1105 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 1106 | int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1107 | // Android updates the metrics service dynamically depending on whether the |
| 1108 | // application is in the foreground or not. Do not start here. |
| 1109 | #if !defined(OS_ANDROID) |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 1110 | // Now that the file thread has been started, start recording. |
| 1111 | StartMetricsRecording(); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1112 | #endif |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 1113 | |
[email protected] | 5016a9dd | 2013-02-02 01:10:02 | [diff] [blame] | 1114 | #if defined(ARCH_CPU_X86_FAMILY) |
| 1115 | LogIntelMicroArchitecture(); |
| 1116 | #endif // defined(ARCH_CPU_X86_FAMILY) |
| 1117 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 1118 | // Create watchdog thread after creating all other threads because it will |
| 1119 | // watch the other threads and they must be running. |
| 1120 | browser_process_->watchdog_thread(); |
[email protected] | 61e9572 | 2009-11-25 06:54:11 | [diff] [blame] | 1121 | |
[email protected] | d2caaa2 | 2011-12-12 03:04:15 | [diff] [blame] | 1122 | // Do any initializating in the browser process that requires all threads |
| 1123 | // running. |
| 1124 | browser_process_->PreMainMessageLoopRun(); |
| 1125 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1126 | // Record last shutdown time into a histogram. |
| 1127 | browser_shutdown::ReadLastShutdownInfo(); |
[email protected] | 04999e6 | 2009-09-25 01:27:31 | [diff] [blame] | 1128 | |
[email protected] | 01109dcf | 2010-03-27 00:56:43 | [diff] [blame] | 1129 | #if defined(OS_WIN) |
[email protected] | 04999e6 | 2009-09-25 01:27:31 | [diff] [blame] | 1130 | // On Windows, we use our startup as an opportunity to do upgrade/uninstall |
| 1131 | // tasks. Those care whether the browser is already running. On Linux/Mac, |
| 1132 | // upgrade/uninstall happen separately. |
[email protected] | a3abd557 | 2011-04-15 02:09:33 | [diff] [blame] | 1133 | bool already_running = browser_util::IsBrowserAlreadyRunning(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1134 | |
| 1135 | // If the command line specifies 'uninstall' then we need to work here |
| 1136 | // unless we detect another chrome browser running. |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1137 | if (parsed_command_line().HasSwitch(switches::kUninstall)) { |
[email protected] | 53c38d23 | 2009-02-13 20:52:18 | [diff] [blame] | 1138 | return DoUninstallTasks(already_running); |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1139 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1140 | |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1141 | if (parsed_command_line().HasSwitch(switches::kHideIcons) || |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1142 | parsed_command_line().HasSwitch(switches::kShowIcons)) { |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1143 | return ChromeBrowserMainPartsWin::HandleIconsCommands( |
| 1144 | parsed_command_line_); |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1145 | } |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1146 | #endif |
| 1147 | |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1148 | if (parsed_command_line().HasSwitch(switches::kMakeDefaultBrowser)) { |
[email protected] | 201028d | 2010-02-12 21:28:01 | [diff] [blame] | 1149 | return ShellIntegration::SetAsDefaultBrowser() ? |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 1150 | static_cast<int>(content::RESULT_CODE_NORMAL_EXIT) : |
| 1151 | static_cast<int>(chrome::RESULT_CODE_SHELL_INTEGRATION_FAILED); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1152 | } |
| 1153 | |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1154 | // Android doesn't support extensions and doesn't implement ProcessSingleton. |
| 1155 | #if !defined(OS_ANDROID) |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 1156 | // If the command line specifies --pack-extension, attempt the pack extension |
| 1157 | // startup action and exit. |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1158 | if (parsed_command_line().HasSwitch(switches::kPackExtension)) { |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 1159 | extensions::StartupHelper extension_startup_helper; |
| 1160 | if (extension_startup_helper.PackExtension(parsed_command_line())) |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 1161 | return content::RESULT_CODE_NORMAL_EXIT; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1162 | return chrome::RESULT_CODE_PACK_EXTENSION_ERROR; |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 1163 | } |
| 1164 | |
[email protected] | ed8ce0b | 2012-07-28 02:18:10 | [diff] [blame] | 1165 | bool pass_command_line = true; |
| 1166 | |
[email protected] | 5425d06 | 2010-04-11 23:16:02 | [diff] [blame] | 1167 | #if !defined(OS_MACOSX) |
| 1168 | // In environments other than Mac OS X we support import of settings |
| 1169 | // from other browsers. In case this process is a short-lived "import" |
| 1170 | // process that another browser runs just to import the settings, we |
| 1171 | // don't want to be checking for another browser process, by design. |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 1172 | pass_command_line = !ProfileManager::IsImportProcess(parsed_command_line()); |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1173 | #endif |
[email protected] | ed8ce0b | 2012-07-28 02:18:10 | [diff] [blame] | 1174 | |
| 1175 | // If we're being launched just to check the connector policy, we are |
| 1176 | // short-lived and don't want to be passing that switch off. |
| 1177 | pass_command_line = pass_command_line && !parsed_command_line().HasSwitch( |
| 1178 | switches::kCheckCloudPrintConnectorPolicy); |
| 1179 | |
| 1180 | if (pass_command_line) { |
[email protected] | 5425d06 | 2010-04-11 23:16:02 | [diff] [blame] | 1181 | // When another process is running, use that process instead of starting a |
| 1182 | // new one. NotifyOtherProcess will currently give the other process up to |
| 1183 | // 20 seconds to respond. Note that this needs to be done before we attempt |
| 1184 | // to read the profile. |
[email protected] | 5d36454 | 2012-04-05 07:15:39 | [diff] [blame] | 1185 | notify_result_ = process_singleton_->NotifyOtherProcessOrCreate( |
| 1186 | base::Bind(&ProcessSingletonNotificationCallback)); |
[email protected] | 7bb9ddc1 | 2012-12-12 00:00:56 | [diff] [blame] | 1187 | UMA_HISTOGRAM_ENUMERATION("NotifyOtherProcessOrCreate.Result", |
| 1188 | notify_result_, |
| 1189 | ProcessSingleton::NUM_NOTIFY_RESULTS); |
[email protected] | 6601392 | 2011-09-13 18:53:42 | [diff] [blame] | 1190 | switch (notify_result_) { |
[email protected] | 5425d06 | 2010-04-11 23:16:02 | [diff] [blame] | 1191 | case ProcessSingleton::PROCESS_NONE: |
| 1192 | // No process already running, fall through to starting a new one. |
| 1193 | break; |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1194 | |
[email protected] | 5425d06 | 2010-04-11 23:16:02 | [diff] [blame] | 1195 | case ProcessSingleton::PROCESS_NOTIFIED: |
| 1196 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 47e870b | 2013-02-24 21:14:53 | [diff] [blame] | 1197 | printf("%s\n", base::SysWideToNativeMB(UTF16ToWide( |
[email protected] | d5c45b7 | 2011-01-04 18:38:51 | [diff] [blame] | 1198 | l10n_util::GetStringUTF16(IDS_USED_EXISTING_BROWSER))).c_str()); |
[email protected] | 5425d06 | 2010-04-11 23:16:02 | [diff] [blame] | 1199 | #endif |
[email protected] | 6829650 | 2012-09-07 19:45:06 | [diff] [blame] | 1200 | // Having a differentiated return type for testing allows for tests to |
| 1201 | // verify proper handling of some switches. When not testing, stick to |
| 1202 | // the standard Unix convention of returning zero when things went as |
| 1203 | // expected. |
| 1204 | if (parsed_command_line().HasSwitch(switches::kTestType)) |
| 1205 | return chrome::RESULT_CODE_NORMAL_EXIT_PROCESS_NOTIFIED; |
| 1206 | return content::RESULT_CODE_NORMAL_EXIT; |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1207 | |
[email protected] | 5425d06 | 2010-04-11 23:16:02 | [diff] [blame] | 1208 | case ProcessSingleton::PROFILE_IN_USE: |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 1209 | return chrome::RESULT_CODE_PROFILE_IN_USE; |
[email protected] | 5425d06 | 2010-04-11 23:16:02 | [diff] [blame] | 1210 | |
[email protected] | 4a44bc3 | 2010-05-28 22:22:44 | [diff] [blame] | 1211 | case ProcessSingleton::LOCK_ERROR: |
| 1212 | LOG(ERROR) << "Failed to create a ProcessSingleton for your profile " |
| 1213 | "directory. This means that running multiple instances " |
| 1214 | "would start multiple browser processes rather than " |
| 1215 | "opening a new window in the existing process. Aborting " |
| 1216 | "now to avoid profile corruption."; |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 1217 | return chrome::RESULT_CODE_PROFILE_IN_USE; |
[email protected] | 4a44bc3 | 2010-05-28 22:22:44 | [diff] [blame] | 1218 | |
[email protected] | 5425d06 | 2010-04-11 23:16:02 | [diff] [blame] | 1219 | default: |
| 1220 | NOTREACHED(); |
| 1221 | } |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1222 | } |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1223 | #endif // !defined(OS_ANDROID) |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1224 | |
[email protected] | 2989d734 | 2010-10-27 02:00:09 | [diff] [blame] | 1225 | #if defined(USE_X11) |
| 1226 | SetBrowserX11ErrorHandlers(); |
| 1227 | #endif |
| 1228 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1229 | // Desktop construction occurs here, (required before profile creation). |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 1230 | PreProfileInit(); |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1231 | |
[email protected] | ec79ca6 | 2012-11-16 01:16:51 | [diff] [blame] | 1232 | std::string try_chrome = |
| 1233 | parsed_command_line().GetSwitchValueASCII(switches::kTryChromeAgain); |
| 1234 | if (!try_chrome.empty()) { |
| 1235 | #if defined(OS_WIN) |
| 1236 | // Setup.exe has determined that we need to run a retention experiment |
[email protected] | 622b764c | 2012-12-04 15:24:00 | [diff] [blame] | 1237 | // and has lauched chrome to show the experiment UI. It is guaranteed that |
| 1238 | // no other Chrome is currently running as the process singleton was |
| 1239 | // sucessfully grabbed above. |
[email protected] | ec79ca6 | 2012-11-16 01:16:51 | [diff] [blame] | 1240 | int try_chrome_int; |
| 1241 | base::StringToInt(try_chrome, &try_chrome_int); |
| 1242 | TryChromeDialogView::Result answer = |
| 1243 | TryChromeDialogView::Show(try_chrome_int, process_singleton_.get()); |
| 1244 | if (answer == TryChromeDialogView::NOT_NOW) |
| 1245 | return chrome::RESULT_CODE_NORMAL_EXIT_CANCEL; |
| 1246 | if (answer == TryChromeDialogView::UNINSTALL_CHROME) |
| 1247 | return chrome::RESULT_CODE_NORMAL_EXIT_EXP2; |
| 1248 | // At this point the user is willing to try chrome again. |
| 1249 | if (answer == TryChromeDialogView::TRY_CHROME_AS_DEFAULT) { |
| 1250 | // Only set in the unattended case, the interactive case is Windows 8. |
| 1251 | if (ShellIntegration::CanSetAsDefaultBrowser() == |
| 1252 | ShellIntegration::SET_DEFAULT_UNATTENDED) |
| 1253 | ShellIntegration::SetAsDefaultBrowser(); |
| 1254 | } |
| 1255 | #else |
| 1256 | // We don't support retention experiments on Mac or Linux. |
| 1257 | return content::RESULT_CODE_NORMAL_EXIT; |
| 1258 | #endif // defined(OS_WIN) |
| 1259 | } |
| 1260 | |
[email protected] | 20271f3 | 2010-03-26 03:04:51 | [diff] [blame] | 1261 | // Profile creation ---------------------------------------------------------- |
[email protected] | 08e6f6d | 2009-12-14 17:42:12 | [diff] [blame] | 1262 | |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 1263 | if (do_first_run_tasks_) { |
[email protected] | d9126802 | 2011-08-26 13:17:37 | [diff] [blame] | 1264 | // Warn the ProfileManager that an import process will run, possibly |
| 1265 | // locking the WebDataService directory of the next Profile created. |
[email protected] | 17e6cde5 | 2012-01-05 00:16:57 | [diff] [blame] | 1266 | browser_process_->profile_manager()->SetWillImport(); |
[email protected] | d9126802 | 2011-08-26 13:17:37 | [diff] [blame] | 1267 | } |
| 1268 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 1269 | profile_ = CreateProfile(parameters(), user_data_dir_, parsed_command_line()); |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1270 | if (!profile_) |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 1271 | return content::RESULT_CODE_NORMAL_EXIT; |
[email protected] | 20271f3 | 2010-03-26 03:04:51 | [diff] [blame] | 1272 | |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1273 | #if defined(ENABLE_BACKGROUND) |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 1274 | // Autoload any profiles which are running background apps. |
| 1275 | // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075. |
[email protected] | d6bbd293 | 2012-03-19 17:10:07 | [diff] [blame] | 1276 | browser_process_->profile_manager()->AutoloadProfiles(); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1277 | #endif |
[email protected] | 20271f3 | 2010-03-26 03:04:51 | [diff] [blame] | 1278 | // Post-profile init --------------------------------------------------------- |
[email protected] | 9acc4860 | 2009-11-30 21:18:51 | [diff] [blame] | 1279 | |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1280 | #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1281 | // Importing other browser settings is done in a browser-like process |
| 1282 | // that exits when this task has finished. |
[email protected] | 3ef4755e | 2010-09-27 20:25:04 | [diff] [blame] | 1283 | // TODO(port): Port the Mac's IPC-based implementation to other platforms to |
| 1284 | // replace this implementation. http://crbug.com/22142 |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 1285 | if (ProfileManager::IsImportProcess(parsed_command_line())) { |
[email protected] | 4b51615 | 2012-01-07 03:09:15 | [diff] [blame] | 1286 | return first_run::ImportNow(profile_, parsed_command_line()); |
[email protected] | 272709ca | 2010-04-01 00:24:47 | [diff] [blame] | 1287 | } |
[email protected] | 7da7f343 | 2009-10-28 20:12:08 | [diff] [blame] | 1288 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1289 | |
[email protected] | 04999e6 | 2009-09-25 01:27:31 | [diff] [blame] | 1290 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1291 | // Do the tasks if chrome has been upgraded while it was last running. |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1292 | if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line())) |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 1293 | return content::RESULT_CODE_NORMAL_EXIT; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1294 | |
[email protected] | 68c921f | 2008-10-15 21:37:46 | [diff] [blame] | 1295 | // Check if there is any machine level Chrome installed on the current |
| 1296 | // machine. If yes and the current Chrome process is user level, we do not |
| 1297 | // allow the user level Chrome to run. So we notify the user and uninstall |
| 1298 | // user level Chrome. |
| 1299 | // Note this check should only happen here, after all the checks above |
| 1300 | // (uninstall, resource bundle initialization, other chrome browser |
| 1301 | // processes etc). |
[email protected] | 6a7748e | 2011-05-27 16:44:31 | [diff] [blame] | 1302 | // Do not allow this to occur for Chrome Frame user-to-system handoffs. |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1303 | if (!parsed_command_line().HasSwitch(switches::kChromeFrame) && |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1304 | ChromeBrowserMainPartsWin::CheckMachineLevelInstall()) { |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 1305 | return chrome::RESULT_CODE_MACHINE_LEVEL_INSTALL_EXISTS; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1306 | } |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1307 | #endif |
[email protected] | 68c921f | 2008-10-15 21:37:46 | [diff] [blame] | 1308 | |
[email protected] | 7e0831b | 2010-02-01 08:45:15 | [diff] [blame] | 1309 | // Create the TranslateManager singleton. |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1310 | translate_manager_ = TranslateManager::GetInstance(); |
| 1311 | DCHECK(translate_manager_ != NULL); |
[email protected] | 7e0831b | 2010-02-01 08:45:15 | [diff] [blame] | 1312 | |
[email protected] | b16cc21 | 2013-02-06 21:09:51 | [diff] [blame] | 1313 | #if !defined(OS_ANDROID) |
[email protected] | a6c7a825 | 2012-06-25 18:28:24 | [diff] [blame] | 1314 | // Initialize Managed Mode. |
| 1315 | ManagedMode::Init(profile_); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1316 | #endif |
[email protected] | a6c7a825 | 2012-06-25 18:28:24 | [diff] [blame] | 1317 | |
[email protected] | d5656f1c | 2013-01-29 01:31:26 | [diff] [blame] | 1318 | // Needs to be done before PostProfileInit, since login manager on CrOS is |
| 1319 | // called inside PostProfileInit. |
| 1320 | content::WebUIControllerFactory::RegisterFactory( |
| 1321 | ChromeWebUIControllerFactory::GetInstance()); |
| 1322 | |
[email protected] | a6c7a825 | 2012-06-25 18:28:24 | [diff] [blame] | 1323 | // TODO(stevenjb): Move WIN and MACOSX specific code to appropriate Parts. |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 1324 | // (requires supporting early exit). |
| 1325 | PostProfileInit(); |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1326 | |
[email protected] | a9830b5 | 2012-12-17 23:30:36 | [diff] [blame] | 1327 | // Retrieve cached GL strings from local state and use them for GPU |
| 1328 | // blacklist decisions. |
| 1329 | if (g_browser_process->gl_string_manager()) |
| 1330 | g_browser_process->gl_string_manager()->Initialize(); |
| 1331 | |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1332 | #if !defined(OS_ANDROID) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1333 | // Show the First Run UI if this is the first time Chrome has been run on |
| 1334 | // this computer, or we're being compelled to do so by a command line flag. |
| 1335 | // Note that this be done _after_ the PrefService is initialized and all |
| 1336 | // preferences are registered, since some of the code that the importer |
| 1337 | // touches reads preferences. |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 1338 | if (do_first_run_tasks_) { |
| 1339 | first_run::AutoImport(profile_, |
| 1340 | master_prefs_->homepage_defined, |
| 1341 | master_prefs_->do_import_items, |
| 1342 | master_prefs_->dont_import_items, |
| 1343 | process_singleton_.get()); |
| 1344 | // Note: this can pop the first run consent dialog on linux. |
| 1345 | first_run::DoPostImportTasks(profile_, master_prefs_->make_chrome_default); |
[email protected] | 96fe2e2 | 2012-03-07 22:54:19 | [diff] [blame] | 1346 | |
[email protected] | 17e6cde5 | 2012-01-05 00:16:57 | [diff] [blame] | 1347 | browser_process_->profile_manager()->OnImportFinished(profile_); |
[email protected] | eed7325 | 2012-08-03 18:47:44 | [diff] [blame] | 1348 | |
[email protected] | 820a140 | 2012-08-09 23:13:51 | [diff] [blame] | 1349 | if (!master_prefs_->suppress_first_run_default_browser_prompt) { |
| 1350 | browser_creator_->set_show_main_browser_window( |
| 1351 | !chrome::ShowFirstRunDefaultBrowserPrompt(profile_)); |
| 1352 | } else { |
[email protected] | eed7325 | 2012-08-03 18:47:44 | [diff] [blame] | 1353 | browser_creator_->set_is_default_browser_dialog_suppressed(true); |
[email protected] | 820a140 | 2012-08-09 23:13:51 | [diff] [blame] | 1354 | } |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 1355 | } // if (do_first_run_tasks_) |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1356 | #endif // !defined(OS_ANDROID) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1357 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1358 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1359 | // Sets things up so that if we crash from this point on, a dialog will |
| 1360 | // popup asking the user to restart chrome. It is done this late to avoid |
| 1361 | // testing against a bunch of special cases that are taken care early on. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1362 | ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment( |
| 1363 | parsed_command_line()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1364 | |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 1365 | // Registers Chrome with the Windows Restart Manager, which will restore the |
| 1366 | // Chrome session when the computer is restarted after a system update. |
| 1367 | // This could be run as late as WM_QUERYENDSESSION for system update reboots, |
| 1368 | // but should run on startup if extended to handle crashes/hangs/patches. |
| 1369 | // Also, better to run once here than once for each HWND's WM_QUERYENDSESSION. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1370 | if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 1371 | ChromeBrowserMainPartsWin::RegisterApplicationRestart( |
| 1372 | parsed_command_line()); |
| 1373 | } |
[email protected] | a442280 | 2012-05-03 09:19:15 | [diff] [blame] | 1374 | |
| 1375 | // Verify that the profile is not on a network share and if so prepare to show |
| 1376 | // notification to the user. |
[email protected] | 297fb7c2 | 2012-06-26 12:37:49 | [diff] [blame] | 1377 | if (NetworkProfileBubble::ShouldCheckNetworkProfile(profile_)) { |
[email protected] | 4d0f173 | 2012-06-25 17:55:20 | [diff] [blame] | 1378 | content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, |
[email protected] | 115dcfe | 2012-11-01 22:32:50 | [diff] [blame] | 1379 | base::Bind(&NetworkProfileBubble::CheckNetworkProfile, |
| 1380 | profile_->GetPath())); |
[email protected] | a442280 | 2012-05-03 09:19:15 | [diff] [blame] | 1381 | } |
[email protected] | 81d9b72d | 2012-03-26 22:29:17 | [diff] [blame] | 1382 | #endif // OS_WIN |
[email protected] | 0fd23af | 2011-02-20 06:33:04 | [diff] [blame] | 1383 | |
[email protected] | e625c3b2 | 2012-11-16 14:55:39 | [diff] [blame] | 1384 | #if defined(ENABLE_RLZ) && !defined(OS_CHROMEOS) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1385 | // Init the RLZ library. This just binds the dll and schedules a task on the |
| 1386 | // file thread to be run sometime later. If this is the first run we record |
| 1387 | // the installation event. |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1388 | PrefService* pref_service = profile_->GetPrefs(); |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 1389 | int ping_delay = do_first_run_tasks_ ? master_prefs_->ping_delay : |
[email protected] | 1b3588d | 2012-10-10 21:17:25 | [diff] [blame] | 1390 | pref_service->GetInteger(first_run::GetPingDelayPrefName().c_str()); |
[email protected] | 99de6a5 | 2012-12-25 13:08:41 | [diff] [blame] | 1391 | // Negative ping delay means to send ping immediately after a first search is |
| 1392 | // recorded. |
| 1393 | RLZTracker::InitRlzFromProfileDelayed( |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 1394 | profile_, do_first_run_tasks_, ping_delay < 0, |
[email protected] | 99de6a5 | 2012-12-25 13:08:41 | [diff] [blame] | 1395 | base::TimeDelta::FromMilliseconds(abs(ping_delay))); |
[email protected] | e625c3b2 | 2012-11-16 14:55:39 | [diff] [blame] | 1396 | #endif // defined(ENABLE_RLZ) && !defined(OS_CHROMEOS) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1397 | |
[email protected] | a12f7fb | 2011-01-20 18:21:08 | [diff] [blame] | 1398 | // Configure modules that need access to resources. |
[email protected] | 64d50ed | 2009-09-22 21:05:47 | [diff] [blame] | 1399 | net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1400 | |
[email protected] | 3dd1f6d5 | 2008-09-15 18:28:09 | [diff] [blame] | 1401 | // In unittest mode, this will do nothing. In normal mode, this will create |
[email protected] | 665fa01 | 2012-05-09 00:24:38 | [diff] [blame] | 1402 | // the global IntranetRedirectDetector instance, which will promptly go to |
| 1403 | // sleep for seven seconds (to avoid slowing startup), and wake up afterwards |
| 1404 | // to see if it should do anything else. |
[email protected] | 3dd1f6d5 | 2008-09-15 18:28:09 | [diff] [blame] | 1405 | // |
| 1406 | // A simpler way of doing all this would be to have some function which could |
[email protected] | 665fa01 | 2012-05-09 00:24:38 | [diff] [blame] | 1407 | // give the time elapsed since startup, and simply have this object check that |
| 1408 | // when asked to initialize itself, but this doesn't seem to exist. |
[email protected] | 3dd1f6d5 | 2008-09-15 18:28:09 | [diff] [blame] | 1409 | // |
[email protected] | 665fa01 | 2012-05-09 00:24:38 | [diff] [blame] | 1410 | // This can't be created in the BrowserProcessImpl constructor because it |
| 1411 | // needs to read prefs that get set after that runs. |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1412 | browser_process_->intranet_redirect_detector(); |
[email protected] | ed66656 | 2012-03-21 19:49:52 | [diff] [blame] | 1413 | GoogleSearchCounter::RegisterForNotifications(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1414 | |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 1415 | // Disable SDCH filtering if switches::kEnableSdch is 0. |
| 1416 | int sdch_enabled = 1; |
| 1417 | if (parsed_command_line().HasSwitch(switches::kEnableSdch)) { |
| 1418 | base::StringToInt(parsed_command_line().GetSwitchValueASCII( |
| 1419 | switches::kEnableSdch), &sdch_enabled); |
| 1420 | if (!sdch_enabled) |
| 1421 | net::SdchManager::EnableSdchSupport(false); |
| 1422 | } |
| 1423 | if (sdch_enabled) { |
| 1424 | // Perform A/B test to measure global impact of SDCH support. |
| 1425 | // Set up a field trial to see what disabling SDCH does to latency of page |
| 1426 | // layout globally. |
| 1427 | base::FieldTrial::Probability kSDCH_DIVISOR = 1000; |
| 1428 | base::FieldTrial::Probability kSDCH_DISABLE_PROBABILITY = 1; // 0.1% prob. |
| 1429 | // After March 31, 2012 builds, it will always be in default group. |
[email protected] | 2d472958 | 2012-04-12 07:08:07 | [diff] [blame] | 1430 | int sdch_enabled_group = -1; |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 1431 | scoped_refptr<base::FieldTrial> sdch_trial( |
[email protected] | 2d472958 | 2012-04-12 07:08:07 | [diff] [blame] | 1432 | base::FieldTrialList::FactoryGetFieldTrial( |
| 1433 | "GlobalSdch", kSDCH_DIVISOR, "global_enable_sdch", 2012, 3, 31, |
| 1434 | &sdch_enabled_group)); |
[email protected] | e695fbd6 | 2009-06-30 16:31:54 | [diff] [blame] | 1435 | |
[email protected] | 58d2d2d | 2010-08-05 22:46:33 | [diff] [blame] | 1436 | sdch_trial->AppendGroup("global_disable_sdch", |
[email protected] | e12d5059 | 2010-01-06 17:35:19 | [diff] [blame] | 1437 | kSDCH_DISABLE_PROBABILITY); |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 1438 | if (sdch_enabled_group != sdch_trial->group()) |
| 1439 | net::SdchManager::EnableSdchSupport(false); |
[email protected] | 6088942 | 2008-09-23 01:18:16 | [diff] [blame] | 1440 | } |
[email protected] | e695fbd6 | 2009-06-30 16:31:54 | [diff] [blame] | 1441 | |
[email protected] | b7672d1 | 2011-11-06 03:19:00 | [diff] [blame] | 1442 | if (parsed_command_line().HasSwitch(switches::kEnableWatchdog)) |
| 1443 | InstallJankometer(parsed_command_line()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1444 | |
[email protected] | e1504d8 | 2009-07-03 15:27:15 | [diff] [blame] | 1445 | #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1446 | if (parsed_command_line().HasSwitch(switches::kDebugPrint)) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1447 | base::FilePath path = |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1448 | parsed_command_line().GetSwitchValuePath(switches::kDebugPrint); |
[email protected] | d9d4299 | 2010-09-13 19:39:19 | [diff] [blame] | 1449 | printing::PrintedDocument::set_debug_dump_path(path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1450 | } |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 1451 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1452 | |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1453 | HandleTestParameters(parsed_command_line()); |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 1454 | RecordBreakpadStatusUMA(browser_process_->metrics_service()); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 1455 | about_flags::RecordUMAStatistics(local_state_); |
[email protected] | 703369a | 2012-11-05 20:40:31 | [diff] [blame] | 1456 | #if defined(ENABLE_LANGUAGE_DETECTION) |
[email protected] | 0426103 | 2011-07-21 08:42:08 | [diff] [blame] | 1457 | LanguageUsageMetrics::RecordAcceptLanguages( |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1458 | profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
[email protected] | 0426103 | 2011-07-21 08:42:08 | [diff] [blame] | 1459 | LanguageUsageMetrics::RecordApplicationLanguage( |
[email protected] | 17e6cde5 | 2012-01-05 00:16:57 | [diff] [blame] | 1460 | browser_process_->GetApplicationLocale()); |
[email protected] | 703369a | 2012-11-05 20:40:31 | [diff] [blame] | 1461 | #endif |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 1462 | |
[email protected] | 8988665 | 2012-12-11 18:09:07 | [diff] [blame] | 1463 | // Querying the default browser state can be slow, do it in the background. |
| 1464 | BrowserThread::GetBlockingPool()->PostDelayedTask( |
| 1465 | FROM_HERE, |
| 1466 | base::Bind(&RecordDefaultBrowserUMAStat), |
| 1467 | base::TimeDelta::FromSeconds(5)); |
| 1468 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 1469 | // The extension service may be available at this point. If the command line |
| 1470 | // specifies --uninstall-extension, attempt the uninstall extension startup |
| 1471 | // action. |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1472 | if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) { |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 1473 | extensions::StartupHelper extension_startup_helper; |
| 1474 | if (extension_startup_helper.UninstallExtension( |
| 1475 | parsed_command_line(), profile_)) |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 1476 | return content::RESULT_CODE_NORMAL_EXIT; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1477 | return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 1478 | } |
| 1479 | |
[email protected] | 08f1c5e | 2011-12-01 01:54:34 | [diff] [blame] | 1480 | // Start watching for hangs during startup. We disarm this hang detector when |
| 1481 | // ThreadWatcher takes over or when browser is shutdown or when |
| 1482 | // startup_watcher_ is deleted. |
| 1483 | startup_watcher_->Arm(base::TimeDelta::FromSeconds(300)); |
| 1484 | |
[email protected] | 84c384e | 2013-03-01 23:20:19 | [diff] [blame] | 1485 | // On mobile, need for clean shutdown arises only when the application comes |
| 1486 | // to foreground (i.e. MetricsService::OnAppEnterForeground is called). |
| 1487 | // http://crbug.com/179143 |
| 1488 | #if !defined(OS_ANDROID) |
[email protected] | c0c55e9 | 2011-09-10 18:47:30 | [diff] [blame] | 1489 | // Start watching for a hang. |
| 1490 | MetricsService::LogNeedForCleanShutdown(); |
[email protected] | 84c384e | 2013-03-01 23:20:19 | [diff] [blame] | 1491 | #endif |
[email protected] | c0c55e9 | 2011-09-10 18:47:30 | [diff] [blame] | 1492 | |
[email protected] | 15406b6a | 2010-04-21 00:35:01 | [diff] [blame] | 1493 | #if defined(OS_WIN) |
[email protected] | 8a9c63e | 2010-04-19 21:27:55 | [diff] [blame] | 1494 | // We check this here because if the profile is OTR (chromeos possibility) |
| 1495 | // it won't still be accessible after browser is destroyed. |
[email protected] | 3f002a3 | 2013-01-02 17:52:38 | [diff] [blame] | 1496 | record_search_engine_ = do_first_run_tasks_ && !profile_->IsOffTheRecord(); |
[email protected] | 15406b6a | 2010-04-21 00:35:01 | [diff] [blame] | 1497 | #endif |
[email protected] | 8a9c63e | 2010-04-19 21:27:55 | [diff] [blame] | 1498 | |
[email protected] | 17543d6 | 2010-10-07 22:37:38 | [diff] [blame] | 1499 | // Create the instance of the cloud print proxy service so that it can launch |
| 1500 | // the service process if needed. This is needed because the service process |
| 1501 | // might have shutdown because an update was available. |
[email protected] | 17cefaaf | 2011-08-02 14:42:58 | [diff] [blame] | 1502 | // TODO(torne): this should maybe be done with |
| 1503 | // ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead? |
[email protected] | 058e573 | 2012-03-01 22:48:03 | [diff] [blame] | 1504 | #if !defined(OS_ANDROID) |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1505 | CloudPrintProxyServiceFactory::GetForProfile(profile_); |
[email protected] | 058e573 | 2012-03-01 22:48:03 | [diff] [blame] | 1506 | #endif |
[email protected] | 17543d6 | 2010-10-07 22:37:38 | [diff] [blame] | 1507 | |
[email protected] | dedfabae | 2011-03-04 04:00:40 | [diff] [blame] | 1508 | // Start watching all browser threads for responsiveness. |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1509 | ThreadWatcherList::StartWatchingAll(parsed_command_line()); |
[email protected] | dedfabae | 2011-03-04 04:00:40 | [diff] [blame] | 1510 | |
[email protected] | 773ebb9 | 2011-11-15 19:06:52 | [diff] [blame] | 1511 | #if !defined(DISABLE_NACL) |
[email protected] | b1511ab0 | 2012-07-02 23:45:51 | [diff] [blame] | 1512 | if (parsed_command_line().HasSwitch(switches::kPnaclDir)) { |
| 1513 | PathService::Override(chrome::DIR_PNACL_BASE, |
| 1514 | parsed_command_line().GetSwitchValuePath( |
| 1515 | switches::kPnaclDir)); |
| 1516 | } |
[email protected] | 773ebb9 | 2011-11-15 19:06:52 | [diff] [blame] | 1517 | NaClProcessHost::EarlyStartup(); |
| 1518 | #endif |
| 1519 | |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 1520 | PreBrowserStart(); |
| 1521 | |
[email protected] | 08745329 | 2011-11-22 00:43:12 | [diff] [blame] | 1522 | // Instantiate the notification UI manager, as this triggers a perf timer |
| 1523 | // used to measure startup time. TODO(stevenjb): Figure out what is actually |
| 1524 | // triggering the timer and call that explicitly in the approprate place. |
| 1525 | // http://crbug.com/105065. |
[email protected] | 17e6cde5 | 2012-01-05 00:16:57 | [diff] [blame] | 1526 | browser_process_->notification_ui_manager(); |
[email protected] | 08745329 | 2011-11-22 00:43:12 | [diff] [blame] | 1527 | |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1528 | #if !defined(OS_ANDROID) |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1529 | // Most general initialization is behind us, but opening a |
| 1530 | // tab and/or session restore and such is still to be done. |
| 1531 | base::TimeTicks browser_open_start = base::TimeTicks::Now(); |
[email protected] | 45d7276 | 2011-04-15 18:58:20 | [diff] [blame] | 1532 | |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1533 | // We are in regular browser boot sequence. Open initial tabs and enter the |
| 1534 | // main message loop. |
| 1535 | int result_code; |
[email protected] | a64ad24 | 2012-01-18 15:17:36 | [diff] [blame] | 1536 | #if defined(OS_CHROMEOS) |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1537 | // On ChromeOS multiple profiles doesn't apply, and will break if we load |
| 1538 | // them this early as the cryptohome hasn't yet been mounted (which happens |
| 1539 | // only once we log in. |
| 1540 | std::vector<Profile*> last_opened_profiles; |
[email protected] | a64ad24 | 2012-01-18 15:17:36 | [diff] [blame] | 1541 | #else |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1542 | std::vector<Profile*> last_opened_profiles = |
| 1543 | g_browser_process->profile_manager()->GetLastOpenedProfiles(); |
[email protected] | a64ad24 | 2012-01-18 15:17:36 | [diff] [blame] | 1544 | #endif |
[email protected] | aec25bc | 2012-10-04 18:45:26 | [diff] [blame] | 1545 | |
[email protected] | 8cebc94 | 2013-01-31 01:28:42 | [diff] [blame] | 1546 | if (!parsed_command_line().HasSwitch(switches::kDisableComponentUpdate)) |
| 1547 | RegisterComponentsForUpdate(parsed_command_line()); |
| 1548 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1549 | if (browser_creator_->Start(parsed_command_line(), base::FilePath(), |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1550 | profile_, last_opened_profiles, &result_code)) { |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 1551 | #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1552 | // Initialize autoupdate timer. Timer callback costs basically nothing |
| 1553 | // when browser is not in persistent mode, so it's OK to let it ride on |
| 1554 | // the main thread. This needs to be done here because we don't want |
| 1555 | // to start the timer when Chrome is run inside a test harness. |
| 1556 | browser_process_->StartAutoupdateTimer(); |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1557 | #endif |
| 1558 | |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 1559 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1560 | // On Linux, the running exe will be updated if an upgrade becomes |
| 1561 | // available while the browser is running. We need to save the last |
| 1562 | // modified time of the exe, so we can compare to determine if there is |
| 1563 | // an upgrade while the browser is kept alive by a persistent extension. |
| 1564 | upgrade_util::SaveLastModifiedTimeOfExe(); |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 1565 | #endif |
| 1566 | |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1567 | // Record now as the last successful chrome start. |
| 1568 | GoogleUpdateSettings::SetLastRunTime(); |
[email protected] | badf5cf | 2011-10-29 03:44:44 | [diff] [blame] | 1569 | |
| 1570 | #if defined(OS_MACOSX) |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1571 | // Call Recycle() here as late as possible, before going into the loop |
| 1572 | // because Start() will add things to it while creating the main window. |
| 1573 | if (parameters().autorelease_pool) |
| 1574 | parameters().autorelease_pool->Recycle(); |
[email protected] | badf5cf | 2011-10-29 03:44:44 | [diff] [blame] | 1575 | #endif |
[email protected] | 45d7276 | 2011-04-15 18:58:20 | [diff] [blame] | 1576 | |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1577 | RecordPreReadExperimentTime("Startup.BrowserOpenTabs", |
| 1578 | base::TimeTicks::Now() - browser_open_start); |
[email protected] | 45d7276 | 2011-04-15 18:58:20 | [diff] [blame] | 1579 | |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1580 | // If we're running tests (ui_task is non-null), then we don't want to |
| 1581 | // call FetchLanguageListFromTranslateServer or |
[email protected] | 88bac3f | 2012-07-22 21:22:57 | [diff] [blame] | 1582 | // StartRepeatedVariationsSeedFetch. |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1583 | if (parameters().ui_task == NULL) { |
| 1584 | // Request new variations seed information from server. |
[email protected] | 58c63cb | 2012-11-26 19:22:11 | [diff] [blame] | 1585 | chrome_variations::VariationsService* variations_service = |
| 1586 | browser_process_->variations_service(); |
[email protected] | 92e669c | 2013-01-30 00:30:02 | [diff] [blame] | 1587 | if (variations_service) { |
[email protected] | 58c63cb | 2012-11-26 19:22:11 | [diff] [blame] | 1588 | variations_service->StartRepeatedVariationsSeedFetch(); |
| 1589 | |
[email protected] | 92e669c | 2013-01-30 00:30:02 | [diff] [blame] | 1590 | #if defined(OS_WIN) |
| 1591 | variations_service->StartGoogleUpdateRegistrySync(); |
| 1592 | #endif |
| 1593 | } |
| 1594 | |
[email protected] | d06ba124 | 2012-09-25 20:51:39 | [diff] [blame] | 1595 | #if !defined(OS_CHROMEOS) |
| 1596 | // TODO(mad): Move this call in a proper place on CrOS. |
| 1597 | // http://crosbug.com/17687 |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1598 | if (translate_manager_ != NULL) { |
| 1599 | translate_manager_->FetchLanguageListFromTranslateServer( |
| 1600 | profile_->GetPrefs()); |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 1601 | } |
[email protected] | bafa00e4 | 2011-07-18 14:47:26 | [diff] [blame] | 1602 | #endif |
[email protected] | d06ba124 | 2012-09-25 20:51:39 | [diff] [blame] | 1603 | } |
[email protected] | fa43697 | 2011-06-23 05:58:01 | [diff] [blame] | 1604 | |
[email protected] | 5b027af | 2012-06-21 18:32:53 | [diff] [blame] | 1605 | run_message_loop_ = true; |
| 1606 | } else { |
| 1607 | run_message_loop_ = false; |
| 1608 | } |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 1609 | browser_creator_.reset(); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1610 | #endif // !defined(OS_ANDROID) |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 1611 | |
[email protected] | b19e0e2e | 2013-02-06 18:15:51 | [diff] [blame] | 1612 | RecordTouchEventState(parsed_command_line()); |
| 1613 | |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 1614 | PostBrowserStart(); |
| 1615 | |
[email protected] | 886f114 | 2012-05-03 20:00:16 | [diff] [blame] | 1616 | if (parameters().ui_task) { |
[email protected] | 0c1c475 | 2012-08-09 20:30:24 | [diff] [blame] | 1617 | // We end the startup timer here if we have parameters to run, because we |
| 1618 | // never start to run the main loop (where we normally stop the timer). |
| 1619 | startup_timer_->SignalStartupComplete( |
| 1620 | performance_monitor::StartupTimer::STARTUP_TEST); |
[email protected] | 886f114 | 2012-05-03 20:00:16 | [diff] [blame] | 1621 | parameters().ui_task->Run(); |
| 1622 | delete parameters().ui_task; |
| 1623 | run_message_loop_ = false; |
| 1624 | } |
| 1625 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1626 | return result_code_; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1627 | } |
| 1628 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1629 | bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { |
[email protected] | 82d2c33 | 2012-08-07 22:46:31 | [diff] [blame] | 1630 | #if defined(OS_ANDROID) |
| 1631 | // Chrome on Android does not use default MessageLoop. It has its own |
| 1632 | // Android specific MessageLoop |
| 1633 | NOTREACHED(); |
| 1634 | return true; |
| 1635 | #else |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 1636 | // Set the result code set in PreMainMessageLoopRun or set above. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1637 | *result_code = result_code_; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1638 | if (!run_message_loop_) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1639 | return true; // Don't run the default message loop. |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1640 | |
[email protected] | 0c1c475 | 2012-08-09 20:30:24 | [diff] [blame] | 1641 | // These should be invoked as close to the start of the browser's |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1642 | // UI thread message loop as possible to get a stable measurement |
| 1643 | // across versions. |
| 1644 | RecordBrowserStartupTime(); |
[email protected] | 0c1c475 | 2012-08-09 20:30:24 | [diff] [blame] | 1645 | startup_timer_->SignalStartupComplete( |
| 1646 | performance_monitor::StartupTimer::STARTUP_NORMAL); |
| 1647 | |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 1648 | DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); |
| 1649 | #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS) |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1650 | views::AcceleratorHandler accelerator_handler; |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 1651 | base::RunLoop run_loop(&accelerator_handler); |
| 1652 | #else |
| 1653 | base::RunLoop run_loop; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1654 | #endif |
[email protected] | d378f19 | 2012-08-14 18:42:03 | [diff] [blame] | 1655 | |
| 1656 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 7fae4295 | 2012-09-05 21:25:27 | [diff] [blame] | 1657 | switches::kPerformanceMonitorGathering)) { |
[email protected] | d378f19 | 2012-08-14 18:42:03 | [diff] [blame] | 1658 | performance_monitor::PerformanceMonitor::GetInstance()->Start(); |
| 1659 | } |
| 1660 | |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 1661 | run_loop.Run(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1662 | |
| 1663 | return true; |
[email protected] | 82d2c33 | 2012-08-07 22:46:31 | [diff] [blame] | 1664 | #endif |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | void ChromeBrowserMainParts::PostMainMessageLoopRun() { |
[email protected] | 82d2c33 | 2012-08-07 22:46:31 | [diff] [blame] | 1668 | #if defined(OS_ANDROID) |
| 1669 | // Chrome on Android does not use default MessageLoop. It has its own |
| 1670 | // Android specific MessageLoop |
| 1671 | NOTREACHED(); |
| 1672 | #else |
[email protected] | 1dd7a8e | 2012-09-16 18:49:29 | [diff] [blame] | 1673 | |
| 1674 | #if defined(USE_X11) |
| 1675 | // Unset the X11 error handlers. The X11 error handlers log the errors using a |
| 1676 | // |PostTask()| on the message-loop. But since the message-loop is in the |
| 1677 | // process of terminating, this can cause errors. |
| 1678 | UnsetBrowserX11ErrorHandlers(); |
| 1679 | #endif |
| 1680 | |
[email protected] | 6d823b4 | 2011-09-05 02:54:02 | [diff] [blame] | 1681 | // Start watching for jank during shutdown. It gets disarmed when |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1682 | // |shutdown_watcher_| object is destructed. |
[email protected] | 56bdb71 | 2012-01-27 00:35:59 | [diff] [blame] | 1683 | shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(300)); |
[email protected] | 6d823b4 | 2011-09-05 02:54:02 | [diff] [blame] | 1684 | |
[email protected] | b6994152 | 2011-10-08 03:17:37 | [diff] [blame] | 1685 | // Disarm the startup hang detector time bomb if it is still Arm'ed. |
[email protected] | 08f1c5e | 2011-12-01 01:54:34 | [diff] [blame] | 1686 | startup_watcher_->Disarm(); |
[email protected] | b6994152 | 2011-10-08 03:17:37 | [diff] [blame] | 1687 | |
[email protected] | ef589af | 2011-12-03 01:07:15 | [diff] [blame] | 1688 | for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1689 | chrome_extra_parts_[i]->PostMainMessageLoopRun(); |
| 1690 | |
[email protected] | aec25bc | 2012-10-04 18:45:26 | [diff] [blame] | 1691 | #if !defined(OS_ANDROID) |
| 1692 | gpu_util::UninstallBrowserMonitor(); |
| 1693 | #endif |
| 1694 | |
[email protected] | 15406b6a | 2010-04-21 00:35:01 | [diff] [blame] | 1695 | #if defined(OS_WIN) |
[email protected] | 2381ed2 | 2012-01-26 04:05:29 | [diff] [blame] | 1696 | // Log the search engine chosen on first run. Do this at shutdown, after any |
| 1697 | // changes are made from the first run bubble link, etc. |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1698 | if (record_search_engine_) { |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 1699 | TemplateURLService* url_service = |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1700 | TemplateURLServiceFactory::GetForProfile(profile_); |
[email protected] | 96b3c5c | 2010-04-16 20:30:14 | [diff] [blame] | 1701 | const TemplateURL* default_search_engine = |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 1702 | url_service->GetDefaultSearchProvider(); |
[email protected] | 32cba2b | 2010-10-19 06:19:48 | [diff] [blame] | 1703 | // The default engine can be NULL if the administrator has disabled |
| 1704 | // default search. |
[email protected] | 2387290 | 2010-10-26 03:43:59 | [diff] [blame] | 1705 | SearchEngineType search_engine_type = |
[email protected] | 360ba05 | 2012-04-04 17:26:13 | [diff] [blame] | 1706 | TemplateURLPrepopulateData::GetEngineType(default_search_engine ? |
| 1707 | default_search_engine->url() : std::string()); |
[email protected] | bf7eb2f9 | 2010-06-28 22:55:55 | [diff] [blame] | 1708 | // Record the search engine chosen. |
[email protected] | b37bdfe | 2012-03-16 20:53:27 | [diff] [blame] | 1709 | UMA_HISTOGRAM_ENUMERATION("Chrome.SearchSelectExempt", search_engine_type, |
[email protected] | 2381ed2 | 2012-01-26 04:05:29 | [diff] [blame] | 1710 | SEARCH_ENGINE_MAX); |
[email protected] | 96b3c5c | 2010-04-16 20:30:14 | [diff] [blame] | 1711 | } |
[email protected] | 15406b6a | 2010-04-21 00:35:01 | [diff] [blame] | 1712 | #endif |
[email protected] | 96b3c5c | 2010-04-16 20:30:14 | [diff] [blame] | 1713 | |
[email protected] | a6e9dce2 | 2011-06-25 00:19:22 | [diff] [blame] | 1714 | // Some tests don't set parameters.ui_task, so they started translate |
| 1715 | // language fetch that was never completed so we need to cleanup here |
| 1716 | // otherwise it will be done by the destructor in a wrong thread. |
[email protected] | 716476c | 2011-12-29 00:07:03 | [diff] [blame] | 1717 | if (parameters().ui_task == NULL && translate_manager_ != NULL) |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1718 | translate_manager_->CleanupPendingUlrFetcher(); |
[email protected] | a6e9dce2 | 2011-06-25 00:19:22 | [diff] [blame] | 1719 | |
[email protected] | 6601392 | 2011-09-13 18:53:42 | [diff] [blame] | 1720 | if (notify_result_ == ProcessSingleton::PROCESS_NONE) |
| 1721 | process_singleton_->Cleanup(); |
[email protected] | 9f20a6d0 | 2009-08-21 01:18:37 | [diff] [blame] | 1722 | |
[email protected] | 0b56518 | 2011-03-02 18:11:15 | [diff] [blame] | 1723 | // Stop all tasks that might run on WatchDogThread. |
| 1724 | ThreadWatcherList::StopWatchingAll(); |
| 1725 | |
[email protected] | 17e6cde5 | 2012-01-05 00:16:57 | [diff] [blame] | 1726 | browser_process_->metrics_service()->Stop(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1727 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 1728 | restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop(); |
| 1729 | browser_process_->StartTearDown(); |
[email protected] | 82d2c33 | 2012-08-07 22:46:31 | [diff] [blame] | 1730 | #endif |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 1731 | } |
| 1732 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 1733 | void ChromeBrowserMainParts::PostDestroyThreads() { |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1734 | #if defined(OS_ANDROID) |
| 1735 | // On Android, there is no quit/exit. So the browser's main message loop will |
| 1736 | // not finish. |
| 1737 | NOTREACHED(); |
| 1738 | #else |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 1739 | browser_process_->PostDestroyThreads(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1740 | // browser_shutdown takes care of deleting browser_process, so we need to |
| 1741 | // release it. |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1742 | ignore_result(browser_process_.release()); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 1743 | browser_shutdown::ShutdownPostThreadsStop(restart_last_session_); |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1744 | master_prefs_.reset(); |
| 1745 | process_singleton_.reset(); |
[email protected] | c0c55e9 | 2011-09-10 18:47:30 | [diff] [blame] | 1746 | |
| 1747 | // We need to do this check as late as possible, but due to modularity, this |
| 1748 | // may be the last point in Chrome. This would be more effective if done at |
| 1749 | // a higher level on the stack, so that it is impossible for an early return |
| 1750 | // to bypass this code. Perhaps we need a *final* hook that is called on all |
| 1751 | // paths from content/browser/browser_main. |
| 1752 | CHECK(MetricsService::UmaMetricsProperlyShutdown()); |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 1753 | #endif |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 1754 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1755 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1756 | // Public members: |
| 1757 | |
| 1758 | void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
| 1759 | chrome_extra_parts_.push_back(parts); |
| 1760 | } |
| 1761 | |
| 1762 | // Misc ------------------------------------------------------------------------ |
| 1763 | |
[email protected] | 843bc46 | 2012-06-19 17:43:31 | [diff] [blame] | 1764 | void RecordBrowserStartupTime() { |
[email protected] | 54676d0e | 2012-10-24 10:28:30 | [diff] [blame] | 1765 | // Don't record any metrics if UI was displayed before this point e.g. |
| 1766 | // warning dialogs. |
| 1767 | if (startup_metric_utils::WasNonBrowserUIDisplayed()) |
| 1768 | return; |
| 1769 | |
[email protected] | 843bc46 | 2012-06-19 17:43:31 | [diff] [blame] | 1770 | // CurrentProcessInfo::CreationTime() is currently only implemented on Mac and |
| 1771 | // Windows. |
| 1772 | #if defined(OS_MACOSX) || defined(OS_WIN) |
| 1773 | const base::Time *process_creation_time = |
| 1774 | base::CurrentProcessInfo::CreationTime(); |
| 1775 | |
| 1776 | if (process_creation_time) |
| 1777 | RecordPreReadExperimentTime("Startup.BrowserMessageLoopStartTime", |
| 1778 | base::Time::Now() - *process_creation_time); |
| 1779 | #endif // OS_MACOSX || OS_WIN |
[email protected] | 54676d0e | 2012-10-24 10:28:30 | [diff] [blame] | 1780 | |
[email protected] | 40c4f41 | 2013-01-15 06:35:57 | [diff] [blame] | 1781 | // Record collected startup metrics. |
| 1782 | startup_metric_utils::OnBrowserStartupComplete(); |
[email protected] | e327c75 | 2013-01-30 11:38:16 | [diff] [blame] | 1783 | |
| 1784 | // Deletes self. |
| 1785 | new LoadCompleteListener(); |
[email protected] | 843bc46 | 2012-06-19 17:43:31 | [diff] [blame] | 1786 | } |
| 1787 | |
[email protected] | 28f576f | 2011-08-26 20:46:55 | [diff] [blame] | 1788 | // This code is specific to the Windows-only PreReadExperiment field-trial. |
| 1789 | void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) { |
| 1790 | DCHECK(name != NULL); |
| 1791 | |
| 1792 | // This gets called with different histogram names, so we don't want to use |
| 1793 | // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the |
| 1794 | // first call wins. |
| 1795 | AddPreReadHistogramTime(name, time); |
| 1796 | |
| 1797 | #if defined(OS_WIN) |
[email protected] | 5bca9ee | 2011-09-03 00:18:42 | [diff] [blame] | 1798 | #if defined(GOOGLE_CHROME_BUILD) |
| 1799 | // The pre-read experiment is Windows and Google Chrome specific. |
[email protected] | 28f576f | 2011-08-26 20:46:55 | [diff] [blame] | 1800 | scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 1801 | |
| 1802 | // Only record the sub-histogram result if the experiment is running |
| 1803 | // (environment variable is set, and valid). |
[email protected] | 48078e5 | 2012-02-09 00:02:26 | [diff] [blame] | 1804 | std::string pre_read_percentage; |
| 1805 | if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read_percentage)) { |
[email protected] | 28f576f | 2011-08-26 20:46:55 | [diff] [blame] | 1806 | std::string uma_name(name); |
[email protected] | ff5ce237 | 2011-12-21 02:00:59 | [diff] [blame] | 1807 | |
| 1808 | // We want XP to record a separate histogram, as the loader on XP |
| 1809 | // is very different from the Vista and Win7 loaders. |
| 1810 | if (base::win::GetVersion() <= base::win::VERSION_XP) |
| 1811 | uma_name += "_XP"; |
| 1812 | |
[email protected] | 48078e5 | 2012-02-09 00:02:26 | [diff] [blame] | 1813 | uma_name += "_PreRead_"; |
| 1814 | uma_name += pre_read_percentage; |
[email protected] | 28f576f | 2011-08-26 20:46:55 | [diff] [blame] | 1815 | AddPreReadHistogramTime(uma_name.c_str(), time); |
| 1816 | } |
| 1817 | #endif |
[email protected] | 5bca9ee | 2011-09-03 00:18:42 | [diff] [blame] | 1818 | #endif |
[email protected] | 28f576f | 2011-08-26 20:46:55 | [diff] [blame] | 1819 | } |