blob: 32e80dd4518a94a5a7bac38221e00e93ef78ee00 [file] [log] [blame]
[email protected]f2a893c2011-01-05 09:38:071// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/browser_process_impl.h"
6
[email protected]3cdacd42010-04-30 18:55:537#include <map>
[email protected]68f88b992011-05-07 02:01:398#include <set>
9#include <vector>
[email protected]3cdacd42010-04-30 18:55:5310
initial.commit09911bf2008-07-26 23:55:2911#include "base/command_line.h"
[email protected]6641bf662009-08-21 00:34:0912#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/path_service.h"
[email protected]985655a2011-02-23 09:54:2514#include "base/synchronization/waitable_event.h"
[email protected]c6032e82010-09-13 20:06:0515#include "base/task.h"
[email protected]34b99632011-01-01 01:01:0616#include "base/threading/thread.h"
17#include "base/threading/thread_restrictions.h"
[email protected]e13ad79b2010-07-22 21:36:5018#include "chrome/browser/automation/automation_provider_list.h"
[email protected]a07676b22011-06-17 16:36:5319#include "chrome/browser/background/background_mode_manager.h"
[email protected]b443cb042009-12-15 22:05:0920#include "chrome/browser/browser_main.h"
[email protected]0ac83682010-01-22 17:46:2721#include "chrome/browser/browser_process_sub_thread.h"
[email protected]ac262c9f2008-10-19 17:45:2122#include "chrome/browser/browser_trial.h"
[email protected]6c69796d2010-07-16 21:41:1623#include "chrome/browser/download/download_file_manager.h"
[email protected]e7f009d2011-06-14 19:35:1024#include "chrome/browser/download/mhtml_generation_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]dcefa302009-05-20 00:24:3931#include "chrome/browser/icon_manager.h"
[email protected]c4ff4952010-01-08 19:12:4732#include "chrome/browser/intranet_redirect_detector.h"
[email protected]0ac83682010-01-22 17:46:2733#include "chrome/browser/io_thread.h"
[email protected]dc6f4962009-02-13 01:25:5034#include "chrome/browser/metrics/metrics_service.h"
[email protected]0b565182011-03-02 18:11:1535#include "chrome/browser/metrics/thread_watcher.h"
[email protected]b2fcd0e2010-12-01 15:19:4036#include "chrome/browser/net/chrome_net_log.h"
[email protected]3530cd92010-06-27 06:22:0137#include "chrome/browser/net/predictor_api.h"
[email protected]d393a0fd2009-05-13 23:32:0138#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]29672ab2009-10-30 03:44:0339#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]6618d1d2010-12-15 21:18:4740#include "chrome/browser/plugin_data_remover.h"
[email protected]985655a2011-02-23 09:54:2541#include "chrome/browser/policy/browser_policy_connector.h"
[email protected]caf63aea2011-04-26 11:04:1042#include "chrome/browser/prefs/browser_prefs.h"
[email protected]37858e52010-08-26 00:22:0243#include "chrome/browser/prefs/pref_service.h"
[email protected]1459fb62011-05-25 19:03:2744#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]68f88b992011-05-07 02:01:3945#include "chrome/browser/printing/background_printing_manager.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]8bcdf072011-06-03 16:52:1549#include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h"
[email protected]a7a5e992010-12-09 23:39:5150#include "chrome/browser/safe_browsing/client_side_detection_service.h"
[email protected]81218f42009-02-05 18:48:0851#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]e450fa62011-02-01 12:52:5652#include "chrome/browser/shell_integration.h"
[email protected]8b8e7c92010-08-19 18:05:5653#include "chrome/browser/sidebar/sidebar_manager.h"
[email protected]9e7f015f2011-05-28 00:24:2554#include "chrome/browser/status_icons/status_tray.h"
[email protected]0b4d3382010-07-14 16:13:0455#include "chrome/browser/tab_closeable_state_watcher.h"
[email protected]71b73f02011-04-06 15:57:2956#include "chrome/browser/ui/browser_list.h"
[email protected]4ef795df2010-02-03 02:35:0857#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2958#include "chrome/common/chrome_paths.h"
59#include "chrome/common/chrome_switches.h"
[email protected]de23f3f2011-05-18 16:20:2360#include "chrome/common/default_plugin.h"
[email protected]f1b6de22010-03-06 12:13:4761#include "chrome/common/extensions/extension_l10n_util.h"
[email protected]985655a2011-02-23 09:54:2562#include "chrome/common/extensions/extension_resource.h"
[email protected]ea587b02010-05-21 15:01:3563#include "chrome/common/json_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2964#include "chrome/common/pref_names.h"
[email protected]5c08f222010-09-22 09:37:2165#include "chrome/common/switch_utils.h"
[email protected]985655a2011-02-23 09:54:2566#include "chrome/common/url_constants.h"
[email protected]bd48c2b02010-04-09 20:32:4267#include "chrome/installer/util/google_update_constants.h"
[email protected]a01efd22011-03-01 00:38:3268#include "content/browser/browser_child_process_host.h"
69#include "content/browser/browser_thread.h"
[email protected]419a0572011-04-18 22:21:4670#include "content/browser/child_process_security_policy.h"
[email protected]b46442d7e2011-06-29 02:16:0671#include "content/browser/debugger/browser_list_tabcontents_provider.h"
72#include "content/browser/debugger/devtools_http_protocol_handler.h"
73#include "content/browser/debugger/devtools_manager.h"
74#include "content/browser/debugger/devtools_protocol_handler.h"
[email protected]d9f37932011-05-09 20:09:2475#include "content/browser/gpu/gpu_process_host_ui_shim.h"
[email protected]a01efd22011-03-01 00:38:3276#include "content/browser/plugin_service.h"
77#include "content/browser/renderer_host/render_process_host.h"
78#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]f20d7332011-03-08 21:11:5379#include "content/common/notification_service.h"
[email protected]d55aaa132009-09-28 21:08:0480#include "ipc/ipc_logging.h"
[email protected]abe2c032011-03-31 18:49:3481#include "net/url_request/url_request_context_getter.h"
[email protected]2dfeaf92011-01-10 21:08:2182#include "ui/base/clipboard/clipboard.h"
[email protected]c051a1b2011-01-21 23:30:1783#include "ui/base/l10n/l10n_util.h"
[email protected]4ef795df2010-02-03 02:35:0884#include "webkit/database/database_tracker.h"
[email protected]de23f3f2011-05-18 16:20:2385#include "webkit/plugins/npapi/plugin_list.h"
[email protected]b112a4c2009-02-01 20:24:0186
87#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0588#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3889#endif
90
[email protected]d55aaa132009-09-28 21:08:0491#if defined(IPC_MESSAGE_LOG_ENABLED)
[email protected]ff47b2962011-03-07 23:51:4992#include "content/common/child_process_messages.h"
[email protected]d55aaa132009-09-28 21:08:0493#endif
94
[email protected]db0e86dd2011-03-16 14:47:2195#if defined(OS_CHROMEOS)
96#include "chrome/browser/chromeos/proxy_config_service_impl.h"
[email protected]2d14b3732011-05-10 16:48:4497#include "chrome/browser/chromeos/web_socket_proxy_controller.h"
[email protected]db0e86dd2011-03-16 14:47:2198#endif // defined(OS_CHROMEOS)
99
[email protected]3cdacd42010-04-30 18:55:53100#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
101// How often to check if the persistent instance of Chrome needs to restart
102// to install an update.
103static const int kUpdateCheckIntervalHours = 6;
104#endif
105
[email protected]c6032e82010-09-13 20:06:05106#if defined(USE_X11)
107// How long to wait for the File thread to complete during EndSession, on
108// Linux. We have a timeout here because we're unable to run the UI messageloop
109// and there's some deadlock risk. Our only option is to exit anyway.
110static const int kEndSessionTimeoutSeconds = 10;
111#endif
112
[email protected]bb975362009-01-21 01:00:22113BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:29114 : created_resource_dispatcher_host_(false),
115 created_metrics_service_(false),
116 created_io_thread_(false),
117 created_file_thread_(false),
118 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:33119 created_process_launcher_thread_(false),
[email protected]875ee822010-05-18 20:58:01120 created_cache_thread_(false),
[email protected]0b565182011-03-02 18:11:15121 created_watchdog_thread_(false),
[email protected]2d14b3732011-05-10 16:48:44122#if defined(OS_CHROMEOS)
123 created_web_socket_proxy_thread_(false),
124#endif
initial.commit09911bf2008-07-26 23:55:29125 created_profile_manager_(false),
126 created_local_state_(false),
[email protected]b112a4c2009-02-01 20:24:01127 created_icon_manager_(false),
[email protected]40ecc902009-03-16 13:42:47128 created_devtools_manager_(false),
[email protected]8b8e7c92010-08-19 18:05:56129 created_sidebar_manager_(false),
[email protected]985655a2011-02-23 09:54:25130 created_browser_policy_connector_(false),
[email protected]29672ab2009-10-30 03:44:03131 created_notification_ui_manager_(false),
[email protected]462a0ff2011-06-02 17:15:34132 created_safe_browsing_service_(false),
[email protected]a7a5e992010-12-09 23:39:51133 created_safe_browsing_detection_service_(false),
initial.commit09911bf2008-07-26 23:55:29134 module_ref_count_(0),
[email protected]afd20c022010-06-10 00:48:20135 did_start_(false),
[email protected]1b2db1a2008-08-08 17:46:13136 checked_for_new_frames_(false),
[email protected]4747caf2011-03-23 20:09:21137 using_new_frames_(false) {
initial.commit09911bf2008-07-26 23:55:29138 g_browser_process = this;
[email protected]2dfeaf92011-01-10 21:08:21139 clipboard_.reset(new ui::Clipboard);
initial.commit09911bf2008-07-26 23:55:29140 main_notification_service_.reset(new NotificationService);
141
[email protected]6618d1d2010-12-15 21:18:47142 notification_registrar_.Add(this,
143 NotificationType::APP_TERMINATING,
144 NotificationService::AllSources());
145
initial.commit09911bf2008-07-26 23:55:29146 // Must be created after the NotificationService.
147 print_job_manager_.reset(new printing::PrintJobManager);
148
[email protected]b2fcd0e2010-12-01 15:19:40149 net_log_.reset(new ChromeNetLog);
[email protected]3ce02412011-03-01 12:01:15150
151 extension_event_router_forwarder_ = new ExtensionEventRouterForwarder;
[email protected]fc4facd2011-03-22 23:18:50152
153 ExtensionTabIdMap::GetInstance()->Init();
initial.commit09911bf2008-07-26 23:55:29154}
155
156BrowserProcessImpl::~BrowserProcessImpl() {
[email protected]4ef795df2010-02-03 02:35:08157 FilePath profile_path;
158 bool clear_local_state_on_exit;
159
160 // Store the profile path for clearing local state data on exit.
161 clear_local_state_on_exit = ShouldClearLocalState(&profile_path);
162
[email protected]2d14b3732011-05-10 16:48:44163#if defined(OS_CHROMEOS)
164 if (web_socket_proxy_thread_.get())
165 chromeos::WebSocketProxyController::Shutdown();
166 web_socket_proxy_thread_.reset();
167#endif
168
initial.commit09911bf2008-07-26 23:55:29169 // Delete the AutomationProviderList before NotificationService,
170 // since it may try to unregister notifications
171 // Both NotificationService and AutomationProvider are singleton instances in
172 // the BrowserProcess. Since AutomationProvider may have some active
173 // notification observers, it is essential that it gets destroyed before the
174 // NotificationService. NotificationService won't be destroyed until after
175 // this destructor is run.
176 automation_provider_list_.reset();
177
[email protected]d393a0fd2009-05-13 23:32:01178 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
179 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
180 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
181 // any pending URLFetchers, and avoid creating any more.
182 SdchDictionaryFetcher::Shutdown();
183
[email protected]51ac040762011-01-20 02:01:04184 // We need to destroy the MetricsService, GoogleURLTracker,
185 // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService
186 // before the io_thread_ gets destroyed, since their destructors can call the
187 // URLFetcher destructor, which does a PostDelayedTask operation on the IO
188 // thread. (The IO thread will handle that URLFetcher operation before going
189 // away.)
initial.commit09911bf2008-07-26 23:55:29190 metrics_service_.reset();
191 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47192 intranet_redirect_detector_.reset();
[email protected]51ac040762011-01-20 02:01:04193 safe_browsing_detection_service_.reset();
initial.commit09911bf2008-07-26 23:55:29194
[email protected]d8a899c2010-09-21 04:50:33195 // Need to clear the desktop notification balloons before the io_thread_ and
196 // before the profiles, since if there are any still showing we will access
197 // those things during teardown.
198 notification_ui_manager_.reset();
199
initial.commit09911bf2008-07-26 23:55:29200 // Need to clear profiles (download managers) before the io_thread_.
201 profile_manager_.reset();
202
203 // Debugger must be cleaned up before IO thread and NotificationService.
[email protected]5613126e2011-01-31 15:27:55204 if (devtools_http_handler_.get()) {
205 devtools_http_handler_->Stop();
206 devtools_http_handler_ = NULL;
207 }
208 if (devtools_legacy_handler_.get()) {
209 devtools_legacy_handler_->Stop();
210 devtools_legacy_handler_ = NULL;
211 }
initial.commit09911bf2008-07-26 23:55:29212
[email protected]462a0ff2011-06-02 17:15:34213 if (safe_browsing_service_.get())
214 safe_browsing_service()->ShutDown();
initial.commit09911bf2008-07-26 23:55:29215
[email protected]462a0ff2011-06-02 17:15:34216 if (resource_dispatcher_host_.get()) {
initial.commit09911bf2008-07-26 23:55:29217 // Cancel pending requests and prevent new requests.
218 resource_dispatcher_host()->Shutdown();
219 }
220
[email protected]fc4facd2011-03-22 23:18:50221 ExtensionTabIdMap::GetInstance()->Shutdown();
222
[email protected]985655a2011-02-23 09:54:25223 // The policy providers managed by |browser_policy_connector_| need to shut
224 // down while the IO and FILE threads are still alive.
225 browser_policy_connector_.reset();
[email protected]f2a893c2011-01-05 09:38:07226
[email protected]6618d1d2010-12-15 21:18:47227 // Wait for removing plugin data to finish before shutting down the IO thread.
228 WaitForPluginDataRemoverToFinish();
229
[email protected]7a31f7c2011-03-21 23:22:04230 // Destroying the GpuProcessHostUIShims on the UI thread posts a task to
231 // delete related objects on the GPU thread. This must be done before
232 // stopping the GPU thread. The GPU thread will close IPC channels to renderer
233 // processes so this has to happen before stopping the IO thread.
234 GpuProcessHostUIShim::DestroyAll();
[email protected]7a31f7c2011-03-21 23:22:04235
initial.commit09911bf2008-07-26 23:55:29236 // Need to stop io_thread_ before resource_dispatcher_host_, since
237 // io_thread_ may still deref ResourceDispatcherHost and handle resource
238 // request before going away.
[email protected]0ac83682010-01-22 17:46:27239 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29240
[email protected]875ee822010-05-18 20:58:01241 // The IO thread was the only user of this thread.
242 cache_thread_.reset();
243
[email protected]914511712009-11-23 19:42:33244 // Stop the process launcher thread after the IO thread, in case the IO thread
245 // posted a task to terminate a process on the process launcher thread.
246 process_launcher_thread_.reset();
247
initial.commit09911bf2008-07-26 23:55:29248 // Clean up state that lives on the file_thread_ before it goes away.
249 if (resource_dispatcher_host_.get()) {
250 resource_dispatcher_host()->download_file_manager()->Shutdown();
251 resource_dispatcher_host()->save_file_manager()->Shutdown();
252 }
253
254 // Need to stop the file_thread_ here to force it to process messages in its
255 // message loop from the previous call to shutdown the DownloadFileManager,
256 // SaveFileManager and SessionService.
257 file_thread_.reset();
258
259 // With the file_thread_ flushed, we can release any icon resources.
260 icon_manager_.reset();
261
262 // Need to destroy ResourceDispatcherHost before PluginService and
[email protected]49f28bc72010-02-04 00:10:01263 // SafeBrowsingService, since it caches a pointer to it. This also
264 // causes the webkit thread to terminate.
initial.commit09911bf2008-07-26 23:55:29265 resource_dispatcher_host_.reset();
266
267 // Wait for the pending print jobs to finish.
268 print_job_manager_->OnQuit();
269 print_job_manager_.reset();
270
[email protected]0b4d3382010-07-14 16:13:04271 // Destroy TabCloseableStateWatcher before NotificationService since the
272 // former registers for notifications.
273 tab_closeable_state_watcher_.reset();
274
initial.commit09911bf2008-07-26 23:55:29275 // Now OK to destroy NotificationService.
276 main_notification_service_.reset();
277
[email protected]49f28bc72010-02-04 00:10:01278 // Prior to clearing local state, we want to complete tasks pending
279 // on the db thread too.
280 db_thread_.reset();
281
[email protected]0b565182011-03-02 18:11:15282 // Stop the watchdog thread after stopping other threads.
283 watchdog_thread_.reset();
284
[email protected]49f28bc72010-02-04 00:10:01285 // At this point, no render process exist and the file, io, db, and
286 // webkit threads in this process have all terminated, so it's safe
287 // to access local state data such as cookies, database, or local storage.
288 if (clear_local_state_on_exit)
289 ClearLocalState(profile_path);
290
initial.commit09911bf2008-07-26 23:55:29291 g_browser_process = NULL;
292}
293
[email protected]c6032e82010-09-13 20:06:05294#if defined(OS_WIN)
[email protected]295039bd2008-08-15 04:32:57295// Send a QuitTask to the given MessageLoop.
296static void PostQuit(MessageLoop* message_loop) {
297 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
298}
[email protected]c6032e82010-09-13 20:06:05299#elif defined(USE_X11)
300static void Signal(base::WaitableEvent* event) {
301 event->Signal();
302}
303#endif
initial.commit09911bf2008-07-26 23:55:29304
[email protected]b443cb042009-12-15 22:05:09305unsigned int BrowserProcessImpl::AddRefModule() {
306 DCHECK(CalledOnValidThread());
[email protected]afd20c022010-06-10 00:48:20307 did_start_ = true;
[email protected]b443cb042009-12-15 22:05:09308 module_ref_count_++;
309 return module_ref_count_;
310}
311
312unsigned int BrowserProcessImpl::ReleaseModule() {
313 DCHECK(CalledOnValidThread());
[email protected]760d970a2010-05-18 00:39:18314 DCHECK_NE(0u, module_ref_count_);
[email protected]b443cb042009-12-15 22:05:09315 module_ref_count_--;
316 if (0 == module_ref_count_) {
[email protected]7d038c32010-12-14 00:40:00317 // Allow UI and IO threads to do blocking IO on shutdown, since we do a lot
318 // of it on shutdown for valid reasons.
319 base::ThreadRestrictions::SetIOAllowed(true);
320 io_thread()->message_loop()->PostTask(
321 FROM_HERE,
322 NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true));
[email protected]b443cb042009-12-15 22:05:09323 MessageLoop::current()->PostTask(
[email protected]34f73fb2010-03-24 20:50:34324 FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop));
[email protected]b443cb042009-12-15 22:05:09325 MessageLoop::current()->Quit();
326 }
327 return module_ref_count_;
328}
329
initial.commit09911bf2008-07-26 23:55:29330void BrowserProcessImpl::EndSession() {
initial.commit09911bf2008-07-26 23:55:29331 // Mark all the profiles as clean.
332 ProfileManager* pm = profile_manager();
[email protected]844a1002011-04-19 11:37:21333 std::vector<Profile*> profiles(pm->GetLoadedProfiles());
334 for (size_t i = 0; i < profiles.size(); ++i)
335 profiles[i]->MarkAsCleanShutdown();
initial.commit09911bf2008-07-26 23:55:29336
337 // Tell the metrics service it was cleanly shutdown.
338 MetricsService* metrics = g_browser_process->metrics_service();
339 if (metrics && local_state()) {
initial.commit09911bf2008-07-26 23:55:29340 metrics->RecordStartOfSessionEnd();
341
342 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36343 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29344 }
345
346 // We must write that the profile and metrics service shutdown cleanly,
347 // otherwise on startup we'll think we crashed. So we block until done and
348 // then proceed with normal shutdown.
[email protected]c6032e82010-09-13 20:06:05349#if defined(USE_X11)
350 // Can't run a local loop on linux. Instead create a waitable event.
351 base::WaitableEvent done_writing(false, false);
[email protected]d04e7662010-10-10 22:24:48352 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]c6032e82010-09-13 20:06:05353 NewRunnableFunction(Signal, &done_writing));
354 done_writing.TimedWait(
355 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds));
356#elif defined(OS_WIN)
[email protected]d04e7662010-10-10 22:24:48357 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57358 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29359 MessageLoop::current()->Run();
[email protected]c6032e82010-09-13 20:06:05360#else
361 NOTIMPLEMENTED();
362#endif
initial.commit09911bf2008-07-26 23:55:29363}
364
[email protected]e13ad79b2010-07-22 21:36:50365ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() {
366 DCHECK(CalledOnValidThread());
367 if (!created_resource_dispatcher_host_)
368 CreateResourceDispatcherHost();
369 return resource_dispatcher_host_.get();
370}
371
372MetricsService* BrowserProcessImpl::metrics_service() {
373 DCHECK(CalledOnValidThread());
374 if (!created_metrics_service_)
375 CreateMetricsService();
376 return metrics_service_.get();
377}
378
379IOThread* BrowserProcessImpl::io_thread() {
380 DCHECK(CalledOnValidThread());
381 if (!created_io_thread_)
382 CreateIOThread();
383 return io_thread_.get();
384}
385
386base::Thread* BrowserProcessImpl::file_thread() {
387 DCHECK(CalledOnValidThread());
388 if (!created_file_thread_)
389 CreateFileThread();
390 return file_thread_.get();
391}
392
393base::Thread* BrowserProcessImpl::db_thread() {
394 DCHECK(CalledOnValidThread());
395 if (!created_db_thread_)
396 CreateDBThread();
397 return db_thread_.get();
398}
399
400base::Thread* BrowserProcessImpl::process_launcher_thread() {
401 DCHECK(CalledOnValidThread());
402 if (!created_process_launcher_thread_)
403 CreateProcessLauncherThread();
404 return process_launcher_thread_.get();
405}
406
407base::Thread* BrowserProcessImpl::cache_thread() {
408 DCHECK(CalledOnValidThread());
409 if (!created_cache_thread_)
410 CreateCacheThread();
411 return cache_thread_.get();
412}
413
[email protected]0b565182011-03-02 18:11:15414WatchDogThread* BrowserProcessImpl::watchdog_thread() {
415 DCHECK(CalledOnValidThread());
416 if (!created_watchdog_thread_)
417 CreateWatchdogThread();
418 DCHECK(watchdog_thread_.get() != NULL);
419 return watchdog_thread_.get();
420}
421
[email protected]2d14b3732011-05-10 16:48:44422#if defined(OS_CHROMEOS)
423base::Thread* BrowserProcessImpl::web_socket_proxy_thread() {
424 DCHECK(CalledOnValidThread());
425 if (!created_web_socket_proxy_thread_)
426 CreateWebSocketProxyThread();
427 DCHECK(web_socket_proxy_thread_.get() != NULL);
428 return web_socket_proxy_thread_.get();
429}
430#endif
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;
[email protected]d9ee002c2011-04-27 12:52:54499 browser_policy_connector_.reset(policy::BrowserPolicyConnector::Create());
[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]68f88b992011-05-07 02:01:39562printing::BackgroundPrintingManager*
563 BrowserProcessImpl::background_printing_manager() {
564 DCHECK(CalledOnValidThread());
565 if (!background_printing_manager_.get())
566 CreateBackgroundPrintingManager();
567 return background_printing_manager_.get();
568}
569
[email protected]e13ad79b2010-07-22 21:36:50570GoogleURLTracker* BrowserProcessImpl::google_url_tracker() {
571 DCHECK(CalledOnValidThread());
572 if (!google_url_tracker_.get())
573 CreateGoogleURLTracker();
574 return google_url_tracker_.get();
575}
576
577IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
578 DCHECK(CalledOnValidThread());
579 if (!intranet_redirect_detector_.get())
580 CreateIntranetRedirectDetector();
581 return intranet_redirect_detector_.get();
582}
583
584const std::string& BrowserProcessImpl::GetApplicationLocale() {
585 DCHECK(!locale_.empty());
586 return locale_;
587}
588
589void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
590 locale_ = locale;
591 extension_l10n_util::SetProcessLocale(locale);
592}
593
[email protected]073ed7b2010-09-27 09:20:02594DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
595 return &download_status_updater_;
596}
597
[email protected]e13ad79b2010-07-22 21:36:50598TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() {
599 DCHECK(CalledOnValidThread());
600 if (!tab_closeable_state_watcher_.get())
601 CreateTabCloseableStateWatcher();
602 return tab_closeable_state_watcher_.get();
603}
604
[email protected]9e7f015f2011-05-28 00:24:25605BackgroundModeManager* BrowserProcessImpl::background_mode_manager() {
606 DCHECK(CalledOnValidThread());
607 if (!background_mode_manager_.get())
608 CreateBackgroundModeManager();
609 return background_mode_manager_.get();
610}
611
612StatusTray* BrowserProcessImpl::status_tray() {
613 DCHECK(CalledOnValidThread());
614 if (!status_tray_.get())
615 CreateStatusTray();
616 return status_tray_.get();
617}
618
[email protected]462a0ff2011-06-02 17:15:34619
620SafeBrowsingService* BrowserProcessImpl::safe_browsing_service() {
621 DCHECK(CalledOnValidThread());
622 if (!created_safe_browsing_service_)
623 CreateSafeBrowsingService();
624 return safe_browsing_service_.get();
625}
626
[email protected]a7a5e992010-12-09 23:39:51627safe_browsing::ClientSideDetectionService*
628 BrowserProcessImpl::safe_browsing_detection_service() {
629 DCHECK(CalledOnValidThread());
[email protected]462a0ff2011-06-02 17:15:34630 if (!created_safe_browsing_detection_service_)
[email protected]a7a5e992010-12-09 23:39:51631 CreateSafeBrowsingDetectionService();
[email protected]a7a5e992010-12-09 23:39:51632 return safe_browsing_detection_service_.get();
633}
634
[email protected]8b08a47f2011-02-25 12:36:37635bool BrowserProcessImpl::plugin_finder_disabled() const {
636 return *plugin_finder_disabled_pref_;
637}
638
[email protected]6618d1d2010-12-15 21:18:47639void BrowserProcessImpl::Observe(NotificationType type,
640 const NotificationSource& source,
641 const NotificationDetails& details) {
642 if (type == NotificationType::APP_TERMINATING) {
643 Profile* profile = ProfileManager::GetDefaultProfile();
644 if (profile) {
645 PrefService* prefs = profile->GetPrefs();
[email protected]2ffc3c6c2011-01-14 12:50:24646 if (prefs->GetBoolean(prefs::kClearSiteDataOnExit) &&
[email protected]6618d1d2010-12-15 21:18:47647 local_state()->GetBoolean(prefs::kClearPluginLSODataEnabled)) {
648 plugin_data_remover_ = new PluginDataRemover();
[email protected]c7d58d62011-01-21 10:27:18649 if (!plugin_data_remover_mime_type().empty())
650 plugin_data_remover_->set_mime_type(plugin_data_remover_mime_type());
651 plugin_data_remover_->StartRemoving(base::Time());
[email protected]6618d1d2010-12-15 21:18:47652 }
653 }
[email protected]e450fa62011-02-01 12:52:56654 } else if (type == NotificationType::PREF_CHANGED) {
655 std::string* pref = Details<std::string>(details).ptr();
656 if (*pref == prefs::kDefaultBrowserSettingEnabled) {
657 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
658 ShellIntegration::SetAsDefaultBrowser();
[email protected]419a0572011-04-18 22:21:46659 } else if (*pref == prefs::kDisabledSchemes) {
660 ApplyDisabledSchemesPolicy();
[email protected]40850a52011-05-26 22:07:35661 } else if (*pref == prefs::kAllowCrossOriginAuthPrompt) {
662 ApplyAllowCrossOriginAuthPromptPolicy();
[email protected]e450fa62011-02-01 12:52:56663 }
[email protected]6618d1d2010-12-15 21:18:47664 } else {
665 NOTREACHED();
666 }
667}
668
669void BrowserProcessImpl::WaitForPluginDataRemoverToFinish() {
[email protected]c7d58d62011-01-21 10:27:18670 if (plugin_data_remover_.get())
671 plugin_data_remover_->Wait();
[email protected]6618d1d2010-12-15 21:18:47672}
673
[email protected]e13ad79b2010-07-22 21:36:50674#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
675void BrowserProcessImpl::StartAutoupdateTimer() {
676 autoupdate_timer_.Start(
677 base::TimeDelta::FromHours(kUpdateCheckIntervalHours),
678 this,
679 &BrowserProcessImpl::OnAutoupdateTimer);
680}
681#endif
682
[email protected]d6f37fc2011-02-13 23:58:41683ChromeNetLog* BrowserProcessImpl::net_log() {
684 return net_log_.get();
685}
686
[email protected]1459fb62011-05-25 19:03:27687prerender::PrerenderTracker* BrowserProcessImpl::prerender_tracker() {
688 if (!prerender_tracker_.get())
689 prerender_tracker_.reset(new prerender::PrerenderTracker);
690
691 return prerender_tracker_.get();
692}
693
[email protected]e7f009d2011-06-14 19:35:10694MHTMLGenerationManager* BrowserProcessImpl::mhtml_generation_manager() {
695 if (!mhtml_generation_manager_.get())
696 mhtml_generation_manager_ = new MHTMLGenerationManager();
697
698 return mhtml_generation_manager_.get();
699}
700
[email protected]4ef795df2010-02-03 02:35:08701void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
[email protected]72cfd90f2010-02-06 03:08:04702 webkit_database::DatabaseTracker::ClearLocalState(profile_path);
[email protected]4ef795df2010-02-03 02:35:08703}
704
705bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
706 FilePath user_data_dir;
707 Profile* profile;
708
[email protected]09584972010-07-03 00:00:59709 // Check for the existence of a profile manager. When quitting early,
[email protected]ed0cf562010-02-05 22:50:41710 // e.g. because another chrome instance is running, or when invoked with
711 // options such as --uninstall or --try-chrome-again=0, the profile manager
712 // does not exist yet.
713 if (!profile_manager_.get())
714 return false;
715
[email protected]4ef795df2010-02-03 02:35:08716 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
717 profile = profile_manager_->GetDefaultProfile(user_data_dir);
[email protected]7bfc674322010-03-05 00:20:57718 if (!profile)
719 return false;
[email protected]4ef795df2010-02-03 02:35:08720 *profile_path = profile->GetPath();
721 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit);
722}
723
initial.commit09911bf2008-07-26 23:55:29724void BrowserProcessImpl::CreateResourceDispatcherHost() {
725 DCHECK(!created_resource_dispatcher_host_ &&
726 resource_dispatcher_host_.get() == NULL);
727 created_resource_dispatcher_host_ = true;
728
[email protected]214538842011-04-01 18:47:24729 // UserScriptListener will delete itself.
730 ResourceQueue::DelegateSet resource_queue_delegates;
731 resource_queue_delegates.insert(new UserScriptListener());
732
733 resource_dispatcher_host_.reset(
734 new ResourceDispatcherHost(resource_queue_delegates));
initial.commit09911bf2008-07-26 23:55:29735 resource_dispatcher_host_->Initialize();
[email protected]1459fb62011-05-25 19:03:27736
[email protected]8bcdf072011-06-03 16:52:15737 resource_dispatcher_host_delegate_.reset(
738 new ChromeResourceDispatcherHostDelegate(resource_dispatcher_host_.get(),
[email protected]92e0a612011-05-30 21:37:00739 prerender_tracker()));
[email protected]8bcdf072011-06-03 16:52:15740 resource_dispatcher_host_->set_delegate(
741 resource_dispatcher_host_delegate_.get());
[email protected]40850a52011-05-26 22:07:35742
743 pref_change_registrar_.Add(prefs::kAllowCrossOriginAuthPrompt, this);
744 ApplyAllowCrossOriginAuthPromptPolicy();
initial.commit09911bf2008-07-26 23:55:29745}
746
747void BrowserProcessImpl::CreateMetricsService() {
748 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
749 created_metrics_service_ = true;
750
751 metrics_service_.reset(new MetricsService);
752}
753
754void BrowserProcessImpl::CreateIOThread() {
755 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
756 created_io_thread_ = true;
757
758 // Prior to starting the io thread, we create the plugin service as
759 // it is predominantly used from the io thread, but must be created
760 // on the main thread. The service ctor is inexpensive and does not
761 // invoke the io_thread() accessor.
762 PluginService::GetInstance();
763
[email protected]de23f3f2011-05-18 16:20:23764 // Add the Chrome specific plugins.
765 chrome::RegisterInternalDefaultPlugin();
766
767 // Register the internal Flash if available.
768 FilePath path;
769 if (!CommandLine::ForCurrentProcess()->HasSwitch(
770 switches::kDisableInternalFlash) &&
771 PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) {
772 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path);
773 }
774
[email protected]f1933792011-06-14 00:49:34775#if defined(OS_POSIX)
776 // Also find plugins in a user-specific plugins dir,
777 // e.g. ~/.config/chromium/Plugins.
778 FilePath user_data_dir;
779 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
780 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(
781 user_data_dir.Append("Plugins"));
782 }
783#endif
784
[email protected]3ce02412011-03-01 12:01:15785 scoped_ptr<IOThread> thread(new IOThread(
786 local_state(), net_log_.get(), extension_event_router_forwarder_.get()));
[email protected]ab820df2008-08-26 05:55:10787 base::Thread::Options options;
788 options.message_loop_type = MessageLoop::TYPE_IO;
789 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29790 return;
791 io_thread_.swap(thread);
792}
793
794void BrowserProcessImpl::CreateFileThread() {
795 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
796 created_file_thread_ = true;
797
[email protected]ab820df2008-08-26 05:55:10798 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48799 new BrowserProcessSubThread(BrowserThread::FILE));
[email protected]a1db3842008-09-17 22:04:06800 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39801#if defined(OS_WIN)
802 // On Windows, the FILE thread needs to be have a UI message loop which pumps
803 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06804 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39805#else
806 options.message_loop_type = MessageLoop::TYPE_IO;
807#endif
[email protected]a1db3842008-09-17 22:04:06808 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29809 return;
810 file_thread_.swap(thread);
811}
812
[email protected]2d14b3732011-05-10 16:48:44813#if defined(OS_CHROMEOS)
814void BrowserProcessImpl::CreateWebSocketProxyThread() {
815 DCHECK(!created_web_socket_proxy_thread_);
816 DCHECK(web_socket_proxy_thread_.get() == NULL);
817 created_web_socket_proxy_thread_ = true;
818
819 scoped_ptr<base::Thread> thread(
820 new BrowserProcessSubThread(BrowserThread::WEB_SOCKET_PROXY));
821 base::Thread::Options options;
822 options.message_loop_type = MessageLoop::TYPE_IO;
823 if (!thread->StartWithOptions(options))
824 return;
825 web_socket_proxy_thread_.swap(thread);
826}
827#endif
828
initial.commit09911bf2008-07-26 23:55:29829void BrowserProcessImpl::CreateDBThread() {
830 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
831 created_db_thread_ = true;
832
[email protected]ab820df2008-08-26 05:55:10833 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48834 new BrowserProcessSubThread(BrowserThread::DB));
initial.commit09911bf2008-07-26 23:55:29835 if (!thread->Start())
836 return;
837 db_thread_.swap(thread);
838}
839
[email protected]914511712009-11-23 19:42:33840void BrowserProcessImpl::CreateProcessLauncherThread() {
841 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
842 created_process_launcher_thread_ = true;
843
844 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48845 new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER));
[email protected]914511712009-11-23 19:42:33846 if (!thread->Start())
847 return;
848 process_launcher_thread_.swap(thread);
849}
850
[email protected]875ee822010-05-18 20:58:01851void BrowserProcessImpl::CreateCacheThread() {
852 DCHECK(!created_cache_thread_ && !cache_thread_.get());
853 created_cache_thread_ = true;
854
855 scoped_ptr<base::Thread> thread(
[email protected]75096332010-11-09 03:28:13856 new BrowserThread(BrowserThread::CACHE));
[email protected]875ee822010-05-18 20:58:01857 base::Thread::Options options;
858 options.message_loop_type = MessageLoop::TYPE_IO;
859 if (!thread->StartWithOptions(options))
860 return;
861 cache_thread_.swap(thread);
862}
863
[email protected]0b565182011-03-02 18:11:15864void BrowserProcessImpl::CreateWatchdogThread() {
865 DCHECK(!created_watchdog_thread_ && watchdog_thread_.get() == NULL);
866 created_watchdog_thread_ = true;
867
868 scoped_ptr<WatchDogThread> thread(new WatchDogThread());
869 if (!thread->Start())
870 return;
871 watchdog_thread_.swap(thread);
872}
873
initial.commit09911bf2008-07-26 23:55:29874void BrowserProcessImpl::CreateProfileManager() {
875 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
876 created_profile_manager_ = true;
877
878 profile_manager_.reset(new ProfileManager());
879}
880
881void BrowserProcessImpl::CreateLocalState() {
882 DCHECK(!created_local_state_ && local_state_.get() == NULL);
883 created_local_state_ = true;
884
[email protected]b9636002009-03-04 00:05:25885 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29886 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]f2d1f612010-12-09 15:10:17887 local_state_.reset(
[email protected]fcf53572011-06-29 15:44:37888 PrefService::CreatePrefService(local_state_path, NULL, false));
[email protected]492d2142010-09-10 13:55:18889
[email protected]caf63aea2011-04-26 11:04:10890 // Initialize the prefs of the local state.
891 browser::RegisterLocalState(local_state_.get());
892
[email protected]2a7e7c152010-10-01 20:12:09893 pref_change_registrar_.Init(local_state_.get());
894
[email protected]f16b9662011-04-27 10:06:07895 print_job_manager_->InitOnUIThread(local_state_.get());
[email protected]e450fa62011-02-01 12:52:56896
897 // Initialize the notification for the default browser setting policy.
898 local_state_->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled,
899 false);
900 if (local_state_->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled)) {
901 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
902 ShellIntegration::SetAsDefaultBrowser();
903 }
904 pref_change_registrar_.Add(prefs::kDefaultBrowserSettingEnabled, this);
[email protected]8b08a47f2011-02-25 12:36:37905
906 // Initialize the preference for the plugin finder policy.
907 // This preference is only needed on the IO thread so make it available there.
908 local_state_->RegisterBooleanPref(prefs::kDisablePluginFinder, false);
909 plugin_finder_disabled_pref_.Init(prefs::kDisablePluginFinder,
910 local_state_.get(), NULL);
911 plugin_finder_disabled_pref_.MoveToThread(BrowserThread::IO);
[email protected]419a0572011-04-18 22:21:46912
[email protected]1f8110b2011-05-24 14:48:30913 // Initialize the disk cache location policy. This policy is not hot update-
914 // able so we need to have it when initializing the profiles.
915 local_state_->RegisterFilePathPref(prefs::kDiskCacheDir, FilePath());
916
[email protected]b99c41c2011-04-27 15:18:48917 // This is observed by ChildProcessSecurityPolicy, which lives in content/
918 // though, so it can't register itself.
[email protected]419a0572011-04-18 22:21:46919 local_state_->RegisterListPref(prefs::kDisabledSchemes);
[email protected]b99c41c2011-04-27 15:18:48920 pref_change_registrar_.Add(prefs::kDisabledSchemes, this);
[email protected]419a0572011-04-18 22:21:46921 ApplyDisabledSchemesPolicy();
[email protected]fd6159a2010-09-03 09:38:39922}
initial.commit09911bf2008-07-26 23:55:29923
initial.commit09911bf2008-07-26 23:55:29924void BrowserProcessImpl::CreateIconManager() {
925 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
926 created_icon_manager_ = true;
927 icon_manager_.reset(new IconManager);
928}
929
[email protected]40ecc902009-03-16 13:42:47930void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44931 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47932 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44933 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47934}
935
[email protected]8b8e7c92010-08-19 18:05:56936void BrowserProcessImpl::CreateSidebarManager() {
937 DCHECK(sidebar_manager_.get() == NULL);
938 created_sidebar_manager_ = true;
939 sidebar_manager_ = new SidebarManager();
940}
941
initial.commit09911bf2008-07-26 23:55:29942void BrowserProcessImpl::CreateGoogleURLTracker() {
943 DCHECK(google_url_tracker_.get() == NULL);
944 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
945 google_url_tracker_.swap(google_url_tracker);
946}
[email protected]6641bf662009-08-21 00:34:09947
[email protected]c4ff4952010-01-08 19:12:47948void BrowserProcessImpl::CreateIntranetRedirectDetector() {
949 DCHECK(intranet_redirect_detector_.get() == NULL);
950 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
951 new IntranetRedirectDetector);
952 intranet_redirect_detector_.swap(intranet_redirect_detector);
953}
954
[email protected]29672ab2009-10-30 03:44:03955void BrowserProcessImpl::CreateNotificationUIManager() {
956 DCHECK(notification_ui_manager_.get() == NULL);
[email protected]b0b2a3dd2011-01-06 00:30:05957 notification_ui_manager_.reset(NotificationUIManager::Create(local_state()));
958
[email protected]29672ab2009-10-30 03:44:03959 created_notification_ui_manager_ = true;
960}
961
[email protected]0b4d3382010-07-14 16:13:04962void BrowserProcessImpl::CreateTabCloseableStateWatcher() {
963 DCHECK(tab_closeable_state_watcher_.get() == NULL);
964 tab_closeable_state_watcher_.reset(TabCloseableStateWatcher::Create());
965}
966
[email protected]9e7f015f2011-05-28 00:24:25967void BrowserProcessImpl::CreateBackgroundModeManager() {
968 DCHECK(background_mode_manager_.get() == NULL);
969 background_mode_manager_.reset(
970 new BackgroundModeManager(CommandLine::ForCurrentProcess()));
971}
972
973void BrowserProcessImpl::CreateStatusTray() {
974 DCHECK(status_tray_.get() == NULL);
975 status_tray_.reset(StatusTray::Create());
976}
977
[email protected]dbeebd52010-11-16 20:34:16978void BrowserProcessImpl::CreatePrintPreviewTabController() {
979 DCHECK(print_preview_tab_controller_.get() == NULL);
980 print_preview_tab_controller_ = new printing::PrintPreviewTabController();
981}
982
[email protected]68f88b992011-05-07 02:01:39983void BrowserProcessImpl::CreateBackgroundPrintingManager() {
984 DCHECK(background_printing_manager_.get() == NULL);
985 background_printing_manager_.reset(new printing::BackgroundPrintingManager());
986}
987
[email protected]462a0ff2011-06-02 17:15:34988void BrowserProcessImpl::CreateSafeBrowsingService() {
989 DCHECK(safe_browsing_service_.get() == NULL);
990 created_safe_browsing_service_ = true;
991 safe_browsing_service_ = SafeBrowsingService::CreateSafeBrowsingService();
992 safe_browsing_service_->Initialize();
993}
994
[email protected]a7a5e992010-12-09 23:39:51995void BrowserProcessImpl::CreateSafeBrowsingDetectionService() {
996 DCHECK(safe_browsing_detection_service_.get() == NULL);
997 // Set this flag to true so that we don't retry indefinitely to
998 // create the service class if there was an error.
999 created_safe_browsing_detection_service_ = true;
1000
[email protected]cae64fe2011-06-17 17:54:501001 FilePath model_file_dir;
[email protected]a7a5e992010-12-09 23:39:511002 Profile* profile = profile_manager() ?
1003 profile_manager()->GetDefaultProfile() : NULL;
1004 if (IsSafeBrowsingDetectionServiceEnabled() &&
[email protected]cae64fe2011-06-17 17:54:501005 PathService::Get(chrome::DIR_USER_DATA, &model_file_dir) &&
[email protected]a7a5e992010-12-09 23:39:511006 profile && profile->GetRequestContext()) {
1007 safe_browsing_detection_service_.reset(
1008 safe_browsing::ClientSideDetectionService::Create(
[email protected]cae64fe2011-06-17 17:54:501009 model_file_dir, profile->GetRequestContext()));
[email protected]a7a5e992010-12-09 23:39:511010 }
1011}
1012
1013bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() {
1014 // The safe browsing client-side detection is enabled only if the switch is
[email protected]436ebd62011-06-09 22:08:111015 // not disabled and when safe browsing related stats are allowed to be
1016 // collected.
[email protected]d081d192011-04-01 02:33:241017#ifdef OS_CHROMEOS
1018 return false;
1019#else
[email protected]d081d192011-04-01 02:33:241020 return !CommandLine::ForCurrentProcess()->HasSwitch(
1021 switches::kDisableClientSidePhishingDetection) &&
[email protected]462a0ff2011-06-02 17:15:341022 safe_browsing_service() &&
[email protected]436ebd62011-06-09 22:08:111023 safe_browsing_service()->CanReportStats();
[email protected]d081d192011-04-01 02:33:241024#endif
[email protected]a7a5e992010-12-09 23:39:511025}
1026
[email protected]419a0572011-04-18 22:21:461027void BrowserProcessImpl::ApplyDisabledSchemesPolicy() {
1028 std::set<std::string> schemes;
[email protected]b99c41c2011-04-27 15:18:481029 const ListValue* scheme_list = local_state_->GetList(prefs::kDisabledSchemes);
1030 for (ListValue::const_iterator iter = scheme_list->begin();
1031 iter != scheme_list->end(); ++iter) {
[email protected]419a0572011-04-18 22:21:461032 std::string scheme;
1033 if ((*iter)->GetAsString(&scheme))
1034 schemes.insert(scheme);
1035 }
1036 ChildProcessSecurityPolicy::GetInstance()->RegisterDisabledSchemes(schemes);
1037}
1038
[email protected]40850a52011-05-26 22:07:351039void BrowserProcessImpl::ApplyAllowCrossOriginAuthPromptPolicy() {
1040 bool value = local_state()->GetBoolean(prefs::kAllowCrossOriginAuthPrompt);
1041 resource_dispatcher_host()->set_allow_cross_origin_auth_prompt(value);
1042}
1043
[email protected]6641bf662009-08-21 00:34:091044// The BrowserProcess object must outlive the file thread so we use traits
1045// which don't do any management.
[email protected]c56428f22010-06-16 02:17:231046DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl);
[email protected]6641bf662009-08-21 00:34:091047
[email protected]d55aaa132009-09-28 21:08:041048#if defined(IPC_MESSAGE_LOG_ENABLED)
1049
1050void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
1051 // First enable myself.
1052 if (enable)
[email protected]8e8bb6d2010-12-13 08:18:551053 IPC::Logging::GetInstance()->Enable();
[email protected]d55aaa132009-09-28 21:08:041054 else
[email protected]8e8bb6d2010-12-13 08:18:551055 IPC::Logging::GetInstance()->Disable();
[email protected]d55aaa132009-09-28 21:08:041056
1057 // Now tell subprocesses. Messages to ChildProcess-derived
1058 // processes must be done on the IO thread.
1059 io_thread()->message_loop()->PostTask
1060 (FROM_HERE,
1061 NewRunnableMethod(
1062 this,
1063 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
1064 enable));
1065
1066 // Finally, tell the renderers which don't derive from ChildProcess.
1067 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:271068 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
1069 !i.IsAtEnd(); i.Advance())
[email protected]ff47b2962011-03-07 23:51:491070 i.GetCurrentValue()->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:041071}
1072
1073// Helper for SetIPCLoggingEnabled.
1074void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d04e7662010-10-10 22:24:481075 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d55aaa132009-09-28 21:08:041076
[email protected]d27893f62010-07-03 05:47:421077 BrowserChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:111078 while (!i.Done()) {
[email protected]ff47b2962011-03-07 23:51:491079 i->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled));
[email protected]34cf97d2009-09-29 22:46:111080 ++i;
[email protected]d55aaa132009-09-28 21:08:041081 }
1082}
1083
1084#endif // IPC_MESSAGE_LOG_ENABLED
1085
[email protected]3cdacd42010-04-30 18:55:531086// Mac is currently not supported.
1087#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:421088
1089bool BrowserProcessImpl::CanAutorestartForUpdate() const {
1090 // Check if browser is in the background and if it needs to be restarted to
1091 // apply a pending update.
[email protected]c10fa3952010-08-24 16:52:531092 return BrowserList::size() == 0 && BrowserList::WillKeepAlive() &&
[email protected]815856722011-04-13 17:19:191093 upgrade_util::IsUpdatePendingRestart();
[email protected]bd48c2b02010-04-09 20:32:421094}
1095
[email protected]5c08f222010-09-22 09:37:211096// Switches to add when auto-restarting Chrome.
[email protected]6c10c972010-08-11 04:15:471097const char* const kSwitchesToAddOnAutorestart[] = {
[email protected]f9a06842010-08-21 00:32:401098 switches::kNoStartupWindow
[email protected]bd48c2b02010-04-09 20:32:421099};
1100
1101void BrowserProcessImpl::RestartPersistentInstance() {
1102 CommandLine* old_cl = CommandLine::ForCurrentProcess();
[email protected]3cdacd42010-04-30 18:55:531103 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram()));
[email protected]bd48c2b02010-04-09 20:32:421104
1105 std::map<std::string, CommandLine::StringType> switches =
1106 old_cl->GetSwitches();
1107
[email protected]5c08f222010-09-22 09:37:211108 switches::RemoveSwitchesForAutostart(&switches);
[email protected]bd48c2b02010-04-09 20:32:421109
1110 // Append the rest of the switches (along with their values, if any)
1111 // to the new command line
1112 for (std::map<std::string, CommandLine::StringType>::const_iterator i =
1113 switches.begin(); i != switches.end(); ++i) {
1114 CommandLine::StringType switch_value = i->second;
1115 if (switch_value.length() > 0) {
[email protected]05076ba22010-07-30 05:59:571116 new_cl->AppendSwitchNative(i->first, i->second);
[email protected]bd48c2b02010-04-09 20:32:421117 } else {
[email protected]3cdacd42010-04-30 18:55:531118 new_cl->AppendSwitch(i->first);
[email protected]bd48c2b02010-04-09 20:32:421119 }
1120 }
1121
[email protected]6c10c972010-08-11 04:15:471122 // Ensure that our desired switches are set on the new process.
[email protected]5c08f222010-09-22 09:37:211123 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) {
[email protected]6c10c972010-08-11 04:15:471124 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i]))
1125 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
1126 }
[email protected]bd48c2b02010-04-09 20:32:421127
[email protected]3cdacd42010-04-30 18:55:531128 DLOG(WARNING) << "Shutting down current instance of the browser.";
[email protected]bc63a072011-06-28 21:12:571129 BrowserList::AttemptExit();
[email protected]3cdacd42010-04-30 18:55:531130
1131 // Transfer ownership to Upgrade.
[email protected]815856722011-04-13 17:19:191132 upgrade_util::SetNewCommandLine(new_cl.release());
[email protected]bd48c2b02010-04-09 20:32:421133}
1134
1135void BrowserProcessImpl::OnAutoupdateTimer() {
1136 if (CanAutorestartForUpdate()) {
[email protected]3cdacd42010-04-30 18:55:531137 DLOG(WARNING) << "Detected update. Restarting browser.";
[email protected]bd48c2b02010-04-09 20:32:421138 RestartPersistentInstance();
1139 }
1140}
1141
[email protected]3cdacd42010-04-30 18:55:531142#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)