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