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