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