blob: 01e703886440e785bae1bc02333826a27624215e [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]bd48c2b02010-04-09 20:32:4217#include "chrome/browser/browser_list.h"
[email protected]b443cb042009-12-15 22:05:0918#include "chrome/browser/browser_main.h"
[email protected]0ac83682010-01-22 17:46:2719#include "chrome/browser/browser_process_sub_thread.h"
[email protected]ac262c9f2008-10-19 17:45:2120#include "chrome/browser/browser_trial.h"
[email protected]9678cb42011-01-31 18:49:4221#include "chrome/browser/debugger/browser_list_tabcontents_provider.h"
[email protected]5613126e2011-01-31 15:27:5522#include "chrome/browser/debugger/devtools_http_protocol_handler.h"
[email protected]40ecc902009-03-16 13:42:4723#include "chrome/browser/debugger/devtools_manager.h"
[email protected]5613126e2011-01-31 15:27:5524#include "chrome/browser/debugger/devtools_protocol_handler.h"
[email protected]6c69796d2010-07-16 21:41:1625#include "chrome/browser/download/download_file_manager.h"
[email protected]5ba0a2c2009-02-19 01:19:3426#include "chrome/browser/download/save_file_manager.h"
[email protected]3ce02412011-03-01 12:01:1527#include "chrome/browser/extensions/extension_event_router_forwarder.h"
[email protected]fc4facd2011-03-22 23:18:5028#include "chrome/browser/extensions/extension_tab_id_map.h"
[email protected]214538842011-04-01 18:47:2429#include "chrome/browser/extensions/user_script_listener.h"
[email protected]820735792010-07-29 23:40:0130#include "chrome/browser/first_run/first_run.h"
[email protected]f7578f52010-08-30 22:22:4931#include "chrome/browser/google/google_url_tracker.h"
[email protected]7a31f7c2011-03-21 23:22:0432#include "chrome/browser/gpu_process_host_ui_shim.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]6618d1d2010-12-15 21:18:4742#include "chrome/browser/plugin_data_remover.h"
[email protected]492d2142010-09-10 13:55:1843#include "chrome/browser/plugin_updater.h"
[email protected]985655a2011-02-23 09:54:2544#include "chrome/browser/policy/browser_policy_connector.h"
[email protected]37858e52010-08-26 00:22:0245#include "chrome/browser/prefs/pref_service.h"
[email protected]e06131d2010-02-10 18:40:3346#include "chrome/browser/printing/print_job_manager.h"
[email protected]dbeebd52010-11-16 20:34:1647#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]8ecad5e2010-12-02 21:18:3348#include "chrome/browser/profiles/profile_manager.h"
[email protected]a7a5e992010-12-09 23:39:5149#include "chrome/browser/safe_browsing/client_side_detection_service.h"
[email protected]81218f42009-02-05 18:48:0850#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]e450fa62011-02-01 12:52:5651#include "chrome/browser/shell_integration.h"
[email protected]8b8e7c92010-08-19 18:05:5652#include "chrome/browser/sidebar/sidebar_manager.h"
[email protected]0b4d3382010-07-14 16:13:0453#include "chrome/browser/tab_closeable_state_watcher.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"
66#include "content/browser/plugin_service.h"
67#include "content/browser/renderer_host/render_process_host.h"
68#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]f20d7332011-03-08 21:11:5369#include "content/common/notification_service.h"
[email protected]d55aaa132009-09-28 21:08:0470#include "ipc/ipc_logging.h"
[email protected]abe2c032011-03-31 18:49:3471#include "net/url_request/url_request_context_getter.h"
[email protected]2dfeaf92011-01-10 21:08:2172#include "ui/base/clipboard/clipboard.h"
[email protected]c051a1b2011-01-21 23:30:1773#include "ui/base/l10n/l10n_util.h"
[email protected]4ef795df2010-02-03 02:35:0874#include "webkit/database/database_tracker.h"
[email protected]b112a4c2009-02-01 20:24:0175
76#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0577#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3878#endif
79
[email protected]d55aaa132009-09-28 21:08:0480#if defined(IPC_MESSAGE_LOG_ENABLED)
[email protected]ff47b2962011-03-07 23:51:4981#include "content/common/child_process_messages.h"
[email protected]d55aaa132009-09-28 21:08:0482#endif
83
[email protected]db0e86dd2011-03-16 14:47:2184#if defined(OS_CHROMEOS)
85#include "chrome/browser/chromeos/proxy_config_service_impl.h"
86#endif // defined(OS_CHROMEOS)
87
[email protected]3cdacd42010-04-30 18:55:5388#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
89// How often to check if the persistent instance of Chrome needs to restart
90// to install an update.
91static const int kUpdateCheckIntervalHours = 6;
92#endif
93
[email protected]c6032e82010-09-13 20:06:0594#if defined(USE_X11)
95// How long to wait for the File thread to complete during EndSession, on
96// Linux. We have a timeout here because we're unable to run the UI messageloop
97// and there's some deadlock risk. Our only option is to exit anyway.
98static const int kEndSessionTimeoutSeconds = 10;
99#endif
100
[email protected]bb975362009-01-21 01:00:22101BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:29102 : created_resource_dispatcher_host_(false),
103 created_metrics_service_(false),
104 created_io_thread_(false),
105 created_file_thread_(false),
106 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:33107 created_process_launcher_thread_(false),
[email protected]875ee822010-05-18 20:58:01108 created_cache_thread_(false),
[email protected]7a31f7c2011-03-21 23:22:04109 created_gpu_thread_(false),
[email protected]0b565182011-03-02 18:11:15110 created_watchdog_thread_(false),
initial.commit09911bf2008-07-26 23:55:29111 created_profile_manager_(false),
112 created_local_state_(false),
[email protected]b112a4c2009-02-01 20:24:01113 created_icon_manager_(false),
[email protected]40ecc902009-03-16 13:42:47114 created_devtools_manager_(false),
[email protected]8b8e7c92010-08-19 18:05:56115 created_sidebar_manager_(false),
[email protected]985655a2011-02-23 09:54:25116 created_browser_policy_connector_(false),
[email protected]29672ab2009-10-30 03:44:03117 created_notification_ui_manager_(false),
[email protected]a7a5e992010-12-09 23:39:51118 created_safe_browsing_detection_service_(false),
initial.commit09911bf2008-07-26 23:55:29119 module_ref_count_(0),
[email protected]afd20c022010-06-10 00:48:20120 did_start_(false),
[email protected]1b2db1a2008-08-08 17:46:13121 checked_for_new_frames_(false),
[email protected]4747caf2011-03-23 20:09:21122 using_new_frames_(false) {
initial.commit09911bf2008-07-26 23:55:29123 g_browser_process = this;
[email protected]2dfeaf92011-01-10 21:08:21124 clipboard_.reset(new ui::Clipboard);
initial.commit09911bf2008-07-26 23:55:29125 main_notification_service_.reset(new NotificationService);
126
[email protected]6618d1d2010-12-15 21:18:47127 notification_registrar_.Add(this,
128 NotificationType::APP_TERMINATING,
129 NotificationService::AllSources());
130
initial.commit09911bf2008-07-26 23:55:29131 // Must be created after the NotificationService.
132 print_job_manager_.reset(new printing::PrintJobManager);
133
[email protected]b797e152009-01-23 16:06:14134 shutdown_event_.reset(new base::WaitableEvent(true, false));
[email protected]b2fcd0e2010-12-01 15:19:40135
136 net_log_.reset(new ChromeNetLog);
[email protected]3ce02412011-03-01 12:01:15137
138 extension_event_router_forwarder_ = new ExtensionEventRouterForwarder;
[email protected]fc4facd2011-03-22 23:18:50139
140 ExtensionTabIdMap::GetInstance()->Init();
initial.commit09911bf2008-07-26 23:55:29141}
142
143BrowserProcessImpl::~BrowserProcessImpl() {
[email protected]4ef795df2010-02-03 02:35:08144 FilePath profile_path;
145 bool clear_local_state_on_exit;
146
147 // Store the profile path for clearing local state data on exit.
148 clear_local_state_on_exit = ShouldClearLocalState(&profile_path);
149
initial.commit09911bf2008-07-26 23:55:29150 // Delete the AutomationProviderList before NotificationService,
151 // since it may try to unregister notifications
152 // Both NotificationService and AutomationProvider are singleton instances in
153 // the BrowserProcess. Since AutomationProvider may have some active
154 // notification observers, it is essential that it gets destroyed before the
155 // NotificationService. NotificationService won't be destroyed until after
156 // this destructor is run.
157 automation_provider_list_.reset();
158
[email protected]d393a0fd2009-05-13 23:32:01159 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
160 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
161 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
162 // any pending URLFetchers, and avoid creating any more.
163 SdchDictionaryFetcher::Shutdown();
164
[email protected]51ac040762011-01-20 02:01:04165 // We need to destroy the MetricsService, GoogleURLTracker,
166 // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService
167 // before the io_thread_ gets destroyed, since their destructors can call the
168 // URLFetcher destructor, which does a PostDelayedTask operation on the IO
169 // thread. (The IO thread will handle that URLFetcher operation before going
170 // away.)
initial.commit09911bf2008-07-26 23:55:29171 metrics_service_.reset();
172 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47173 intranet_redirect_detector_.reset();
[email protected]51ac040762011-01-20 02:01:04174 safe_browsing_detection_service_.reset();
initial.commit09911bf2008-07-26 23:55:29175
[email protected]d8a899c2010-09-21 04:50:33176 // Need to clear the desktop notification balloons before the io_thread_ and
177 // before the profiles, since if there are any still showing we will access
178 // those things during teardown.
179 notification_ui_manager_.reset();
180
initial.commit09911bf2008-07-26 23:55:29181 // Need to clear profiles (download managers) before the io_thread_.
182 profile_manager_.reset();
183
184 // Debugger must be cleaned up before IO thread and NotificationService.
[email protected]5613126e2011-01-31 15:27:55185 if (devtools_http_handler_.get()) {
186 devtools_http_handler_->Stop();
187 devtools_http_handler_ = NULL;
188 }
189 if (devtools_legacy_handler_.get()) {
190 devtools_legacy_handler_->Stop();
191 devtools_legacy_handler_ = NULL;
192 }
initial.commit09911bf2008-07-26 23:55:29193
194 if (resource_dispatcher_host_.get()) {
195 // Need to tell Safe Browsing Service that the IO thread is going away
196 // since it cached a pointer to it.
197 if (resource_dispatcher_host()->safe_browsing_service())
198 resource_dispatcher_host()->safe_browsing_service()->ShutDown();
199
200 // Cancel pending requests and prevent new requests.
201 resource_dispatcher_host()->Shutdown();
202 }
203
[email protected]fc4facd2011-03-22 23:18:50204 ExtensionTabIdMap::GetInstance()->Shutdown();
205
[email protected]985655a2011-02-23 09:54:25206 // The policy providers managed by |browser_policy_connector_| need to shut
207 // down while the IO and FILE threads are still alive.
208 browser_policy_connector_.reset();
[email protected]f2a893c2011-01-05 09:38:07209
[email protected]753efc42010-03-09 19:52:16210#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06211 // The IO thread must outlive the BACKGROUND_X11 thread.
212 background_x11_thread_.reset();
213#endif
214
[email protected]6618d1d2010-12-15 21:18:47215 // Wait for removing plugin data to finish before shutting down the IO thread.
216 WaitForPluginDataRemoverToFinish();
217
[email protected]7a31f7c2011-03-21 23:22:04218 // Destroying the GpuProcessHostUIShims on the UI thread posts a task to
219 // delete related objects on the GPU thread. This must be done before
220 // stopping the GPU thread. The GPU thread will close IPC channels to renderer
221 // processes so this has to happen before stopping the IO thread.
222 GpuProcessHostUIShim::DestroyAll();
223 gpu_thread_.reset();
224
initial.commit09911bf2008-07-26 23:55:29225 // Need to stop io_thread_ before resource_dispatcher_host_, since
226 // io_thread_ may still deref ResourceDispatcherHost and handle resource
227 // request before going away.
[email protected]0ac83682010-01-22 17:46:27228 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29229
[email protected]875ee822010-05-18 20:58:01230 // The IO thread was the only user of this thread.
231 cache_thread_.reset();
232
[email protected]914511712009-11-23 19:42:33233 // Stop the process launcher thread after the IO thread, in case the IO thread
234 // posted a task to terminate a process on the process launcher thread.
235 process_launcher_thread_.reset();
236
initial.commit09911bf2008-07-26 23:55:29237 // Clean up state that lives on the file_thread_ before it goes away.
238 if (resource_dispatcher_host_.get()) {
239 resource_dispatcher_host()->download_file_manager()->Shutdown();
240 resource_dispatcher_host()->save_file_manager()->Shutdown();
241 }
242
243 // Need to stop the file_thread_ here to force it to process messages in its
244 // message loop from the previous call to shutdown the DownloadFileManager,
245 // SaveFileManager and SessionService.
246 file_thread_.reset();
247
248 // With the file_thread_ flushed, we can release any icon resources.
249 icon_manager_.reset();
250
251 // Need to destroy ResourceDispatcherHost before PluginService and
[email protected]49f28bc72010-02-04 00:10:01252 // SafeBrowsingService, since it caches a pointer to it. This also
253 // causes the webkit thread to terminate.
initial.commit09911bf2008-07-26 23:55:29254 resource_dispatcher_host_.reset();
255
256 // Wait for the pending print jobs to finish.
257 print_job_manager_->OnQuit();
258 print_job_manager_.reset();
259
[email protected]0b4d3382010-07-14 16:13:04260 // Destroy TabCloseableStateWatcher before NotificationService since the
261 // former registers for notifications.
262 tab_closeable_state_watcher_.reset();
263
initial.commit09911bf2008-07-26 23:55:29264 // Now OK to destroy NotificationService.
265 main_notification_service_.reset();
266
[email protected]49f28bc72010-02-04 00:10:01267 // Prior to clearing local state, we want to complete tasks pending
268 // on the db thread too.
269 db_thread_.reset();
270
[email protected]0b565182011-03-02 18:11:15271 // Stop the watchdog thread after stopping other threads.
272 watchdog_thread_.reset();
273
[email protected]49f28bc72010-02-04 00:10:01274 // At this point, no render process exist and the file, io, db, and
275 // webkit threads in this process have all terminated, so it's safe
276 // to access local state data such as cookies, database, or local storage.
277 if (clear_local_state_on_exit)
278 ClearLocalState(profile_path);
279
initial.commit09911bf2008-07-26 23:55:29280 g_browser_process = NULL;
281}
282
[email protected]c6032e82010-09-13 20:06:05283#if defined(OS_WIN)
[email protected]295039bd2008-08-15 04:32:57284// Send a QuitTask to the given MessageLoop.
285static void PostQuit(MessageLoop* message_loop) {
286 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
287}
[email protected]c6032e82010-09-13 20:06:05288#elif defined(USE_X11)
289static void Signal(base::WaitableEvent* event) {
290 event->Signal();
291}
292#endif
initial.commit09911bf2008-07-26 23:55:29293
[email protected]b443cb042009-12-15 22:05:09294unsigned int BrowserProcessImpl::AddRefModule() {
295 DCHECK(CalledOnValidThread());
[email protected]afd20c022010-06-10 00:48:20296 did_start_ = true;
[email protected]b443cb042009-12-15 22:05:09297 module_ref_count_++;
298 return module_ref_count_;
299}
300
301unsigned int BrowserProcessImpl::ReleaseModule() {
302 DCHECK(CalledOnValidThread());
[email protected]760d970a2010-05-18 00:39:18303 DCHECK_NE(0u, module_ref_count_);
[email protected]b443cb042009-12-15 22:05:09304 module_ref_count_--;
305 if (0 == module_ref_count_) {
[email protected]7d038c32010-12-14 00:40:00306 // Allow UI and IO threads to do blocking IO on shutdown, since we do a lot
307 // of it on shutdown for valid reasons.
308 base::ThreadRestrictions::SetIOAllowed(true);
309 io_thread()->message_loop()->PostTask(
310 FROM_HERE,
311 NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true));
[email protected]b443cb042009-12-15 22:05:09312 MessageLoop::current()->PostTask(
[email protected]34f73fb2010-03-24 20:50:34313 FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop));
[email protected]b443cb042009-12-15 22:05:09314 MessageLoop::current()->Quit();
315 }
316 return module_ref_count_;
317}
318
initial.commit09911bf2008-07-26 23:55:29319void BrowserProcessImpl::EndSession() {
[email protected]c6032e82010-09-13 20:06:05320#if defined(OS_WIN) || defined(USE_X11)
[email protected]d65cab7a2008-08-12 01:25:41321 // Notify we are going away.
[email protected]c6032e82010-09-13 20:06:05322 shutdown_event_->Signal();
[email protected]b112a4c2009-02-01 20:24:01323#endif
[email protected]d65cab7a2008-08-12 01:25:41324
initial.commit09911bf2008-07-26 23:55:29325 // Mark all the profiles as clean.
326 ProfileManager* pm = profile_manager();
327 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i)
328 (*i)->MarkAsCleanShutdown();
329
330 // Tell the metrics service it was cleanly shutdown.
331 MetricsService* metrics = g_browser_process->metrics_service();
332 if (metrics && local_state()) {
initial.commit09911bf2008-07-26 23:55:29333 metrics->RecordStartOfSessionEnd();
334
335 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36336 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29337 }
338
339 // We must write that the profile and metrics service shutdown cleanly,
340 // otherwise on startup we'll think we crashed. So we block until done and
341 // then proceed with normal shutdown.
[email protected]c6032e82010-09-13 20:06:05342#if defined(USE_X11)
343 // Can't run a local loop on linux. Instead create a waitable event.
344 base::WaitableEvent done_writing(false, false);
[email protected]d04e7662010-10-10 22:24:48345 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]c6032e82010-09-13 20:06:05346 NewRunnableFunction(Signal, &done_writing));
347 done_writing.TimedWait(
348 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds));
349#elif defined(OS_WIN)
[email protected]d04e7662010-10-10 22:24:48350 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57351 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29352 MessageLoop::current()->Run();
[email protected]c6032e82010-09-13 20:06:05353#else
354 NOTIMPLEMENTED();
355#endif
initial.commit09911bf2008-07-26 23:55:29356}
357
[email protected]e13ad79b2010-07-22 21:36:50358ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() {
359 DCHECK(CalledOnValidThread());
360 if (!created_resource_dispatcher_host_)
361 CreateResourceDispatcherHost();
362 return resource_dispatcher_host_.get();
363}
364
365MetricsService* BrowserProcessImpl::metrics_service() {
366 DCHECK(CalledOnValidThread());
367 if (!created_metrics_service_)
368 CreateMetricsService();
369 return metrics_service_.get();
370}
371
372IOThread* BrowserProcessImpl::io_thread() {
373 DCHECK(CalledOnValidThread());
374 if (!created_io_thread_)
375 CreateIOThread();
376 return io_thread_.get();
377}
378
379base::Thread* BrowserProcessImpl::file_thread() {
380 DCHECK(CalledOnValidThread());
381 if (!created_file_thread_)
382 CreateFileThread();
383 return file_thread_.get();
384}
385
386base::Thread* BrowserProcessImpl::db_thread() {
387 DCHECK(CalledOnValidThread());
388 if (!created_db_thread_)
389 CreateDBThread();
390 return db_thread_.get();
391}
392
393base::Thread* BrowserProcessImpl::process_launcher_thread() {
394 DCHECK(CalledOnValidThread());
395 if (!created_process_launcher_thread_)
396 CreateProcessLauncherThread();
397 return process_launcher_thread_.get();
398}
399
400base::Thread* BrowserProcessImpl::cache_thread() {
401 DCHECK(CalledOnValidThread());
402 if (!created_cache_thread_)
403 CreateCacheThread();
404 return cache_thread_.get();
405}
406
[email protected]7a31f7c2011-03-21 23:22:04407base::Thread* BrowserProcessImpl::gpu_thread() {
408 DCHECK(CalledOnValidThread());
409 if (!created_gpu_thread_)
410 CreateGpuThread();
411 return gpu_thread_.get();
412}
413
[email protected]e13ad79b2010-07-22 21:36:50414#if defined(USE_X11)
415base::Thread* BrowserProcessImpl::background_x11_thread() {
416 DCHECK(CalledOnValidThread());
417 // The BACKGROUND_X11 thread is created when the IO thread is created.
418 if (!created_io_thread_)
419 CreateIOThread();
420 return background_x11_thread_.get();
421}
422#endif
423
[email protected]0b565182011-03-02 18:11:15424WatchDogThread* BrowserProcessImpl::watchdog_thread() {
425 DCHECK(CalledOnValidThread());
426 if (!created_watchdog_thread_)
427 CreateWatchdogThread();
428 DCHECK(watchdog_thread_.get() != NULL);
429 return watchdog_thread_.get();
430}
431
[email protected]e13ad79b2010-07-22 21:36:50432ProfileManager* BrowserProcessImpl::profile_manager() {
433 DCHECK(CalledOnValidThread());
434 if (!created_profile_manager_)
435 CreateProfileManager();
436 return profile_manager_.get();
437}
438
439PrefService* BrowserProcessImpl::local_state() {
440 DCHECK(CalledOnValidThread());
441 if (!created_local_state_)
442 CreateLocalState();
443 return local_state_.get();
444}
445
446DevToolsManager* BrowserProcessImpl::devtools_manager() {
447 DCHECK(CalledOnValidThread());
448 if (!created_devtools_manager_)
449 CreateDevToolsManager();
450 return devtools_manager_.get();
451}
452
[email protected]8b8e7c92010-08-19 18:05:56453SidebarManager* BrowserProcessImpl::sidebar_manager() {
454 DCHECK(CalledOnValidThread());
455 if (!created_sidebar_manager_)
456 CreateSidebarManager();
457 return sidebar_manager_.get();
458}
459
[email protected]2dfeaf92011-01-10 21:08:21460ui::Clipboard* BrowserProcessImpl::clipboard() {
[email protected]e13ad79b2010-07-22 21:36:50461 DCHECK(CalledOnValidThread());
462 return clipboard_.get();
463}
464
[email protected]abe2c032011-03-31 18:49:34465net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() {
[email protected]db0e86dd2011-03-16 14:47:21466 DCHECK(CalledOnValidThread());
467 return io_thread()->system_url_request_context_getter();
468}
469
470#if defined(OS_CHROMEOS)
471chromeos::ProxyConfigServiceImpl*
472BrowserProcessImpl::chromeos_proxy_config_service_impl() {
473 DCHECK(CalledOnValidThread());
474 if (!chromeos_proxy_config_service_impl_) {
475 chromeos_proxy_config_service_impl_ =
476 new chromeos::ProxyConfigServiceImpl();
477 }
478 return chromeos_proxy_config_service_impl_;
479}
480#endif // defined(OS_CHROMEOS)
481
[email protected]3ce02412011-03-01 12:01:15482ExtensionEventRouterForwarder*
483BrowserProcessImpl::extension_event_router_forwarder() {
484 return extension_event_router_forwarder_.get();
485}
486
[email protected]e13ad79b2010-07-22 21:36:50487NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
488 DCHECK(CalledOnValidThread());
489 if (!created_notification_ui_manager_)
490 CreateNotificationUIManager();
491 return notification_ui_manager_.get();
492}
493
[email protected]985655a2011-02-23 09:54:25494policy::BrowserPolicyConnector* BrowserProcessImpl::browser_policy_connector() {
[email protected]f2a893c2011-01-05 09:38:07495 DCHECK(CalledOnValidThread());
[email protected]985655a2011-02-23 09:54:25496 if (!created_browser_policy_connector_) {
497 DCHECK(browser_policy_connector_.get() == NULL);
498 created_browser_policy_connector_ = true;
499 browser_policy_connector_.reset(new policy::BrowserPolicyConnector());
[email protected]f2a893c2011-01-05 09:38:07500 }
[email protected]985655a2011-02-23 09:54:25501 return browser_policy_connector_.get();
[email protected]f2a893c2011-01-05 09:38:07502}
503
[email protected]e13ad79b2010-07-22 21:36:50504IconManager* BrowserProcessImpl::icon_manager() {
505 DCHECK(CalledOnValidThread());
506 if (!created_icon_manager_)
507 CreateIconManager();
508 return icon_manager_.get();
509}
510
511ThumbnailGenerator* BrowserProcessImpl::GetThumbnailGenerator() {
512 return &thumbnail_generator_;
513}
514
515AutomationProviderList* BrowserProcessImpl::InitAutomationProviderList() {
516 DCHECK(CalledOnValidThread());
517 if (automation_provider_list_.get() == NULL) {
518 automation_provider_list_.reset(AutomationProviderList::GetInstance());
519 }
520 return automation_provider_list_.get();
521}
522
[email protected]5613126e2011-01-31 15:27:55523void BrowserProcessImpl::InitDevToolsHttpProtocolHandler(
[email protected]01000cf12011-02-04 11:39:22524 const std::string& ip,
[email protected]5613126e2011-01-31 15:27:55525 int port,
526 const std::string& frontend_url) {
[email protected]e13ad79b2010-07-22 21:36:50527 DCHECK(CalledOnValidThread());
[email protected]5613126e2011-01-31 15:27:55528 devtools_http_handler_ =
[email protected]01000cf12011-02-04 11:39:22529 DevToolsHttpProtocolHandler::Start(ip,
530 port,
[email protected]9678cb42011-01-31 18:49:42531 frontend_url,
532 new BrowserListTabContentsProvider());
[email protected]5613126e2011-01-31 15:27:55533}
534
535void BrowserProcessImpl::InitDevToolsLegacyProtocolHandler(int port) {
536 DCHECK(CalledOnValidThread());
537 devtools_legacy_handler_ = DevToolsProtocolHandler::Start(port);
[email protected]e13ad79b2010-07-22 21:36:50538}
539
540bool BrowserProcessImpl::IsShuttingDown() {
541 DCHECK(CalledOnValidThread());
542 return did_start_ && 0 == module_ref_count_;
543}
544
initial.commit09911bf2008-07-26 23:55:29545printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
546 // TODO(abarth): DCHECK(CalledOnValidThread());
[email protected]d8922f22010-05-07 00:57:27547 // http://code.google.com/p/chromium/issues/detail?id=6828
initial.commit09911bf2008-07-26 23:55:29548 // print_job_manager_ is initialized in the constructor and destroyed in the
549 // destructor, so it should always be valid.
550 DCHECK(print_job_manager_.get());
551 return print_job_manager_.get();
552}
553
[email protected]dbeebd52010-11-16 20:34:16554printing::PrintPreviewTabController*
555 BrowserProcessImpl::print_preview_tab_controller() {
556 DCHECK(CalledOnValidThread());
557 if (!print_preview_tab_controller_.get())
558 CreatePrintPreviewTabController();
559 return print_preview_tab_controller_.get();
560}
561
[email protected]e13ad79b2010-07-22 21:36:50562GoogleURLTracker* BrowserProcessImpl::google_url_tracker() {
563 DCHECK(CalledOnValidThread());
564 if (!google_url_tracker_.get())
565 CreateGoogleURLTracker();
566 return google_url_tracker_.get();
567}
568
569IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
570 DCHECK(CalledOnValidThread());
571 if (!intranet_redirect_detector_.get())
572 CreateIntranetRedirectDetector();
573 return intranet_redirect_detector_.get();
574}
575
576const std::string& BrowserProcessImpl::GetApplicationLocale() {
577 DCHECK(!locale_.empty());
578 return locale_;
579}
580
581void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
582 locale_ = locale;
583 extension_l10n_util::SetProcessLocale(locale);
584}
585
[email protected]073ed7b2010-09-27 09:20:02586DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
587 return &download_status_updater_;
588}
589
[email protected]e13ad79b2010-07-22 21:36:50590base::WaitableEvent* BrowserProcessImpl::shutdown_event() {
591 return shutdown_event_.get();
592}
593
594TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() {
595 DCHECK(CalledOnValidThread());
596 if (!tab_closeable_state_watcher_.get())
597 CreateTabCloseableStateWatcher();
598 return tab_closeable_state_watcher_.get();
599}
600
[email protected]a7a5e992010-12-09 23:39:51601safe_browsing::ClientSideDetectionService*
602 BrowserProcessImpl::safe_browsing_detection_service() {
603 DCHECK(CalledOnValidThread());
604 if (!created_safe_browsing_detection_service_) {
605 CreateSafeBrowsingDetectionService();
606 }
607 return safe_browsing_detection_service_.get();
608}
609
[email protected]8b08a47f2011-02-25 12:36:37610bool BrowserProcessImpl::plugin_finder_disabled() const {
611 return *plugin_finder_disabled_pref_;
612}
613
[email protected]6618d1d2010-12-15 21:18:47614void BrowserProcessImpl::Observe(NotificationType type,
615 const NotificationSource& source,
616 const NotificationDetails& details) {
617 if (type == NotificationType::APP_TERMINATING) {
618 Profile* profile = ProfileManager::GetDefaultProfile();
619 if (profile) {
620 PrefService* prefs = profile->GetPrefs();
[email protected]2ffc3c6c2011-01-14 12:50:24621 if (prefs->GetBoolean(prefs::kClearSiteDataOnExit) &&
[email protected]6618d1d2010-12-15 21:18:47622 local_state()->GetBoolean(prefs::kClearPluginLSODataEnabled)) {
623 plugin_data_remover_ = new PluginDataRemover();
[email protected]c7d58d62011-01-21 10:27:18624 if (!plugin_data_remover_mime_type().empty())
625 plugin_data_remover_->set_mime_type(plugin_data_remover_mime_type());
626 plugin_data_remover_->StartRemoving(base::Time());
[email protected]6618d1d2010-12-15 21:18:47627 }
628 }
[email protected]e450fa62011-02-01 12:52:56629 } else if (type == NotificationType::PREF_CHANGED) {
630 std::string* pref = Details<std::string>(details).ptr();
631 if (*pref == prefs::kDefaultBrowserSettingEnabled) {
632 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
633 ShellIntegration::SetAsDefaultBrowser();
634 }
[email protected]6618d1d2010-12-15 21:18:47635 } else {
636 NOTREACHED();
637 }
638}
639
640void BrowserProcessImpl::WaitForPluginDataRemoverToFinish() {
[email protected]c7d58d62011-01-21 10:27:18641 if (plugin_data_remover_.get())
642 plugin_data_remover_->Wait();
[email protected]6618d1d2010-12-15 21:18:47643}
644
[email protected]e13ad79b2010-07-22 21:36:50645#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
646void BrowserProcessImpl::StartAutoupdateTimer() {
647 autoupdate_timer_.Start(
648 base::TimeDelta::FromHours(kUpdateCheckIntervalHours),
649 this,
650 &BrowserProcessImpl::OnAutoupdateTimer);
651}
652#endif
653
[email protected]d6f37fc2011-02-13 23:58:41654ChromeNetLog* BrowserProcessImpl::net_log() {
655 return net_log_.get();
656}
657
[email protected]4ef795df2010-02-03 02:35:08658void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
[email protected]72cfd90f2010-02-06 03:08:04659 webkit_database::DatabaseTracker::ClearLocalState(profile_path);
[email protected]4ef795df2010-02-03 02:35:08660}
661
662bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
663 FilePath user_data_dir;
664 Profile* profile;
665
[email protected]09584972010-07-03 00:00:59666 // Check for the existence of a profile manager. When quitting early,
[email protected]ed0cf562010-02-05 22:50:41667 // e.g. because another chrome instance is running, or when invoked with
668 // options such as --uninstall or --try-chrome-again=0, the profile manager
669 // does not exist yet.
670 if (!profile_manager_.get())
671 return false;
672
[email protected]4ef795df2010-02-03 02:35:08673 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
674 profile = profile_manager_->GetDefaultProfile(user_data_dir);
[email protected]7bfc674322010-03-05 00:20:57675 if (!profile)
676 return false;
[email protected]4ef795df2010-02-03 02:35:08677 *profile_path = profile->GetPath();
678 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit);
679}
680
initial.commit09911bf2008-07-26 23:55:29681void BrowserProcessImpl::CreateResourceDispatcherHost() {
682 DCHECK(!created_resource_dispatcher_host_ &&
683 resource_dispatcher_host_.get() == NULL);
684 created_resource_dispatcher_host_ = true;
685
[email protected]214538842011-04-01 18:47:24686 // UserScriptListener will delete itself.
687 ResourceQueue::DelegateSet resource_queue_delegates;
688 resource_queue_delegates.insert(new UserScriptListener());
689
690 resource_dispatcher_host_.reset(
691 new ResourceDispatcherHost(resource_queue_delegates));
initial.commit09911bf2008-07-26 23:55:29692 resource_dispatcher_host_->Initialize();
693}
694
695void BrowserProcessImpl::CreateMetricsService() {
696 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
697 created_metrics_service_ = true;
698
699 metrics_service_.reset(new MetricsService);
700}
701
702void BrowserProcessImpl::CreateIOThread() {
703 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
704 created_io_thread_ = true;
705
706 // Prior to starting the io thread, we create the plugin service as
707 // it is predominantly used from the io thread, but must be created
708 // on the main thread. The service ctor is inexpensive and does not
709 // invoke the io_thread() accessor.
710 PluginService::GetInstance();
711
[email protected]753efc42010-03-09 19:52:16712#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06713 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so
714 // we start it now.
715 scoped_ptr<base::Thread> background_x11_thread(
[email protected]d04e7662010-10-10 22:24:48716 new BrowserProcessSubThread(BrowserThread::BACKGROUND_X11));
[email protected]4c3cd7412009-04-22 17:56:06717 if (!background_x11_thread->Start())
718 return;
719 background_x11_thread_.swap(background_x11_thread);
720#endif
721
[email protected]3ce02412011-03-01 12:01:15722 scoped_ptr<IOThread> thread(new IOThread(
723 local_state(), net_log_.get(), extension_event_router_forwarder_.get()));
[email protected]ab820df2008-08-26 05:55:10724 base::Thread::Options options;
725 options.message_loop_type = MessageLoop::TYPE_IO;
726 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29727 return;
728 io_thread_.swap(thread);
729}
730
731void BrowserProcessImpl::CreateFileThread() {
732 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
733 created_file_thread_ = true;
734
[email protected]ab820df2008-08-26 05:55:10735 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48736 new BrowserProcessSubThread(BrowserThread::FILE));
[email protected]a1db3842008-09-17 22:04:06737 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39738#if defined(OS_WIN)
739 // On Windows, the FILE thread needs to be have a UI message loop which pumps
740 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06741 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39742#else
743 options.message_loop_type = MessageLoop::TYPE_IO;
744#endif
[email protected]a1db3842008-09-17 22:04:06745 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29746 return;
747 file_thread_.swap(thread);
748}
749
750void BrowserProcessImpl::CreateDBThread() {
751 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
752 created_db_thread_ = true;
753
[email protected]ab820df2008-08-26 05:55:10754 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48755 new BrowserProcessSubThread(BrowserThread::DB));
initial.commit09911bf2008-07-26 23:55:29756 if (!thread->Start())
757 return;
758 db_thread_.swap(thread);
759}
760
[email protected]914511712009-11-23 19:42:33761void BrowserProcessImpl::CreateProcessLauncherThread() {
762 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
763 created_process_launcher_thread_ = true;
764
765 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48766 new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER));
[email protected]914511712009-11-23 19:42:33767 if (!thread->Start())
768 return;
769 process_launcher_thread_.swap(thread);
770}
771
[email protected]875ee822010-05-18 20:58:01772void BrowserProcessImpl::CreateCacheThread() {
773 DCHECK(!created_cache_thread_ && !cache_thread_.get());
774 created_cache_thread_ = true;
775
776 scoped_ptr<base::Thread> thread(
[email protected]75096332010-11-09 03:28:13777 new BrowserThread(BrowserThread::CACHE));
[email protected]875ee822010-05-18 20:58:01778 base::Thread::Options options;
779 options.message_loop_type = MessageLoop::TYPE_IO;
780 if (!thread->StartWithOptions(options))
781 return;
782 cache_thread_.swap(thread);
783}
784
[email protected]7a31f7c2011-03-21 23:22:04785void BrowserProcessImpl::CreateGpuThread() {
786 DCHECK(!created_gpu_thread_ && !gpu_thread_.get());
787 created_gpu_thread_ = true;
788
789 scoped_ptr<base::Thread> thread(new BrowserThread(BrowserThread::GPU));
790
791 base::Thread::Options options;
792#if defined(OS_WIN)
793 // On Windows the GPU thread needs to pump the compositor child window's
794 // message loop. TODO(apatrick): make this an IO thread if / when we get rid
795 // of this child window. Unfortunately it might always be necessary for
796 // Windows XP because we cannot share the backing store textures between
797 // processes.
798 options.message_loop_type = MessageLoop::TYPE_UI;
799#else
800 options.message_loop_type = MessageLoop::TYPE_IO;
801#endif
802
803 if (!thread->StartWithOptions(options))
804 return;
805 gpu_thread_.swap(thread);
806}
807
[email protected]0b565182011-03-02 18:11:15808void BrowserProcessImpl::CreateWatchdogThread() {
809 DCHECK(!created_watchdog_thread_ && watchdog_thread_.get() == NULL);
810 created_watchdog_thread_ = true;
811
812 scoped_ptr<WatchDogThread> thread(new WatchDogThread());
813 if (!thread->Start())
814 return;
815 watchdog_thread_.swap(thread);
816}
817
initial.commit09911bf2008-07-26 23:55:29818void BrowserProcessImpl::CreateProfileManager() {
819 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
820 created_profile_manager_ = true;
821
822 profile_manager_.reset(new ProfileManager());
823}
824
825void BrowserProcessImpl::CreateLocalState() {
826 DCHECK(!created_local_state_ && local_state_.get() == NULL);
827 created_local_state_ = true;
828
[email protected]b9636002009-03-04 00:05:25829 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29830 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]f2d1f612010-12-09 15:10:17831 local_state_.reset(
832 PrefService::CreatePrefService(local_state_path, NULL, NULL));
[email protected]492d2142010-09-10 13:55:18833
[email protected]2a7e7c152010-10-01 20:12:09834 pref_change_registrar_.Init(local_state_.get());
835
[email protected]492d2142010-09-10 13:55:18836 // Make sure the the plugin updater gets notifications of changes
[email protected]24ff43d72011-03-01 13:28:58837 // in the plugin policy lists.
838 local_state_->RegisterListPref(prefs::kPluginsDisabledPlugins);
839 pref_change_registrar_.Add(prefs::kPluginsDisabledPlugins,
840 PluginUpdater::GetInstance());
841 local_state_->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions);
842 pref_change_registrar_.Add(prefs::kPluginsDisabledPluginsExceptions,
843 PluginUpdater::GetInstance());
844 local_state_->RegisterListPref(prefs::kPluginsEnabledPlugins);
845 pref_change_registrar_.Add(prefs::kPluginsEnabledPlugins,
[email protected]8e8bb6d2010-12-13 08:18:55846 PluginUpdater::GetInstance());
[email protected]2a7e7c152010-10-01 20:12:09847
848 // Initialize and set up notifications for the printing enabled
849 // preference.
850 local_state_->RegisterBooleanPref(prefs::kPrintingEnabled, true);
851 bool printing_enabled =
852 local_state_->GetBoolean(prefs::kPrintingEnabled);
853 print_job_manager_->set_printing_enabled(printing_enabled);
854 pref_change_registrar_.Add(prefs::kPrintingEnabled,
855 print_job_manager_.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]fd6159a2010-09-03 09:38:39872}
initial.commit09911bf2008-07-26 23:55:29873
initial.commit09911bf2008-07-26 23:55:29874void BrowserProcessImpl::CreateIconManager() {
875 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
876 created_icon_manager_ = true;
877 icon_manager_.reset(new IconManager);
878}
879
[email protected]40ecc902009-03-16 13:42:47880void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44881 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47882 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44883 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47884}
885
[email protected]8b8e7c92010-08-19 18:05:56886void BrowserProcessImpl::CreateSidebarManager() {
887 DCHECK(sidebar_manager_.get() == NULL);
888 created_sidebar_manager_ = true;
889 sidebar_manager_ = new SidebarManager();
890}
891
initial.commit09911bf2008-07-26 23:55:29892void BrowserProcessImpl::CreateGoogleURLTracker() {
893 DCHECK(google_url_tracker_.get() == NULL);
894 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
895 google_url_tracker_.swap(google_url_tracker);
896}
[email protected]6641bf662009-08-21 00:34:09897
[email protected]c4ff4952010-01-08 19:12:47898void BrowserProcessImpl::CreateIntranetRedirectDetector() {
899 DCHECK(intranet_redirect_detector_.get() == NULL);
900 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
901 new IntranetRedirectDetector);
902 intranet_redirect_detector_.swap(intranet_redirect_detector);
903}
904
[email protected]29672ab2009-10-30 03:44:03905void BrowserProcessImpl::CreateNotificationUIManager() {
906 DCHECK(notification_ui_manager_.get() == NULL);
[email protected]b0b2a3dd2011-01-06 00:30:05907 notification_ui_manager_.reset(NotificationUIManager::Create(local_state()));
908
[email protected]29672ab2009-10-30 03:44:03909 created_notification_ui_manager_ = true;
910}
911
[email protected]0b4d3382010-07-14 16:13:04912void BrowserProcessImpl::CreateTabCloseableStateWatcher() {
913 DCHECK(tab_closeable_state_watcher_.get() == NULL);
914 tab_closeable_state_watcher_.reset(TabCloseableStateWatcher::Create());
915}
916
[email protected]dbeebd52010-11-16 20:34:16917void BrowserProcessImpl::CreatePrintPreviewTabController() {
918 DCHECK(print_preview_tab_controller_.get() == NULL);
919 print_preview_tab_controller_ = new printing::PrintPreviewTabController();
920}
921
[email protected]a7a5e992010-12-09 23:39:51922void BrowserProcessImpl::CreateSafeBrowsingDetectionService() {
923 DCHECK(safe_browsing_detection_service_.get() == NULL);
924 // Set this flag to true so that we don't retry indefinitely to
925 // create the service class if there was an error.
926 created_safe_browsing_detection_service_ = true;
927
928 FilePath model_file_path;
929 Profile* profile = profile_manager() ?
930 profile_manager()->GetDefaultProfile() : NULL;
931 if (IsSafeBrowsingDetectionServiceEnabled() &&
932 PathService::Get(chrome::DIR_USER_DATA, &model_file_path) &&
933 profile && profile->GetRequestContext()) {
934 safe_browsing_detection_service_.reset(
935 safe_browsing::ClientSideDetectionService::Create(
936 model_file_path.Append(chrome::kSafeBrowsingPhishingModelFilename),
937 profile->GetRequestContext()));
938 }
939}
940
941bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() {
942 // The safe browsing client-side detection is enabled only if the switch is
[email protected]42930de42011-01-13 23:26:28943 // enabled and when safe browsing related stats is allowed to be collected.
[email protected]d081d192011-04-01 02:33:24944#ifdef OS_CHROMEOS
945 return false;
946#else
947 return !CommandLine::ForCurrentProcess()->HasSwitch(
948 switches::kDisableClientSidePhishingDetection) &&
[email protected]42930de42011-01-13 23:26:28949 resource_dispatcher_host()->safe_browsing_service() &&
950 resource_dispatcher_host()->safe_browsing_service()->CanReportStats();
[email protected]d081d192011-04-01 02:33:24951#endif
[email protected]a7a5e992010-12-09 23:39:51952}
953
[email protected]6641bf662009-08-21 00:34:09954// The BrowserProcess object must outlive the file thread so we use traits
955// which don't do any management.
[email protected]c56428f22010-06-16 02:17:23956DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl);
[email protected]6641bf662009-08-21 00:34:09957
[email protected]d55aaa132009-09-28 21:08:04958#if defined(IPC_MESSAGE_LOG_ENABLED)
959
960void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
961 // First enable myself.
962 if (enable)
[email protected]8e8bb6d2010-12-13 08:18:55963 IPC::Logging::GetInstance()->Enable();
[email protected]d55aaa132009-09-28 21:08:04964 else
[email protected]8e8bb6d2010-12-13 08:18:55965 IPC::Logging::GetInstance()->Disable();
[email protected]d55aaa132009-09-28 21:08:04966
967 // Now tell subprocesses. Messages to ChildProcess-derived
968 // processes must be done on the IO thread.
969 io_thread()->message_loop()->PostTask
970 (FROM_HERE,
971 NewRunnableMethod(
972 this,
973 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
974 enable));
975
976 // Finally, tell the renderers which don't derive from ChildProcess.
977 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:27978 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
979 !i.IsAtEnd(); i.Advance())
[email protected]ff47b2962011-03-07 23:51:49980 i.GetCurrentValue()->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:04981}
982
983// Helper for SetIPCLoggingEnabled.
984void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d04e7662010-10-10 22:24:48985 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d55aaa132009-09-28 21:08:04986
[email protected]d27893f62010-07-03 05:47:42987 BrowserChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:11988 while (!i.Done()) {
[email protected]ff47b2962011-03-07 23:51:49989 i->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled));
[email protected]34cf97d2009-09-29 22:46:11990 ++i;
[email protected]d55aaa132009-09-28 21:08:04991 }
992}
993
994#endif // IPC_MESSAGE_LOG_ENABLED
995
[email protected]3cdacd42010-04-30 18:55:53996// Mac is currently not supported.
997#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:42998
999bool BrowserProcessImpl::CanAutorestartForUpdate() const {
1000 // Check if browser is in the background and if it needs to be restarted to
1001 // apply a pending update.
[email protected]c10fa3952010-08-24 16:52:531002 return BrowserList::size() == 0 && BrowserList::WillKeepAlive() &&
[email protected]c984d9f2010-07-20 20:52:201003 Upgrade::IsUpdatePendingRestart();
[email protected]bd48c2b02010-04-09 20:32:421004}
1005
[email protected]5c08f222010-09-22 09:37:211006// Switches to add when auto-restarting Chrome.
[email protected]6c10c972010-08-11 04:15:471007const char* const kSwitchesToAddOnAutorestart[] = {
[email protected]f9a06842010-08-21 00:32:401008 switches::kNoStartupWindow
[email protected]bd48c2b02010-04-09 20:32:421009};
1010
1011void BrowserProcessImpl::RestartPersistentInstance() {
1012 CommandLine* old_cl = CommandLine::ForCurrentProcess();
[email protected]3cdacd42010-04-30 18:55:531013 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram()));
[email protected]bd48c2b02010-04-09 20:32:421014
1015 std::map<std::string, CommandLine::StringType> switches =
1016 old_cl->GetSwitches();
1017
[email protected]5c08f222010-09-22 09:37:211018 switches::RemoveSwitchesForAutostart(&switches);
[email protected]bd48c2b02010-04-09 20:32:421019
1020 // Append the rest of the switches (along with their values, if any)
1021 // to the new command line
1022 for (std::map<std::string, CommandLine::StringType>::const_iterator i =
1023 switches.begin(); i != switches.end(); ++i) {
1024 CommandLine::StringType switch_value = i->second;
1025 if (switch_value.length() > 0) {
[email protected]05076ba22010-07-30 05:59:571026 new_cl->AppendSwitchNative(i->first, i->second);
[email protected]bd48c2b02010-04-09 20:32:421027 } else {
[email protected]3cdacd42010-04-30 18:55:531028 new_cl->AppendSwitch(i->first);
[email protected]bd48c2b02010-04-09 20:32:421029 }
1030 }
1031
[email protected]6c10c972010-08-11 04:15:471032 // Ensure that our desired switches are set on the new process.
[email protected]5c08f222010-09-22 09:37:211033 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) {
[email protected]6c10c972010-08-11 04:15:471034 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i]))
1035 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
1036 }
[email protected]bd48c2b02010-04-09 20:32:421037
[email protected]3cdacd42010-04-30 18:55:531038 DLOG(WARNING) << "Shutting down current instance of the browser.";
1039 BrowserList::CloseAllBrowsersAndExit();
1040
1041 // Transfer ownership to Upgrade.
1042 Upgrade::SetNewCommandLine(new_cl.release());
[email protected]bd48c2b02010-04-09 20:32:421043}
1044
1045void BrowserProcessImpl::OnAutoupdateTimer() {
1046 if (CanAutorestartForUpdate()) {
[email protected]3cdacd42010-04-30 18:55:531047 DLOG(WARNING) << "Detected update. Restarting browser.";
[email protected]bd48c2b02010-04-09 20:32:421048 RestartPersistentInstance();
1049 }
1050}
1051
[email protected]3cdacd42010-04-30 18:55:531052#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)