[email protected] | f2a893c | 2011-01-05 09:38:07 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | |
| 5 | #include "chrome/browser/browser_process_impl.h" |
| 6 | |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 7 | #include <map> |
| 8 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | #include "base/command_line.h" |
[email protected] | 6641bf66 | 2009-08-21 00:34:09 | [diff] [blame] | 10 | #include "base/file_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | #include "base/path_service.h" |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 12 | #include "base/synchronization/waitable_event.h" |
[email protected] | c6032e8 | 2010-09-13 20:06:05 | [diff] [blame] | 13 | #include "base/task.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 14 | #include "base/threading/thread.h" |
| 15 | #include "base/threading/thread_restrictions.h" |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 16 | #include "chrome/browser/automation/automation_provider_list.h" |
[email protected] | b443cb04 | 2009-12-15 22:05:09 | [diff] [blame] | 17 | #include "chrome/browser/browser_main.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 18 | #include "chrome/browser/browser_process_sub_thread.h" |
[email protected] | ac262c9f | 2008-10-19 17:45:21 | [diff] [blame] | 19 | #include "chrome/browser/browser_trial.h" |
[email protected] | 9678cb4 | 2011-01-31 18:49:42 | [diff] [blame] | 20 | #include "chrome/browser/debugger/browser_list_tabcontents_provider.h" |
[email protected] | 5613126e | 2011-01-31 15:27:55 | [diff] [blame] | 21 | #include "chrome/browser/debugger/devtools_http_protocol_handler.h" |
[email protected] | 40ecc90 | 2009-03-16 13:42:47 | [diff] [blame] | 22 | #include "chrome/browser/debugger/devtools_manager.h" |
[email protected] | 5613126e | 2011-01-31 15:27:55 | [diff] [blame] | 23 | #include "chrome/browser/debugger/devtools_protocol_handler.h" |
[email protected] | 6c69796d | 2010-07-16 21:41:16 | [diff] [blame] | 24 | #include "chrome/browser/download/download_file_manager.h" |
[email protected] | 5ba0a2c | 2009-02-19 01:19:34 | [diff] [blame] | 25 | #include "chrome/browser/download/save_file_manager.h" |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 26 | #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
[email protected] | fc4facd | 2011-03-22 23:18:50 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_tab_id_map.h" |
[email protected] | 21453884 | 2011-04-01 18:47:24 | [diff] [blame] | 28 | #include "chrome/browser/extensions/user_script_listener.h" |
[email protected] | 81585672 | 2011-04-13 17:19:19 | [diff] [blame] | 29 | #include "chrome/browser/first_run/upgrade_util.h" |
[email protected] | f7578f5 | 2010-08-30 22:22:49 | [diff] [blame] | 30 | #include "chrome/browser/google/google_url_tracker.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 31 | #include "chrome/browser/gpu_process_host_ui_shim.h" |
[email protected] | dcefa30 | 2009-05-20 00:24:39 | [diff] [blame] | 32 | #include "chrome/browser/icon_manager.h" |
[email protected] | c4ff495 | 2010-01-08 19:12:47 | [diff] [blame] | 33 | #include "chrome/browser/intranet_redirect_detector.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 34 | #include "chrome/browser/io_thread.h" |
[email protected] | dc6f496 | 2009-02-13 01:25:50 | [diff] [blame] | 35 | #include "chrome/browser/metrics/metrics_service.h" |
[email protected] | 0b56518 | 2011-03-02 18:11:15 | [diff] [blame] | 36 | #include "chrome/browser/metrics/thread_watcher.h" |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 37 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | 3530cd9 | 2010-06-27 06:22:01 | [diff] [blame] | 38 | #include "chrome/browser/net/predictor_api.h" |
[email protected] | d393a0fd | 2009-05-13 23:32:01 | [diff] [blame] | 39 | #include "chrome/browser/net/sdch_dictionary_fetcher.h" |
[email protected] | 29672ab | 2009-10-30 03:44:03 | [diff] [blame] | 40 | #include "chrome/browser/notifications/notification_ui_manager.h" |
[email protected] | 6618d1d | 2010-12-15 21:18:47 | [diff] [blame] | 41 | #include "chrome/browser/plugin_data_remover.h" |
[email protected] | 492d214 | 2010-09-10 13:55:18 | [diff] [blame] | 42 | #include "chrome/browser/plugin_updater.h" |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 43 | #include "chrome/browser/policy/browser_policy_connector.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 44 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | e06131d | 2010-02-10 18:40:33 | [diff] [blame] | 45 | #include "chrome/browser/printing/print_job_manager.h" |
[email protected] | dbeebd5 | 2010-11-16 20:34:16 | [diff] [blame] | 46 | #include "chrome/browser/printing/print_preview_tab_controller.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 47 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | a7a5e99 | 2010-12-09 23:39:51 | [diff] [blame] | 48 | #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
[email protected] | 81218f4 | 2009-02-05 18:48:08 | [diff] [blame] | 49 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
[email protected] | e450fa6 | 2011-02-01 12:52:56 | [diff] [blame] | 50 | #include "chrome/browser/shell_integration.h" |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 51 | #include "chrome/browser/sidebar/sidebar_manager.h" |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 52 | #include "chrome/browser/tab_closeable_state_watcher.h" |
[email protected] | 71b73f0 | 2011-04-06 15:57:29 | [diff] [blame] | 53 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 4ef795df | 2010-02-03 02:35:08 | [diff] [blame] | 54 | #include "chrome/common/chrome_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 55 | #include "chrome/common/chrome_paths.h" |
| 56 | #include "chrome/common/chrome_switches.h" |
[email protected] | f1b6de2 | 2010-03-06 12:13:47 | [diff] [blame] | 57 | #include "chrome/common/extensions/extension_l10n_util.h" |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 58 | #include "chrome/common/extensions/extension_resource.h" |
[email protected] | ea587b0 | 2010-05-21 15:01:35 | [diff] [blame] | 59 | #include "chrome/common/json_pref_store.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 60 | #include "chrome/common/pref_names.h" |
[email protected] | 5c08f22 | 2010-09-22 09:37:21 | [diff] [blame] | 61 | #include "chrome/common/switch_utils.h" |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 62 | #include "chrome/common/url_constants.h" |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 63 | #include "chrome/installer/util/google_update_constants.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 64 | #include "content/browser/browser_child_process_host.h" |
| 65 | #include "content/browser/browser_thread.h" |
[email protected] | 419a057 | 2011-04-18 22:21:46 | [diff] [blame] | 66 | #include "content/browser/child_process_security_policy.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 67 | #include "content/browser/plugin_service.h" |
| 68 | #include "content/browser/renderer_host/render_process_host.h" |
| 69 | #include "content/browser/renderer_host/resource_dispatcher_host.h" |
[email protected] | f20d733 | 2011-03-08 21:11:53 | [diff] [blame] | 70 | #include "content/common/notification_service.h" |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 71 | #include "ipc/ipc_logging.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 72 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | 2dfeaf9 | 2011-01-10 21:08:21 | [diff] [blame] | 73 | #include "ui/base/clipboard/clipboard.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 74 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 4ef795df | 2010-02-03 02:35:08 | [diff] [blame] | 75 | #include "webkit/database/database_tracker.h" |
[email protected] | b112a4c | 2009-02-01 20:24:01 | [diff] [blame] | 76 | |
| 77 | #if defined(OS_WIN) |
[email protected] | 2362e4f | 2009-05-08 00:34:05 | [diff] [blame] | 78 | #include "views/focus/view_storage.h" |
[email protected] | 86230b9 | 2009-11-23 20:38:38 | [diff] [blame] | 79 | #endif |
| 80 | |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 81 | #if defined(IPC_MESSAGE_LOG_ENABLED) |
[email protected] | ff47b296 | 2011-03-07 23:51:49 | [diff] [blame] | 82 | #include "content/common/child_process_messages.h" |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 83 | #endif |
| 84 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 85 | #if defined(OS_CHROMEOS) |
| 86 | #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 87 | #endif // defined(OS_CHROMEOS) |
| 88 | |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 89 | #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| 90 | // How often to check if the persistent instance of Chrome needs to restart |
| 91 | // to install an update. |
| 92 | static const int kUpdateCheckIntervalHours = 6; |
| 93 | #endif |
| 94 | |
[email protected] | c6032e8 | 2010-09-13 20:06:05 | [diff] [blame] | 95 | #if defined(USE_X11) |
| 96 | // How long to wait for the File thread to complete during EndSession, on |
| 97 | // Linux. We have a timeout here because we're unable to run the UI messageloop |
| 98 | // and there's some deadlock risk. Our only option is to exit anyway. |
| 99 | static const int kEndSessionTimeoutSeconds = 10; |
| 100 | #endif |
| 101 | |
[email protected] | bb97536 | 2009-01-21 01:00:22 | [diff] [blame] | 102 | BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 103 | : created_resource_dispatcher_host_(false), |
| 104 | created_metrics_service_(false), |
| 105 | created_io_thread_(false), |
| 106 | created_file_thread_(false), |
| 107 | created_db_thread_(false), |
[email protected] | 91451171 | 2009-11-23 19:42:33 | [diff] [blame] | 108 | created_process_launcher_thread_(false), |
[email protected] | 875ee82 | 2010-05-18 20:58:01 | [diff] [blame] | 109 | created_cache_thread_(false), |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 110 | created_gpu_thread_(false), |
[email protected] | 0b56518 | 2011-03-02 18:11:15 | [diff] [blame] | 111 | created_watchdog_thread_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 112 | created_profile_manager_(false), |
| 113 | created_local_state_(false), |
[email protected] | b112a4c | 2009-02-01 20:24:01 | [diff] [blame] | 114 | created_icon_manager_(false), |
[email protected] | 40ecc90 | 2009-03-16 13:42:47 | [diff] [blame] | 115 | created_devtools_manager_(false), |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 116 | created_sidebar_manager_(false), |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 117 | created_browser_policy_connector_(false), |
[email protected] | 29672ab | 2009-10-30 03:44:03 | [diff] [blame] | 118 | created_notification_ui_manager_(false), |
[email protected] | a7a5e99 | 2010-12-09 23:39:51 | [diff] [blame] | 119 | created_safe_browsing_detection_service_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 120 | module_ref_count_(0), |
[email protected] | afd20c02 | 2010-06-10 00:48:20 | [diff] [blame] | 121 | did_start_(false), |
[email protected] | 1b2db1a | 2008-08-08 17:46:13 | [diff] [blame] | 122 | checked_for_new_frames_(false), |
[email protected] | 4747caf | 2011-03-23 20:09:21 | [diff] [blame] | 123 | using_new_frames_(false) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 124 | g_browser_process = this; |
[email protected] | 2dfeaf9 | 2011-01-10 21:08:21 | [diff] [blame] | 125 | clipboard_.reset(new ui::Clipboard); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 126 | main_notification_service_.reset(new NotificationService); |
| 127 | |
[email protected] | 6618d1d | 2010-12-15 21:18:47 | [diff] [blame] | 128 | notification_registrar_.Add(this, |
| 129 | NotificationType::APP_TERMINATING, |
| 130 | NotificationService::AllSources()); |
| 131 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 132 | // Must be created after the NotificationService. |
| 133 | print_job_manager_.reset(new printing::PrintJobManager); |
| 134 | |
[email protected] | b797e15 | 2009-01-23 16:06:14 | [diff] [blame] | 135 | shutdown_event_.reset(new base::WaitableEvent(true, false)); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 136 | |
| 137 | net_log_.reset(new ChromeNetLog); |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 138 | |
| 139 | extension_event_router_forwarder_ = new ExtensionEventRouterForwarder; |
[email protected] | fc4facd | 2011-03-22 23:18:50 | [diff] [blame] | 140 | |
| 141 | ExtensionTabIdMap::GetInstance()->Init(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | BrowserProcessImpl::~BrowserProcessImpl() { |
[email protected] | 4ef795df | 2010-02-03 02:35:08 | [diff] [blame] | 145 | FilePath profile_path; |
| 146 | bool clear_local_state_on_exit; |
| 147 | |
| 148 | // Store the profile path for clearing local state data on exit. |
| 149 | clear_local_state_on_exit = ShouldClearLocalState(&profile_path); |
| 150 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 151 | // Delete the AutomationProviderList before NotificationService, |
| 152 | // since it may try to unregister notifications |
| 153 | // Both NotificationService and AutomationProvider are singleton instances in |
| 154 | // the BrowserProcess. Since AutomationProvider may have some active |
| 155 | // notification observers, it is essential that it gets destroyed before the |
| 156 | // NotificationService. NotificationService won't be destroyed until after |
| 157 | // this destructor is run. |
| 158 | automation_provider_list_.reset(); |
| 159 | |
[email protected] | d393a0fd | 2009-05-13 23:32:01 | [diff] [blame] | 160 | // We need to shutdown the SdchDictionaryFetcher as it regularly holds |
| 161 | // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do |
| 162 | // a PostDelayedTask onto the IO thread. This shutdown call will both discard |
| 163 | // any pending URLFetchers, and avoid creating any more. |
| 164 | SdchDictionaryFetcher::Shutdown(); |
| 165 | |
[email protected] | 51ac04076 | 2011-01-20 02:01:04 | [diff] [blame] | 166 | // We need to destroy the MetricsService, GoogleURLTracker, |
| 167 | // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService |
| 168 | // before the io_thread_ gets destroyed, since their destructors can call the |
| 169 | // URLFetcher destructor, which does a PostDelayedTask operation on the IO |
| 170 | // thread. (The IO thread will handle that URLFetcher operation before going |
| 171 | // away.) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 172 | metrics_service_.reset(); |
| 173 | google_url_tracker_.reset(); |
[email protected] | c4ff495 | 2010-01-08 19:12:47 | [diff] [blame] | 174 | intranet_redirect_detector_.reset(); |
[email protected] | 51ac04076 | 2011-01-20 02:01:04 | [diff] [blame] | 175 | safe_browsing_detection_service_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 176 | |
[email protected] | d8a899c | 2010-09-21 04:50:33 | [diff] [blame] | 177 | // Need to clear the desktop notification balloons before the io_thread_ and |
| 178 | // before the profiles, since if there are any still showing we will access |
| 179 | // those things during teardown. |
| 180 | notification_ui_manager_.reset(); |
| 181 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 182 | // Need to clear profiles (download managers) before the io_thread_. |
| 183 | profile_manager_.reset(); |
| 184 | |
| 185 | // Debugger must be cleaned up before IO thread and NotificationService. |
[email protected] | 5613126e | 2011-01-31 15:27:55 | [diff] [blame] | 186 | if (devtools_http_handler_.get()) { |
| 187 | devtools_http_handler_->Stop(); |
| 188 | devtools_http_handler_ = NULL; |
| 189 | } |
| 190 | if (devtools_legacy_handler_.get()) { |
| 191 | devtools_legacy_handler_->Stop(); |
| 192 | devtools_legacy_handler_ = NULL; |
| 193 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 194 | |
| 195 | if (resource_dispatcher_host_.get()) { |
| 196 | // Need to tell Safe Browsing Service that the IO thread is going away |
| 197 | // since it cached a pointer to it. |
| 198 | if (resource_dispatcher_host()->safe_browsing_service()) |
| 199 | resource_dispatcher_host()->safe_browsing_service()->ShutDown(); |
| 200 | |
| 201 | // Cancel pending requests and prevent new requests. |
| 202 | resource_dispatcher_host()->Shutdown(); |
| 203 | } |
| 204 | |
[email protected] | fc4facd | 2011-03-22 23:18:50 | [diff] [blame] | 205 | ExtensionTabIdMap::GetInstance()->Shutdown(); |
| 206 | |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 207 | // The policy providers managed by |browser_policy_connector_| need to shut |
| 208 | // down while the IO and FILE threads are still alive. |
| 209 | browser_policy_connector_.reset(); |
[email protected] | f2a893c | 2011-01-05 09:38:07 | [diff] [blame] | 210 | |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 211 | #if defined(USE_X11) |
[email protected] | 4c3cd741 | 2009-04-22 17:56:06 | [diff] [blame] | 212 | // The IO thread must outlive the BACKGROUND_X11 thread. |
| 213 | background_x11_thread_.reset(); |
| 214 | #endif |
| 215 | |
[email protected] | 6618d1d | 2010-12-15 21:18:47 | [diff] [blame] | 216 | // Wait for removing plugin data to finish before shutting down the IO thread. |
| 217 | WaitForPluginDataRemoverToFinish(); |
| 218 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 219 | // Destroying the GpuProcessHostUIShims on the UI thread posts a task to |
| 220 | // delete related objects on the GPU thread. This must be done before |
| 221 | // stopping the GPU thread. The GPU thread will close IPC channels to renderer |
| 222 | // processes so this has to happen before stopping the IO thread. |
| 223 | GpuProcessHostUIShim::DestroyAll(); |
| 224 | gpu_thread_.reset(); |
| 225 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 226 | // Need to stop io_thread_ before resource_dispatcher_host_, since |
| 227 | // io_thread_ may still deref ResourceDispatcherHost and handle resource |
| 228 | // request before going away. |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 229 | io_thread_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 230 | |
[email protected] | 875ee82 | 2010-05-18 20:58:01 | [diff] [blame] | 231 | // The IO thread was the only user of this thread. |
| 232 | cache_thread_.reset(); |
| 233 | |
[email protected] | 91451171 | 2009-11-23 19:42:33 | [diff] [blame] | 234 | // Stop the process launcher thread after the IO thread, in case the IO thread |
| 235 | // posted a task to terminate a process on the process launcher thread. |
| 236 | process_launcher_thread_.reset(); |
| 237 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 238 | // Clean up state that lives on the file_thread_ before it goes away. |
| 239 | if (resource_dispatcher_host_.get()) { |
| 240 | resource_dispatcher_host()->download_file_manager()->Shutdown(); |
| 241 | resource_dispatcher_host()->save_file_manager()->Shutdown(); |
| 242 | } |
| 243 | |
| 244 | // Need to stop the file_thread_ here to force it to process messages in its |
| 245 | // message loop from the previous call to shutdown the DownloadFileManager, |
| 246 | // SaveFileManager and SessionService. |
| 247 | file_thread_.reset(); |
| 248 | |
| 249 | // With the file_thread_ flushed, we can release any icon resources. |
| 250 | icon_manager_.reset(); |
| 251 | |
| 252 | // Need to destroy ResourceDispatcherHost before PluginService and |
[email protected] | 49f28bc7 | 2010-02-04 00:10:01 | [diff] [blame] | 253 | // SafeBrowsingService, since it caches a pointer to it. This also |
| 254 | // causes the webkit thread to terminate. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 255 | resource_dispatcher_host_.reset(); |
| 256 | |
| 257 | // Wait for the pending print jobs to finish. |
| 258 | print_job_manager_->OnQuit(); |
| 259 | print_job_manager_.reset(); |
| 260 | |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 261 | // Destroy TabCloseableStateWatcher before NotificationService since the |
| 262 | // former registers for notifications. |
| 263 | tab_closeable_state_watcher_.reset(); |
| 264 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 265 | // Now OK to destroy NotificationService. |
| 266 | main_notification_service_.reset(); |
| 267 | |
[email protected] | 49f28bc7 | 2010-02-04 00:10:01 | [diff] [blame] | 268 | // Prior to clearing local state, we want to complete tasks pending |
| 269 | // on the db thread too. |
| 270 | db_thread_.reset(); |
| 271 | |
[email protected] | 0b56518 | 2011-03-02 18:11:15 | [diff] [blame] | 272 | // Stop the watchdog thread after stopping other threads. |
| 273 | watchdog_thread_.reset(); |
| 274 | |
[email protected] | 49f28bc7 | 2010-02-04 00:10:01 | [diff] [blame] | 275 | // At this point, no render process exist and the file, io, db, and |
| 276 | // webkit threads in this process have all terminated, so it's safe |
| 277 | // to access local state data such as cookies, database, or local storage. |
| 278 | if (clear_local_state_on_exit) |
| 279 | ClearLocalState(profile_path); |
| 280 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 281 | g_browser_process = NULL; |
| 282 | } |
| 283 | |
[email protected] | c6032e8 | 2010-09-13 20:06:05 | [diff] [blame] | 284 | #if defined(OS_WIN) |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 285 | // Send a QuitTask to the given MessageLoop. |
| 286 | static void PostQuit(MessageLoop* message_loop) { |
| 287 | message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 288 | } |
[email protected] | c6032e8 | 2010-09-13 20:06:05 | [diff] [blame] | 289 | #elif defined(USE_X11) |
| 290 | static void Signal(base::WaitableEvent* event) { |
| 291 | event->Signal(); |
| 292 | } |
| 293 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 294 | |
[email protected] | b443cb04 | 2009-12-15 22:05:09 | [diff] [blame] | 295 | unsigned int BrowserProcessImpl::AddRefModule() { |
| 296 | DCHECK(CalledOnValidThread()); |
[email protected] | afd20c02 | 2010-06-10 00:48:20 | [diff] [blame] | 297 | did_start_ = true; |
[email protected] | b443cb04 | 2009-12-15 22:05:09 | [diff] [blame] | 298 | module_ref_count_++; |
| 299 | return module_ref_count_; |
| 300 | } |
| 301 | |
| 302 | unsigned int BrowserProcessImpl::ReleaseModule() { |
| 303 | DCHECK(CalledOnValidThread()); |
[email protected] | 760d970a | 2010-05-18 00:39:18 | [diff] [blame] | 304 | DCHECK_NE(0u, module_ref_count_); |
[email protected] | b443cb04 | 2009-12-15 22:05:09 | [diff] [blame] | 305 | module_ref_count_--; |
| 306 | if (0 == module_ref_count_) { |
[email protected] | 7d038c3 | 2010-12-14 00:40:00 | [diff] [blame] | 307 | // Allow UI and IO threads to do blocking IO on shutdown, since we do a lot |
| 308 | // of it on shutdown for valid reasons. |
| 309 | base::ThreadRestrictions::SetIOAllowed(true); |
| 310 | io_thread()->message_loop()->PostTask( |
| 311 | FROM_HERE, |
| 312 | NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true)); |
[email protected] | b443cb04 | 2009-12-15 22:05:09 | [diff] [blame] | 313 | MessageLoop::current()->PostTask( |
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 314 | FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop)); |
[email protected] | b443cb04 | 2009-12-15 22:05:09 | [diff] [blame] | 315 | MessageLoop::current()->Quit(); |
| 316 | } |
| 317 | return module_ref_count_; |
| 318 | } |
| 319 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 320 | void BrowserProcessImpl::EndSession() { |
[email protected] | c6032e8 | 2010-09-13 20:06:05 | [diff] [blame] | 321 | #if defined(OS_WIN) || defined(USE_X11) |
[email protected] | d65cab7a | 2008-08-12 01:25:41 | [diff] [blame] | 322 | // Notify we are going away. |
[email protected] | c6032e8 | 2010-09-13 20:06:05 | [diff] [blame] | 323 | shutdown_event_->Signal(); |
[email protected] | b112a4c | 2009-02-01 20:24:01 | [diff] [blame] | 324 | #endif |
[email protected] | d65cab7a | 2008-08-12 01:25:41 | [diff] [blame] | 325 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 326 | // Mark all the profiles as clean. |
| 327 | ProfileManager* pm = profile_manager(); |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 328 | std::vector<Profile*> profiles(pm->GetLoadedProfiles()); |
| 329 | for (size_t i = 0; i < profiles.size(); ++i) |
| 330 | profiles[i]->MarkAsCleanShutdown(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 331 | |
| 332 | // Tell the metrics service it was cleanly shutdown. |
| 333 | MetricsService* metrics = g_browser_process->metrics_service(); |
| 334 | if (metrics && local_state()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 335 | metrics->RecordStartOfSessionEnd(); |
| 336 | |
| 337 | // MetricsService lazily writes to prefs, force it to write now. |
[email protected] | 6faa0e0d | 2009-04-28 06:50:36 | [diff] [blame] | 338 | local_state()->SavePersistentPrefs(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | // We must write that the profile and metrics service shutdown cleanly, |
| 342 | // otherwise on startup we'll think we crashed. So we block until done and |
| 343 | // then proceed with normal shutdown. |
[email protected] | c6032e8 | 2010-09-13 20:06:05 | [diff] [blame] | 344 | #if defined(USE_X11) |
| 345 | // Can't run a local loop on linux. Instead create a waitable event. |
| 346 | base::WaitableEvent done_writing(false, false); |
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 347 | BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
[email protected] | c6032e8 | 2010-09-13 20:06:05 | [diff] [blame] | 348 | NewRunnableFunction(Signal, &done_writing)); |
| 349 | done_writing.TimedWait( |
| 350 | base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds)); |
| 351 | #elif defined(OS_WIN) |
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 352 | BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 353 | NewRunnableFunction(PostQuit, MessageLoop::current())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 354 | MessageLoop::current()->Run(); |
[email protected] | c6032e8 | 2010-09-13 20:06:05 | [diff] [blame] | 355 | #else |
| 356 | NOTIMPLEMENTED(); |
| 357 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 358 | } |
| 359 | |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 360 | ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() { |
| 361 | DCHECK(CalledOnValidThread()); |
| 362 | if (!created_resource_dispatcher_host_) |
| 363 | CreateResourceDispatcherHost(); |
| 364 | return resource_dispatcher_host_.get(); |
| 365 | } |
| 366 | |
| 367 | MetricsService* BrowserProcessImpl::metrics_service() { |
| 368 | DCHECK(CalledOnValidThread()); |
| 369 | if (!created_metrics_service_) |
| 370 | CreateMetricsService(); |
| 371 | return metrics_service_.get(); |
| 372 | } |
| 373 | |
| 374 | IOThread* BrowserProcessImpl::io_thread() { |
| 375 | DCHECK(CalledOnValidThread()); |
| 376 | if (!created_io_thread_) |
| 377 | CreateIOThread(); |
| 378 | return io_thread_.get(); |
| 379 | } |
| 380 | |
| 381 | base::Thread* BrowserProcessImpl::file_thread() { |
| 382 | DCHECK(CalledOnValidThread()); |
| 383 | if (!created_file_thread_) |
| 384 | CreateFileThread(); |
| 385 | return file_thread_.get(); |
| 386 | } |
| 387 | |
| 388 | base::Thread* BrowserProcessImpl::db_thread() { |
| 389 | DCHECK(CalledOnValidThread()); |
| 390 | if (!created_db_thread_) |
| 391 | CreateDBThread(); |
| 392 | return db_thread_.get(); |
| 393 | } |
| 394 | |
| 395 | base::Thread* BrowserProcessImpl::process_launcher_thread() { |
| 396 | DCHECK(CalledOnValidThread()); |
| 397 | if (!created_process_launcher_thread_) |
| 398 | CreateProcessLauncherThread(); |
| 399 | return process_launcher_thread_.get(); |
| 400 | } |
| 401 | |
| 402 | base::Thread* BrowserProcessImpl::cache_thread() { |
| 403 | DCHECK(CalledOnValidThread()); |
| 404 | if (!created_cache_thread_) |
| 405 | CreateCacheThread(); |
| 406 | return cache_thread_.get(); |
| 407 | } |
| 408 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 409 | base::Thread* BrowserProcessImpl::gpu_thread() { |
| 410 | DCHECK(CalledOnValidThread()); |
| 411 | if (!created_gpu_thread_) |
| 412 | CreateGpuThread(); |
| 413 | return gpu_thread_.get(); |
| 414 | } |
| 415 | |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 416 | #if defined(USE_X11) |
| 417 | base::Thread* BrowserProcessImpl::background_x11_thread() { |
| 418 | DCHECK(CalledOnValidThread()); |
| 419 | // The BACKGROUND_X11 thread is created when the IO thread is created. |
| 420 | if (!created_io_thread_) |
| 421 | CreateIOThread(); |
| 422 | return background_x11_thread_.get(); |
| 423 | } |
| 424 | #endif |
| 425 | |
[email protected] | 0b56518 | 2011-03-02 18:11:15 | [diff] [blame] | 426 | WatchDogThread* BrowserProcessImpl::watchdog_thread() { |
| 427 | DCHECK(CalledOnValidThread()); |
| 428 | if (!created_watchdog_thread_) |
| 429 | CreateWatchdogThread(); |
| 430 | DCHECK(watchdog_thread_.get() != NULL); |
| 431 | return watchdog_thread_.get(); |
| 432 | } |
| 433 | |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 434 | ProfileManager* BrowserProcessImpl::profile_manager() { |
| 435 | DCHECK(CalledOnValidThread()); |
| 436 | if (!created_profile_manager_) |
| 437 | CreateProfileManager(); |
| 438 | return profile_manager_.get(); |
| 439 | } |
| 440 | |
| 441 | PrefService* BrowserProcessImpl::local_state() { |
| 442 | DCHECK(CalledOnValidThread()); |
| 443 | if (!created_local_state_) |
| 444 | CreateLocalState(); |
| 445 | return local_state_.get(); |
| 446 | } |
| 447 | |
| 448 | DevToolsManager* BrowserProcessImpl::devtools_manager() { |
| 449 | DCHECK(CalledOnValidThread()); |
| 450 | if (!created_devtools_manager_) |
| 451 | CreateDevToolsManager(); |
| 452 | return devtools_manager_.get(); |
| 453 | } |
| 454 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 455 | SidebarManager* BrowserProcessImpl::sidebar_manager() { |
| 456 | DCHECK(CalledOnValidThread()); |
| 457 | if (!created_sidebar_manager_) |
| 458 | CreateSidebarManager(); |
| 459 | return sidebar_manager_.get(); |
| 460 | } |
| 461 | |
[email protected] | 2dfeaf9 | 2011-01-10 21:08:21 | [diff] [blame] | 462 | ui::Clipboard* BrowserProcessImpl::clipboard() { |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 463 | DCHECK(CalledOnValidThread()); |
| 464 | return clipboard_.get(); |
| 465 | } |
| 466 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 467 | net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 468 | DCHECK(CalledOnValidThread()); |
| 469 | return io_thread()->system_url_request_context_getter(); |
| 470 | } |
| 471 | |
| 472 | #if defined(OS_CHROMEOS) |
| 473 | chromeos::ProxyConfigServiceImpl* |
| 474 | BrowserProcessImpl::chromeos_proxy_config_service_impl() { |
| 475 | DCHECK(CalledOnValidThread()); |
| 476 | if (!chromeos_proxy_config_service_impl_) { |
| 477 | chromeos_proxy_config_service_impl_ = |
| 478 | new chromeos::ProxyConfigServiceImpl(); |
| 479 | } |
| 480 | return chromeos_proxy_config_service_impl_; |
| 481 | } |
| 482 | #endif // defined(OS_CHROMEOS) |
| 483 | |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 484 | ExtensionEventRouterForwarder* |
| 485 | BrowserProcessImpl::extension_event_router_forwarder() { |
| 486 | return extension_event_router_forwarder_.get(); |
| 487 | } |
| 488 | |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 489 | NotificationUIManager* BrowserProcessImpl::notification_ui_manager() { |
| 490 | DCHECK(CalledOnValidThread()); |
| 491 | if (!created_notification_ui_manager_) |
| 492 | CreateNotificationUIManager(); |
| 493 | return notification_ui_manager_.get(); |
| 494 | } |
| 495 | |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 496 | policy::BrowserPolicyConnector* BrowserProcessImpl::browser_policy_connector() { |
[email protected] | f2a893c | 2011-01-05 09:38:07 | [diff] [blame] | 497 | DCHECK(CalledOnValidThread()); |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 498 | if (!created_browser_policy_connector_) { |
| 499 | DCHECK(browser_policy_connector_.get() == NULL); |
| 500 | created_browser_policy_connector_ = true; |
| 501 | browser_policy_connector_.reset(new policy::BrowserPolicyConnector()); |
[email protected] | f2a893c | 2011-01-05 09:38:07 | [diff] [blame] | 502 | } |
[email protected] | 985655a | 2011-02-23 09:54:25 | [diff] [blame] | 503 | return browser_policy_connector_.get(); |
[email protected] | f2a893c | 2011-01-05 09:38:07 | [diff] [blame] | 504 | } |
| 505 | |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 506 | IconManager* BrowserProcessImpl::icon_manager() { |
| 507 | DCHECK(CalledOnValidThread()); |
| 508 | if (!created_icon_manager_) |
| 509 | CreateIconManager(); |
| 510 | return icon_manager_.get(); |
| 511 | } |
| 512 | |
| 513 | ThumbnailGenerator* BrowserProcessImpl::GetThumbnailGenerator() { |
| 514 | return &thumbnail_generator_; |
| 515 | } |
| 516 | |
| 517 | AutomationProviderList* BrowserProcessImpl::InitAutomationProviderList() { |
| 518 | DCHECK(CalledOnValidThread()); |
| 519 | if (automation_provider_list_.get() == NULL) { |
| 520 | automation_provider_list_.reset(AutomationProviderList::GetInstance()); |
| 521 | } |
| 522 | return automation_provider_list_.get(); |
| 523 | } |
| 524 | |
[email protected] | 5613126e | 2011-01-31 15:27:55 | [diff] [blame] | 525 | void BrowserProcessImpl::InitDevToolsHttpProtocolHandler( |
[email protected] | 01000cf1 | 2011-02-04 11:39:22 | [diff] [blame] | 526 | const std::string& ip, |
[email protected] | 5613126e | 2011-01-31 15:27:55 | [diff] [blame] | 527 | int port, |
| 528 | const std::string& frontend_url) { |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 529 | DCHECK(CalledOnValidThread()); |
[email protected] | 5613126e | 2011-01-31 15:27:55 | [diff] [blame] | 530 | devtools_http_handler_ = |
[email protected] | 01000cf1 | 2011-02-04 11:39:22 | [diff] [blame] | 531 | DevToolsHttpProtocolHandler::Start(ip, |
| 532 | port, |
[email protected] | 9678cb4 | 2011-01-31 18:49:42 | [diff] [blame] | 533 | frontend_url, |
| 534 | new BrowserListTabContentsProvider()); |
[email protected] | 5613126e | 2011-01-31 15:27:55 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | void BrowserProcessImpl::InitDevToolsLegacyProtocolHandler(int port) { |
| 538 | DCHECK(CalledOnValidThread()); |
| 539 | devtools_legacy_handler_ = DevToolsProtocolHandler::Start(port); |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | bool BrowserProcessImpl::IsShuttingDown() { |
| 543 | DCHECK(CalledOnValidThread()); |
| 544 | return did_start_ && 0 == module_ref_count_; |
| 545 | } |
| 546 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 547 | printing::PrintJobManager* BrowserProcessImpl::print_job_manager() { |
| 548 | // TODO(abarth): DCHECK(CalledOnValidThread()); |
[email protected] | d8922f2 | 2010-05-07 00:57:27 | [diff] [blame] | 549 | // http://code.google.com/p/chromium/issues/detail?id=6828 |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 550 | // print_job_manager_ is initialized in the constructor and destroyed in the |
| 551 | // destructor, so it should always be valid. |
| 552 | DCHECK(print_job_manager_.get()); |
| 553 | return print_job_manager_.get(); |
| 554 | } |
| 555 | |
[email protected] | dbeebd5 | 2010-11-16 20:34:16 | [diff] [blame] | 556 | printing::PrintPreviewTabController* |
| 557 | BrowserProcessImpl::print_preview_tab_controller() { |
| 558 | DCHECK(CalledOnValidThread()); |
| 559 | if (!print_preview_tab_controller_.get()) |
| 560 | CreatePrintPreviewTabController(); |
| 561 | return print_preview_tab_controller_.get(); |
| 562 | } |
| 563 | |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 564 | GoogleURLTracker* BrowserProcessImpl::google_url_tracker() { |
| 565 | DCHECK(CalledOnValidThread()); |
| 566 | if (!google_url_tracker_.get()) |
| 567 | CreateGoogleURLTracker(); |
| 568 | return google_url_tracker_.get(); |
| 569 | } |
| 570 | |
| 571 | IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() { |
| 572 | DCHECK(CalledOnValidThread()); |
| 573 | if (!intranet_redirect_detector_.get()) |
| 574 | CreateIntranetRedirectDetector(); |
| 575 | return intranet_redirect_detector_.get(); |
| 576 | } |
| 577 | |
| 578 | const std::string& BrowserProcessImpl::GetApplicationLocale() { |
| 579 | DCHECK(!locale_.empty()); |
| 580 | return locale_; |
| 581 | } |
| 582 | |
| 583 | void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) { |
| 584 | locale_ = locale; |
| 585 | extension_l10n_util::SetProcessLocale(locale); |
| 586 | } |
| 587 | |
[email protected] | 073ed7b | 2010-09-27 09:20:02 | [diff] [blame] | 588 | DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() { |
| 589 | return &download_status_updater_; |
| 590 | } |
| 591 | |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 592 | base::WaitableEvent* BrowserProcessImpl::shutdown_event() { |
| 593 | return shutdown_event_.get(); |
| 594 | } |
| 595 | |
| 596 | TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() { |
| 597 | DCHECK(CalledOnValidThread()); |
| 598 | if (!tab_closeable_state_watcher_.get()) |
| 599 | CreateTabCloseableStateWatcher(); |
| 600 | return tab_closeable_state_watcher_.get(); |
| 601 | } |
| 602 | |
[email protected] | a7a5e99 | 2010-12-09 23:39:51 | [diff] [blame] | 603 | safe_browsing::ClientSideDetectionService* |
| 604 | BrowserProcessImpl::safe_browsing_detection_service() { |
| 605 | DCHECK(CalledOnValidThread()); |
| 606 | if (!created_safe_browsing_detection_service_) { |
| 607 | CreateSafeBrowsingDetectionService(); |
| 608 | } |
| 609 | return safe_browsing_detection_service_.get(); |
| 610 | } |
| 611 | |
[email protected] | 8b08a47f | 2011-02-25 12:36:37 | [diff] [blame] | 612 | bool BrowserProcessImpl::plugin_finder_disabled() const { |
| 613 | return *plugin_finder_disabled_pref_; |
| 614 | } |
| 615 | |
[email protected] | 6618d1d | 2010-12-15 21:18:47 | [diff] [blame] | 616 | void BrowserProcessImpl::Observe(NotificationType type, |
| 617 | const NotificationSource& source, |
| 618 | const NotificationDetails& details) { |
| 619 | if (type == NotificationType::APP_TERMINATING) { |
| 620 | Profile* profile = ProfileManager::GetDefaultProfile(); |
| 621 | if (profile) { |
| 622 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | 2ffc3c6c | 2011-01-14 12:50:24 | [diff] [blame] | 623 | if (prefs->GetBoolean(prefs::kClearSiteDataOnExit) && |
[email protected] | 6618d1d | 2010-12-15 21:18:47 | [diff] [blame] | 624 | local_state()->GetBoolean(prefs::kClearPluginLSODataEnabled)) { |
| 625 | plugin_data_remover_ = new PluginDataRemover(); |
[email protected] | c7d58d6 | 2011-01-21 10:27:18 | [diff] [blame] | 626 | if (!plugin_data_remover_mime_type().empty()) |
| 627 | plugin_data_remover_->set_mime_type(plugin_data_remover_mime_type()); |
| 628 | plugin_data_remover_->StartRemoving(base::Time()); |
[email protected] | 6618d1d | 2010-12-15 21:18:47 | [diff] [blame] | 629 | } |
| 630 | } |
[email protected] | e450fa6 | 2011-02-01 12:52:56 | [diff] [blame] | 631 | } else if (type == NotificationType::PREF_CHANGED) { |
| 632 | std::string* pref = Details<std::string>(details).ptr(); |
| 633 | if (*pref == prefs::kDefaultBrowserSettingEnabled) { |
| 634 | if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) |
| 635 | ShellIntegration::SetAsDefaultBrowser(); |
[email protected] | 419a057 | 2011-04-18 22:21:46 | [diff] [blame] | 636 | } else if (*pref == prefs::kDisabledSchemes) { |
| 637 | ApplyDisabledSchemesPolicy(); |
[email protected] | e450fa6 | 2011-02-01 12:52:56 | [diff] [blame] | 638 | } |
[email protected] | 6618d1d | 2010-12-15 21:18:47 | [diff] [blame] | 639 | } else { |
| 640 | NOTREACHED(); |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | void BrowserProcessImpl::WaitForPluginDataRemoverToFinish() { |
[email protected] | c7d58d6 | 2011-01-21 10:27:18 | [diff] [blame] | 645 | if (plugin_data_remover_.get()) |
| 646 | plugin_data_remover_->Wait(); |
[email protected] | 6618d1d | 2010-12-15 21:18:47 | [diff] [blame] | 647 | } |
| 648 | |
[email protected] | e13ad79b | 2010-07-22 21:36:50 | [diff] [blame] | 649 | #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| 650 | void BrowserProcessImpl::StartAutoupdateTimer() { |
| 651 | autoupdate_timer_.Start( |
| 652 | base::TimeDelta::FromHours(kUpdateCheckIntervalHours), |
| 653 | this, |
| 654 | &BrowserProcessImpl::OnAutoupdateTimer); |
| 655 | } |
| 656 | #endif |
| 657 | |
[email protected] | d6f37fc | 2011-02-13 23:58:41 | [diff] [blame] | 658 | ChromeNetLog* BrowserProcessImpl::net_log() { |
| 659 | return net_log_.get(); |
| 660 | } |
| 661 | |
[email protected] | 4ef795df | 2010-02-03 02:35:08 | [diff] [blame] | 662 | void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) { |
[email protected] | 72cfd90f | 2010-02-06 03:08:04 | [diff] [blame] | 663 | webkit_database::DatabaseTracker::ClearLocalState(profile_path); |
[email protected] | 4ef795df | 2010-02-03 02:35:08 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) { |
| 667 | FilePath user_data_dir; |
| 668 | Profile* profile; |
| 669 | |
[email protected] | 0958497 | 2010-07-03 00:00:59 | [diff] [blame] | 670 | // Check for the existence of a profile manager. When quitting early, |
[email protected] | ed0cf56 | 2010-02-05 22:50:41 | [diff] [blame] | 671 | // e.g. because another chrome instance is running, or when invoked with |
| 672 | // options such as --uninstall or --try-chrome-again=0, the profile manager |
| 673 | // does not exist yet. |
| 674 | if (!profile_manager_.get()) |
| 675 | return false; |
| 676 | |
[email protected] | 4ef795df | 2010-02-03 02:35:08 | [diff] [blame] | 677 | PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 678 | profile = profile_manager_->GetDefaultProfile(user_data_dir); |
[email protected] | 7bfc67432 | 2010-03-05 00:20:57 | [diff] [blame] | 679 | if (!profile) |
| 680 | return false; |
[email protected] | 4ef795df | 2010-02-03 02:35:08 | [diff] [blame] | 681 | *profile_path = profile->GetPath(); |
| 682 | return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit); |
| 683 | } |
| 684 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 685 | void BrowserProcessImpl::CreateResourceDispatcherHost() { |
| 686 | DCHECK(!created_resource_dispatcher_host_ && |
| 687 | resource_dispatcher_host_.get() == NULL); |
| 688 | created_resource_dispatcher_host_ = true; |
| 689 | |
[email protected] | 21453884 | 2011-04-01 18:47:24 | [diff] [blame] | 690 | // UserScriptListener will delete itself. |
| 691 | ResourceQueue::DelegateSet resource_queue_delegates; |
| 692 | resource_queue_delegates.insert(new UserScriptListener()); |
| 693 | |
| 694 | resource_dispatcher_host_.reset( |
| 695 | new ResourceDispatcherHost(resource_queue_delegates)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 696 | resource_dispatcher_host_->Initialize(); |
| 697 | } |
| 698 | |
| 699 | void BrowserProcessImpl::CreateMetricsService() { |
| 700 | DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL); |
| 701 | created_metrics_service_ = true; |
| 702 | |
| 703 | metrics_service_.reset(new MetricsService); |
| 704 | } |
| 705 | |
| 706 | void BrowserProcessImpl::CreateIOThread() { |
| 707 | DCHECK(!created_io_thread_ && io_thread_.get() == NULL); |
| 708 | created_io_thread_ = true; |
| 709 | |
| 710 | // Prior to starting the io thread, we create the plugin service as |
| 711 | // it is predominantly used from the io thread, but must be created |
| 712 | // on the main thread. The service ctor is inexpensive and does not |
| 713 | // invoke the io_thread() accessor. |
| 714 | PluginService::GetInstance(); |
| 715 | |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 716 | #if defined(USE_X11) |
[email protected] | 4c3cd741 | 2009-04-22 17:56:06 | [diff] [blame] | 717 | // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so |
| 718 | // we start it now. |
| 719 | scoped_ptr<base::Thread> background_x11_thread( |
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 720 | new BrowserProcessSubThread(BrowserThread::BACKGROUND_X11)); |
[email protected] | 4c3cd741 | 2009-04-22 17:56:06 | [diff] [blame] | 721 | if (!background_x11_thread->Start()) |
| 722 | return; |
| 723 | background_x11_thread_.swap(background_x11_thread); |
| 724 | #endif |
| 725 | |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 726 | scoped_ptr<IOThread> thread(new IOThread( |
| 727 | local_state(), net_log_.get(), extension_event_router_forwarder_.get())); |
[email protected] | ab820df | 2008-08-26 05:55:10 | [diff] [blame] | 728 | base::Thread::Options options; |
| 729 | options.message_loop_type = MessageLoop::TYPE_IO; |
| 730 | if (!thread->StartWithOptions(options)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 731 | return; |
| 732 | io_thread_.swap(thread); |
| 733 | } |
| 734 | |
| 735 | void BrowserProcessImpl::CreateFileThread() { |
| 736 | DCHECK(!created_file_thread_ && file_thread_.get() == NULL); |
| 737 | created_file_thread_ = true; |
| 738 | |
[email protected] | ab820df | 2008-08-26 05:55:10 | [diff] [blame] | 739 | scoped_ptr<base::Thread> thread( |
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 740 | new BrowserProcessSubThread(BrowserThread::FILE)); |
[email protected] | a1db384 | 2008-09-17 22:04:06 | [diff] [blame] | 741 | base::Thread::Options options; |
[email protected] | 9e549b58 | 2009-02-05 21:13:39 | [diff] [blame] | 742 | #if defined(OS_WIN) |
| 743 | // On Windows, the FILE thread needs to be have a UI message loop which pumps |
| 744 | // messages in such a way that Google Update can communicate back to us. |
[email protected] | a1db384 | 2008-09-17 22:04:06 | [diff] [blame] | 745 | options.message_loop_type = MessageLoop::TYPE_UI; |
[email protected] | 9e549b58 | 2009-02-05 21:13:39 | [diff] [blame] | 746 | #else |
| 747 | options.message_loop_type = MessageLoop::TYPE_IO; |
| 748 | #endif |
[email protected] | a1db384 | 2008-09-17 22:04:06 | [diff] [blame] | 749 | if (!thread->StartWithOptions(options)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 750 | return; |
| 751 | file_thread_.swap(thread); |
| 752 | } |
| 753 | |
| 754 | void BrowserProcessImpl::CreateDBThread() { |
| 755 | DCHECK(!created_db_thread_ && db_thread_.get() == NULL); |
| 756 | created_db_thread_ = true; |
| 757 | |
[email protected] | ab820df | 2008-08-26 05:55:10 | [diff] [blame] | 758 | scoped_ptr<base::Thread> thread( |
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 759 | new BrowserProcessSubThread(BrowserThread::DB)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 760 | if (!thread->Start()) |
| 761 | return; |
| 762 | db_thread_.swap(thread); |
| 763 | } |
| 764 | |
[email protected] | 91451171 | 2009-11-23 19:42:33 | [diff] [blame] | 765 | void BrowserProcessImpl::CreateProcessLauncherThread() { |
| 766 | DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get()); |
| 767 | created_process_launcher_thread_ = true; |
| 768 | |
| 769 | scoped_ptr<base::Thread> thread( |
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 770 | new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER)); |
[email protected] | 91451171 | 2009-11-23 19:42:33 | [diff] [blame] | 771 | if (!thread->Start()) |
| 772 | return; |
| 773 | process_launcher_thread_.swap(thread); |
| 774 | } |
| 775 | |
[email protected] | 875ee82 | 2010-05-18 20:58:01 | [diff] [blame] | 776 | void BrowserProcessImpl::CreateCacheThread() { |
| 777 | DCHECK(!created_cache_thread_ && !cache_thread_.get()); |
| 778 | created_cache_thread_ = true; |
| 779 | |
| 780 | scoped_ptr<base::Thread> thread( |
[email protected] | 7509633 | 2010-11-09 03:28:13 | [diff] [blame] | 781 | new BrowserThread(BrowserThread::CACHE)); |
[email protected] | 875ee82 | 2010-05-18 20:58:01 | [diff] [blame] | 782 | base::Thread::Options options; |
| 783 | options.message_loop_type = MessageLoop::TYPE_IO; |
| 784 | if (!thread->StartWithOptions(options)) |
| 785 | return; |
| 786 | cache_thread_.swap(thread); |
| 787 | } |
| 788 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 789 | void BrowserProcessImpl::CreateGpuThread() { |
| 790 | DCHECK(!created_gpu_thread_ && !gpu_thread_.get()); |
| 791 | created_gpu_thread_ = true; |
| 792 | |
| 793 | scoped_ptr<base::Thread> thread(new BrowserThread(BrowserThread::GPU)); |
| 794 | |
| 795 | base::Thread::Options options; |
| 796 | #if defined(OS_WIN) |
| 797 | // On Windows the GPU thread needs to pump the compositor child window's |
| 798 | // message loop. TODO(apatrick): make this an IO thread if / when we get rid |
| 799 | // of this child window. Unfortunately it might always be necessary for |
| 800 | // Windows XP because we cannot share the backing store textures between |
| 801 | // processes. |
| 802 | options.message_loop_type = MessageLoop::TYPE_UI; |
| 803 | #else |
| 804 | options.message_loop_type = MessageLoop::TYPE_IO; |
| 805 | #endif |
| 806 | |
| 807 | if (!thread->StartWithOptions(options)) |
| 808 | return; |
| 809 | gpu_thread_.swap(thread); |
| 810 | } |
| 811 | |
[email protected] | 0b56518 | 2011-03-02 18:11:15 | [diff] [blame] | 812 | void BrowserProcessImpl::CreateWatchdogThread() { |
| 813 | DCHECK(!created_watchdog_thread_ && watchdog_thread_.get() == NULL); |
| 814 | created_watchdog_thread_ = true; |
| 815 | |
| 816 | scoped_ptr<WatchDogThread> thread(new WatchDogThread()); |
| 817 | if (!thread->Start()) |
| 818 | return; |
| 819 | watchdog_thread_.swap(thread); |
| 820 | } |
| 821 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 822 | void BrowserProcessImpl::CreateProfileManager() { |
| 823 | DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL); |
| 824 | created_profile_manager_ = true; |
| 825 | |
| 826 | profile_manager_.reset(new ProfileManager()); |
| 827 | } |
| 828 | |
| 829 | void BrowserProcessImpl::CreateLocalState() { |
| 830 | DCHECK(!created_local_state_ && local_state_.get() == NULL); |
| 831 | created_local_state_ = true; |
| 832 | |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 833 | FilePath local_state_path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 834 | PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 835 | local_state_.reset( |
| 836 | PrefService::CreatePrefService(local_state_path, NULL, NULL)); |
[email protected] | 492d214 | 2010-09-10 13:55:18 | [diff] [blame] | 837 | |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 838 | pref_change_registrar_.Init(local_state_.get()); |
| 839 | |
[email protected] | 492d214 | 2010-09-10 13:55:18 | [diff] [blame] | 840 | // Make sure the the plugin updater gets notifications of changes |
[email protected] | 24ff43d7 | 2011-03-01 13:28:58 | [diff] [blame] | 841 | // in the plugin policy lists. |
| 842 | local_state_->RegisterListPref(prefs::kPluginsDisabledPlugins); |
| 843 | pref_change_registrar_.Add(prefs::kPluginsDisabledPlugins, |
| 844 | PluginUpdater::GetInstance()); |
| 845 | local_state_->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions); |
| 846 | pref_change_registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, |
| 847 | PluginUpdater::GetInstance()); |
| 848 | local_state_->RegisterListPref(prefs::kPluginsEnabledPlugins); |
| 849 | pref_change_registrar_.Add(prefs::kPluginsEnabledPlugins, |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 850 | PluginUpdater::GetInstance()); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 851 | |
| 852 | // Initialize and set up notifications for the printing enabled |
| 853 | // preference. |
| 854 | local_state_->RegisterBooleanPref(prefs::kPrintingEnabled, true); |
| 855 | bool printing_enabled = |
| 856 | local_state_->GetBoolean(prefs::kPrintingEnabled); |
| 857 | print_job_manager_->set_printing_enabled(printing_enabled); |
| 858 | pref_change_registrar_.Add(prefs::kPrintingEnabled, |
| 859 | print_job_manager_.get()); |
[email protected] | e450fa6 | 2011-02-01 12:52:56 | [diff] [blame] | 860 | |
| 861 | // Initialize the notification for the default browser setting policy. |
| 862 | local_state_->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled, |
| 863 | false); |
| 864 | if (local_state_->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled)) { |
| 865 | if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) |
| 866 | ShellIntegration::SetAsDefaultBrowser(); |
| 867 | } |
| 868 | pref_change_registrar_.Add(prefs::kDefaultBrowserSettingEnabled, this); |
[email protected] | 8b08a47f | 2011-02-25 12:36:37 | [diff] [blame] | 869 | |
| 870 | // Initialize the preference for the plugin finder policy. |
| 871 | // This preference is only needed on the IO thread so make it available there. |
| 872 | local_state_->RegisterBooleanPref(prefs::kDisablePluginFinder, false); |
| 873 | plugin_finder_disabled_pref_.Init(prefs::kDisablePluginFinder, |
| 874 | local_state_.get(), NULL); |
| 875 | plugin_finder_disabled_pref_.MoveToThread(BrowserThread::IO); |
[email protected] | 419a057 | 2011-04-18 22:21:46 | [diff] [blame] | 876 | |
| 877 | // Initialize the preference for the disabled schemes policy, and |
| 878 | // load the initial policy on startup. |
| 879 | local_state_->RegisterListPref(prefs::kDisabledSchemes); |
| 880 | disabled_schemes_pref_.Init(prefs::kDisabledSchemes, local_state_.get(), |
| 881 | this); |
| 882 | ApplyDisabledSchemesPolicy(); |
[email protected] | fd6159a | 2010-09-03 09:38:39 | [diff] [blame] | 883 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 884 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 885 | void BrowserProcessImpl::CreateIconManager() { |
| 886 | DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL); |
| 887 | created_icon_manager_ = true; |
| 888 | icon_manager_.reset(new IconManager); |
| 889 | } |
| 890 | |
[email protected] | 40ecc90 | 2009-03-16 13:42:47 | [diff] [blame] | 891 | void BrowserProcessImpl::CreateDevToolsManager() { |
[email protected] | 73ee0152 | 2009-06-05 10:13:44 | [diff] [blame] | 892 | DCHECK(devtools_manager_.get() == NULL); |
[email protected] | 40ecc90 | 2009-03-16 13:42:47 | [diff] [blame] | 893 | created_devtools_manager_ = true; |
[email protected] | 73ee0152 | 2009-06-05 10:13:44 | [diff] [blame] | 894 | devtools_manager_ = new DevToolsManager(); |
[email protected] | 40ecc90 | 2009-03-16 13:42:47 | [diff] [blame] | 895 | } |
| 896 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 897 | void BrowserProcessImpl::CreateSidebarManager() { |
| 898 | DCHECK(sidebar_manager_.get() == NULL); |
| 899 | created_sidebar_manager_ = true; |
| 900 | sidebar_manager_ = new SidebarManager(); |
| 901 | } |
| 902 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 903 | void BrowserProcessImpl::CreateGoogleURLTracker() { |
| 904 | DCHECK(google_url_tracker_.get() == NULL); |
| 905 | scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker); |
| 906 | google_url_tracker_.swap(google_url_tracker); |
| 907 | } |
[email protected] | 6641bf66 | 2009-08-21 00:34:09 | [diff] [blame] | 908 | |
[email protected] | c4ff495 | 2010-01-08 19:12:47 | [diff] [blame] | 909 | void BrowserProcessImpl::CreateIntranetRedirectDetector() { |
| 910 | DCHECK(intranet_redirect_detector_.get() == NULL); |
| 911 | scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector( |
| 912 | new IntranetRedirectDetector); |
| 913 | intranet_redirect_detector_.swap(intranet_redirect_detector); |
| 914 | } |
| 915 | |
[email protected] | 29672ab | 2009-10-30 03:44:03 | [diff] [blame] | 916 | void BrowserProcessImpl::CreateNotificationUIManager() { |
| 917 | DCHECK(notification_ui_manager_.get() == NULL); |
[email protected] | b0b2a3dd | 2011-01-06 00:30:05 | [diff] [blame] | 918 | notification_ui_manager_.reset(NotificationUIManager::Create(local_state())); |
| 919 | |
[email protected] | 29672ab | 2009-10-30 03:44:03 | [diff] [blame] | 920 | created_notification_ui_manager_ = true; |
| 921 | } |
| 922 | |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 923 | void BrowserProcessImpl::CreateTabCloseableStateWatcher() { |
| 924 | DCHECK(tab_closeable_state_watcher_.get() == NULL); |
| 925 | tab_closeable_state_watcher_.reset(TabCloseableStateWatcher::Create()); |
| 926 | } |
| 927 | |
[email protected] | dbeebd5 | 2010-11-16 20:34:16 | [diff] [blame] | 928 | void BrowserProcessImpl::CreatePrintPreviewTabController() { |
| 929 | DCHECK(print_preview_tab_controller_.get() == NULL); |
| 930 | print_preview_tab_controller_ = new printing::PrintPreviewTabController(); |
| 931 | } |
| 932 | |
[email protected] | a7a5e99 | 2010-12-09 23:39:51 | [diff] [blame] | 933 | void BrowserProcessImpl::CreateSafeBrowsingDetectionService() { |
| 934 | DCHECK(safe_browsing_detection_service_.get() == NULL); |
| 935 | // Set this flag to true so that we don't retry indefinitely to |
| 936 | // create the service class if there was an error. |
| 937 | created_safe_browsing_detection_service_ = true; |
| 938 | |
| 939 | FilePath model_file_path; |
| 940 | Profile* profile = profile_manager() ? |
| 941 | profile_manager()->GetDefaultProfile() : NULL; |
| 942 | if (IsSafeBrowsingDetectionServiceEnabled() && |
| 943 | PathService::Get(chrome::DIR_USER_DATA, &model_file_path) && |
| 944 | profile && profile->GetRequestContext()) { |
| 945 | safe_browsing_detection_service_.reset( |
| 946 | safe_browsing::ClientSideDetectionService::Create( |
| 947 | model_file_path.Append(chrome::kSafeBrowsingPhishingModelFilename), |
| 948 | profile->GetRequestContext())); |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() { |
| 953 | // The safe browsing client-side detection is enabled only if the switch is |
[email protected] | 42930de4 | 2011-01-13 23:26:28 | [diff] [blame] | 954 | // enabled and when safe browsing related stats is allowed to be collected. |
[email protected] | d081d19 | 2011-04-01 02:33:24 | [diff] [blame] | 955 | #ifdef OS_CHROMEOS |
| 956 | return false; |
| 957 | #else |
| 958 | return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 959 | switches::kDisableClientSidePhishingDetection) && |
[email protected] | 42930de4 | 2011-01-13 23:26:28 | [diff] [blame] | 960 | resource_dispatcher_host()->safe_browsing_service() && |
| 961 | resource_dispatcher_host()->safe_browsing_service()->CanReportStats(); |
[email protected] | d081d19 | 2011-04-01 02:33:24 | [diff] [blame] | 962 | #endif |
[email protected] | a7a5e99 | 2010-12-09 23:39:51 | [diff] [blame] | 963 | } |
| 964 | |
[email protected] | 419a057 | 2011-04-18 22:21:46 | [diff] [blame] | 965 | void BrowserProcessImpl::ApplyDisabledSchemesPolicy() { |
| 966 | std::set<std::string> schemes; |
| 967 | for (ListValue::const_iterator iter = (*disabled_schemes_pref_)->begin(); |
| 968 | iter != (*disabled_schemes_pref_)->end(); ++iter) { |
| 969 | std::string scheme; |
| 970 | if ((*iter)->GetAsString(&scheme)) |
| 971 | schemes.insert(scheme); |
| 972 | } |
| 973 | ChildProcessSecurityPolicy::GetInstance()->RegisterDisabledSchemes(schemes); |
| 974 | } |
| 975 | |
[email protected] | 6641bf66 | 2009-08-21 00:34:09 | [diff] [blame] | 976 | // The BrowserProcess object must outlive the file thread so we use traits |
| 977 | // which don't do any management. |
[email protected] | c56428f2 | 2010-06-16 02:17:23 | [diff] [blame] | 978 | DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl); |
[email protected] | 6641bf66 | 2009-08-21 00:34:09 | [diff] [blame] | 979 | |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 980 | #if defined(IPC_MESSAGE_LOG_ENABLED) |
| 981 | |
| 982 | void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) { |
| 983 | // First enable myself. |
| 984 | if (enable) |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 985 | IPC::Logging::GetInstance()->Enable(); |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 986 | else |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 987 | IPC::Logging::GetInstance()->Disable(); |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 988 | |
| 989 | // Now tell subprocesses. Messages to ChildProcess-derived |
| 990 | // processes must be done on the IO thread. |
| 991 | io_thread()->message_loop()->PostTask |
| 992 | (FROM_HERE, |
| 993 | NewRunnableMethod( |
| 994 | this, |
| 995 | &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses, |
| 996 | enable)); |
| 997 | |
| 998 | // Finally, tell the renderers which don't derive from ChildProcess. |
| 999 | // Messages to the renderers must be done on the UI (main) thread. |
[email protected] | 019191a | 2009-10-02 20:37:27 | [diff] [blame] | 1000 | for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 1001 | !i.IsAtEnd(); i.Advance()) |
[email protected] | ff47b296 | 2011-03-07 23:51:49 | [diff] [blame] | 1002 | i.GetCurrentValue()->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enable)); |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | // Helper for SetIPCLoggingEnabled. |
| 1006 | void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) { |
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 1007 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 1008 | |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 1009 | BrowserChildProcessHost::Iterator i; // default constr references a singleton |
[email protected] | 34cf97d | 2009-09-29 22:46:11 | [diff] [blame] | 1010 | while (!i.Done()) { |
[email protected] | ff47b296 | 2011-03-07 23:51:49 | [diff] [blame] | 1011 | i->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); |
[email protected] | 34cf97d | 2009-09-29 22:46:11 | [diff] [blame] | 1012 | ++i; |
[email protected] | d55aaa13 | 2009-09-28 21:08:04 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | #endif // IPC_MESSAGE_LOG_ENABLED |
| 1017 | |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 1018 | // Mac is currently not supported. |
| 1019 | #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1020 | |
| 1021 | bool BrowserProcessImpl::CanAutorestartForUpdate() const { |
| 1022 | // Check if browser is in the background and if it needs to be restarted to |
| 1023 | // apply a pending update. |
[email protected] | c10fa395 | 2010-08-24 16:52:53 | [diff] [blame] | 1024 | return BrowserList::size() == 0 && BrowserList::WillKeepAlive() && |
[email protected] | 81585672 | 2011-04-13 17:19:19 | [diff] [blame] | 1025 | upgrade_util::IsUpdatePendingRestart(); |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1026 | } |
| 1027 | |
[email protected] | 5c08f22 | 2010-09-22 09:37:21 | [diff] [blame] | 1028 | // Switches to add when auto-restarting Chrome. |
[email protected] | 6c10c97 | 2010-08-11 04:15:47 | [diff] [blame] | 1029 | const char* const kSwitchesToAddOnAutorestart[] = { |
[email protected] | f9a0684 | 2010-08-21 00:32:40 | [diff] [blame] | 1030 | switches::kNoStartupWindow |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1031 | }; |
| 1032 | |
| 1033 | void BrowserProcessImpl::RestartPersistentInstance() { |
| 1034 | CommandLine* old_cl = CommandLine::ForCurrentProcess(); |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 1035 | scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram())); |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1036 | |
| 1037 | std::map<std::string, CommandLine::StringType> switches = |
| 1038 | old_cl->GetSwitches(); |
| 1039 | |
[email protected] | 5c08f22 | 2010-09-22 09:37:21 | [diff] [blame] | 1040 | switches::RemoveSwitchesForAutostart(&switches); |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1041 | |
| 1042 | // Append the rest of the switches (along with their values, if any) |
| 1043 | // to the new command line |
| 1044 | for (std::map<std::string, CommandLine::StringType>::const_iterator i = |
| 1045 | switches.begin(); i != switches.end(); ++i) { |
| 1046 | CommandLine::StringType switch_value = i->second; |
| 1047 | if (switch_value.length() > 0) { |
[email protected] | 05076ba2 | 2010-07-30 05:59:57 | [diff] [blame] | 1048 | new_cl->AppendSwitchNative(i->first, i->second); |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1049 | } else { |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 1050 | new_cl->AppendSwitch(i->first); |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | |
[email protected] | 6c10c97 | 2010-08-11 04:15:47 | [diff] [blame] | 1054 | // Ensure that our desired switches are set on the new process. |
[email protected] | 5c08f22 | 2010-09-22 09:37:21 | [diff] [blame] | 1055 | for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) { |
[email protected] | 6c10c97 | 2010-08-11 04:15:47 | [diff] [blame] | 1056 | if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i])) |
| 1057 | new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]); |
| 1058 | } |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1059 | |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 1060 | DLOG(WARNING) << "Shutting down current instance of the browser."; |
| 1061 | BrowserList::CloseAllBrowsersAndExit(); |
| 1062 | |
| 1063 | // Transfer ownership to Upgrade. |
[email protected] | 81585672 | 2011-04-13 17:19:19 | [diff] [blame] | 1064 | upgrade_util::SetNewCommandLine(new_cl.release()); |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | void BrowserProcessImpl::OnAutoupdateTimer() { |
| 1068 | if (CanAutorestartForUpdate()) { |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 1069 | DLOG(WARNING) << "Detected update. Restarting browser."; |
[email protected] | bd48c2b0 | 2010-04-09 20:32:42 | [diff] [blame] | 1070 | RestartPersistentInstance(); |
| 1071 | } |
| 1072 | } |
| 1073 | |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 1074 | #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |