blob: 559ed7e7debaa8db6cb367ad7a02b9e1086875f7 [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]9e7f015f2011-05-28 00:24:2519#include "chrome/browser/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]6ccb5e52011-05-19 23:36:2523#include "chrome/browser/browsing_data_remover.h"
[email protected]9678cb42011-01-31 18:49:4224#include "chrome/browser/debugger/browser_list_tabcontents_provider.h"
[email protected]5613126e2011-01-31 15:27:5525#include "chrome/browser/debugger/devtools_http_protocol_handler.h"
[email protected]40ecc902009-03-16 13:42:4726#include "chrome/browser/debugger/devtools_manager.h"
[email protected]5613126e2011-01-31 15:27:5527#include "chrome/browser/debugger/devtools_protocol_handler.h"
[email protected]6c69796d2010-07-16 21:41:1628#include "chrome/browser/download/download_file_manager.h"
[email protected]5ba0a2c2009-02-19 01:19:3429#include "chrome/browser/download/save_file_manager.h"
[email protected]3ce02412011-03-01 12:01:1530#include "chrome/browser/extensions/extension_event_router_forwarder.h"
[email protected]fc4facd2011-03-22 23:18:5031#include "chrome/browser/extensions/extension_tab_id_map.h"
[email protected]214538842011-04-01 18:47:2432#include "chrome/browser/extensions/user_script_listener.h"
[email protected]815856722011-04-13 17:19:1933#include "chrome/browser/first_run/upgrade_util.h"
[email protected]f7578f52010-08-30 22:22:4934#include "chrome/browser/google/google_url_tracker.h"
[email protected]dcefa302009-05-20 00:24:3935#include "chrome/browser/icon_manager.h"
[email protected]c4ff4952010-01-08 19:12:4736#include "chrome/browser/intranet_redirect_detector.h"
[email protected]0ac83682010-01-22 17:46:2737#include "chrome/browser/io_thread.h"
[email protected]dc6f4962009-02-13 01:25:5038#include "chrome/browser/metrics/metrics_service.h"
[email protected]0b565182011-03-02 18:11:1539#include "chrome/browser/metrics/thread_watcher.h"
[email protected]b2fcd0e2010-12-01 15:19:4040#include "chrome/browser/net/chrome_net_log.h"
[email protected]3530cd92010-06-27 06:22:0141#include "chrome/browser/net/predictor_api.h"
[email protected]d393a0fd2009-05-13 23:32:0142#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]29672ab2009-10-30 03:44:0343#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]838dd914a2011-05-09 02:50:5844#include "chrome/browser/platform_util.h"
[email protected]6618d1d2010-12-15 21:18:4745#include "chrome/browser/plugin_data_remover.h"
[email protected]985655a2011-02-23 09:54:2546#include "chrome/browser/policy/browser_policy_connector.h"
[email protected]caf63aea2011-04-26 11:04:1047#include "chrome/browser/prefs/browser_prefs.h"
[email protected]37858e52010-08-26 00:22:0248#include "chrome/browser/prefs/pref_service.h"
[email protected]1459fb62011-05-25 19:03:2749#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]68f88b992011-05-07 02:01:3950#include "chrome/browser/printing/background_printing_manager.h"
[email protected]e06131d2010-02-10 18:40:3351#include "chrome/browser/printing/print_job_manager.h"
[email protected]dbeebd52010-11-16 20:34:1652#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]8ecad5e2010-12-02 21:18:3353#include "chrome/browser/profiles/profile_manager.h"
[email protected]1459fb62011-05-25 19:03:2754#include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_observer.h"
[email protected]a7a5e992010-12-09 23:39:5155#include "chrome/browser/safe_browsing/client_side_detection_service.h"
[email protected]81218f42009-02-05 18:48:0856#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]e450fa62011-02-01 12:52:5657#include "chrome/browser/shell_integration.h"
[email protected]8b8e7c92010-08-19 18:05:5658#include "chrome/browser/sidebar/sidebar_manager.h"
[email protected]9e7f015f2011-05-28 00:24:2559#include "chrome/browser/status_icons/status_tray.h"
[email protected]0b4d3382010-07-14 16:13:0460#include "chrome/browser/tab_closeable_state_watcher.h"
[email protected]71b73f02011-04-06 15:57:2961#include "chrome/browser/ui/browser_list.h"
[email protected]4ef795df2010-02-03 02:35:0862#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2963#include "chrome/common/chrome_paths.h"
64#include "chrome/common/chrome_switches.h"
[email protected]de23f3f2011-05-18 16:20:2365#include "chrome/common/default_plugin.h"
[email protected]f1b6de22010-03-06 12:13:4766#include "chrome/common/extensions/extension_l10n_util.h"
[email protected]985655a2011-02-23 09:54:2567#include "chrome/common/extensions/extension_resource.h"
[email protected]ea587b02010-05-21 15:01:3568#include "chrome/common/json_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2969#include "chrome/common/pref_names.h"
[email protected]5c08f222010-09-22 09:37:2170#include "chrome/common/switch_utils.h"
[email protected]985655a2011-02-23 09:54:2571#include "chrome/common/url_constants.h"
[email protected]bd48c2b02010-04-09 20:32:4272#include "chrome/installer/util/google_update_constants.h"
[email protected]a01efd22011-03-01 00:38:3273#include "content/browser/browser_child_process_host.h"
74#include "content/browser/browser_thread.h"
[email protected]419a0572011-04-18 22:21:4675#include "content/browser/child_process_security_policy.h"
[email protected]d9f37932011-05-09 20:09:2476#include "content/browser/gpu/gpu_process_host_ui_shim.h"
[email protected]a01efd22011-03-01 00:38:3277#include "content/browser/plugin_service.h"
78#include "content/browser/renderer_host/render_process_host.h"
79#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]f20d7332011-03-08 21:11:5380#include "content/common/notification_service.h"
[email protected]d55aaa132009-09-28 21:08:0481#include "ipc/ipc_logging.h"
[email protected]abe2c032011-03-31 18:49:3482#include "net/url_request/url_request_context_getter.h"
[email protected]2dfeaf92011-01-10 21:08:2183#include "ui/base/clipboard/clipboard.h"
[email protected]c051a1b2011-01-21 23:30:1784#include "ui/base/l10n/l10n_util.h"
[email protected]4ef795df2010-02-03 02:35:0885#include "webkit/database/database_tracker.h"
[email protected]de23f3f2011-05-18 16:20:2386#include "webkit/plugins/npapi/plugin_list.h"
[email protected]b112a4c2009-02-01 20:24:0187
88#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0589#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3890#endif
91
[email protected]d55aaa132009-09-28 21:08:0492#if defined(IPC_MESSAGE_LOG_ENABLED)
[email protected]ff47b2962011-03-07 23:51:4993#include "content/common/child_process_messages.h"
[email protected]d55aaa132009-09-28 21:08:0494#endif
95
[email protected]db0e86dd2011-03-16 14:47:2196#if defined(OS_CHROMEOS)
97#include "chrome/browser/chromeos/proxy_config_service_impl.h"
[email protected]2d14b3732011-05-10 16:48:4498#include "chrome/browser/chromeos/web_socket_proxy_controller.h"
[email protected]db0e86dd2011-03-16 14:47:2199#endif // defined(OS_CHROMEOS)
100
[email protected]3cdacd42010-04-30 18:55:53101#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
102// How often to check if the persistent instance of Chrome needs to restart
103// to install an update.
104static const int kUpdateCheckIntervalHours = 6;
105#endif
106
[email protected]c6032e82010-09-13 20:06:05107#if defined(USE_X11)
108// How long to wait for the File thread to complete during EndSession, on
109// Linux. We have a timeout here because we're unable to run the UI messageloop
110// and there's some deadlock risk. Our only option is to exit anyway.
111static const int kEndSessionTimeoutSeconds = 10;
112#endif
113
[email protected]bb975362009-01-21 01:00:22114BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:29115 : created_resource_dispatcher_host_(false),
116 created_metrics_service_(false),
117 created_io_thread_(false),
118 created_file_thread_(false),
119 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:33120 created_process_launcher_thread_(false),
[email protected]875ee822010-05-18 20:58:01121 created_cache_thread_(false),
[email protected]0b565182011-03-02 18:11:15122 created_watchdog_thread_(false),
[email protected]2d14b3732011-05-10 16:48:44123#if defined(OS_CHROMEOS)
124 created_web_socket_proxy_thread_(false),
125#endif
initial.commit09911bf2008-07-26 23:55:29126 created_profile_manager_(false),
127 created_local_state_(false),
[email protected]b112a4c2009-02-01 20:24:01128 created_icon_manager_(false),
[email protected]40ecc902009-03-16 13:42:47129 created_devtools_manager_(false),
[email protected]8b8e7c92010-08-19 18:05:56130 created_sidebar_manager_(false),
[email protected]985655a2011-02-23 09:54:25131 created_browser_policy_connector_(false),
[email protected]29672ab2009-10-30 03:44:03132 created_notification_ui_manager_(false),
[email protected]462a0ff2011-06-02 17:15:34133 created_safe_browsing_service_(false),
[email protected]a7a5e992010-12-09 23:39:51134 created_safe_browsing_detection_service_(false),
initial.commit09911bf2008-07-26 23:55:29135 module_ref_count_(0),
[email protected]afd20c022010-06-10 00:48:20136 did_start_(false),
[email protected]1b2db1a2008-08-08 17:46:13137 checked_for_new_frames_(false),
[email protected]4747caf2011-03-23 20:09:21138 using_new_frames_(false) {
initial.commit09911bf2008-07-26 23:55:29139 g_browser_process = this;
[email protected]2dfeaf92011-01-10 21:08:21140 clipboard_.reset(new ui::Clipboard);
initial.commit09911bf2008-07-26 23:55:29141 main_notification_service_.reset(new NotificationService);
142
[email protected]6618d1d2010-12-15 21:18:47143 notification_registrar_.Add(this,
144 NotificationType::APP_TERMINATING,
145 NotificationService::AllSources());
146
initial.commit09911bf2008-07-26 23:55:29147 // Must be created after the NotificationService.
148 print_job_manager_.reset(new printing::PrintJobManager);
149
[email protected]b797e152009-01-23 16:06:14150 shutdown_event_.reset(new base::WaitableEvent(true, false));
[email protected]b2fcd0e2010-12-01 15:19:40151
152 net_log_.reset(new ChromeNetLog);
[email protected]3ce02412011-03-01 12:01:15153
154 extension_event_router_forwarder_ = new ExtensionEventRouterForwarder;
[email protected]fc4facd2011-03-22 23:18:50155
156 ExtensionTabIdMap::GetInstance()->Init();
initial.commit09911bf2008-07-26 23:55:29157}
158
159BrowserProcessImpl::~BrowserProcessImpl() {
[email protected]4ef795df2010-02-03 02:35:08160 FilePath profile_path;
161 bool clear_local_state_on_exit;
162
163 // Store the profile path for clearing local state data on exit.
164 clear_local_state_on_exit = ShouldClearLocalState(&profile_path);
165
[email protected]2d14b3732011-05-10 16:48:44166#if defined(OS_CHROMEOS)
167 if (web_socket_proxy_thread_.get())
168 chromeos::WebSocketProxyController::Shutdown();
169 web_socket_proxy_thread_.reset();
170#endif
171
initial.commit09911bf2008-07-26 23:55:29172 // Delete the AutomationProviderList before NotificationService,
173 // since it may try to unregister notifications
174 // Both NotificationService and AutomationProvider are singleton instances in
175 // the BrowserProcess. Since AutomationProvider may have some active
176 // notification observers, it is essential that it gets destroyed before the
177 // NotificationService. NotificationService won't be destroyed until after
178 // this destructor is run.
179 automation_provider_list_.reset();
180
[email protected]d393a0fd2009-05-13 23:32:01181 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
182 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
183 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
184 // any pending URLFetchers, and avoid creating any more.
185 SdchDictionaryFetcher::Shutdown();
186
[email protected]51ac040762011-01-20 02:01:04187 // We need to destroy the MetricsService, GoogleURLTracker,
188 // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService
189 // before the io_thread_ gets destroyed, since their destructors can call the
190 // URLFetcher destructor, which does a PostDelayedTask operation on the IO
191 // thread. (The IO thread will handle that URLFetcher operation before going
192 // away.)
initial.commit09911bf2008-07-26 23:55:29193 metrics_service_.reset();
194 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47195 intranet_redirect_detector_.reset();
[email protected]51ac040762011-01-20 02:01:04196 safe_browsing_detection_service_.reset();
initial.commit09911bf2008-07-26 23:55:29197
[email protected]d8a899c2010-09-21 04:50:33198 // Need to clear the desktop notification balloons before the io_thread_ and
199 // before the profiles, since if there are any still showing we will access
200 // those things during teardown.
201 notification_ui_manager_.reset();
202
initial.commit09911bf2008-07-26 23:55:29203 // Need to clear profiles (download managers) before the io_thread_.
204 profile_manager_.reset();
205
206 // Debugger must be cleaned up before IO thread and NotificationService.
[email protected]5613126e2011-01-31 15:27:55207 if (devtools_http_handler_.get()) {
208 devtools_http_handler_->Stop();
209 devtools_http_handler_ = NULL;
210 }
211 if (devtools_legacy_handler_.get()) {
212 devtools_legacy_handler_->Stop();
213 devtools_legacy_handler_ = NULL;
214 }
initial.commit09911bf2008-07-26 23:55:29215
[email protected]462a0ff2011-06-02 17:15:34216 if (safe_browsing_service_.get())
217 safe_browsing_service()->ShutDown();
initial.commit09911bf2008-07-26 23:55:29218
[email protected]462a0ff2011-06-02 17:15:34219 if (resource_dispatcher_host_.get()) {
initial.commit09911bf2008-07-26 23:55:29220 // Cancel pending requests and prevent new requests.
221 resource_dispatcher_host()->Shutdown();
222 }
223
[email protected]fc4facd2011-03-22 23:18:50224 ExtensionTabIdMap::GetInstance()->Shutdown();
225
[email protected]985655a2011-02-23 09:54:25226 // The policy providers managed by |browser_policy_connector_| need to shut
227 // down while the IO and FILE threads are still alive.
228 browser_policy_connector_.reset();
[email protected]f2a893c2011-01-05 09:38:07229
[email protected]6618d1d2010-12-15 21:18:47230 // Wait for removing plugin data to finish before shutting down the IO thread.
231 WaitForPluginDataRemoverToFinish();
232
[email protected]7a31f7c2011-03-21 23:22:04233 // Destroying the GpuProcessHostUIShims on the UI thread posts a task to
234 // delete related objects on the GPU thread. This must be done before
235 // stopping the GPU thread. The GPU thread will close IPC channels to renderer
236 // processes so this has to happen before stopping the IO thread.
237 GpuProcessHostUIShim::DestroyAll();
[email protected]7a31f7c2011-03-21 23:22:04238
initial.commit09911bf2008-07-26 23:55:29239 // Need to stop io_thread_ before resource_dispatcher_host_, since
240 // io_thread_ may still deref ResourceDispatcherHost and handle resource
241 // request before going away.
[email protected]0ac83682010-01-22 17:46:27242 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29243
[email protected]875ee822010-05-18 20:58:01244 // The IO thread was the only user of this thread.
245 cache_thread_.reset();
246
[email protected]914511712009-11-23 19:42:33247 // Stop the process launcher thread after the IO thread, in case the IO thread
248 // posted a task to terminate a process on the process launcher thread.
249 process_launcher_thread_.reset();
250
initial.commit09911bf2008-07-26 23:55:29251 // Clean up state that lives on the file_thread_ before it goes away.
252 if (resource_dispatcher_host_.get()) {
253 resource_dispatcher_host()->download_file_manager()->Shutdown();
254 resource_dispatcher_host()->save_file_manager()->Shutdown();
255 }
256
257 // Need to stop the file_thread_ here to force it to process messages in its
258 // message loop from the previous call to shutdown the DownloadFileManager,
259 // SaveFileManager and SessionService.
260 file_thread_.reset();
261
262 // With the file_thread_ flushed, we can release any icon resources.
263 icon_manager_.reset();
264
265 // Need to destroy ResourceDispatcherHost before PluginService and
[email protected]49f28bc72010-02-04 00:10:01266 // SafeBrowsingService, since it caches a pointer to it. This also
267 // causes the webkit thread to terminate.
initial.commit09911bf2008-07-26 23:55:29268 resource_dispatcher_host_.reset();
269
270 // Wait for the pending print jobs to finish.
271 print_job_manager_->OnQuit();
272 print_job_manager_.reset();
273
[email protected]0b4d3382010-07-14 16:13:04274 // Destroy TabCloseableStateWatcher before NotificationService since the
275 // former registers for notifications.
276 tab_closeable_state_watcher_.reset();
277
initial.commit09911bf2008-07-26 23:55:29278 // Now OK to destroy NotificationService.
279 main_notification_service_.reset();
280
[email protected]49f28bc72010-02-04 00:10:01281 // Prior to clearing local state, we want to complete tasks pending
282 // on the db thread too.
283 db_thread_.reset();
284
[email protected]0b565182011-03-02 18:11:15285 // Stop the watchdog thread after stopping other threads.
286 watchdog_thread_.reset();
287
[email protected]49f28bc72010-02-04 00:10:01288 // At this point, no render process exist and the file, io, db, and
289 // webkit threads in this process have all terminated, so it's safe
290 // to access local state data such as cookies, database, or local storage.
291 if (clear_local_state_on_exit)
292 ClearLocalState(profile_path);
293
initial.commit09911bf2008-07-26 23:55:29294 g_browser_process = NULL;
295}
296
[email protected]c6032e82010-09-13 20:06:05297#if defined(OS_WIN)
[email protected]295039bd2008-08-15 04:32:57298// Send a QuitTask to the given MessageLoop.
299static void PostQuit(MessageLoop* message_loop) {
300 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
301}
[email protected]c6032e82010-09-13 20:06:05302#elif defined(USE_X11)
303static void Signal(base::WaitableEvent* event) {
304 event->Signal();
305}
306#endif
initial.commit09911bf2008-07-26 23:55:29307
[email protected]b443cb042009-12-15 22:05:09308unsigned int BrowserProcessImpl::AddRefModule() {
309 DCHECK(CalledOnValidThread());
[email protected]afd20c022010-06-10 00:48:20310 did_start_ = true;
[email protected]b443cb042009-12-15 22:05:09311 module_ref_count_++;
312 return module_ref_count_;
313}
314
315unsigned int BrowserProcessImpl::ReleaseModule() {
316 DCHECK(CalledOnValidThread());
[email protected]760d970a2010-05-18 00:39:18317 DCHECK_NE(0u, module_ref_count_);
[email protected]b443cb042009-12-15 22:05:09318 module_ref_count_--;
319 if (0 == module_ref_count_) {
[email protected]7d038c32010-12-14 00:40:00320 // Allow UI and IO threads to do blocking IO on shutdown, since we do a lot
321 // of it on shutdown for valid reasons.
322 base::ThreadRestrictions::SetIOAllowed(true);
323 io_thread()->message_loop()->PostTask(
324 FROM_HERE,
325 NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true));
[email protected]b443cb042009-12-15 22:05:09326 MessageLoop::current()->PostTask(
[email protected]34f73fb2010-03-24 20:50:34327 FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop));
[email protected]b443cb042009-12-15 22:05:09328 MessageLoop::current()->Quit();
329 }
330 return module_ref_count_;
331}
332
initial.commit09911bf2008-07-26 23:55:29333void BrowserProcessImpl::EndSession() {
[email protected]c6032e82010-09-13 20:06:05334#if defined(OS_WIN) || defined(USE_X11)
[email protected]d65cab7a2008-08-12 01:25:41335 // Notify we are going away.
[email protected]c6032e82010-09-13 20:06:05336 shutdown_event_->Signal();
[email protected]b112a4c2009-02-01 20:24:01337#endif
[email protected]d65cab7a2008-08-12 01:25:41338
initial.commit09911bf2008-07-26 23:55:29339 // Mark all the profiles as clean.
340 ProfileManager* pm = profile_manager();
[email protected]844a1002011-04-19 11:37:21341 std::vector<Profile*> profiles(pm->GetLoadedProfiles());
342 for (size_t i = 0; i < profiles.size(); ++i)
343 profiles[i]->MarkAsCleanShutdown();
initial.commit09911bf2008-07-26 23:55:29344
345 // Tell the metrics service it was cleanly shutdown.
346 MetricsService* metrics = g_browser_process->metrics_service();
347 if (metrics && local_state()) {
initial.commit09911bf2008-07-26 23:55:29348 metrics->RecordStartOfSessionEnd();
349
350 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36351 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29352 }
353
354 // We must write that the profile and metrics service shutdown cleanly,
355 // otherwise on startup we'll think we crashed. So we block until done and
356 // then proceed with normal shutdown.
[email protected]c6032e82010-09-13 20:06:05357#if defined(USE_X11)
358 // Can't run a local loop on linux. Instead create a waitable event.
359 base::WaitableEvent done_writing(false, false);
[email protected]d04e7662010-10-10 22:24:48360 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]c6032e82010-09-13 20:06:05361 NewRunnableFunction(Signal, &done_writing));
362 done_writing.TimedWait(
363 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds));
364#elif defined(OS_WIN)
[email protected]d04e7662010-10-10 22:24:48365 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57366 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29367 MessageLoop::current()->Run();
[email protected]c6032e82010-09-13 20:06:05368#else
369 NOTIMPLEMENTED();
370#endif
initial.commit09911bf2008-07-26 23:55:29371}
372
[email protected]e13ad79b2010-07-22 21:36:50373ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() {
374 DCHECK(CalledOnValidThread());
375 if (!created_resource_dispatcher_host_)
376 CreateResourceDispatcherHost();
377 return resource_dispatcher_host_.get();
378}
379
380MetricsService* BrowserProcessImpl::metrics_service() {
381 DCHECK(CalledOnValidThread());
382 if (!created_metrics_service_)
383 CreateMetricsService();
384 return metrics_service_.get();
385}
386
387IOThread* BrowserProcessImpl::io_thread() {
388 DCHECK(CalledOnValidThread());
389 if (!created_io_thread_)
390 CreateIOThread();
391 return io_thread_.get();
392}
393
394base::Thread* BrowserProcessImpl::file_thread() {
395 DCHECK(CalledOnValidThread());
396 if (!created_file_thread_)
397 CreateFileThread();
398 return file_thread_.get();
399}
400
401base::Thread* BrowserProcessImpl::db_thread() {
402 DCHECK(CalledOnValidThread());
403 if (!created_db_thread_)
404 CreateDBThread();
405 return db_thread_.get();
406}
407
408base::Thread* BrowserProcessImpl::process_launcher_thread() {
409 DCHECK(CalledOnValidThread());
410 if (!created_process_launcher_thread_)
411 CreateProcessLauncherThread();
412 return process_launcher_thread_.get();
413}
414
415base::Thread* BrowserProcessImpl::cache_thread() {
416 DCHECK(CalledOnValidThread());
417 if (!created_cache_thread_)
418 CreateCacheThread();
419 return cache_thread_.get();
420}
421
[email protected]0b565182011-03-02 18:11:15422WatchDogThread* BrowserProcessImpl::watchdog_thread() {
423 DCHECK(CalledOnValidThread());
424 if (!created_watchdog_thread_)
425 CreateWatchdogThread();
426 DCHECK(watchdog_thread_.get() != NULL);
427 return watchdog_thread_.get();
428}
429
[email protected]2d14b3732011-05-10 16:48:44430#if defined(OS_CHROMEOS)
431base::Thread* BrowserProcessImpl::web_socket_proxy_thread() {
432 DCHECK(CalledOnValidThread());
433 if (!created_web_socket_proxy_thread_)
434 CreateWebSocketProxyThread();
435 DCHECK(web_socket_proxy_thread_.get() != NULL);
436 return web_socket_proxy_thread_.get();
437}
438#endif
439
[email protected]e13ad79b2010-07-22 21:36:50440ProfileManager* BrowserProcessImpl::profile_manager() {
441 DCHECK(CalledOnValidThread());
442 if (!created_profile_manager_)
443 CreateProfileManager();
444 return profile_manager_.get();
445}
446
447PrefService* BrowserProcessImpl::local_state() {
448 DCHECK(CalledOnValidThread());
449 if (!created_local_state_)
450 CreateLocalState();
451 return local_state_.get();
452}
453
454DevToolsManager* BrowserProcessImpl::devtools_manager() {
455 DCHECK(CalledOnValidThread());
456 if (!created_devtools_manager_)
457 CreateDevToolsManager();
458 return devtools_manager_.get();
459}
460
[email protected]8b8e7c92010-08-19 18:05:56461SidebarManager* BrowserProcessImpl::sidebar_manager() {
462 DCHECK(CalledOnValidThread());
463 if (!created_sidebar_manager_)
464 CreateSidebarManager();
465 return sidebar_manager_.get();
466}
467
[email protected]2dfeaf92011-01-10 21:08:21468ui::Clipboard* BrowserProcessImpl::clipboard() {
[email protected]e13ad79b2010-07-22 21:36:50469 DCHECK(CalledOnValidThread());
470 return clipboard_.get();
471}
472
[email protected]abe2c032011-03-31 18:49:34473net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() {
[email protected]db0e86dd2011-03-16 14:47:21474 DCHECK(CalledOnValidThread());
475 return io_thread()->system_url_request_context_getter();
476}
477
478#if defined(OS_CHROMEOS)
479chromeos::ProxyConfigServiceImpl*
480BrowserProcessImpl::chromeos_proxy_config_service_impl() {
481 DCHECK(CalledOnValidThread());
482 if (!chromeos_proxy_config_service_impl_) {
483 chromeos_proxy_config_service_impl_ =
484 new chromeos::ProxyConfigServiceImpl();
485 }
486 return chromeos_proxy_config_service_impl_;
487}
488#endif // defined(OS_CHROMEOS)
489
[email protected]3ce02412011-03-01 12:01:15490ExtensionEventRouterForwarder*
491BrowserProcessImpl::extension_event_router_forwarder() {
492 return extension_event_router_forwarder_.get();
493}
494
[email protected]e13ad79b2010-07-22 21:36:50495NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
496 DCHECK(CalledOnValidThread());
497 if (!created_notification_ui_manager_)
498 CreateNotificationUIManager();
499 return notification_ui_manager_.get();
500}
501
[email protected]985655a2011-02-23 09:54:25502policy::BrowserPolicyConnector* BrowserProcessImpl::browser_policy_connector() {
[email protected]f2a893c2011-01-05 09:38:07503 DCHECK(CalledOnValidThread());
[email protected]985655a2011-02-23 09:54:25504 if (!created_browser_policy_connector_) {
505 DCHECK(browser_policy_connector_.get() == NULL);
506 created_browser_policy_connector_ = true;
[email protected]d9ee002c2011-04-27 12:52:54507 browser_policy_connector_.reset(policy::BrowserPolicyConnector::Create());
[email protected]f2a893c2011-01-05 09:38:07508 }
[email protected]985655a2011-02-23 09:54:25509 return browser_policy_connector_.get();
[email protected]f2a893c2011-01-05 09:38:07510}
511
[email protected]e13ad79b2010-07-22 21:36:50512IconManager* BrowserProcessImpl::icon_manager() {
513 DCHECK(CalledOnValidThread());
514 if (!created_icon_manager_)
515 CreateIconManager();
516 return icon_manager_.get();
517}
518
519ThumbnailGenerator* BrowserProcessImpl::GetThumbnailGenerator() {
520 return &thumbnail_generator_;
521}
522
523AutomationProviderList* BrowserProcessImpl::InitAutomationProviderList() {
524 DCHECK(CalledOnValidThread());
525 if (automation_provider_list_.get() == NULL) {
526 automation_provider_list_.reset(AutomationProviderList::GetInstance());
527 }
528 return automation_provider_list_.get();
529}
530
[email protected]5613126e2011-01-31 15:27:55531void BrowserProcessImpl::InitDevToolsHttpProtocolHandler(
[email protected]01000cf12011-02-04 11:39:22532 const std::string& ip,
[email protected]5613126e2011-01-31 15:27:55533 int port,
534 const std::string& frontend_url) {
[email protected]e13ad79b2010-07-22 21:36:50535 DCHECK(CalledOnValidThread());
[email protected]5613126e2011-01-31 15:27:55536 devtools_http_handler_ =
[email protected]01000cf12011-02-04 11:39:22537 DevToolsHttpProtocolHandler::Start(ip,
538 port,
[email protected]9678cb42011-01-31 18:49:42539 frontend_url,
540 new BrowserListTabContentsProvider());
[email protected]5613126e2011-01-31 15:27:55541}
542
543void BrowserProcessImpl::InitDevToolsLegacyProtocolHandler(int port) {
544 DCHECK(CalledOnValidThread());
545 devtools_legacy_handler_ = DevToolsProtocolHandler::Start(port);
[email protected]e13ad79b2010-07-22 21:36:50546}
547
548bool BrowserProcessImpl::IsShuttingDown() {
549 DCHECK(CalledOnValidThread());
550 return did_start_ && 0 == module_ref_count_;
551}
552
initial.commit09911bf2008-07-26 23:55:29553printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
554 // TODO(abarth): DCHECK(CalledOnValidThread());
[email protected]d8922f22010-05-07 00:57:27555 // http://code.google.com/p/chromium/issues/detail?id=6828
initial.commit09911bf2008-07-26 23:55:29556 // print_job_manager_ is initialized in the constructor and destroyed in the
557 // destructor, so it should always be valid.
558 DCHECK(print_job_manager_.get());
559 return print_job_manager_.get();
560}
561
[email protected]dbeebd52010-11-16 20:34:16562printing::PrintPreviewTabController*
563 BrowserProcessImpl::print_preview_tab_controller() {
564 DCHECK(CalledOnValidThread());
565 if (!print_preview_tab_controller_.get())
566 CreatePrintPreviewTabController();
567 return print_preview_tab_controller_.get();
568}
569
[email protected]68f88b992011-05-07 02:01:39570printing::BackgroundPrintingManager*
571 BrowserProcessImpl::background_printing_manager() {
572 DCHECK(CalledOnValidThread());
573 if (!background_printing_manager_.get())
574 CreateBackgroundPrintingManager();
575 return background_printing_manager_.get();
576}
577
[email protected]e13ad79b2010-07-22 21:36:50578GoogleURLTracker* BrowserProcessImpl::google_url_tracker() {
579 DCHECK(CalledOnValidThread());
580 if (!google_url_tracker_.get())
581 CreateGoogleURLTracker();
582 return google_url_tracker_.get();
583}
584
585IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
586 DCHECK(CalledOnValidThread());
587 if (!intranet_redirect_detector_.get())
588 CreateIntranetRedirectDetector();
589 return intranet_redirect_detector_.get();
590}
591
592const std::string& BrowserProcessImpl::GetApplicationLocale() {
593 DCHECK(!locale_.empty());
594 return locale_;
595}
596
597void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
598 locale_ = locale;
599 extension_l10n_util::SetProcessLocale(locale);
600}
601
[email protected]073ed7b2010-09-27 09:20:02602DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
603 return &download_status_updater_;
604}
605
[email protected]e13ad79b2010-07-22 21:36:50606base::WaitableEvent* BrowserProcessImpl::shutdown_event() {
607 return shutdown_event_.get();
608}
609
610TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() {
611 DCHECK(CalledOnValidThread());
612 if (!tab_closeable_state_watcher_.get())
613 CreateTabCloseableStateWatcher();
614 return tab_closeable_state_watcher_.get();
615}
616
[email protected]9e7f015f2011-05-28 00:24:25617BackgroundModeManager* BrowserProcessImpl::background_mode_manager() {
618 DCHECK(CalledOnValidThread());
619 if (!background_mode_manager_.get())
620 CreateBackgroundModeManager();
621 return background_mode_manager_.get();
622}
623
624StatusTray* BrowserProcessImpl::status_tray() {
625 DCHECK(CalledOnValidThread());
626 if (!status_tray_.get())
627 CreateStatusTray();
628 return status_tray_.get();
629}
630
[email protected]462a0ff2011-06-02 17:15:34631
632SafeBrowsingService* BrowserProcessImpl::safe_browsing_service() {
633 DCHECK(CalledOnValidThread());
634 if (!created_safe_browsing_service_)
635 CreateSafeBrowsingService();
636 return safe_browsing_service_.get();
637}
638
[email protected]a7a5e992010-12-09 23:39:51639safe_browsing::ClientSideDetectionService*
640 BrowserProcessImpl::safe_browsing_detection_service() {
641 DCHECK(CalledOnValidThread());
[email protected]462a0ff2011-06-02 17:15:34642 if (!created_safe_browsing_detection_service_)
[email protected]a7a5e992010-12-09 23:39:51643 CreateSafeBrowsingDetectionService();
[email protected]a7a5e992010-12-09 23:39:51644 return safe_browsing_detection_service_.get();
645}
646
[email protected]8b08a47f2011-02-25 12:36:37647bool BrowserProcessImpl::plugin_finder_disabled() const {
648 return *plugin_finder_disabled_pref_;
649}
650
[email protected]6618d1d2010-12-15 21:18:47651void BrowserProcessImpl::Observe(NotificationType type,
652 const NotificationSource& source,
653 const NotificationDetails& details) {
654 if (type == NotificationType::APP_TERMINATING) {
655 Profile* profile = ProfileManager::GetDefaultProfile();
656 if (profile) {
657 PrefService* prefs = profile->GetPrefs();
[email protected]2ffc3c6c2011-01-14 12:50:24658 if (prefs->GetBoolean(prefs::kClearSiteDataOnExit) &&
[email protected]6618d1d2010-12-15 21:18:47659 local_state()->GetBoolean(prefs::kClearPluginLSODataEnabled)) {
660 plugin_data_remover_ = new PluginDataRemover();
[email protected]c7d58d62011-01-21 10:27:18661 if (!plugin_data_remover_mime_type().empty())
662 plugin_data_remover_->set_mime_type(plugin_data_remover_mime_type());
663 plugin_data_remover_->StartRemoving(base::Time());
[email protected]6618d1d2010-12-15 21:18:47664 }
665 }
[email protected]e450fa62011-02-01 12:52:56666 } else if (type == NotificationType::PREF_CHANGED) {
667 std::string* pref = Details<std::string>(details).ptr();
668 if (*pref == prefs::kDefaultBrowserSettingEnabled) {
669 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
670 ShellIntegration::SetAsDefaultBrowser();
[email protected]419a0572011-04-18 22:21:46671 } else if (*pref == prefs::kDisabledSchemes) {
672 ApplyDisabledSchemesPolicy();
[email protected]40850a52011-05-26 22:07:35673 } else if (*pref == prefs::kAllowCrossOriginAuthPrompt) {
674 ApplyAllowCrossOriginAuthPromptPolicy();
[email protected]e450fa62011-02-01 12:52:56675 }
[email protected]6618d1d2010-12-15 21:18:47676 } else {
677 NOTREACHED();
678 }
679}
680
681void BrowserProcessImpl::WaitForPluginDataRemoverToFinish() {
[email protected]c7d58d62011-01-21 10:27:18682 if (plugin_data_remover_.get())
683 plugin_data_remover_->Wait();
[email protected]6618d1d2010-12-15 21:18:47684}
685
[email protected]e13ad79b2010-07-22 21:36:50686#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
687void BrowserProcessImpl::StartAutoupdateTimer() {
688 autoupdate_timer_.Start(
689 base::TimeDelta::FromHours(kUpdateCheckIntervalHours),
690 this,
691 &BrowserProcessImpl::OnAutoupdateTimer);
692}
693#endif
694
[email protected]d6f37fc2011-02-13 23:58:41695ChromeNetLog* BrowserProcessImpl::net_log() {
696 return net_log_.get();
697}
698
[email protected]1459fb62011-05-25 19:03:27699prerender::PrerenderTracker* BrowserProcessImpl::prerender_tracker() {
700 if (!prerender_tracker_.get())
701 prerender_tracker_.reset(new prerender::PrerenderTracker);
702
703 return prerender_tracker_.get();
704}
705
[email protected]4ef795df2010-02-03 02:35:08706void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
[email protected]72cfd90f2010-02-06 03:08:04707 webkit_database::DatabaseTracker::ClearLocalState(profile_path);
[email protected]6ccb5e52011-05-19 23:36:25708 BrowsingDataRemover::ClearGearsData(profile_path);
[email protected]4ef795df2010-02-03 02:35:08709}
710
711bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
712 FilePath user_data_dir;
713 Profile* profile;
714
[email protected]09584972010-07-03 00:00:59715 // Check for the existence of a profile manager. When quitting early,
[email protected]ed0cf562010-02-05 22:50:41716 // e.g. because another chrome instance is running, or when invoked with
717 // options such as --uninstall or --try-chrome-again=0, the profile manager
718 // does not exist yet.
719 if (!profile_manager_.get())
720 return false;
721
[email protected]4ef795df2010-02-03 02:35:08722 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
723 profile = profile_manager_->GetDefaultProfile(user_data_dir);
[email protected]7bfc674322010-03-05 00:20:57724 if (!profile)
725 return false;
[email protected]4ef795df2010-02-03 02:35:08726 *profile_path = profile->GetPath();
727 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit);
728}
729
initial.commit09911bf2008-07-26 23:55:29730void BrowserProcessImpl::CreateResourceDispatcherHost() {
731 DCHECK(!created_resource_dispatcher_host_ &&
732 resource_dispatcher_host_.get() == NULL);
733 created_resource_dispatcher_host_ = true;
734
[email protected]214538842011-04-01 18:47:24735 // UserScriptListener will delete itself.
736 ResourceQueue::DelegateSet resource_queue_delegates;
737 resource_queue_delegates.insert(new UserScriptListener());
738
739 resource_dispatcher_host_.reset(
740 new ResourceDispatcherHost(resource_queue_delegates));
initial.commit09911bf2008-07-26 23:55:29741 resource_dispatcher_host_->Initialize();
[email protected]1459fb62011-05-25 19:03:27742
743 resource_dispatcher_host_observer_.reset(
[email protected]92e0a612011-05-30 21:37:00744 new ChromeResourceDispatcherHostObserver(resource_dispatcher_host_.get(),
745 prerender_tracker()));
[email protected]1459fb62011-05-25 19:03:27746 resource_dispatcher_host_->set_observer(
747 resource_dispatcher_host_observer_.get());
[email protected]40850a52011-05-26 22:07:35748
749 pref_change_registrar_.Add(prefs::kAllowCrossOriginAuthPrompt, this);
750 ApplyAllowCrossOriginAuthPromptPolicy();
initial.commit09911bf2008-07-26 23:55:29751}
752
753void BrowserProcessImpl::CreateMetricsService() {
754 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
755 created_metrics_service_ = true;
756
757 metrics_service_.reset(new MetricsService);
758}
759
760void BrowserProcessImpl::CreateIOThread() {
761 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
762 created_io_thread_ = true;
763
764 // Prior to starting the io thread, we create the plugin service as
765 // it is predominantly used from the io thread, but must be created
766 // on the main thread. The service ctor is inexpensive and does not
767 // invoke the io_thread() accessor.
768 PluginService::GetInstance();
769
[email protected]de23f3f2011-05-18 16:20:23770 // Add the Chrome specific plugins.
771 chrome::RegisterInternalDefaultPlugin();
772
773 // Register the internal Flash if available.
774 FilePath path;
775 if (!CommandLine::ForCurrentProcess()->HasSwitch(
776 switches::kDisableInternalFlash) &&
777 PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) {
778 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path);
779 }
780
[email protected]3ce02412011-03-01 12:01:15781 scoped_ptr<IOThread> thread(new IOThread(
782 local_state(), net_log_.get(), extension_event_router_forwarder_.get()));
[email protected]ab820df2008-08-26 05:55:10783 base::Thread::Options options;
784 options.message_loop_type = MessageLoop::TYPE_IO;
785 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29786 return;
787 io_thread_.swap(thread);
788}
789
790void BrowserProcessImpl::CreateFileThread() {
791 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
792 created_file_thread_ = true;
793
[email protected]ab820df2008-08-26 05:55:10794 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48795 new BrowserProcessSubThread(BrowserThread::FILE));
[email protected]a1db3842008-09-17 22:04:06796 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39797#if defined(OS_WIN)
798 // On Windows, the FILE thread needs to be have a UI message loop which pumps
799 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06800 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39801#else
802 options.message_loop_type = MessageLoop::TYPE_IO;
803#endif
[email protected]a1db3842008-09-17 22:04:06804 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29805 return;
806 file_thread_.swap(thread);
807}
808
[email protected]2d14b3732011-05-10 16:48:44809#if defined(OS_CHROMEOS)
810void BrowserProcessImpl::CreateWebSocketProxyThread() {
811 DCHECK(!created_web_socket_proxy_thread_);
812 DCHECK(web_socket_proxy_thread_.get() == NULL);
813 created_web_socket_proxy_thread_ = true;
814
815 scoped_ptr<base::Thread> thread(
816 new BrowserProcessSubThread(BrowserThread::WEB_SOCKET_PROXY));
817 base::Thread::Options options;
818 options.message_loop_type = MessageLoop::TYPE_IO;
819 if (!thread->StartWithOptions(options))
820 return;
821 web_socket_proxy_thread_.swap(thread);
822}
823#endif
824
initial.commit09911bf2008-07-26 23:55:29825void BrowserProcessImpl::CreateDBThread() {
826 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
827 created_db_thread_ = true;
828
[email protected]ab820df2008-08-26 05:55:10829 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48830 new BrowserProcessSubThread(BrowserThread::DB));
initial.commit09911bf2008-07-26 23:55:29831 if (!thread->Start())
832 return;
833 db_thread_.swap(thread);
834}
835
[email protected]914511712009-11-23 19:42:33836void BrowserProcessImpl::CreateProcessLauncherThread() {
837 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
838 created_process_launcher_thread_ = true;
839
840 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48841 new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER));
[email protected]914511712009-11-23 19:42:33842 if (!thread->Start())
843 return;
844 process_launcher_thread_.swap(thread);
845}
846
[email protected]875ee822010-05-18 20:58:01847void BrowserProcessImpl::CreateCacheThread() {
848 DCHECK(!created_cache_thread_ && !cache_thread_.get());
849 created_cache_thread_ = true;
850
851 scoped_ptr<base::Thread> thread(
[email protected]75096332010-11-09 03:28:13852 new BrowserThread(BrowserThread::CACHE));
[email protected]875ee822010-05-18 20:58:01853 base::Thread::Options options;
854 options.message_loop_type = MessageLoop::TYPE_IO;
855 if (!thread->StartWithOptions(options))
856 return;
857 cache_thread_.swap(thread);
858}
859
[email protected]0b565182011-03-02 18:11:15860void BrowserProcessImpl::CreateWatchdogThread() {
861 DCHECK(!created_watchdog_thread_ && watchdog_thread_.get() == NULL);
862 created_watchdog_thread_ = true;
863
864 scoped_ptr<WatchDogThread> thread(new WatchDogThread());
865 if (!thread->Start())
866 return;
867 watchdog_thread_.swap(thread);
868}
869
initial.commit09911bf2008-07-26 23:55:29870void BrowserProcessImpl::CreateProfileManager() {
871 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
872 created_profile_manager_ = true;
873
874 profile_manager_.reset(new ProfileManager());
875}
876
877void BrowserProcessImpl::CreateLocalState() {
878 DCHECK(!created_local_state_ && local_state_.get() == NULL);
879 created_local_state_ = true;
880
[email protected]b9636002009-03-04 00:05:25881 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29882 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]f2d1f612010-12-09 15:10:17883 local_state_.reset(
[email protected]845b43a82011-05-11 10:14:43884 PrefService::CreatePrefService(local_state_path, NULL, NULL, false));
[email protected]492d2142010-09-10 13:55:18885
[email protected]caf63aea2011-04-26 11:04:10886 // Initialize the prefs of the local state.
887 browser::RegisterLocalState(local_state_.get());
888
[email protected]2a7e7c152010-10-01 20:12:09889 pref_change_registrar_.Init(local_state_.get());
890
[email protected]f16b9662011-04-27 10:06:07891 print_job_manager_->InitOnUIThread(local_state_.get());
[email protected]e450fa62011-02-01 12:52:56892
893 // Initialize the notification for the default browser setting policy.
894 local_state_->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled,
895 false);
896 if (local_state_->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled)) {
897 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
898 ShellIntegration::SetAsDefaultBrowser();
899 }
900 pref_change_registrar_.Add(prefs::kDefaultBrowserSettingEnabled, this);
[email protected]8b08a47f2011-02-25 12:36:37901
902 // Initialize the preference for the plugin finder policy.
903 // This preference is only needed on the IO thread so make it available there.
904 local_state_->RegisterBooleanPref(prefs::kDisablePluginFinder, false);
905 plugin_finder_disabled_pref_.Init(prefs::kDisablePluginFinder,
906 local_state_.get(), NULL);
907 plugin_finder_disabled_pref_.MoveToThread(BrowserThread::IO);
[email protected]419a0572011-04-18 22:21:46908
[email protected]1f8110b2011-05-24 14:48:30909 // Initialize the disk cache location policy. This policy is not hot update-
910 // able so we need to have it when initializing the profiles.
911 local_state_->RegisterFilePathPref(prefs::kDiskCacheDir, FilePath());
912
[email protected]b99c41c2011-04-27 15:18:48913 // This is observed by ChildProcessSecurityPolicy, which lives in content/
914 // though, so it can't register itself.
[email protected]419a0572011-04-18 22:21:46915 local_state_->RegisterListPref(prefs::kDisabledSchemes);
[email protected]b99c41c2011-04-27 15:18:48916 pref_change_registrar_.Add(prefs::kDisabledSchemes, this);
[email protected]419a0572011-04-18 22:21:46917 ApplyDisabledSchemesPolicy();
[email protected]fd6159a2010-09-03 09:38:39918}
initial.commit09911bf2008-07-26 23:55:29919
initial.commit09911bf2008-07-26 23:55:29920void BrowserProcessImpl::CreateIconManager() {
921 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
922 created_icon_manager_ = true;
923 icon_manager_.reset(new IconManager);
924}
925
[email protected]40ecc902009-03-16 13:42:47926void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44927 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47928 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44929 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47930}
931
[email protected]8b8e7c92010-08-19 18:05:56932void BrowserProcessImpl::CreateSidebarManager() {
933 DCHECK(sidebar_manager_.get() == NULL);
934 created_sidebar_manager_ = true;
935 sidebar_manager_ = new SidebarManager();
936}
937
initial.commit09911bf2008-07-26 23:55:29938void BrowserProcessImpl::CreateGoogleURLTracker() {
939 DCHECK(google_url_tracker_.get() == NULL);
940 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
941 google_url_tracker_.swap(google_url_tracker);
942}
[email protected]6641bf662009-08-21 00:34:09943
[email protected]c4ff4952010-01-08 19:12:47944void BrowserProcessImpl::CreateIntranetRedirectDetector() {
945 DCHECK(intranet_redirect_detector_.get() == NULL);
946 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
947 new IntranetRedirectDetector);
948 intranet_redirect_detector_.swap(intranet_redirect_detector);
949}
950
[email protected]29672ab2009-10-30 03:44:03951void BrowserProcessImpl::CreateNotificationUIManager() {
952 DCHECK(notification_ui_manager_.get() == NULL);
[email protected]b0b2a3dd2011-01-06 00:30:05953 notification_ui_manager_.reset(NotificationUIManager::Create(local_state()));
954
[email protected]29672ab2009-10-30 03:44:03955 created_notification_ui_manager_ = true;
956}
957
[email protected]0b4d3382010-07-14 16:13:04958void BrowserProcessImpl::CreateTabCloseableStateWatcher() {
959 DCHECK(tab_closeable_state_watcher_.get() == NULL);
960 tab_closeable_state_watcher_.reset(TabCloseableStateWatcher::Create());
961}
962
[email protected]9e7f015f2011-05-28 00:24:25963void BrowserProcessImpl::CreateBackgroundModeManager() {
964 DCHECK(background_mode_manager_.get() == NULL);
965 background_mode_manager_.reset(
966 new BackgroundModeManager(CommandLine::ForCurrentProcess()));
967}
968
969void BrowserProcessImpl::CreateStatusTray() {
970 DCHECK(status_tray_.get() == NULL);
971 status_tray_.reset(StatusTray::Create());
972}
973
[email protected]dbeebd52010-11-16 20:34:16974void BrowserProcessImpl::CreatePrintPreviewTabController() {
975 DCHECK(print_preview_tab_controller_.get() == NULL);
976 print_preview_tab_controller_ = new printing::PrintPreviewTabController();
977}
978
[email protected]68f88b992011-05-07 02:01:39979void BrowserProcessImpl::CreateBackgroundPrintingManager() {
980 DCHECK(background_printing_manager_.get() == NULL);
981 background_printing_manager_.reset(new printing::BackgroundPrintingManager());
982}
983
[email protected]462a0ff2011-06-02 17:15:34984void BrowserProcessImpl::CreateSafeBrowsingService() {
985 DCHECK(safe_browsing_service_.get() == NULL);
986 created_safe_browsing_service_ = true;
987 safe_browsing_service_ = SafeBrowsingService::CreateSafeBrowsingService();
988 safe_browsing_service_->Initialize();
989}
990
[email protected]a7a5e992010-12-09 23:39:51991void BrowserProcessImpl::CreateSafeBrowsingDetectionService() {
992 DCHECK(safe_browsing_detection_service_.get() == NULL);
993 // Set this flag to true so that we don't retry indefinitely to
994 // create the service class if there was an error.
995 created_safe_browsing_detection_service_ = true;
996
997 FilePath model_file_path;
998 Profile* profile = profile_manager() ?
999 profile_manager()->GetDefaultProfile() : NULL;
1000 if (IsSafeBrowsingDetectionServiceEnabled() &&
1001 PathService::Get(chrome::DIR_USER_DATA, &model_file_path) &&
1002 profile && profile->GetRequestContext()) {
1003 safe_browsing_detection_service_.reset(
1004 safe_browsing::ClientSideDetectionService::Create(
1005 model_file_path.Append(chrome::kSafeBrowsingPhishingModelFilename),
1006 profile->GetRequestContext()));
1007 }
1008}
1009
1010bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() {
1011 // The safe browsing client-side detection is enabled only if the switch is
[email protected]42930de42011-01-13 23:26:281012 // enabled and when safe browsing related stats is allowed to be collected.
[email protected]838dd914a2011-05-09 02:50:581013 // For now we only enable client-side detection on the canary, dev and beta
1014 // channel.
[email protected]d081d192011-04-01 02:33:241015#ifdef OS_CHROMEOS
1016 return false;
1017#else
[email protected]838dd914a2011-05-09 02:50:581018 std::string channel = platform_util::GetVersionStringModifier();
[email protected]d081d192011-04-01 02:33:241019 return !CommandLine::ForCurrentProcess()->HasSwitch(
1020 switches::kDisableClientSidePhishingDetection) &&
[email protected]462a0ff2011-06-02 17:15:341021 safe_browsing_service() &&
1022 safe_browsing_service()->CanReportStats() &&
[email protected]c5f08902011-05-24 23:42:131023 // TODO(noelutz): use platform_util::GetChannel() once it has been
1024 // pushed to the release branch.
1025 (channel == "beta" || channel == "dev" || channel == "canary" ||
1026 channel == "beta-m" || channel == "dev-m" || channel == "canary-m");
1027
[email protected]d081d192011-04-01 02:33:241028#endif
[email protected]a7a5e992010-12-09 23:39:511029}
1030
[email protected]419a0572011-04-18 22:21:461031void BrowserProcessImpl::ApplyDisabledSchemesPolicy() {
1032 std::set<std::string> schemes;
[email protected]b99c41c2011-04-27 15:18:481033 const ListValue* scheme_list = local_state_->GetList(prefs::kDisabledSchemes);
1034 for (ListValue::const_iterator iter = scheme_list->begin();
1035 iter != scheme_list->end(); ++iter) {
[email protected]419a0572011-04-18 22:21:461036 std::string scheme;
1037 if ((*iter)->GetAsString(&scheme))
1038 schemes.insert(scheme);
1039 }
1040 ChildProcessSecurityPolicy::GetInstance()->RegisterDisabledSchemes(schemes);
1041}
1042
[email protected]40850a52011-05-26 22:07:351043void BrowserProcessImpl::ApplyAllowCrossOriginAuthPromptPolicy() {
1044 bool value = local_state()->GetBoolean(prefs::kAllowCrossOriginAuthPrompt);
1045 resource_dispatcher_host()->set_allow_cross_origin_auth_prompt(value);
1046}
1047
[email protected]6641bf662009-08-21 00:34:091048// The BrowserProcess object must outlive the file thread so we use traits
1049// which don't do any management.
[email protected]c56428f22010-06-16 02:17:231050DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl);
[email protected]6641bf662009-08-21 00:34:091051
[email protected]d55aaa132009-09-28 21:08:041052#if defined(IPC_MESSAGE_LOG_ENABLED)
1053
1054void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
1055 // First enable myself.
1056 if (enable)
[email protected]8e8bb6d2010-12-13 08:18:551057 IPC::Logging::GetInstance()->Enable();
[email protected]d55aaa132009-09-28 21:08:041058 else
[email protected]8e8bb6d2010-12-13 08:18:551059 IPC::Logging::GetInstance()->Disable();
[email protected]d55aaa132009-09-28 21:08:041060
1061 // Now tell subprocesses. Messages to ChildProcess-derived
1062 // processes must be done on the IO thread.
1063 io_thread()->message_loop()->PostTask
1064 (FROM_HERE,
1065 NewRunnableMethod(
1066 this,
1067 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
1068 enable));
1069
1070 // Finally, tell the renderers which don't derive from ChildProcess.
1071 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:271072 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
1073 !i.IsAtEnd(); i.Advance())
[email protected]ff47b2962011-03-07 23:51:491074 i.GetCurrentValue()->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:041075}
1076
1077// Helper for SetIPCLoggingEnabled.
1078void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d04e7662010-10-10 22:24:481079 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d55aaa132009-09-28 21:08:041080
[email protected]d27893f62010-07-03 05:47:421081 BrowserChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:111082 while (!i.Done()) {
[email protected]ff47b2962011-03-07 23:51:491083 i->Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled));
[email protected]34cf97d2009-09-29 22:46:111084 ++i;
[email protected]d55aaa132009-09-28 21:08:041085 }
1086}
1087
1088#endif // IPC_MESSAGE_LOG_ENABLED
1089
[email protected]3cdacd42010-04-30 18:55:531090// Mac is currently not supported.
1091#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:421092
1093bool BrowserProcessImpl::CanAutorestartForUpdate() const {
1094 // Check if browser is in the background and if it needs to be restarted to
1095 // apply a pending update.
[email protected]c10fa3952010-08-24 16:52:531096 return BrowserList::size() == 0 && BrowserList::WillKeepAlive() &&
[email protected]815856722011-04-13 17:19:191097 upgrade_util::IsUpdatePendingRestart();
[email protected]bd48c2b02010-04-09 20:32:421098}
1099
[email protected]5c08f222010-09-22 09:37:211100// Switches to add when auto-restarting Chrome.
[email protected]6c10c972010-08-11 04:15:471101const char* const kSwitchesToAddOnAutorestart[] = {
[email protected]f9a06842010-08-21 00:32:401102 switches::kNoStartupWindow
[email protected]bd48c2b02010-04-09 20:32:421103};
1104
1105void BrowserProcessImpl::RestartPersistentInstance() {
1106 CommandLine* old_cl = CommandLine::ForCurrentProcess();
[email protected]3cdacd42010-04-30 18:55:531107 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram()));
[email protected]bd48c2b02010-04-09 20:32:421108
1109 std::map<std::string, CommandLine::StringType> switches =
1110 old_cl->GetSwitches();
1111
[email protected]5c08f222010-09-22 09:37:211112 switches::RemoveSwitchesForAutostart(&switches);
[email protected]bd48c2b02010-04-09 20:32:421113
1114 // Append the rest of the switches (along with their values, if any)
1115 // to the new command line
1116 for (std::map<std::string, CommandLine::StringType>::const_iterator i =
1117 switches.begin(); i != switches.end(); ++i) {
1118 CommandLine::StringType switch_value = i->second;
1119 if (switch_value.length() > 0) {
[email protected]05076ba22010-07-30 05:59:571120 new_cl->AppendSwitchNative(i->first, i->second);
[email protected]bd48c2b02010-04-09 20:32:421121 } else {
[email protected]3cdacd42010-04-30 18:55:531122 new_cl->AppendSwitch(i->first);
[email protected]bd48c2b02010-04-09 20:32:421123 }
1124 }
1125
[email protected]6c10c972010-08-11 04:15:471126 // Ensure that our desired switches are set on the new process.
[email protected]5c08f222010-09-22 09:37:211127 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) {
[email protected]6c10c972010-08-11 04:15:471128 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i]))
1129 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
1130 }
[email protected]bd48c2b02010-04-09 20:32:421131
[email protected]3cdacd42010-04-30 18:55:531132 DLOG(WARNING) << "Shutting down current instance of the browser.";
1133 BrowserList::CloseAllBrowsersAndExit();
1134
1135 // Transfer ownership to Upgrade.
[email protected]815856722011-04-13 17:19:191136 upgrade_util::SetNewCommandLine(new_cl.release());
[email protected]bd48c2b02010-04-09 20:32:421137}
1138
1139void BrowserProcessImpl::OnAutoupdateTimer() {
1140 if (CanAutorestartForUpdate()) {
[email protected]3cdacd42010-04-30 18:55:531141 DLOG(WARNING) << "Detected update. Restarting browser.";
[email protected]bd48c2b02010-04-09 20:32:421142 RestartPersistentInstance();
1143 }
1144}
1145
[email protected]3cdacd42010-04-30 18:55:531146#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)