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