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