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