blob: f8a96d269608167ff99a4d2f373c9fa9ad0f9b88 [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>
8
initial.commit09911bf2008-07-26 23:55:299#include "base/command_line.h"
[email protected]6641bf662009-08-21 00:34:0910#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/path_service.h"
[email protected]985655a2011-02-23 09:54:2512#include "base/synchronization/waitable_event.h"
[email protected]c6032e82010-09-13 20:06:0513#include "base/task.h"
[email protected]34b99632011-01-01 01:01:0614#include "base/threading/thread.h"
15#include "base/threading/thread_restrictions.h"
[email protected]e13ad79b2010-07-22 21:36:5016#include "chrome/browser/automation/automation_provider_list.h"
[email protected]b443cb042009-12-15 22:05:0917#include "chrome/browser/browser_main.h"
[email protected]0ac83682010-01-22 17:46:2718#include "chrome/browser/browser_process_sub_thread.h"
[email protected]ac262c9f2008-10-19 17:45:2119#include "chrome/browser/browser_trial.h"
[email protected]9678cb42011-01-31 18:49:4220#include "chrome/browser/debugger/browser_list_tabcontents_provider.h"
[email protected]5613126e2011-01-31 15:27:5521#include "chrome/browser/debugger/devtools_http_protocol_handler.h"
[email protected]40ecc902009-03-16 13:42:4722#include "chrome/browser/debugger/devtools_manager.h"
[email protected]5613126e2011-01-31 15:27:5523#include "chrome/browser/debugger/devtools_protocol_handler.h"
[email protected]6c69796d2010-07-16 21:41:1624#include "chrome/browser/download/download_file_manager.h"
[email protected]5ba0a2c2009-02-19 01:19:3425#include "chrome/browser/download/save_file_manager.h"
[email protected]3ce02412011-03-01 12:01:1526#include "chrome/browser/extensions/extension_event_router_forwarder.h"
[email protected]fc4facd2011-03-22 23:18:5027#include "chrome/browser/extensions/extension_tab_id_map.h"
[email protected]214538842011-04-01 18:47:2428#include "chrome/browser/extensions/user_script_listener.h"
[email protected]815856722011-04-13 17:19:1929#include "chrome/browser/first_run/upgrade_util.h"
[email protected]f7578f52010-08-30 22:22:4930#include "chrome/browser/google/google_url_tracker.h"
[email protected]7a31f7c2011-03-21 23:22:0431#include "chrome/browser/gpu_process_host_ui_shim.h"
[email protected]dcefa302009-05-20 00:24:3932#include "chrome/browser/icon_manager.h"
[email protected]c4ff4952010-01-08 19:12:4733#include "chrome/browser/intranet_redirect_detector.h"
[email protected]0ac83682010-01-22 17:46:2734#include "chrome/browser/io_thread.h"
[email protected]dc6f4962009-02-13 01:25:5035#include "chrome/browser/metrics/metrics_service.h"
[email protected]0b565182011-03-02 18:11:1536#include "chrome/browser/metrics/thread_watcher.h"
[email protected]b2fcd0e2010-12-01 15:19:4037#include "chrome/browser/net/chrome_net_log.h"
[email protected]3530cd92010-06-27 06:22:0138#include "chrome/browser/net/predictor_api.h"
[email protected]d393a0fd2009-05-13 23:32:0139#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]29672ab2009-10-30 03:44:0340#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]6618d1d2010-12-15 21:18:4741#include "chrome/browser/plugin_data_remover.h"
[email protected]492d2142010-09-10 13:55:1842#include "chrome/browser/plugin_updater.h"
[email protected]985655a2011-02-23 09:54:2543#include "chrome/browser/policy/browser_policy_connector.h"
[email protected]37858e52010-08-26 00:22:0244#include "chrome/browser/prefs/pref_service.h"
[email protected]e06131d2010-02-10 18:40:3345#include "chrome/browser/printing/print_job_manager.h"
[email protected]dbeebd52010-11-16 20:34:1646#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]8ecad5e2010-12-02 21:18:3347#include "chrome/browser/profiles/profile_manager.h"
[email protected]a7a5e992010-12-09 23:39:5148#include "chrome/browser/safe_browsing/client_side_detection_service.h"
[email protected]81218f42009-02-05 18:48:0849#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]e450fa62011-02-01 12:52:5650#include "chrome/browser/shell_integration.h"
[email protected]8b8e7c92010-08-19 18:05:5651#include "chrome/browser/sidebar/sidebar_manager.h"
[email protected]0b4d3382010-07-14 16:13:0452#include "chrome/browser/tab_closeable_state_watcher.h"
[email protected]71b73f02011-04-06 15:57:2953#include "chrome/browser/ui/browser_list.h"
[email protected]4ef795df2010-02-03 02:35:0854#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2955#include "chrome/common/chrome_paths.h"
56#include "chrome/common/chrome_switches.h"
[email protected]f1b6de22010-03-06 12:13:4757#include "chrome/common/extensions/extension_l10n_util.h"
[email protected]985655a2011-02-23 09:54:2558#include "chrome/common/extensions/extension_resource.h"
[email protected]ea587b02010-05-21 15:01:3559#include "chrome/common/json_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2960#include "chrome/common/pref_names.h"
[email protected]5c08f222010-09-22 09:37:2161#include "chrome/common/switch_utils.h"
[email protected]985655a2011-02-23 09:54:2562#include "chrome/common/url_constants.h"
[email protected]bd48c2b02010-04-09 20:32:4263#include "chrome/installer/util/google_update_constants.h"
[email protected]a01efd22011-03-01 00:38:3264#include "content/browser/browser_child_process_host.h"
65#include "content/browser/browser_thread.h"
[email protected]419a0572011-04-18 22:21:4666#include "content/browser/child_process_security_policy.h"
[email protected]a01efd22011-03-01 00:38:3267#include "content/browser/plugin_service.h"
68#include "content/browser/renderer_host/render_process_host.h"
69#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]f20d7332011-03-08 21:11:5370#include "content/common/notification_service.h"
[email protected]d55aaa132009-09-28 21:08:0471#include "ipc/ipc_logging.h"
[email protected]abe2c032011-03-31 18:49:3472#include "net/url_request/url_request_context_getter.h"
[email protected]2dfeaf92011-01-10 21:08:2173#include "ui/base/clipboard/clipboard.h"
[email protected]c051a1b2011-01-21 23:30:1774#include "ui/base/l10n/l10n_util.h"
[email protected]4ef795df2010-02-03 02:35:0875#include "webkit/database/database_tracker.h"
[email protected]b112a4c2009-02-01 20:24:0176
77#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0578#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3879#endif
80
[email protected]d55aaa132009-09-28 21:08:0481#if defined(IPC_MESSAGE_LOG_ENABLED)
[email protected]ff47b2962011-03-07 23:51:4982#include "content/common/child_process_messages.h"
[email protected]d55aaa132009-09-28 21:08:0483#endif
84
[email protected]db0e86dd2011-03-16 14:47:2185#if defined(OS_CHROMEOS)
86#include "chrome/browser/chromeos/proxy_config_service_impl.h"
87#endif // defined(OS_CHROMEOS)
88
[email protected]3cdacd42010-04-30 18:55:5389#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
90// How often to check if the persistent instance of Chrome needs to restart
91// to install an update.
92static const int kUpdateCheckIntervalHours = 6;
93#endif
94
[email protected]c6032e82010-09-13 20:06:0595#if defined(USE_X11)
96// How long to wait for the File thread to complete during EndSession, on
97// Linux. We have a timeout here because we're unable to run the UI messageloop
98// and there's some deadlock risk. Our only option is to exit anyway.
99static const int kEndSessionTimeoutSeconds = 10;
100#endif
101
[email protected]bb975362009-01-21 01:00:22102BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:29103 : created_resource_dispatcher_host_(false),
104 created_metrics_service_(false),
105 created_io_thread_(false),
106 created_file_thread_(false),
107 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:33108 created_process_launcher_thread_(false),
[email protected]875ee822010-05-18 20:58:01109 created_cache_thread_(false),
[email protected]7a31f7c2011-03-21 23:22:04110 created_gpu_thread_(false),
[email protected]0b565182011-03-02 18:11:15111 created_watchdog_thread_(false),
initial.commit09911bf2008-07-26 23:55:29112 created_profile_manager_(false),
113 created_local_state_(false),
[email protected]b112a4c2009-02-01 20:24:01114 created_icon_manager_(false),
[email protected]40ecc902009-03-16 13:42:47115 created_devtools_manager_(false),
[email protected]8b8e7c92010-08-19 18:05:56116 created_sidebar_manager_(false),
[email protected]985655a2011-02-23 09:54:25117 created_browser_policy_connector_(false),
[email protected]29672ab2009-10-30 03:44:03118 created_notification_ui_manager_(false),
[email protected]a7a5e992010-12-09 23:39:51119 created_safe_browsing_detection_service_(false),
initial.commit09911bf2008-07-26 23:55:29120 module_ref_count_(0),
[email protected]afd20c022010-06-10 00:48:20121 did_start_(false),
[email protected]1b2db1a2008-08-08 17:46:13122 checked_for_new_frames_(false),
[email protected]4747caf2011-03-23 20:09:21123 using_new_frames_(false) {
initial.commit09911bf2008-07-26 23:55:29124 g_browser_process = this;
[email protected]2dfeaf92011-01-10 21:08:21125 clipboard_.reset(new ui::Clipboard);
initial.commit09911bf2008-07-26 23:55:29126 main_notification_service_.reset(new NotificationService);
127
[email protected]6618d1d2010-12-15 21:18:47128 notification_registrar_.Add(this,
129 NotificationType::APP_TERMINATING,
130 NotificationService::AllSources());
131
initial.commit09911bf2008-07-26 23:55:29132 // Must be created after the NotificationService.
133 print_job_manager_.reset(new printing::PrintJobManager);
134
[email protected]b797e152009-01-23 16:06:14135 shutdown_event_.reset(new base::WaitableEvent(true, false));
[email protected]b2fcd0e2010-12-01 15:19:40136
137 net_log_.reset(new ChromeNetLog);
[email protected]3ce02412011-03-01 12:01:15138
139 extension_event_router_forwarder_ = new ExtensionEventRouterForwarder;
[email protected]fc4facd2011-03-22 23:18:50140
141 ExtensionTabIdMap::GetInstance()->Init();
initial.commit09911bf2008-07-26 23:55:29142}
143
144BrowserProcessImpl::~BrowserProcessImpl() {
[email protected]4ef795df2010-02-03 02:35:08145 FilePath profile_path;
146 bool clear_local_state_on_exit;
147
148 // Store the profile path for clearing local state data on exit.
149 clear_local_state_on_exit = ShouldClearLocalState(&profile_path);
150
initial.commit09911bf2008-07-26 23:55:29151 // Delete the AutomationProviderList before NotificationService,
152 // since it may try to unregister notifications
153 // Both NotificationService and AutomationProvider are singleton instances in
154 // the BrowserProcess. Since AutomationProvider may have some active
155 // notification observers, it is essential that it gets destroyed before the
156 // NotificationService. NotificationService won't be destroyed until after
157 // this destructor is run.
158 automation_provider_list_.reset();
159
[email protected]d393a0fd2009-05-13 23:32:01160 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
161 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
162 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
163 // any pending URLFetchers, and avoid creating any more.
164 SdchDictionaryFetcher::Shutdown();
165
[email protected]51ac040762011-01-20 02:01:04166 // We need to destroy the MetricsService, GoogleURLTracker,
167 // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService
168 // before the io_thread_ gets destroyed, since their destructors can call the
169 // URLFetcher destructor, which does a PostDelayedTask operation on the IO
170 // thread. (The IO thread will handle that URLFetcher operation before going
171 // away.)
initial.commit09911bf2008-07-26 23:55:29172 metrics_service_.reset();
173 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47174 intranet_redirect_detector_.reset();
[email protected]51ac040762011-01-20 02:01:04175 safe_browsing_detection_service_.reset();
initial.commit09911bf2008-07-26 23:55:29176
[email protected]d8a899c2010-09-21 04:50:33177 // Need to clear the desktop notification balloons before the io_thread_ and
178 // before the profiles, since if there are any still showing we will access
179 // those things during teardown.
180 notification_ui_manager_.reset();
181
initial.commit09911bf2008-07-26 23:55:29182 // Need to clear profiles (download managers) before the io_thread_.
183 profile_manager_.reset();
184
185 // Debugger must be cleaned up before IO thread and NotificationService.
[email protected]5613126e2011-01-31 15:27:55186 if (devtools_http_handler_.get()) {
187 devtools_http_handler_->Stop();
188 devtools_http_handler_ = NULL;
189 }
190 if (devtools_legacy_handler_.get()) {
191 devtools_legacy_handler_->Stop();
192 devtools_legacy_handler_ = NULL;
193 }
initial.commit09911bf2008-07-26 23:55:29194
195 if (resource_dispatcher_host_.get()) {
196 // Need to tell Safe Browsing Service that the IO thread is going away
197 // since it cached a pointer to it.
198 if (resource_dispatcher_host()->safe_browsing_service())
199 resource_dispatcher_host()->safe_browsing_service()->ShutDown();
200
201 // Cancel pending requests and prevent new requests.
202 resource_dispatcher_host()->Shutdown();
203 }
204
[email protected]fc4facd2011-03-22 23:18:50205 ExtensionTabIdMap::GetInstance()->Shutdown();
206
[email protected]985655a2011-02-23 09:54:25207 // The policy providers managed by |browser_policy_connector_| need to shut
208 // down while the IO and FILE threads are still alive.
209 browser_policy_connector_.reset();
[email protected]f2a893c2011-01-05 09:38:07210
[email protected]753efc42010-03-09 19:52:16211#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06212 // The IO thread must outlive the BACKGROUND_X11 thread.
213 background_x11_thread_.reset();
214#endif
215
[email protected]6618d1d2010-12-15 21:18:47216 // Wait for removing plugin data to finish before shutting down the IO thread.
217 WaitForPluginDataRemoverToFinish();
218
[email protected]7a31f7c2011-03-21 23:22:04219 // Destroying the GpuProcessHostUIShims on the UI thread posts a task to
220 // delete related objects on the GPU thread. This must be done before
221 // stopping the GPU thread. The GPU thread will close IPC channels to renderer
222 // processes so this has to happen before stopping the IO thread.
223 GpuProcessHostUIShim::DestroyAll();
224 gpu_thread_.reset();
225
initial.commit09911bf2008-07-26 23:55:29226 // Need to stop io_thread_ before resource_dispatcher_host_, since
227 // io_thread_ may still deref ResourceDispatcherHost and handle resource
228 // request before going away.
[email protected]0ac83682010-01-22 17:46:27229 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29230
[email protected]875ee822010-05-18 20:58:01231 // The IO thread was the only user of this thread.
232 cache_thread_.reset();
233
[email protected]914511712009-11-23 19:42:33234 // Stop the process launcher thread after the IO thread, in case the IO thread
235 // posted a task to terminate a process on the process launcher thread.
236 process_launcher_thread_.reset();
237
initial.commit09911bf2008-07-26 23:55:29238 // Clean up state that lives on the file_thread_ before it goes away.
239 if (resource_dispatcher_host_.get()) {
240 resource_dispatcher_host()->download_file_manager()->Shutdown();
241 resource_dispatcher_host()->save_file_manager()->Shutdown();
242 }
243
244 // Need to stop the file_thread_ here to force it to process messages in its
245 // message loop from the previous call to shutdown the DownloadFileManager,
246 // SaveFileManager and SessionService.
247 file_thread_.reset();
248
249 // With the file_thread_ flushed, we can release any icon resources.
250 icon_manager_.reset();
251
252 // Need to destroy ResourceDispatcherHost before PluginService and
[email protected]49f28bc72010-02-04 00:10:01253 // SafeBrowsingService, since it caches a pointer to it. This also
254 // causes the webkit thread to terminate.
initial.commit09911bf2008-07-26 23:55:29255 resource_dispatcher_host_.reset();
256
257 // Wait for the pending print jobs to finish.
258 print_job_manager_->OnQuit();
259 print_job_manager_.reset();
260
[email protected]0b4d3382010-07-14 16:13:04261 // Destroy TabCloseableStateWatcher before NotificationService since the
262 // former registers for notifications.
263 tab_closeable_state_watcher_.reset();
264
initial.commit09911bf2008-07-26 23:55:29265 // Now OK to destroy NotificationService.
266 main_notification_service_.reset();
267
[email protected]49f28bc72010-02-04 00:10:01268 // Prior to clearing local state, we want to complete tasks pending
269 // on the db thread too.
270 db_thread_.reset();
271
[email protected]0b565182011-03-02 18:11:15272 // Stop the watchdog thread after stopping other threads.
273 watchdog_thread_.reset();
274
[email protected]49f28bc72010-02-04 00:10:01275 // At this point, no render process exist and the file, io, db, and
276 // webkit threads in this process have all terminated, so it's safe
277 // to access local state data such as cookies, database, or local storage.
278 if (clear_local_state_on_exit)
279 ClearLocalState(profile_path);
280
initial.commit09911bf2008-07-26 23:55:29281 g_browser_process = NULL;
282}
283
[email protected]c6032e82010-09-13 20:06:05284#if defined(OS_WIN)
[email protected]295039bd2008-08-15 04:32:57285// Send a QuitTask to the given MessageLoop.
286static void PostQuit(MessageLoop* message_loop) {
287 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
288}
[email protected]c6032e82010-09-13 20:06:05289#elif defined(USE_X11)
290static void Signal(base::WaitableEvent* event) {
291 event->Signal();
292}
293#endif
initial.commit09911bf2008-07-26 23:55:29294
[email protected]b443cb042009-12-15 22:05:09295unsigned int BrowserProcessImpl::AddRefModule() {
296 DCHECK(CalledOnValidThread());
[email protected]afd20c022010-06-10 00:48:20297 did_start_ = true;
[email protected]b443cb042009-12-15 22:05:09298 module_ref_count_++;
299 return module_ref_count_;
300}
301
302unsigned int BrowserProcessImpl::ReleaseModule() {
303 DCHECK(CalledOnValidThread());
[email protected]760d970a2010-05-18 00:39:18304 DCHECK_NE(0u, module_ref_count_);
[email protected]b443cb042009-12-15 22:05:09305 module_ref_count_--;
306 if (0 == module_ref_count_) {
[email protected]7d038c32010-12-14 00:40:00307 // Allow UI and IO threads to do blocking IO on shutdown, since we do a lot
308 // of it on shutdown for valid reasons.
309 base::ThreadRestrictions::SetIOAllowed(true);
310 io_thread()->message_loop()->PostTask(
311 FROM_HERE,
312 NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true));
[email protected]b443cb042009-12-15 22:05:09313 MessageLoop::current()->PostTask(
[email protected]34f73fb2010-03-24 20:50:34314 FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop));
[email protected]b443cb042009-12-15 22:05:09315 MessageLoop::current()->Quit();
316 }
317 return module_ref_count_;
318}
319
initial.commit09911bf2008-07-26 23:55:29320void BrowserProcessImpl::EndSession() {
[email protected]c6032e82010-09-13 20:06:05321#if defined(OS_WIN) || defined(USE_X11)
[email protected]d65cab7a2008-08-12 01:25:41322 // Notify we are going away.
[email protected]c6032e82010-09-13 20:06:05323 shutdown_event_->Signal();
[email protected]b112a4c2009-02-01 20:24:01324#endif
[email protected]d65cab7a2008-08-12 01:25:41325
initial.commit09911bf2008-07-26 23:55:29326 // Mark all the profiles as clean.
327 ProfileManager* pm = profile_manager();
[email protected]844a1002011-04-19 11:37:21328 std::vector<Profile*> profiles(pm->GetLoadedProfiles());
329 for (size_t i = 0; i < profiles.size(); ++i)
330 profiles[i]->MarkAsCleanShutdown();
initial.commit09911bf2008-07-26 23:55:29331
332 // Tell the metrics service it was cleanly shutdown.
333 MetricsService* metrics = g_browser_process->metrics_service();
334 if (metrics && local_state()) {
initial.commit09911bf2008-07-26 23:55:29335 metrics->RecordStartOfSessionEnd();
336
337 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36338 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29339 }
340
341 // We must write that the profile and metrics service shutdown cleanly,
342 // otherwise on startup we'll think we crashed. So we block until done and
343 // then proceed with normal shutdown.
[email protected]c6032e82010-09-13 20:06:05344#if defined(USE_X11)
345 // Can't run a local loop on linux. Instead create a waitable event.
346 base::WaitableEvent done_writing(false, false);
[email protected]d04e7662010-10-10 22:24:48347 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]c6032e82010-09-13 20:06:05348 NewRunnableFunction(Signal, &done_writing));
349 done_writing.TimedWait(
350 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds));
351#elif defined(OS_WIN)
[email protected]d04e7662010-10-10 22:24:48352 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57353 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29354 MessageLoop::current()->Run();
[email protected]c6032e82010-09-13 20:06:05355#else
356 NOTIMPLEMENTED();
357#endif
initial.commit09911bf2008-07-26 23:55:29358}
359
[email protected]e13ad79b2010-07-22 21:36:50360ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() {
361 DCHECK(CalledOnValidThread());
362 if (!created_resource_dispatcher_host_)
363 CreateResourceDispatcherHost();
364 return resource_dispatcher_host_.get();
365}
366
367MetricsService* BrowserProcessImpl::metrics_service() {
368 DCHECK(CalledOnValidThread());
369 if (!created_metrics_service_)
370 CreateMetricsService();
371 return metrics_service_.get();
372}
373
374IOThread* BrowserProcessImpl::io_thread() {
375 DCHECK(CalledOnValidThread());
376 if (!created_io_thread_)
377 CreateIOThread();
378 return io_thread_.get();
379}
380
381base::Thread* BrowserProcessImpl::file_thread() {
382 DCHECK(CalledOnValidThread());
383 if (!created_file_thread_)
384 CreateFileThread();
385 return file_thread_.get();
386}
387
388base::Thread* BrowserProcessImpl::db_thread() {
389 DCHECK(CalledOnValidThread());
390 if (!created_db_thread_)
391 CreateDBThread();
392 return db_thread_.get();
393}
394
395base::Thread* BrowserProcessImpl::process_launcher_thread() {
396 DCHECK(CalledOnValidThread());
397 if (!created_process_launcher_thread_)
398 CreateProcessLauncherThread();
399 return process_launcher_thread_.get();
400}
401
402base::Thread* BrowserProcessImpl::cache_thread() {
403 DCHECK(CalledOnValidThread());
404 if (!created_cache_thread_)
405 CreateCacheThread();
406 return cache_thread_.get();
407}
408
[email protected]7a31f7c2011-03-21 23:22:04409base::Thread* BrowserProcessImpl::gpu_thread() {
410 DCHECK(CalledOnValidThread());
411 if (!created_gpu_thread_)
412 CreateGpuThread();
413 return gpu_thread_.get();
414}
415
[email protected]e13ad79b2010-07-22 21:36:50416#if defined(USE_X11)
417base::Thread* BrowserProcessImpl::background_x11_thread() {
418 DCHECK(CalledOnValidThread());
419 // The BACKGROUND_X11 thread is created when the IO thread is created.
420 if (!created_io_thread_)
421 CreateIOThread();
422 return background_x11_thread_.get();
423}
424#endif
425
[email protected]0b565182011-03-02 18:11:15426WatchDogThread* BrowserProcessImpl::watchdog_thread() {
427 DCHECK(CalledOnValidThread());
428 if (!created_watchdog_thread_)
429 CreateWatchdogThread();
430 DCHECK(watchdog_thread_.get() != NULL);
431 return watchdog_thread_.get();
432}
433
[email protected]e13ad79b2010-07-22 21:36:50434ProfileManager* BrowserProcessImpl::profile_manager() {
435 DCHECK(CalledOnValidThread());
436 if (!created_profile_manager_)
437 CreateProfileManager();
438 return profile_manager_.get();
439}
440
441PrefService* BrowserProcessImpl::local_state() {
442 DCHECK(CalledOnValidThread());
443 if (!created_local_state_)
444 CreateLocalState();
445 return local_state_.get();
446}
447
448DevToolsManager* BrowserProcessImpl::devtools_manager() {
449 DCHECK(CalledOnValidThread());
450 if (!created_devtools_manager_)
451 CreateDevToolsManager();
452 return devtools_manager_.get();
453}
454
[email protected]8b8e7c92010-08-19 18:05:56455SidebarManager* BrowserProcessImpl::sidebar_manager() {
456 DCHECK(CalledOnValidThread());
457 if (!created_sidebar_manager_)
458 CreateSidebarManager();
459 return sidebar_manager_.get();
460}
461
[email protected]2dfeaf92011-01-10 21:08:21462ui::Clipboard* BrowserProcessImpl::clipboard() {
[email protected]e13ad79b2010-07-22 21:36:50463 DCHECK(CalledOnValidThread());
464 return clipboard_.get();
465}
466
[email protected]abe2c032011-03-31 18:49:34467net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() {
[email protected]db0e86dd2011-03-16 14:47:21468 DCHECK(CalledOnValidThread());
469 return io_thread()->system_url_request_context_getter();
470}
471
472#if defined(OS_CHROMEOS)
473chromeos::ProxyConfigServiceImpl*
474BrowserProcessImpl::chromeos_proxy_config_service_impl() {
475 DCHECK(CalledOnValidThread());
476 if (!chromeos_proxy_config_service_impl_) {
477 chromeos_proxy_config_service_impl_ =
478 new chromeos::ProxyConfigServiceImpl();
479 }
480 return chromeos_proxy_config_service_impl_;
481}
482#endif // defined(OS_CHROMEOS)
483
[email protected]3ce02412011-03-01 12:01:15484ExtensionEventRouterForwarder*
485BrowserProcessImpl::extension_event_router_forwarder() {
486 return extension_event_router_forwarder_.get();
487}
488
[email protected]e13ad79b2010-07-22 21:36:50489NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
490 DCHECK(CalledOnValidThread());
491 if (!created_notification_ui_manager_)
492 CreateNotificationUIManager();
493 return notification_ui_manager_.get();
494}
495
[email protected]985655a2011-02-23 09:54:25496policy::BrowserPolicyConnector* BrowserProcessImpl::browser_policy_connector() {
[email protected]f2a893c2011-01-05 09:38:07497 DCHECK(CalledOnValidThread());
[email protected]985655a2011-02-23 09:54:25498 if (!created_browser_policy_connector_) {
499 DCHECK(browser_policy_connector_.get() == NULL);
500 created_browser_policy_connector_ = true;
501 browser_policy_connector_.reset(new policy::BrowserPolicyConnector());
[email protected]f2a893c2011-01-05 09:38:07502 }
[email protected]985655a2011-02-23 09:54:25503 return browser_policy_connector_.get();
[email protected]f2a893c2011-01-05 09:38:07504}
505
[email protected]e13ad79b2010-07-22 21:36:50506IconManager* BrowserProcessImpl::icon_manager() {
507 DCHECK(CalledOnValidThread());
508 if (!created_icon_manager_)
509 CreateIconManager();
510 return icon_manager_.get();
511}
512
513ThumbnailGenerator* BrowserProcessImpl::GetThumbnailGenerator() {
514 return &thumbnail_generator_;
515}
516
517AutomationProviderList* BrowserProcessImpl::InitAutomationProviderList() {
518 DCHECK(CalledOnValidThread());
519 if (automation_provider_list_.get() == NULL) {
520 automation_provider_list_.reset(AutomationProviderList::GetInstance());
521 }
522 return automation_provider_list_.get();
523}
524
[email protected]5613126e2011-01-31 15:27:55525void BrowserProcessImpl::InitDevToolsHttpProtocolHandler(
[email protected]01000cf12011-02-04 11:39:22526 const std::string& ip,
[email protected]5613126e2011-01-31 15:27:55527 int port,
528 const std::string& frontend_url) {
[email protected]e13ad79b2010-07-22 21:36:50529 DCHECK(CalledOnValidThread());
[email protected]5613126e2011-01-31 15:27:55530 devtools_http_handler_ =
[email protected]01000cf12011-02-04 11:39:22531 DevToolsHttpProtocolHandler::Start(ip,
532 port,
[email protected]9678cb42011-01-31 18:49:42533 frontend_url,
534 new BrowserListTabContentsProvider());
[email protected]5613126e2011-01-31 15:27:55535}
536
537void BrowserProcessImpl::InitDevToolsLegacyProtocolHandler(int port) {
538 DCHECK(CalledOnValidThread());
539 devtools_legacy_handler_ = DevToolsProtocolHandler::Start(port);
[email protected]e13ad79b2010-07-22 21:36:50540}
541
542bool BrowserProcessImpl::IsShuttingDown() {
543 DCHECK(CalledOnValidThread());
544 return did_start_ && 0 == module_ref_count_;
545}
546
initial.commit09911bf2008-07-26 23:55:29547printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
548 // TODO(abarth): DCHECK(CalledOnValidThread());
[email protected]d8922f22010-05-07 00:57:27549 // http://code.google.com/p/chromium/issues/detail?id=6828
initial.commit09911bf2008-07-26 23:55:29550 // print_job_manager_ is initialized in the constructor and destroyed in the
551 // destructor, so it should always be valid.
552 DCHECK(print_job_manager_.get());
553 return print_job_manager_.get();
554}
555
[email protected]dbeebd52010-11-16 20:34:16556printing::PrintPreviewTabController*
557 BrowserProcessImpl::print_preview_tab_controller() {
558 DCHECK(CalledOnValidThread());
559 if (!print_preview_tab_controller_.get())
560 CreatePrintPreviewTabController();
561 return print_preview_tab_controller_.get();
562}
563
[email protected]e13ad79b2010-07-22 21:36:50564GoogleURLTracker* BrowserProcessImpl::google_url_tracker() {
565 DCHECK(CalledOnValidThread());
566 if (!google_url_tracker_.get())
567 CreateGoogleURLTracker();
568 return google_url_tracker_.get();
569}
570
571IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
572 DCHECK(CalledOnValidThread());
573 if (!intranet_redirect_detector_.get())
574 CreateIntranetRedirectDetector();
575 return intranet_redirect_detector_.get();
576}
577
578const std::string& BrowserProcessImpl::GetApplicationLocale() {
579 DCHECK(!locale_.empty());
580 return locale_;
581}
582
583void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
584 locale_ = locale;
585 extension_l10n_util::SetProcessLocale(locale);
586}
587
[email protected]073ed7b2010-09-27 09:20:02588DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
589 return &download_status_updater_;
590}
591
[email protected]e13ad79b2010-07-22 21:36:50592base::WaitableEvent* BrowserProcessImpl::shutdown_event() {
593 return shutdown_event_.get();
594}
595
596TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() {
597 DCHECK(CalledOnValidThread());
598 if (!tab_closeable_state_watcher_.get())
599 CreateTabCloseableStateWatcher();
600 return tab_closeable_state_watcher_.get();
601}
602
[email protected]a7a5e992010-12-09 23:39:51603safe_browsing::ClientSideDetectionService*
604 BrowserProcessImpl::safe_browsing_detection_service() {
605 DCHECK(CalledOnValidThread());
606 if (!created_safe_browsing_detection_service_) {
607 CreateSafeBrowsingDetectionService();
608 }
609 return safe_browsing_detection_service_.get();
610}
611
[email protected]8b08a47f2011-02-25 12:36:37612bool BrowserProcessImpl::plugin_finder_disabled() const {
613 return *plugin_finder_disabled_pref_;
614}
615
[email protected]6618d1d2010-12-15 21:18:47616void BrowserProcessImpl::Observe(NotificationType type,
617 const NotificationSource& source,
618 const NotificationDetails& details) {
619 if (type == NotificationType::APP_TERMINATING) {
620 Profile* profile = ProfileManager::GetDefaultProfile();
621 if (profile) {
622 PrefService* prefs = profile->GetPrefs();
[email protected]2ffc3c6c2011-01-14 12:50:24623 if (prefs->GetBoolean(prefs::kClearSiteDataOnExit) &&
[email protected]6618d1d2010-12-15 21:18:47624 local_state()->GetBoolean(prefs::kClearPluginLSODataEnabled)) {
625 plugin_data_remover_ = new PluginDataRemover();
[email protected]c7d58d62011-01-21 10:27:18626 if (!plugin_data_remover_mime_type().empty())
627 plugin_data_remover_->set_mime_type(plugin_data_remover_mime_type());
628 plugin_data_remover_->StartRemoving(base::Time());
[email protected]6618d1d2010-12-15 21:18:47629 }
630 }
[email protected]e450fa62011-02-01 12:52:56631 } else if (type == NotificationType::PREF_CHANGED) {
632 std::string* pref = Details<std::string>(details).ptr();
633 if (*pref == prefs::kDefaultBrowserSettingEnabled) {
634 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
635 ShellIntegration::SetAsDefaultBrowser();
[email protected]419a0572011-04-18 22:21:46636 } else if (*pref == prefs::kDisabledSchemes) {
637 ApplyDisabledSchemesPolicy();
[email protected]e450fa62011-02-01 12:52:56638 }
[email protected]6618d1d2010-12-15 21:18:47639 } else {
640 NOTREACHED();
641 }
642}
643
644void BrowserProcessImpl::WaitForPluginDataRemoverToFinish() {
[email protected]c7d58d62011-01-21 10:27:18645 if (plugin_data_remover_.get())
646 plugin_data_remover_->Wait();
[email protected]6618d1d2010-12-15 21:18:47647}
648
[email protected]e13ad79b2010-07-22 21:36:50649#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
650void BrowserProcessImpl::StartAutoupdateTimer() {
651 autoupdate_timer_.Start(
652 base::TimeDelta::FromHours(kUpdateCheckIntervalHours),
653 this,
654 &BrowserProcessImpl::OnAutoupdateTimer);
655}
656#endif
657
[email protected]d6f37fc2011-02-13 23:58:41658ChromeNetLog* BrowserProcessImpl::net_log() {
659 return net_log_.get();
660}
661
[email protected]4ef795df2010-02-03 02:35:08662void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
[email protected]72cfd90f2010-02-06 03:08:04663 webkit_database::DatabaseTracker::ClearLocalState(profile_path);
[email protected]4ef795df2010-02-03 02:35:08664}
665
666bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
667 FilePath user_data_dir;
668 Profile* profile;
669
[email protected]09584972010-07-03 00:00:59670 // Check for the existence of a profile manager. When quitting early,
[email protected]ed0cf562010-02-05 22:50:41671 // e.g. because another chrome instance is running, or when invoked with
672 // options such as --uninstall or --try-chrome-again=0, the profile manager
673 // does not exist yet.
674 if (!profile_manager_.get())
675 return false;
676
[email protected]4ef795df2010-02-03 02:35:08677 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
678 profile = profile_manager_->GetDefaultProfile(user_data_dir);
[email protected]7bfc674322010-03-05 00:20:57679 if (!profile)
680 return false;
[email protected]4ef795df2010-02-03 02:35:08681 *profile_path = profile->GetPath();
682 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit);
683}
684
initial.commit09911bf2008-07-26 23:55:29685void BrowserProcessImpl::CreateResourceDispatcherHost() {
686 DCHECK(!created_resource_dispatcher_host_ &&
687 resource_dispatcher_host_.get() == NULL);
688 created_resource_dispatcher_host_ = true;
689
[email protected]214538842011-04-01 18:47:24690 // UserScriptListener will delete itself.
691 ResourceQueue::DelegateSet resource_queue_delegates;
692 resource_queue_delegates.insert(new UserScriptListener());
693
694 resource_dispatcher_host_.reset(
695 new ResourceDispatcherHost(resource_queue_delegates));
initial.commit09911bf2008-07-26 23:55:29696 resource_dispatcher_host_->Initialize();
697}
698
699void BrowserProcessImpl::CreateMetricsService() {
700 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
701 created_metrics_service_ = true;
702
703 metrics_service_.reset(new MetricsService);
704}
705
706void BrowserProcessImpl::CreateIOThread() {
707 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
708 created_io_thread_ = true;
709
710 // Prior to starting the io thread, we create the plugin service as
711 // it is predominantly used from the io thread, but must be created
712 // on the main thread. The service ctor is inexpensive and does not
713 // invoke the io_thread() accessor.
714 PluginService::GetInstance();
715
[email protected]753efc42010-03-09 19:52:16716#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06717 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so
718 // we start it now.
719 scoped_ptr<base::Thread> background_x11_thread(
[email protected]d04e7662010-10-10 22:24:48720 new BrowserProcessSubThread(BrowserThread::BACKGROUND_X11));
[email protected]4c3cd7412009-04-22 17:56:06721 if (!background_x11_thread->Start())
722 return;
723 background_x11_thread_.swap(background_x11_thread);
724#endif
725
[email protected]3ce02412011-03-01 12:01:15726 scoped_ptr<IOThread> thread(new IOThread(
727 local_state(), net_log_.get(), extension_event_router_forwarder_.get()));
[email protected]ab820df2008-08-26 05:55:10728 base::Thread::Options options;
729 options.message_loop_type = MessageLoop::TYPE_IO;
730 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29731 return;
732 io_thread_.swap(thread);
733}
734
735void BrowserProcessImpl::CreateFileThread() {
736 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
737 created_file_thread_ = true;
738
[email protected]ab820df2008-08-26 05:55:10739 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48740 new BrowserProcessSubThread(BrowserThread::FILE));
[email protected]a1db3842008-09-17 22:04:06741 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39742#if defined(OS_WIN)
743 // On Windows, the FILE thread needs to be have a UI message loop which pumps
744 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06745 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39746#else
747 options.message_loop_type = MessageLoop::TYPE_IO;
748#endif
[email protected]a1db3842008-09-17 22:04:06749 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29750 return;
751 file_thread_.swap(thread);
752}
753
754void BrowserProcessImpl::CreateDBThread() {
755 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
756 created_db_thread_ = true;
757
[email protected]ab820df2008-08-26 05:55:10758 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48759 new BrowserProcessSubThread(BrowserThread::DB));
initial.commit09911bf2008-07-26 23:55:29760 if (!thread->Start())
761 return;
762 db_thread_.swap(thread);
763}
764
[email protected]914511712009-11-23 19:42:33765void BrowserProcessImpl::CreateProcessLauncherThread() {
766 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
767 created_process_launcher_thread_ = true;
768
769 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48770 new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER));
[email protected]914511712009-11-23 19:42:33771 if (!thread->Start())
772 return;
773 process_launcher_thread_.swap(thread);
774}
775
[email protected]875ee822010-05-18 20:58:01776void BrowserProcessImpl::CreateCacheThread() {
777 DCHECK(!created_cache_thread_ && !cache_thread_.get());
778 created_cache_thread_ = true;
779
780 scoped_ptr<base::Thread> thread(
[email protected]75096332010-11-09 03:28:13781 new BrowserThread(BrowserThread::CACHE));
[email protected]875ee822010-05-18 20:58:01782 base::Thread::Options options;
783 options.message_loop_type = MessageLoop::TYPE_IO;
784 if (!thread->StartWithOptions(options))
785 return;
786 cache_thread_.swap(thread);
787}
788
[email protected]7a31f7c2011-03-21 23:22:04789void BrowserProcessImpl::CreateGpuThread() {
790 DCHECK(!created_gpu_thread_ && !gpu_thread_.get());
791 created_gpu_thread_ = true;
792
793 scoped_ptr<base::Thread> thread(new BrowserThread(BrowserThread::GPU));
794
795 base::Thread::Options options;
796#if defined(OS_WIN)
797 // On Windows the GPU thread needs to pump the compositor child window's
798 // message loop. TODO(apatrick): make this an IO thread if / when we get rid
799 // of this child window. Unfortunately it might always be necessary for
800 // Windows XP because we cannot share the backing store textures between
801 // processes.
802 options.message_loop_type = MessageLoop::TYPE_UI;
803#else
804 options.message_loop_type = MessageLoop::TYPE_IO;
805#endif
806
807 if (!thread->StartWithOptions(options))
808 return;
809 gpu_thread_.swap(thread);
810}
811
[email protected]0b565182011-03-02 18:11:15812void BrowserProcessImpl::CreateWatchdogThread() {
813 DCHECK(!created_watchdog_thread_ && watchdog_thread_.get() == NULL);
814 created_watchdog_thread_ = true;
815
816 scoped_ptr<WatchDogThread> thread(new WatchDogThread());
817 if (!thread->Start())
818 return;
819 watchdog_thread_.swap(thread);
820}
821
initial.commit09911bf2008-07-26 23:55:29822void BrowserProcessImpl::CreateProfileManager() {
823 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
824 created_profile_manager_ = true;
825
826 profile_manager_.reset(new ProfileManager());
827}
828
829void BrowserProcessImpl::CreateLocalState() {
830 DCHECK(!created_local_state_ && local_state_.get() == NULL);
831 created_local_state_ = true;
832
[email protected]b9636002009-03-04 00:05:25833 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29834 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]f2d1f612010-12-09 15:10:17835 local_state_.reset(
836 PrefService::CreatePrefService(local_state_path, NULL, NULL));
[email protected]492d2142010-09-10 13:55:18837
[email protected]2a7e7c152010-10-01 20:12:09838 pref_change_registrar_.Init(local_state_.get());
839
[email protected]492d2142010-09-10 13:55:18840 // Make sure the the plugin updater gets notifications of changes
[email protected]24ff43d72011-03-01 13:28:58841 // in the plugin policy lists.
842 local_state_->RegisterListPref(prefs::kPluginsDisabledPlugins);
843 pref_change_registrar_.Add(prefs::kPluginsDisabledPlugins,
844 PluginUpdater::GetInstance());
845 local_state_->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions);
846 pref_change_registrar_.Add(prefs::kPluginsDisabledPluginsExceptions,
847 PluginUpdater::GetInstance());
848 local_state_->RegisterListPref(prefs::kPluginsEnabledPlugins);
849 pref_change_registrar_.Add(prefs::kPluginsEnabledPlugins,
[email protected]8e8bb6d2010-12-13 08:18:55850 PluginUpdater::GetInstance());
[email protected]2a7e7c152010-10-01 20:12:09851
852 // Initialize and set up notifications for the printing enabled
853 // preference.
854 local_state_->RegisterBooleanPref(prefs::kPrintingEnabled, true);
855 bool printing_enabled =
856 local_state_->GetBoolean(prefs::kPrintingEnabled);
857 print_job_manager_->set_printing_enabled(printing_enabled);
858 pref_change_registrar_.Add(prefs::kPrintingEnabled,
859 print_job_manager_.get());
[email protected]e450fa62011-02-01 12:52:56860
861 // Initialize the notification for the default browser setting policy.
862 local_state_->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled,
863 false);
864 if (local_state_->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled)) {
865 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
866 ShellIntegration::SetAsDefaultBrowser();
867 }
868 pref_change_registrar_.Add(prefs::kDefaultBrowserSettingEnabled, this);
[email protected]8b08a47f2011-02-25 12:36:37869
870 // Initialize the preference for the plugin finder policy.
871 // This preference is only needed on the IO thread so make it available there.
872 local_state_->RegisterBooleanPref(prefs::kDisablePluginFinder, false);
873 plugin_finder_disabled_pref_.Init(prefs::kDisablePluginFinder,
874 local_state_.get(), NULL);
875 plugin_finder_disabled_pref_.MoveToThread(BrowserThread::IO);
[email protected]419a0572011-04-18 22:21:46876
877 // Initialize the preference for the disabled schemes policy, and
878 // load the initial policy on startup.
879 local_state_->RegisterListPref(prefs::kDisabledSchemes);
880 disabled_schemes_pref_.Init(prefs::kDisabledSchemes, local_state_.get(),
881 this);
882 ApplyDisabledSchemesPolicy();
[email protected]fd6159a2010-09-03 09:38:39883}
initial.commit09911bf2008-07-26 23:55:29884
initial.commit09911bf2008-07-26 23:55:29885void BrowserProcessImpl::CreateIconManager() {
886 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
887 created_icon_manager_ = true;
888 icon_manager_.reset(new IconManager);
889}
890
[email protected]40ecc902009-03-16 13:42:47891void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44892 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47893 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44894 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47895}
896
[email protected]8b8e7c92010-08-19 18:05:56897void BrowserProcessImpl::CreateSidebarManager() {
898 DCHECK(sidebar_manager_.get() == NULL);
899 created_sidebar_manager_ = true;
900 sidebar_manager_ = new SidebarManager();
901}
902
initial.commit09911bf2008-07-26 23:55:29903void BrowserProcessImpl::CreateGoogleURLTracker() {
904 DCHECK(google_url_tracker_.get() == NULL);
905 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
906 google_url_tracker_.swap(google_url_tracker);
907}
[email protected]6641bf662009-08-21 00:34:09908
[email protected]c4ff4952010-01-08 19:12:47909void BrowserProcessImpl::CreateIntranetRedirectDetector() {
910 DCHECK(intranet_redirect_detector_.get() == NULL);
911 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
912 new IntranetRedirectDetector);
913 intranet_redirect_detector_.swap(intranet_redirect_detector);
914}
915
[email protected]29672ab2009-10-30 03:44:03916void BrowserProcessImpl::CreateNotificationUIManager() {
917 DCHECK(notification_ui_manager_.get() == NULL);
[email protected]b0b2a3dd2011-01-06 00:30:05918 notification_ui_manager_.reset(NotificationUIManager::Create(local_state()));
919
[email protected]29672ab2009-10-30 03:44:03920 created_notification_ui_manager_ = true;
921}
922
[email protected]0b4d3382010-07-14 16:13:04923void BrowserProcessImpl::CreateTabCloseableStateWatcher() {
924 DCHECK(tab_closeable_state_watcher_.get() == NULL);
925 tab_closeable_state_watcher_.reset(TabCloseableStateWatcher::Create());
926}
927
[email protected]dbeebd52010-11-16 20:34:16928void BrowserProcessImpl::CreatePrintPreviewTabController() {
929 DCHECK(print_preview_tab_controller_.get() == NULL);
930 print_preview_tab_controller_ = new printing::PrintPreviewTabController();
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]d081d192011-04-01 02:33:24955#ifdef OS_CHROMEOS
956 return false;
957#else
958 return !CommandLine::ForCurrentProcess()->HasSwitch(
959 switches::kDisableClientSidePhishingDetection) &&
[email protected]42930de42011-01-13 23:26:28960 resource_dispatcher_host()->safe_browsing_service() &&
961 resource_dispatcher_host()->safe_browsing_service()->CanReportStats();
[email protected]d081d192011-04-01 02:33:24962#endif
[email protected]a7a5e992010-12-09 23:39:51963}
964
[email protected]419a0572011-04-18 22:21:46965void BrowserProcessImpl::ApplyDisabledSchemesPolicy() {
966 std::set<std::string> schemes;
967 for (ListValue::const_iterator iter = (*disabled_schemes_pref_)->begin();
968 iter != (*disabled_schemes_pref_)->end(); ++iter) {
969 std::string scheme;
970 if ((*iter)->GetAsString(&scheme))
971 schemes.insert(scheme);
972 }
973 ChildProcessSecurityPolicy::GetInstance()->RegisterDisabledSchemes(schemes);
974}
975
[email protected]6641bf662009-08-21 00:34:09976// The BrowserProcess object must outlive the file thread so we use traits
977// which don't do any management.
[email protected]c56428f22010-06-16 02:17:23978DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl);
[email protected]6641bf662009-08-21 00:34:09979
[email protected]d55aaa132009-09-28 21:08:04980#if defined(IPC_MESSAGE_LOG_ENABLED)
981
982void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
983 // First enable myself.
984 if (enable)
[email protected]8e8bb6d2010-12-13 08:18:55985 IPC::Logging::GetInstance()->Enable();
[email protected]d55aaa132009-09-28 21:08:04986 else
[email protected]8e8bb6d2010-12-13 08:18:55987 IPC::Logging::GetInstance()->Disable();
[email protected]d55aaa132009-09-28 21:08:04988
989 // Now tell subprocesses. Messages to ChildProcess-derived
990 // processes must be done on the IO thread.
991 io_thread()->message_loop()->PostTask
992 (FROM_HERE,
993 NewRunnableMethod(
994 this,
995 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
996 enable));
997
998 // Finally, tell the renderers which don't derive from ChildProcess.
999 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:271000 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
1001 !i.IsAtEnd(); i.Advance())
[email protected]ff47b2962011-03-07 23:51:491002 i.GetCurrentValue()->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:041003}
1004
1005// Helper for SetIPCLoggingEnabled.
1006void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d04e7662010-10-10 22:24:481007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d55aaa132009-09-28 21:08:041008
[email protected]d27893f62010-07-03 05:47:421009 BrowserChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:111010 while (!i.Done()) {
[email protected]ff47b2962011-03-07 23:51:491011 i->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled));
[email protected]34cf97d2009-09-29 22:46:111012 ++i;
[email protected]d55aaa132009-09-28 21:08:041013 }
1014}
1015
1016#endif // IPC_MESSAGE_LOG_ENABLED
1017
[email protected]3cdacd42010-04-30 18:55:531018// Mac is currently not supported.
1019#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:421020
1021bool BrowserProcessImpl::CanAutorestartForUpdate() const {
1022 // Check if browser is in the background and if it needs to be restarted to
1023 // apply a pending update.
[email protected]c10fa3952010-08-24 16:52:531024 return BrowserList::size() == 0 && BrowserList::WillKeepAlive() &&
[email protected]815856722011-04-13 17:19:191025 upgrade_util::IsUpdatePendingRestart();
[email protected]bd48c2b02010-04-09 20:32:421026}
1027
[email protected]5c08f222010-09-22 09:37:211028// Switches to add when auto-restarting Chrome.
[email protected]6c10c972010-08-11 04:15:471029const char* const kSwitchesToAddOnAutorestart[] = {
[email protected]f9a06842010-08-21 00:32:401030 switches::kNoStartupWindow
[email protected]bd48c2b02010-04-09 20:32:421031};
1032
1033void BrowserProcessImpl::RestartPersistentInstance() {
1034 CommandLine* old_cl = CommandLine::ForCurrentProcess();
[email protected]3cdacd42010-04-30 18:55:531035 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram()));
[email protected]bd48c2b02010-04-09 20:32:421036
1037 std::map<std::string, CommandLine::StringType> switches =
1038 old_cl->GetSwitches();
1039
[email protected]5c08f222010-09-22 09:37:211040 switches::RemoveSwitchesForAutostart(&switches);
[email protected]bd48c2b02010-04-09 20:32:421041
1042 // Append the rest of the switches (along with their values, if any)
1043 // to the new command line
1044 for (std::map<std::string, CommandLine::StringType>::const_iterator i =
1045 switches.begin(); i != switches.end(); ++i) {
1046 CommandLine::StringType switch_value = i->second;
1047 if (switch_value.length() > 0) {
[email protected]05076ba22010-07-30 05:59:571048 new_cl->AppendSwitchNative(i->first, i->second);
[email protected]bd48c2b02010-04-09 20:32:421049 } else {
[email protected]3cdacd42010-04-30 18:55:531050 new_cl->AppendSwitch(i->first);
[email protected]bd48c2b02010-04-09 20:32:421051 }
1052 }
1053
[email protected]6c10c972010-08-11 04:15:471054 // Ensure that our desired switches are set on the new process.
[email protected]5c08f222010-09-22 09:37:211055 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) {
[email protected]6c10c972010-08-11 04:15:471056 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i]))
1057 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
1058 }
[email protected]bd48c2b02010-04-09 20:32:421059
[email protected]3cdacd42010-04-30 18:55:531060 DLOG(WARNING) << "Shutting down current instance of the browser.";
1061 BrowserList::CloseAllBrowsersAndExit();
1062
1063 // Transfer ownership to Upgrade.
[email protected]815856722011-04-13 17:19:191064 upgrade_util::SetNewCommandLine(new_cl.release());
[email protected]bd48c2b02010-04-09 20:32:421065}
1066
1067void BrowserProcessImpl::OnAutoupdateTimer() {
1068 if (CanAutorestartForUpdate()) {
[email protected]3cdacd42010-04-30 18:55:531069 DLOG(WARNING) << "Detected update. Restarting browser.";
[email protected]bd48c2b02010-04-09 20:32:421070 RestartPersistentInstance();
1071 }
1072}
1073
[email protected]3cdacd42010-04-30 18:55:531074#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)