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