blob: f1b30a52450a0effc6250c06f9f0553e8df127a7 [file] [log] [blame]
[email protected]f2a893c2011-01-05 09:38:071// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/browser_process_impl.h"
6
[email protected]3cdacd42010-04-30 18:55:537#include <map>
[email protected]68f88b992011-05-07 02:01:398#include <set>
9#include <vector>
[email protected]3cdacd42010-04-30 18:55:5310
initial.commit09911bf2008-07-26 23:55:2911#include "base/command_line.h"
[email protected]6641bf662009-08-21 00:34:0912#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/path_service.h"
[email protected]985655a2011-02-23 09:54:2514#include "base/synchronization/waitable_event.h"
[email protected]c6032e82010-09-13 20:06:0515#include "base/task.h"
[email protected]34b99632011-01-01 01:01:0616#include "base/threading/thread.h"
17#include "base/threading/thread_restrictions.h"
[email protected]e13ad79b2010-07-22 21:36:5018#include "chrome/browser/automation/automation_provider_list.h"
[email protected]b443cb042009-12-15 22:05:0919#include "chrome/browser/browser_main.h"
[email protected]0ac83682010-01-22 17:46:2720#include "chrome/browser/browser_process_sub_thread.h"
[email protected]ac262c9f2008-10-19 17:45:2121#include "chrome/browser/browser_trial.h"
[email protected]9678cb42011-01-31 18:49:4222#include "chrome/browser/debugger/browser_list_tabcontents_provider.h"
[email protected]5613126e2011-01-31 15:27:5523#include "chrome/browser/debugger/devtools_http_protocol_handler.h"
[email protected]40ecc902009-03-16 13:42:4724#include "chrome/browser/debugger/devtools_manager.h"
[email protected]5613126e2011-01-31 15:27:5525#include "chrome/browser/debugger/devtools_protocol_handler.h"
[email protected]6c69796d2010-07-16 21:41:1626#include "chrome/browser/download/download_file_manager.h"
[email protected]5ba0a2c2009-02-19 01:19:3427#include "chrome/browser/download/save_file_manager.h"
[email protected]3ce02412011-03-01 12:01:1528#include "chrome/browser/extensions/extension_event_router_forwarder.h"
[email protected]fc4facd2011-03-22 23:18:5029#include "chrome/browser/extensions/extension_tab_id_map.h"
[email protected]214538842011-04-01 18:47:2430#include "chrome/browser/extensions/user_script_listener.h"
[email protected]815856722011-04-13 17:19:1931#include "chrome/browser/first_run/upgrade_util.h"
[email protected]f7578f52010-08-30 22:22:4932#include "chrome/browser/google/google_url_tracker.h"
[email protected]dcefa302009-05-20 00:24:3933#include "chrome/browser/icon_manager.h"
[email protected]c4ff4952010-01-08 19:12:4734#include "chrome/browser/intranet_redirect_detector.h"
[email protected]0ac83682010-01-22 17:46:2735#include "chrome/browser/io_thread.h"
[email protected]dc6f4962009-02-13 01:25:5036#include "chrome/browser/metrics/metrics_service.h"
[email protected]0b565182011-03-02 18:11:1537#include "chrome/browser/metrics/thread_watcher.h"
[email protected]b2fcd0e2010-12-01 15:19:4038#include "chrome/browser/net/chrome_net_log.h"
[email protected]3530cd92010-06-27 06:22:0139#include "chrome/browser/net/predictor_api.h"
[email protected]d393a0fd2009-05-13 23:32:0140#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]29672ab2009-10-30 03:44:0341#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]838dd914a2011-05-09 02:50:5842#include "chrome/browser/platform_util.h"
[email protected]6618d1d2010-12-15 21:18:4743#include "chrome/browser/plugin_data_remover.h"
[email protected]985655a2011-02-23 09:54:2544#include "chrome/browser/policy/browser_policy_connector.h"
[email protected]caf63aea2011-04-26 11:04:1045#include "chrome/browser/prefs/browser_prefs.h"
[email protected]37858e52010-08-26 00:22:0246#include "chrome/browser/prefs/pref_service.h"
[email protected]68f88b992011-05-07 02:01:3947#include "chrome/browser/printing/background_printing_manager.h"
[email protected]e06131d2010-02-10 18:40:3348#include "chrome/browser/printing/print_job_manager.h"
[email protected]dbeebd52010-11-16 20:34:1649#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]8ecad5e2010-12-02 21:18:3350#include "chrome/browser/profiles/profile_manager.h"
[email protected]a7a5e992010-12-09 23:39:5151#include "chrome/browser/safe_browsing/client_side_detection_service.h"
[email protected]81218f42009-02-05 18:48:0852#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]e450fa62011-02-01 12:52:5653#include "chrome/browser/shell_integration.h"
[email protected]8b8e7c92010-08-19 18:05:5654#include "chrome/browser/sidebar/sidebar_manager.h"
[email protected]0b4d3382010-07-14 16:13:0455#include "chrome/browser/tab_closeable_state_watcher.h"
[email protected]71b73f02011-04-06 15:57:2956#include "chrome/browser/ui/browser_list.h"
[email protected]4ef795df2010-02-03 02:35:0857#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2958#include "chrome/common/chrome_paths.h"
59#include "chrome/common/chrome_switches.h"
[email protected]f1b6de22010-03-06 12:13:4760#include "chrome/common/extensions/extension_l10n_util.h"
[email protected]985655a2011-02-23 09:54:2561#include "chrome/common/extensions/extension_resource.h"
[email protected]ea587b02010-05-21 15:01:3562#include "chrome/common/json_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2963#include "chrome/common/pref_names.h"
[email protected]5c08f222010-09-22 09:37:2164#include "chrome/common/switch_utils.h"
[email protected]985655a2011-02-23 09:54:2565#include "chrome/common/url_constants.h"
[email protected]bd48c2b02010-04-09 20:32:4266#include "chrome/installer/util/google_update_constants.h"
[email protected]a01efd22011-03-01 00:38:3267#include "content/browser/browser_child_process_host.h"
68#include "content/browser/browser_thread.h"
[email protected]419a0572011-04-18 22:21:4669#include "content/browser/child_process_security_policy.h"
[email protected]d9f37932011-05-09 20:09:2470#include "content/browser/gpu/gpu_process_host_ui_shim.h"
[email protected]a01efd22011-03-01 00:38:3271#include "content/browser/plugin_service.h"
72#include "content/browser/renderer_host/render_process_host.h"
73#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]f20d7332011-03-08 21:11:5374#include "content/common/notification_service.h"
[email protected]d55aaa132009-09-28 21:08:0475#include "ipc/ipc_logging.h"
[email protected]abe2c032011-03-31 18:49:3476#include "net/url_request/url_request_context_getter.h"
[email protected]2dfeaf92011-01-10 21:08:2177#include "ui/base/clipboard/clipboard.h"
[email protected]c051a1b2011-01-21 23:30:1778#include "ui/base/l10n/l10n_util.h"
[email protected]4ef795df2010-02-03 02:35:0879#include "webkit/database/database_tracker.h"
[email protected]b112a4c2009-02-01 20:24:0180
81#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0582#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3883#endif
84
[email protected]d55aaa132009-09-28 21:08:0485#if defined(IPC_MESSAGE_LOG_ENABLED)
[email protected]ff47b2962011-03-07 23:51:4986#include "content/common/child_process_messages.h"
[email protected]d55aaa132009-09-28 21:08:0487#endif
88
[email protected]db0e86dd2011-03-16 14:47:2189#if defined(OS_CHROMEOS)
90#include "chrome/browser/chromeos/proxy_config_service_impl.h"
91#endif // defined(OS_CHROMEOS)
92
[email protected]3cdacd42010-04-30 18:55:5393#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
94// How often to check if the persistent instance of Chrome needs to restart
95// to install an update.
96static const int kUpdateCheckIntervalHours = 6;
97#endif
98
[email protected]c6032e82010-09-13 20:06:0599#if defined(USE_X11)
100// How long to wait for the File thread to complete during EndSession, on
101// Linux. We have a timeout here because we're unable to run the UI messageloop
102// and there's some deadlock risk. Our only option is to exit anyway.
103static const int kEndSessionTimeoutSeconds = 10;
104#endif
105
[email protected]bb975362009-01-21 01:00:22106BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:29107 : created_resource_dispatcher_host_(false),
108 created_metrics_service_(false),
109 created_io_thread_(false),
110 created_file_thread_(false),
111 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:33112 created_process_launcher_thread_(false),
[email protected]875ee822010-05-18 20:58:01113 created_cache_thread_(false),
[email protected]7a31f7c2011-03-21 23:22:04114 created_gpu_thread_(false),
[email protected]0b565182011-03-02 18:11:15115 created_watchdog_thread_(false),
initial.commit09911bf2008-07-26 23:55:29116 created_profile_manager_(false),
117 created_local_state_(false),
[email protected]b112a4c2009-02-01 20:24:01118 created_icon_manager_(false),
[email protected]40ecc902009-03-16 13:42:47119 created_devtools_manager_(false),
[email protected]8b8e7c92010-08-19 18:05:56120 created_sidebar_manager_(false),
[email protected]985655a2011-02-23 09:54:25121 created_browser_policy_connector_(false),
[email protected]29672ab2009-10-30 03:44:03122 created_notification_ui_manager_(false),
[email protected]a7a5e992010-12-09 23:39:51123 created_safe_browsing_detection_service_(false),
initial.commit09911bf2008-07-26 23:55:29124 module_ref_count_(0),
[email protected]afd20c022010-06-10 00:48:20125 did_start_(false),
[email protected]1b2db1a2008-08-08 17:46:13126 checked_for_new_frames_(false),
[email protected]4747caf2011-03-23 20:09:21127 using_new_frames_(false) {
initial.commit09911bf2008-07-26 23:55:29128 g_browser_process = this;
[email protected]2dfeaf92011-01-10 21:08:21129 clipboard_.reset(new ui::Clipboard);
initial.commit09911bf2008-07-26 23:55:29130 main_notification_service_.reset(new NotificationService);
131
[email protected]6618d1d2010-12-15 21:18:47132 notification_registrar_.Add(this,
133 NotificationType::APP_TERMINATING,
134 NotificationService::AllSources());
135
initial.commit09911bf2008-07-26 23:55:29136 // Must be created after the NotificationService.
137 print_job_manager_.reset(new printing::PrintJobManager);
138
[email protected]b797e152009-01-23 16:06:14139 shutdown_event_.reset(new base::WaitableEvent(true, false));
[email protected]b2fcd0e2010-12-01 15:19:40140
141 net_log_.reset(new ChromeNetLog);
[email protected]3ce02412011-03-01 12:01:15142
143 extension_event_router_forwarder_ = new ExtensionEventRouterForwarder;
[email protected]fc4facd2011-03-22 23:18:50144
145 ExtensionTabIdMap::GetInstance()->Init();
initial.commit09911bf2008-07-26 23:55:29146}
147
148BrowserProcessImpl::~BrowserProcessImpl() {
[email protected]4ef795df2010-02-03 02:35:08149 FilePath profile_path;
150 bool clear_local_state_on_exit;
151
152 // Store the profile path for clearing local state data on exit.
153 clear_local_state_on_exit = ShouldClearLocalState(&profile_path);
154
initial.commit09911bf2008-07-26 23:55:29155 // Delete the AutomationProviderList before NotificationService,
156 // since it may try to unregister notifications
157 // Both NotificationService and AutomationProvider are singleton instances in
158 // the BrowserProcess. Since AutomationProvider may have some active
159 // notification observers, it is essential that it gets destroyed before the
160 // NotificationService. NotificationService won't be destroyed until after
161 // this destructor is run.
162 automation_provider_list_.reset();
163
[email protected]d393a0fd2009-05-13 23:32:01164 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
165 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
166 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
167 // any pending URLFetchers, and avoid creating any more.
168 SdchDictionaryFetcher::Shutdown();
169
[email protected]51ac040762011-01-20 02:01:04170 // We need to destroy the MetricsService, GoogleURLTracker,
171 // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService
172 // before the io_thread_ gets destroyed, since their destructors can call the
173 // URLFetcher destructor, which does a PostDelayedTask operation on the IO
174 // thread. (The IO thread will handle that URLFetcher operation before going
175 // away.)
initial.commit09911bf2008-07-26 23:55:29176 metrics_service_.reset();
177 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47178 intranet_redirect_detector_.reset();
[email protected]51ac040762011-01-20 02:01:04179 safe_browsing_detection_service_.reset();
initial.commit09911bf2008-07-26 23:55:29180
[email protected]d8a899c2010-09-21 04:50:33181 // Need to clear the desktop notification balloons before the io_thread_ and
182 // before the profiles, since if there are any still showing we will access
183 // those things during teardown.
184 notification_ui_manager_.reset();
185
initial.commit09911bf2008-07-26 23:55:29186 // Need to clear profiles (download managers) before the io_thread_.
187 profile_manager_.reset();
188
189 // Debugger must be cleaned up before IO thread and NotificationService.
[email protected]5613126e2011-01-31 15:27:55190 if (devtools_http_handler_.get()) {
191 devtools_http_handler_->Stop();
192 devtools_http_handler_ = NULL;
193 }
194 if (devtools_legacy_handler_.get()) {
195 devtools_legacy_handler_->Stop();
196 devtools_legacy_handler_ = NULL;
197 }
initial.commit09911bf2008-07-26 23:55:29198
199 if (resource_dispatcher_host_.get()) {
200 // Need to tell Safe Browsing Service that the IO thread is going away
201 // since it cached a pointer to it.
202 if (resource_dispatcher_host()->safe_browsing_service())
203 resource_dispatcher_host()->safe_browsing_service()->ShutDown();
204
205 // Cancel pending requests and prevent new requests.
206 resource_dispatcher_host()->Shutdown();
207 }
208
[email protected]fc4facd2011-03-22 23:18:50209 ExtensionTabIdMap::GetInstance()->Shutdown();
210
[email protected]985655a2011-02-23 09:54:25211 // The policy providers managed by |browser_policy_connector_| need to shut
212 // down while the IO and FILE threads are still alive.
213 browser_policy_connector_.reset();
[email protected]f2a893c2011-01-05 09:38:07214
[email protected]753efc42010-03-09 19:52:16215#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06216 // The IO thread must outlive the BACKGROUND_X11 thread.
217 background_x11_thread_.reset();
218#endif
219
[email protected]6618d1d2010-12-15 21:18:47220 // Wait for removing plugin data to finish before shutting down the IO thread.
221 WaitForPluginDataRemoverToFinish();
222
[email protected]7a31f7c2011-03-21 23:22:04223 // Destroying the GpuProcessHostUIShims on the UI thread posts a task to
224 // delete related objects on the GPU thread. This must be done before
225 // stopping the GPU thread. The GPU thread will close IPC channels to renderer
226 // processes so this has to happen before stopping the IO thread.
227 GpuProcessHostUIShim::DestroyAll();
228 gpu_thread_.reset();
229
initial.commit09911bf2008-07-26 23:55:29230 // Need to stop io_thread_ before resource_dispatcher_host_, since
231 // io_thread_ may still deref ResourceDispatcherHost and handle resource
232 // request before going away.
[email protected]0ac83682010-01-22 17:46:27233 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29234
[email protected]875ee822010-05-18 20:58:01235 // The IO thread was the only user of this thread.
236 cache_thread_.reset();
237
[email protected]914511712009-11-23 19:42:33238 // Stop the process launcher thread after the IO thread, in case the IO thread
239 // posted a task to terminate a process on the process launcher thread.
240 process_launcher_thread_.reset();
241
initial.commit09911bf2008-07-26 23:55:29242 // Clean up state that lives on the file_thread_ before it goes away.
243 if (resource_dispatcher_host_.get()) {
244 resource_dispatcher_host()->download_file_manager()->Shutdown();
245 resource_dispatcher_host()->save_file_manager()->Shutdown();
246 }
247
248 // Need to stop the file_thread_ here to force it to process messages in its
249 // message loop from the previous call to shutdown the DownloadFileManager,
250 // SaveFileManager and SessionService.
251 file_thread_.reset();
252
253 // With the file_thread_ flushed, we can release any icon resources.
254 icon_manager_.reset();
255
256 // Need to destroy ResourceDispatcherHost before PluginService and
[email protected]49f28bc72010-02-04 00:10:01257 // SafeBrowsingService, since it caches a pointer to it. This also
258 // causes the webkit thread to terminate.
initial.commit09911bf2008-07-26 23:55:29259 resource_dispatcher_host_.reset();
260
261 // Wait for the pending print jobs to finish.
262 print_job_manager_->OnQuit();
263 print_job_manager_.reset();
264
[email protected]0b4d3382010-07-14 16:13:04265 // Destroy TabCloseableStateWatcher before NotificationService since the
266 // former registers for notifications.
267 tab_closeable_state_watcher_.reset();
268
initial.commit09911bf2008-07-26 23:55:29269 // Now OK to destroy NotificationService.
270 main_notification_service_.reset();
271
[email protected]49f28bc72010-02-04 00:10:01272 // Prior to clearing local state, we want to complete tasks pending
273 // on the db thread too.
274 db_thread_.reset();
275
[email protected]0b565182011-03-02 18:11:15276 // Stop the watchdog thread after stopping other threads.
277 watchdog_thread_.reset();
278
[email protected]49f28bc72010-02-04 00:10:01279 // At this point, no render process exist and the file, io, db, and
280 // webkit threads in this process have all terminated, so it's safe
281 // to access local state data such as cookies, database, or local storage.
282 if (clear_local_state_on_exit)
283 ClearLocalState(profile_path);
284
initial.commit09911bf2008-07-26 23:55:29285 g_browser_process = NULL;
286}
287
[email protected]c6032e82010-09-13 20:06:05288#if defined(OS_WIN)
[email protected]295039bd2008-08-15 04:32:57289// Send a QuitTask to the given MessageLoop.
290static void PostQuit(MessageLoop* message_loop) {
291 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
292}
[email protected]c6032e82010-09-13 20:06:05293#elif defined(USE_X11)
294static void Signal(base::WaitableEvent* event) {
295 event->Signal();
296}
297#endif
initial.commit09911bf2008-07-26 23:55:29298
[email protected]b443cb042009-12-15 22:05:09299unsigned int BrowserProcessImpl::AddRefModule() {
300 DCHECK(CalledOnValidThread());
[email protected]afd20c022010-06-10 00:48:20301 did_start_ = true;
[email protected]b443cb042009-12-15 22:05:09302 module_ref_count_++;
303 return module_ref_count_;
304}
305
306unsigned int BrowserProcessImpl::ReleaseModule() {
307 DCHECK(CalledOnValidThread());
[email protected]760d970a2010-05-18 00:39:18308 DCHECK_NE(0u, module_ref_count_);
[email protected]b443cb042009-12-15 22:05:09309 module_ref_count_--;
310 if (0 == module_ref_count_) {
[email protected]7d038c32010-12-14 00:40:00311 // Allow UI and IO threads to do blocking IO on shutdown, since we do a lot
312 // of it on shutdown for valid reasons.
313 base::ThreadRestrictions::SetIOAllowed(true);
314 io_thread()->message_loop()->PostTask(
315 FROM_HERE,
316 NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true));
[email protected]b443cb042009-12-15 22:05:09317 MessageLoop::current()->PostTask(
[email protected]34f73fb2010-03-24 20:50:34318 FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop));
[email protected]b443cb042009-12-15 22:05:09319 MessageLoop::current()->Quit();
320 }
321 return module_ref_count_;
322}
323
initial.commit09911bf2008-07-26 23:55:29324void BrowserProcessImpl::EndSession() {
[email protected]c6032e82010-09-13 20:06:05325#if defined(OS_WIN) || defined(USE_X11)
[email protected]d65cab7a2008-08-12 01:25:41326 // Notify we are going away.
[email protected]c6032e82010-09-13 20:06:05327 shutdown_event_->Signal();
[email protected]b112a4c2009-02-01 20:24:01328#endif
[email protected]d65cab7a2008-08-12 01:25:41329
initial.commit09911bf2008-07-26 23:55:29330 // Mark all the profiles as clean.
331 ProfileManager* pm = profile_manager();
[email protected]844a1002011-04-19 11:37:21332 std::vector<Profile*> profiles(pm->GetLoadedProfiles());
333 for (size_t i = 0; i < profiles.size(); ++i)
334 profiles[i]->MarkAsCleanShutdown();
initial.commit09911bf2008-07-26 23:55:29335
336 // Tell the metrics service it was cleanly shutdown.
337 MetricsService* metrics = g_browser_process->metrics_service();
338 if (metrics && local_state()) {
initial.commit09911bf2008-07-26 23:55:29339 metrics->RecordStartOfSessionEnd();
340
341 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36342 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29343 }
344
345 // We must write that the profile and metrics service shutdown cleanly,
346 // otherwise on startup we'll think we crashed. So we block until done and
347 // then proceed with normal shutdown.
[email protected]c6032e82010-09-13 20:06:05348#if defined(USE_X11)
349 // Can't run a local loop on linux. Instead create a waitable event.
350 base::WaitableEvent done_writing(false, false);
[email protected]d04e7662010-10-10 22:24:48351 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]c6032e82010-09-13 20:06:05352 NewRunnableFunction(Signal, &done_writing));
353 done_writing.TimedWait(
354 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds));
355#elif defined(OS_WIN)
[email protected]d04e7662010-10-10 22:24:48356 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57357 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29358 MessageLoop::current()->Run();
[email protected]c6032e82010-09-13 20:06:05359#else
360 NOTIMPLEMENTED();
361#endif
initial.commit09911bf2008-07-26 23:55:29362}
363
[email protected]e13ad79b2010-07-22 21:36:50364ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() {
365 DCHECK(CalledOnValidThread());
366 if (!created_resource_dispatcher_host_)
367 CreateResourceDispatcherHost();
368 return resource_dispatcher_host_.get();
369}
370
371MetricsService* BrowserProcessImpl::metrics_service() {
372 DCHECK(CalledOnValidThread());
373 if (!created_metrics_service_)
374 CreateMetricsService();
375 return metrics_service_.get();
376}
377
378IOThread* BrowserProcessImpl::io_thread() {
379 DCHECK(CalledOnValidThread());
380 if (!created_io_thread_)
381 CreateIOThread();
382 return io_thread_.get();
383}
384
385base::Thread* BrowserProcessImpl::file_thread() {
386 DCHECK(CalledOnValidThread());
387 if (!created_file_thread_)
388 CreateFileThread();
389 return file_thread_.get();
390}
391
392base::Thread* BrowserProcessImpl::db_thread() {
393 DCHECK(CalledOnValidThread());
394 if (!created_db_thread_)
395 CreateDBThread();
396 return db_thread_.get();
397}
398
399base::Thread* BrowserProcessImpl::process_launcher_thread() {
400 DCHECK(CalledOnValidThread());
401 if (!created_process_launcher_thread_)
402 CreateProcessLauncherThread();
403 return process_launcher_thread_.get();
404}
405
406base::Thread* BrowserProcessImpl::cache_thread() {
407 DCHECK(CalledOnValidThread());
408 if (!created_cache_thread_)
409 CreateCacheThread();
410 return cache_thread_.get();
411}
412
[email protected]7a31f7c2011-03-21 23:22:04413base::Thread* BrowserProcessImpl::gpu_thread() {
414 DCHECK(CalledOnValidThread());
415 if (!created_gpu_thread_)
416 CreateGpuThread();
417 return gpu_thread_.get();
418}
419
[email protected]e13ad79b2010-07-22 21:36:50420#if defined(USE_X11)
421base::Thread* BrowserProcessImpl::background_x11_thread() {
422 DCHECK(CalledOnValidThread());
423 // The BACKGROUND_X11 thread is created when the IO thread is created.
424 if (!created_io_thread_)
425 CreateIOThread();
426 return background_x11_thread_.get();
427}
428#endif
429
[email protected]0b565182011-03-02 18:11:15430WatchDogThread* BrowserProcessImpl::watchdog_thread() {
431 DCHECK(CalledOnValidThread());
432 if (!created_watchdog_thread_)
433 CreateWatchdogThread();
434 DCHECK(watchdog_thread_.get() != NULL);
435 return watchdog_thread_.get();
436}
437
[email protected]e13ad79b2010-07-22 21:36:50438ProfileManager* BrowserProcessImpl::profile_manager() {
439 DCHECK(CalledOnValidThread());
440 if (!created_profile_manager_)
441 CreateProfileManager();
442 return profile_manager_.get();
443}
444
445PrefService* BrowserProcessImpl::local_state() {
446 DCHECK(CalledOnValidThread());
447 if (!created_local_state_)
448 CreateLocalState();
449 return local_state_.get();
450}
451
452DevToolsManager* BrowserProcessImpl::devtools_manager() {
453 DCHECK(CalledOnValidThread());
454 if (!created_devtools_manager_)
455 CreateDevToolsManager();
456 return devtools_manager_.get();
457}
458
[email protected]8b8e7c92010-08-19 18:05:56459SidebarManager* BrowserProcessImpl::sidebar_manager() {
460 DCHECK(CalledOnValidThread());
461 if (!created_sidebar_manager_)
462 CreateSidebarManager();
463 return sidebar_manager_.get();
464}
465
[email protected]2dfeaf92011-01-10 21:08:21466ui::Clipboard* BrowserProcessImpl::clipboard() {
[email protected]e13ad79b2010-07-22 21:36:50467 DCHECK(CalledOnValidThread());
468 return clipboard_.get();
469}
470
[email protected]abe2c032011-03-31 18:49:34471net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() {
[email protected]db0e86dd2011-03-16 14:47:21472 DCHECK(CalledOnValidThread());
473 return io_thread()->system_url_request_context_getter();
474}
475
476#if defined(OS_CHROMEOS)
477chromeos::ProxyConfigServiceImpl*
478BrowserProcessImpl::chromeos_proxy_config_service_impl() {
479 DCHECK(CalledOnValidThread());
480 if (!chromeos_proxy_config_service_impl_) {
481 chromeos_proxy_config_service_impl_ =
482 new chromeos::ProxyConfigServiceImpl();
483 }
484 return chromeos_proxy_config_service_impl_;
485}
486#endif // defined(OS_CHROMEOS)
487
[email protected]3ce02412011-03-01 12:01:15488ExtensionEventRouterForwarder*
489BrowserProcessImpl::extension_event_router_forwarder() {
490 return extension_event_router_forwarder_.get();
491}
492
[email protected]e13ad79b2010-07-22 21:36:50493NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
494 DCHECK(CalledOnValidThread());
495 if (!created_notification_ui_manager_)
496 CreateNotificationUIManager();
497 return notification_ui_manager_.get();
498}
499
[email protected]985655a2011-02-23 09:54:25500policy::BrowserPolicyConnector* BrowserProcessImpl::browser_policy_connector() {
[email protected]f2a893c2011-01-05 09:38:07501 DCHECK(CalledOnValidThread());
[email protected]985655a2011-02-23 09:54:25502 if (!created_browser_policy_connector_) {
503 DCHECK(browser_policy_connector_.get() == NULL);
504 created_browser_policy_connector_ = true;
[email protected]d9ee002c2011-04-27 12:52:54505 browser_policy_connector_.reset(policy::BrowserPolicyConnector::Create());
[email protected]f2a893c2011-01-05 09:38:07506 }
[email protected]985655a2011-02-23 09:54:25507 return browser_policy_connector_.get();
[email protected]f2a893c2011-01-05 09:38:07508}
509
[email protected]e13ad79b2010-07-22 21:36:50510IconManager* BrowserProcessImpl::icon_manager() {
511 DCHECK(CalledOnValidThread());
512 if (!created_icon_manager_)
513 CreateIconManager();
514 return icon_manager_.get();
515}
516
517ThumbnailGenerator* BrowserProcessImpl::GetThumbnailGenerator() {
518 return &thumbnail_generator_;
519}
520
521AutomationProviderList* BrowserProcessImpl::InitAutomationProviderList() {
522 DCHECK(CalledOnValidThread());
523 if (automation_provider_list_.get() == NULL) {
524 automation_provider_list_.reset(AutomationProviderList::GetInstance());
525 }
526 return automation_provider_list_.get();
527}
528
[email protected]5613126e2011-01-31 15:27:55529void BrowserProcessImpl::InitDevToolsHttpProtocolHandler(
[email protected]01000cf12011-02-04 11:39:22530 const std::string& ip,
[email protected]5613126e2011-01-31 15:27:55531 int port,
532 const std::string& frontend_url) {
[email protected]e13ad79b2010-07-22 21:36:50533 DCHECK(CalledOnValidThread());
[email protected]5613126e2011-01-31 15:27:55534 devtools_http_handler_ =
[email protected]01000cf12011-02-04 11:39:22535 DevToolsHttpProtocolHandler::Start(ip,
536 port,
[email protected]9678cb42011-01-31 18:49:42537 frontend_url,
538 new BrowserListTabContentsProvider());
[email protected]5613126e2011-01-31 15:27:55539}
540
541void BrowserProcessImpl::InitDevToolsLegacyProtocolHandler(int port) {
542 DCHECK(CalledOnValidThread());
543 devtools_legacy_handler_ = DevToolsProtocolHandler::Start(port);
[email protected]e13ad79b2010-07-22 21:36:50544}
545
546bool BrowserProcessImpl::IsShuttingDown() {
547 DCHECK(CalledOnValidThread());
548 return did_start_ && 0 == module_ref_count_;
549}
550
initial.commit09911bf2008-07-26 23:55:29551printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
552 // TODO(abarth): DCHECK(CalledOnValidThread());
[email protected]d8922f22010-05-07 00:57:27553 // http://code.google.com/p/chromium/issues/detail?id=6828
initial.commit09911bf2008-07-26 23:55:29554 // print_job_manager_ is initialized in the constructor and destroyed in the
555 // destructor, so it should always be valid.
556 DCHECK(print_job_manager_.get());
557 return print_job_manager_.get();
558}
559
[email protected]dbeebd52010-11-16 20:34:16560printing::PrintPreviewTabController*
561 BrowserProcessImpl::print_preview_tab_controller() {
562 DCHECK(CalledOnValidThread());
563 if (!print_preview_tab_controller_.get())
564 CreatePrintPreviewTabController();
565 return print_preview_tab_controller_.get();
566}
567
[email protected]68f88b992011-05-07 02:01:39568printing::BackgroundPrintingManager*
569 BrowserProcessImpl::background_printing_manager() {
570 DCHECK(CalledOnValidThread());
571 if (!background_printing_manager_.get())
572 CreateBackgroundPrintingManager();
573 return background_printing_manager_.get();
574}
575
[email protected]e13ad79b2010-07-22 21:36:50576GoogleURLTracker* BrowserProcessImpl::google_url_tracker() {
577 DCHECK(CalledOnValidThread());
578 if (!google_url_tracker_.get())
579 CreateGoogleURLTracker();
580 return google_url_tracker_.get();
581}
582
583IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
584 DCHECK(CalledOnValidThread());
585 if (!intranet_redirect_detector_.get())
586 CreateIntranetRedirectDetector();
587 return intranet_redirect_detector_.get();
588}
589
590const std::string& BrowserProcessImpl::GetApplicationLocale() {
591 DCHECK(!locale_.empty());
592 return locale_;
593}
594
595void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
596 locale_ = locale;
597 extension_l10n_util::SetProcessLocale(locale);
598}
599
[email protected]073ed7b2010-09-27 09:20:02600DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
601 return &download_status_updater_;
602}
603
[email protected]e13ad79b2010-07-22 21:36:50604base::WaitableEvent* BrowserProcessImpl::shutdown_event() {
605 return shutdown_event_.get();
606}
607
608TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() {
609 DCHECK(CalledOnValidThread());
610 if (!tab_closeable_state_watcher_.get())
611 CreateTabCloseableStateWatcher();
612 return tab_closeable_state_watcher_.get();
613}
614
[email protected]a7a5e992010-12-09 23:39:51615safe_browsing::ClientSideDetectionService*
616 BrowserProcessImpl::safe_browsing_detection_service() {
617 DCHECK(CalledOnValidThread());
618 if (!created_safe_browsing_detection_service_) {
619 CreateSafeBrowsingDetectionService();
620 }
621 return safe_browsing_detection_service_.get();
622}
623
[email protected]8b08a47f2011-02-25 12:36:37624bool BrowserProcessImpl::plugin_finder_disabled() const {
625 return *plugin_finder_disabled_pref_;
626}
627
[email protected]6618d1d2010-12-15 21:18:47628void BrowserProcessImpl::Observe(NotificationType type,
629 const NotificationSource& source,
630 const NotificationDetails& details) {
631 if (type == NotificationType::APP_TERMINATING) {
632 Profile* profile = ProfileManager::GetDefaultProfile();
633 if (profile) {
634 PrefService* prefs = profile->GetPrefs();
[email protected]2ffc3c6c2011-01-14 12:50:24635 if (prefs->GetBoolean(prefs::kClearSiteDataOnExit) &&
[email protected]6618d1d2010-12-15 21:18:47636 local_state()->GetBoolean(prefs::kClearPluginLSODataEnabled)) {
637 plugin_data_remover_ = new PluginDataRemover();
[email protected]c7d58d62011-01-21 10:27:18638 if (!plugin_data_remover_mime_type().empty())
639 plugin_data_remover_->set_mime_type(plugin_data_remover_mime_type());
640 plugin_data_remover_->StartRemoving(base::Time());
[email protected]6618d1d2010-12-15 21:18:47641 }
642 }
[email protected]e450fa62011-02-01 12:52:56643 } else if (type == NotificationType::PREF_CHANGED) {
644 std::string* pref = Details<std::string>(details).ptr();
645 if (*pref == prefs::kDefaultBrowserSettingEnabled) {
646 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
647 ShellIntegration::SetAsDefaultBrowser();
[email protected]419a0572011-04-18 22:21:46648 } else if (*pref == prefs::kDisabledSchemes) {
649 ApplyDisabledSchemesPolicy();
[email protected]e450fa62011-02-01 12:52:56650 }
[email protected]6618d1d2010-12-15 21:18:47651 } else {
652 NOTREACHED();
653 }
654}
655
656void BrowserProcessImpl::WaitForPluginDataRemoverToFinish() {
[email protected]c7d58d62011-01-21 10:27:18657 if (plugin_data_remover_.get())
658 plugin_data_remover_->Wait();
[email protected]6618d1d2010-12-15 21:18:47659}
660
[email protected]e13ad79b2010-07-22 21:36:50661#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
662void BrowserProcessImpl::StartAutoupdateTimer() {
663 autoupdate_timer_.Start(
664 base::TimeDelta::FromHours(kUpdateCheckIntervalHours),
665 this,
666 &BrowserProcessImpl::OnAutoupdateTimer);
667}
668#endif
669
[email protected]d6f37fc2011-02-13 23:58:41670ChromeNetLog* BrowserProcessImpl::net_log() {
671 return net_log_.get();
672}
673
[email protected]4ef795df2010-02-03 02:35:08674void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
[email protected]72cfd90f2010-02-06 03:08:04675 webkit_database::DatabaseTracker::ClearLocalState(profile_path);
[email protected]4ef795df2010-02-03 02:35:08676}
677
678bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
679 FilePath user_data_dir;
680 Profile* profile;
681
[email protected]09584972010-07-03 00:00:59682 // Check for the existence of a profile manager. When quitting early,
[email protected]ed0cf562010-02-05 22:50:41683 // e.g. because another chrome instance is running, or when invoked with
684 // options such as --uninstall or --try-chrome-again=0, the profile manager
685 // does not exist yet.
686 if (!profile_manager_.get())
687 return false;
688
[email protected]4ef795df2010-02-03 02:35:08689 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
690 profile = profile_manager_->GetDefaultProfile(user_data_dir);
[email protected]7bfc674322010-03-05 00:20:57691 if (!profile)
692 return false;
[email protected]4ef795df2010-02-03 02:35:08693 *profile_path = profile->GetPath();
694 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit);
695}
696
initial.commit09911bf2008-07-26 23:55:29697void BrowserProcessImpl::CreateResourceDispatcherHost() {
698 DCHECK(!created_resource_dispatcher_host_ &&
699 resource_dispatcher_host_.get() == NULL);
700 created_resource_dispatcher_host_ = true;
701
[email protected]214538842011-04-01 18:47:24702 // UserScriptListener will delete itself.
703 ResourceQueue::DelegateSet resource_queue_delegates;
704 resource_queue_delegates.insert(new UserScriptListener());
705
706 resource_dispatcher_host_.reset(
707 new ResourceDispatcherHost(resource_queue_delegates));
initial.commit09911bf2008-07-26 23:55:29708 resource_dispatcher_host_->Initialize();
709}
710
711void BrowserProcessImpl::CreateMetricsService() {
712 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
713 created_metrics_service_ = true;
714
715 metrics_service_.reset(new MetricsService);
716}
717
718void BrowserProcessImpl::CreateIOThread() {
719 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
720 created_io_thread_ = true;
721
722 // Prior to starting the io thread, we create the plugin service as
723 // it is predominantly used from the io thread, but must be created
724 // on the main thread. The service ctor is inexpensive and does not
725 // invoke the io_thread() accessor.
726 PluginService::GetInstance();
727
[email protected]753efc42010-03-09 19:52:16728#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06729 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so
730 // we start it now.
731 scoped_ptr<base::Thread> background_x11_thread(
[email protected]d04e7662010-10-10 22:24:48732 new BrowserProcessSubThread(BrowserThread::BACKGROUND_X11));
[email protected]4c3cd7412009-04-22 17:56:06733 if (!background_x11_thread->Start())
734 return;
735 background_x11_thread_.swap(background_x11_thread);
736#endif
737
[email protected]3ce02412011-03-01 12:01:15738 scoped_ptr<IOThread> thread(new IOThread(
739 local_state(), net_log_.get(), extension_event_router_forwarder_.get()));
[email protected]ab820df2008-08-26 05:55:10740 base::Thread::Options options;
741 options.message_loop_type = MessageLoop::TYPE_IO;
742 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29743 return;
744 io_thread_.swap(thread);
745}
746
747void BrowserProcessImpl::CreateFileThread() {
748 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
749 created_file_thread_ = true;
750
[email protected]ab820df2008-08-26 05:55:10751 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48752 new BrowserProcessSubThread(BrowserThread::FILE));
[email protected]a1db3842008-09-17 22:04:06753 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39754#if defined(OS_WIN)
755 // On Windows, the FILE thread needs to be have a UI message loop which pumps
756 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06757 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39758#else
759 options.message_loop_type = MessageLoop::TYPE_IO;
760#endif
[email protected]a1db3842008-09-17 22:04:06761 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29762 return;
763 file_thread_.swap(thread);
764}
765
766void BrowserProcessImpl::CreateDBThread() {
767 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
768 created_db_thread_ = true;
769
[email protected]ab820df2008-08-26 05:55:10770 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48771 new BrowserProcessSubThread(BrowserThread::DB));
initial.commit09911bf2008-07-26 23:55:29772 if (!thread->Start())
773 return;
774 db_thread_.swap(thread);
775}
776
[email protected]914511712009-11-23 19:42:33777void BrowserProcessImpl::CreateProcessLauncherThread() {
778 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
779 created_process_launcher_thread_ = true;
780
781 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48782 new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER));
[email protected]914511712009-11-23 19:42:33783 if (!thread->Start())
784 return;
785 process_launcher_thread_.swap(thread);
786}
787
[email protected]875ee822010-05-18 20:58:01788void BrowserProcessImpl::CreateCacheThread() {
789 DCHECK(!created_cache_thread_ && !cache_thread_.get());
790 created_cache_thread_ = true;
791
792 scoped_ptr<base::Thread> thread(
[email protected]75096332010-11-09 03:28:13793 new BrowserThread(BrowserThread::CACHE));
[email protected]875ee822010-05-18 20:58:01794 base::Thread::Options options;
795 options.message_loop_type = MessageLoop::TYPE_IO;
796 if (!thread->StartWithOptions(options))
797 return;
798 cache_thread_.swap(thread);
799}
800
[email protected]7a31f7c2011-03-21 23:22:04801void BrowserProcessImpl::CreateGpuThread() {
802 DCHECK(!created_gpu_thread_ && !gpu_thread_.get());
803 created_gpu_thread_ = true;
804
805 scoped_ptr<base::Thread> thread(new BrowserThread(BrowserThread::GPU));
806
807 base::Thread::Options options;
808#if defined(OS_WIN)
809 // On Windows the GPU thread needs to pump the compositor child window's
810 // message loop. TODO(apatrick): make this an IO thread if / when we get rid
811 // of this child window. Unfortunately it might always be necessary for
812 // Windows XP because we cannot share the backing store textures between
813 // processes.
814 options.message_loop_type = MessageLoop::TYPE_UI;
815#else
816 options.message_loop_type = MessageLoop::TYPE_IO;
817#endif
818
819 if (!thread->StartWithOptions(options))
820 return;
821 gpu_thread_.swap(thread);
822}
823
[email protected]0b565182011-03-02 18:11:15824void BrowserProcessImpl::CreateWatchdogThread() {
825 DCHECK(!created_watchdog_thread_ && watchdog_thread_.get() == NULL);
826 created_watchdog_thread_ = true;
827
828 scoped_ptr<WatchDogThread> thread(new WatchDogThread());
829 if (!thread->Start())
830 return;
831 watchdog_thread_.swap(thread);
832}
833
initial.commit09911bf2008-07-26 23:55:29834void BrowserProcessImpl::CreateProfileManager() {
835 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
836 created_profile_manager_ = true;
837
838 profile_manager_.reset(new ProfileManager());
839}
840
841void BrowserProcessImpl::CreateLocalState() {
842 DCHECK(!created_local_state_ && local_state_.get() == NULL);
843 created_local_state_ = true;
844
[email protected]b9636002009-03-04 00:05:25845 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29846 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]f2d1f612010-12-09 15:10:17847 local_state_.reset(
848 PrefService::CreatePrefService(local_state_path, NULL, NULL));
[email protected]492d2142010-09-10 13:55:18849
[email protected]caf63aea2011-04-26 11:04:10850 // Initialize the prefs of the local state.
851 browser::RegisterLocalState(local_state_.get());
852
[email protected]2a7e7c152010-10-01 20:12:09853 pref_change_registrar_.Init(local_state_.get());
854
[email protected]f16b9662011-04-27 10:06:07855 print_job_manager_->InitOnUIThread(local_state_.get());
[email protected]e450fa62011-02-01 12:52:56856
857 // Initialize the notification for the default browser setting policy.
858 local_state_->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled,
859 false);
860 if (local_state_->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled)) {
861 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
862 ShellIntegration::SetAsDefaultBrowser();
863 }
864 pref_change_registrar_.Add(prefs::kDefaultBrowserSettingEnabled, this);
[email protected]8b08a47f2011-02-25 12:36:37865
866 // Initialize the preference for the plugin finder policy.
867 // This preference is only needed on the IO thread so make it available there.
868 local_state_->RegisterBooleanPref(prefs::kDisablePluginFinder, false);
869 plugin_finder_disabled_pref_.Init(prefs::kDisablePluginFinder,
870 local_state_.get(), NULL);
871 plugin_finder_disabled_pref_.MoveToThread(BrowserThread::IO);
[email protected]419a0572011-04-18 22:21:46872
[email protected]b99c41c2011-04-27 15:18:48873 // This is observed by ChildProcessSecurityPolicy, which lives in content/
874 // though, so it can't register itself.
[email protected]419a0572011-04-18 22:21:46875 local_state_->RegisterListPref(prefs::kDisabledSchemes);
[email protected]b99c41c2011-04-27 15:18:48876 pref_change_registrar_.Add(prefs::kDisabledSchemes, this);
[email protected]419a0572011-04-18 22:21:46877 ApplyDisabledSchemesPolicy();
[email protected]fd6159a2010-09-03 09:38:39878}
initial.commit09911bf2008-07-26 23:55:29879
initial.commit09911bf2008-07-26 23:55:29880void BrowserProcessImpl::CreateIconManager() {
881 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
882 created_icon_manager_ = true;
883 icon_manager_.reset(new IconManager);
884}
885
[email protected]40ecc902009-03-16 13:42:47886void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44887 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47888 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44889 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47890}
891
[email protected]8b8e7c92010-08-19 18:05:56892void BrowserProcessImpl::CreateSidebarManager() {
893 DCHECK(sidebar_manager_.get() == NULL);
894 created_sidebar_manager_ = true;
895 sidebar_manager_ = new SidebarManager();
896}
897
initial.commit09911bf2008-07-26 23:55:29898void BrowserProcessImpl::CreateGoogleURLTracker() {
899 DCHECK(google_url_tracker_.get() == NULL);
900 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
901 google_url_tracker_.swap(google_url_tracker);
902}
[email protected]6641bf662009-08-21 00:34:09903
[email protected]c4ff4952010-01-08 19:12:47904void BrowserProcessImpl::CreateIntranetRedirectDetector() {
905 DCHECK(intranet_redirect_detector_.get() == NULL);
906 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
907 new IntranetRedirectDetector);
908 intranet_redirect_detector_.swap(intranet_redirect_detector);
909}
910
[email protected]29672ab2009-10-30 03:44:03911void BrowserProcessImpl::CreateNotificationUIManager() {
912 DCHECK(notification_ui_manager_.get() == NULL);
[email protected]b0b2a3dd2011-01-06 00:30:05913 notification_ui_manager_.reset(NotificationUIManager::Create(local_state()));
914
[email protected]29672ab2009-10-30 03:44:03915 created_notification_ui_manager_ = true;
916}
917
[email protected]0b4d3382010-07-14 16:13:04918void BrowserProcessImpl::CreateTabCloseableStateWatcher() {
919 DCHECK(tab_closeable_state_watcher_.get() == NULL);
920 tab_closeable_state_watcher_.reset(TabCloseableStateWatcher::Create());
921}
922
[email protected]dbeebd52010-11-16 20:34:16923void BrowserProcessImpl::CreatePrintPreviewTabController() {
924 DCHECK(print_preview_tab_controller_.get() == NULL);
925 print_preview_tab_controller_ = new printing::PrintPreviewTabController();
926}
927
[email protected]68f88b992011-05-07 02:01:39928void BrowserProcessImpl::CreateBackgroundPrintingManager() {
929 DCHECK(background_printing_manager_.get() == NULL);
930 background_printing_manager_.reset(new printing::BackgroundPrintingManager());
931}
932
[email protected]a7a5e992010-12-09 23:39:51933void BrowserProcessImpl::CreateSafeBrowsingDetectionService() {
934 DCHECK(safe_browsing_detection_service_.get() == NULL);
935 // Set this flag to true so that we don't retry indefinitely to
936 // create the service class if there was an error.
937 created_safe_browsing_detection_service_ = true;
938
939 FilePath model_file_path;
940 Profile* profile = profile_manager() ?
941 profile_manager()->GetDefaultProfile() : NULL;
942 if (IsSafeBrowsingDetectionServiceEnabled() &&
943 PathService::Get(chrome::DIR_USER_DATA, &model_file_path) &&
944 profile && profile->GetRequestContext()) {
945 safe_browsing_detection_service_.reset(
946 safe_browsing::ClientSideDetectionService::Create(
947 model_file_path.Append(chrome::kSafeBrowsingPhishingModelFilename),
948 profile->GetRequestContext()));
949 }
950}
951
952bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() {
953 // The safe browsing client-side detection is enabled only if the switch is
[email protected]42930de42011-01-13 23:26:28954 // enabled and when safe browsing related stats is allowed to be collected.
[email protected]838dd914a2011-05-09 02:50:58955 // For now we only enable client-side detection on the canary, dev and beta
956 // channel.
[email protected]d081d192011-04-01 02:33:24957#ifdef OS_CHROMEOS
958 return false;
959#else
[email protected]838dd914a2011-05-09 02:50:58960 std::string channel = platform_util::GetVersionStringModifier();
[email protected]d081d192011-04-01 02:33:24961 return !CommandLine::ForCurrentProcess()->HasSwitch(
962 switches::kDisableClientSidePhishingDetection) &&
[email protected]42930de42011-01-13 23:26:28963 resource_dispatcher_host()->safe_browsing_service() &&
[email protected]838dd914a2011-05-09 02:50:58964 resource_dispatcher_host()->safe_browsing_service()->CanReportStats() &&
965 (channel == "beta" || channel == "dev" || channel == "canary");
[email protected]d081d192011-04-01 02:33:24966#endif
[email protected]a7a5e992010-12-09 23:39:51967}
968
[email protected]419a0572011-04-18 22:21:46969void BrowserProcessImpl::ApplyDisabledSchemesPolicy() {
970 std::set<std::string> schemes;
[email protected]b99c41c2011-04-27 15:18:48971 const ListValue* scheme_list = local_state_->GetList(prefs::kDisabledSchemes);
972 for (ListValue::const_iterator iter = scheme_list->begin();
973 iter != scheme_list->end(); ++iter) {
[email protected]419a0572011-04-18 22:21:46974 std::string scheme;
975 if ((*iter)->GetAsString(&scheme))
976 schemes.insert(scheme);
977 }
978 ChildProcessSecurityPolicy::GetInstance()->RegisterDisabledSchemes(schemes);
979}
980
[email protected]6641bf662009-08-21 00:34:09981// The BrowserProcess object must outlive the file thread so we use traits
982// which don't do any management.
[email protected]c56428f22010-06-16 02:17:23983DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl);
[email protected]6641bf662009-08-21 00:34:09984
[email protected]d55aaa132009-09-28 21:08:04985#if defined(IPC_MESSAGE_LOG_ENABLED)
986
987void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
988 // First enable myself.
989 if (enable)
[email protected]8e8bb6d2010-12-13 08:18:55990 IPC::Logging::GetInstance()->Enable();
[email protected]d55aaa132009-09-28 21:08:04991 else
[email protected]8e8bb6d2010-12-13 08:18:55992 IPC::Logging::GetInstance()->Disable();
[email protected]d55aaa132009-09-28 21:08:04993
994 // Now tell subprocesses. Messages to ChildProcess-derived
995 // processes must be done on the IO thread.
996 io_thread()->message_loop()->PostTask
997 (FROM_HERE,
998 NewRunnableMethod(
999 this,
1000 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
1001 enable));
1002
1003 // Finally, tell the renderers which don't derive from ChildProcess.
1004 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:271005 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
1006 !i.IsAtEnd(); i.Advance())
[email protected]ff47b2962011-03-07 23:51:491007 i.GetCurrentValue()->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:041008}
1009
1010// Helper for SetIPCLoggingEnabled.
1011void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d04e7662010-10-10 22:24:481012 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d55aaa132009-09-28 21:08:041013
[email protected]d27893f62010-07-03 05:47:421014 BrowserChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:111015 while (!i.Done()) {
[email protected]ff47b2962011-03-07 23:51:491016 i->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled));
[email protected]34cf97d2009-09-29 22:46:111017 ++i;
[email protected]d55aaa132009-09-28 21:08:041018 }
1019}
1020
1021#endif // IPC_MESSAGE_LOG_ENABLED
1022
[email protected]3cdacd42010-04-30 18:55:531023// Mac is currently not supported.
1024#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:421025
1026bool BrowserProcessImpl::CanAutorestartForUpdate() const {
1027 // Check if browser is in the background and if it needs to be restarted to
1028 // apply a pending update.
[email protected]c10fa3952010-08-24 16:52:531029 return BrowserList::size() == 0 && BrowserList::WillKeepAlive() &&
[email protected]815856722011-04-13 17:19:191030 upgrade_util::IsUpdatePendingRestart();
[email protected]bd48c2b02010-04-09 20:32:421031}
1032
[email protected]5c08f222010-09-22 09:37:211033// Switches to add when auto-restarting Chrome.
[email protected]6c10c972010-08-11 04:15:471034const char* const kSwitchesToAddOnAutorestart[] = {
[email protected]f9a06842010-08-21 00:32:401035 switches::kNoStartupWindow
[email protected]bd48c2b02010-04-09 20:32:421036};
1037
1038void BrowserProcessImpl::RestartPersistentInstance() {
1039 CommandLine* old_cl = CommandLine::ForCurrentProcess();
[email protected]3cdacd42010-04-30 18:55:531040 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram()));
[email protected]bd48c2b02010-04-09 20:32:421041
1042 std::map<std::string, CommandLine::StringType> switches =
1043 old_cl->GetSwitches();
1044
[email protected]5c08f222010-09-22 09:37:211045 switches::RemoveSwitchesForAutostart(&switches);
[email protected]bd48c2b02010-04-09 20:32:421046
1047 // Append the rest of the switches (along with their values, if any)
1048 // to the new command line
1049 for (std::map<std::string, CommandLine::StringType>::const_iterator i =
1050 switches.begin(); i != switches.end(); ++i) {
1051 CommandLine::StringType switch_value = i->second;
1052 if (switch_value.length() > 0) {
[email protected]05076ba22010-07-30 05:59:571053 new_cl->AppendSwitchNative(i->first, i->second);
[email protected]bd48c2b02010-04-09 20:32:421054 } else {
[email protected]3cdacd42010-04-30 18:55:531055 new_cl->AppendSwitch(i->first);
[email protected]bd48c2b02010-04-09 20:32:421056 }
1057 }
1058
[email protected]6c10c972010-08-11 04:15:471059 // Ensure that our desired switches are set on the new process.
[email protected]5c08f222010-09-22 09:37:211060 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) {
[email protected]6c10c972010-08-11 04:15:471061 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i]))
1062 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
1063 }
[email protected]bd48c2b02010-04-09 20:32:421064
[email protected]3cdacd42010-04-30 18:55:531065 DLOG(WARNING) << "Shutting down current instance of the browser.";
1066 BrowserList::CloseAllBrowsersAndExit();
1067
1068 // Transfer ownership to Upgrade.
[email protected]815856722011-04-13 17:19:191069 upgrade_util::SetNewCommandLine(new_cl.release());
[email protected]bd48c2b02010-04-09 20:32:421070}
1071
1072void BrowserProcessImpl::OnAutoupdateTimer() {
1073 if (CanAutorestartForUpdate()) {
[email protected]3cdacd42010-04-30 18:55:531074 DLOG(WARNING) << "Detected update. Restarting browser.";
[email protected]bd48c2b02010-04-09 20:32:421075 RestartPersistentInstance();
1076 }
1077}
1078
[email protected]3cdacd42010-04-30 18:55:531079#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)