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