blob: dfbb509843456985a49a79418edc15d39595cfe6 [file] [log] [blame]
[email protected]3a80ea332012-01-09 19:53:291// Copyright (c) 2012 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]38489a32012-05-11 02:24:547#include <algorithm>
[email protected]3cdacd42010-04-30 18:55:538#include <map>
[email protected]68f88b992011-05-07 02:01:399#include <vector>
[email protected]3cdacd42010-04-30 18:55:5310
[email protected]b3cc0542011-11-19 22:43:4411#include "base/bind.h"
12#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/command_line.h"
[email protected]6b4e6852012-02-14 04:02:4814#include "base/debug/alias.h"
[email protected]69c019472013-10-15 05:03:4715#include "base/debug/leak_annotations.h"
initial.commit09911bf2008-07-26 23:55:2916#include "base/path_service.h"
[email protected]03b9b4e2012-10-22 20:01:5217#include "base/prefs/json_pref_store.h"
[email protected]3853a4c2013-02-11 17:15:5718#include "base/prefs/pref_registry_simple.h"
19#include "base/prefs/pref_service.h"
[email protected]985655a2011-02-23 09:54:2520#include "base/synchronization/waitable_event.h"
[email protected]34b99632011-01-01 01:01:0621#include "base/threading/thread.h"
22#include "base/threading/thread_restrictions.h"
[email protected]01996a592013-09-13 06:55:0423#include "chrome/browser/apps/chrome_apps_client.h"
[email protected]a07676b22011-06-17 16:36:5324#include "chrome/browser/background/background_mode_manager.h"
[email protected]c38831a12011-10-28 12:44:4925#include "chrome/browser/chrome_browser_main.h"
[email protected]572f40c9b2012-07-06 20:35:3326#include "chrome/browser/chrome_content_browser_client.h"
[email protected]fdf40f3e2013-07-11 23:55:4627#include "chrome/browser/chrome_notification_types.h"
[email protected]c1adf5a2011-08-03 22:11:3728#include "chrome/browser/component_updater/component_updater_configurator.h"
29#include "chrome/browser/component_updater/component_updater_service.h"
[email protected]9f108f22013-04-09 00:39:5630#include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
[email protected]195c99c2012-10-31 06:24:5131#include "chrome/browser/defaults.h"
[email protected]70019152012-12-19 11:44:1932#include "chrome/browser/devtools/remote_debugging_server.h"
[email protected]254ed742011-08-16 18:45:2733#include "chrome/browser/download/download_request_limiter.h"
[email protected]75e51b52012-02-04 16:57:5434#include "chrome/browser/download/download_status_updater.h"
[email protected]9fe42042013-10-29 21:13:3335#include "chrome/browser/extensions/chrome_extensions_browser_client.h"
[email protected]5a38dfd2012-07-23 23:22:1036#include "chrome/browser/extensions/event_router_forwarder.h"
[email protected]d5570942013-01-24 01:42:4337#include "chrome/browser/extensions/extension_renderer_state.h"
[email protected]815856722011-04-13 17:19:1938#include "chrome/browser/first_run/upgrade_util.h"
[email protected]a9830b52012-12-17 23:30:3639#include "chrome/browser/gpu/gl_string_manager.h"
[email protected]e6933d2a2013-03-12 22:32:2140#include "chrome/browser/gpu/gpu_mode_manager.h"
[email protected]dcefa302009-05-20 00:24:3941#include "chrome/browser/icon_manager.h"
[email protected]91901092013-01-31 01:53:5942#include "chrome/browser/idle.h"
[email protected]c4ff4952010-01-08 19:12:4743#include "chrome/browser/intranet_redirect_detector.h"
[email protected]0ac83682010-01-22 17:46:2744#include "chrome/browser/io_thread.h"
[email protected]2e6389f2012-05-18 19:41:2545#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]dc6f4962009-02-13 01:25:5046#include "chrome/browser/metrics/metrics_service.h"
[email protected]0b565182011-03-02 18:11:1547#include "chrome/browser/metrics/thread_watcher.h"
[email protected]cf265dc02012-08-15 01:01:1648#include "chrome/browser/metrics/variations/variations_service.h"
[email protected]b2fcd0e2010-12-01 15:19:4049#include "chrome/browser/net/chrome_net_log.h"
[email protected]ca167a32011-09-30 15:19:1150#include "chrome/browser/net/crl_set_fetcher.h"
[email protected]d393a0fd2009-05-13 23:32:0151#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]29672ab2009-10-30 03:44:0352#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]c2295f72013-01-03 22:18:5653#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
[email protected]de75c702012-09-25 23:06:0254#include "chrome/browser/plugins/plugin_finder.h"
[email protected]caf63aea2011-04-26 11:04:1055#include "chrome/browser/prefs/browser_prefs.h"
[email protected]5b199522012-12-22 17:24:4456#include "chrome/browser/prefs/chrome_pref_service_factory.h"
[email protected]1459fb62011-05-25 19:03:2757#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]68f88b992011-05-07 02:01:3958#include "chrome/browser/printing/background_printing_manager.h"
[email protected]e06131d2010-02-10 18:40:3359#include "chrome/browser/printing/print_job_manager.h"
[email protected]d8ce31e2012-12-19 05:09:2160#include "chrome/browser/printing/print_preview_dialog_controller.h"
[email protected]8ecad5e2010-12-02 21:18:3361#include "chrome/browser/profiles/profile_manager.h"
[email protected]8bcdf072011-06-03 16:52:1562#include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h"
[email protected]81218f42009-02-05 18:48:0863#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]e450fa62011-02-01 12:52:5664#include "chrome/browser/shell_integration.h"
[email protected]9e7f015f2011-05-28 00:24:2565#include "chrome/browser/status_icons/status_tray.h"
[email protected]195c99c2012-10-31 06:24:5166#include "chrome/browser/ui/bookmarks/bookmark_prompt_controller.h"
[email protected]94840bb2013-12-17 19:43:3867#include "chrome/browser/ui/browser_dialogs.h"
[email protected]0665ebe2013-02-13 09:53:1968#include "chrome/browser/ui/browser_finder.h"
[email protected]ed304482013-01-04 04:45:3269#include "chrome/browser/web_resource/promo_resource_service.h"
[email protected]4ef795df2010-02-03 02:35:0870#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2971#include "chrome/common/chrome_paths.h"
72#include "chrome/common/chrome_switches.h"
[email protected]ad8b4ba2013-08-09 19:52:4473#include "chrome/common/extensions/chrome_extensions_client.h"
initial.commit09911bf2008-07-26 23:55:2974#include "chrome/common/pref_names.h"
[email protected]5c08f222010-09-22 09:37:2175#include "chrome/common/switch_utils.h"
[email protected]985655a2011-02-23 09:54:2576#include "chrome/common/url_constants.h"
[email protected]bd48c2b02010-04-09 20:32:4277#include "chrome/installer/util/google_update_constants.h"
[email protected]76b4b152013-12-08 21:10:0478#include "components/policy/core/common/policy_service.h"
[email protected]2a172e42014-02-21 04:06:1079#include "components/rappor/rappor_service.h"
[email protected]1c799ff2014-04-16 01:44:5280#include "components/signin/core/common/profile_management_switches.h"
[email protected]bb1c86cd2014-01-29 18:22:1881#include "components/translate/core/browser/translate_download_manager.h"
[email protected]c38831a12011-10-28 12:44:4982#include "content/public/browser/browser_thread.h"
[email protected]b9535422012-02-09 01:47:5983#include "content/public/browser/child_process_security_policy.h"
[email protected]ad50def52011-10-19 23:17:0784#include "content/public/browser/notification_details.h"
[email protected]3a5180ae2011-12-21 02:39:3885#include "content/public/browser/plugin_service.h"
[email protected]f3b1a082011-11-18 00:34:3086#include "content/public/browser/render_process_host.h"
[email protected]ea114722012-03-12 01:11:2587#include "content/public/browser/resource_dispatcher_host.h"
[email protected]885c0e92012-11-13 20:27:4288#include "extensions/common/constants.h"
[email protected]6668e5d2014-04-08 23:32:5289#include "extensions/common/extension_l10n_util.h"
[email protected]12c84e22011-07-11 09:35:4590#include "net/socket/client_socket_pool_manager.h"
[email protected]abe2c032011-03-31 18:49:3491#include "net/url_request/url_request_context_getter.h"
[email protected]c051a1b2011-01-21 23:30:1792#include "ui/base/l10n/l10n_util.h"
[email protected]fb1aac12013-05-14 05:30:2493#include "ui/message_center/message_center.h"
[email protected]b112a4c2009-02-01 20:24:0194
[email protected]3b19e8e2012-10-17 19:15:4995#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]97275822014-01-21 19:30:3696#include "components/policy/core/browser/browser_policy_connector.h"
[email protected]3b19e8e2012-10-17 19:15:4997#else
[email protected]76b4b152013-12-08 21:10:0498#include "components/policy/core/common/policy_service_stub.h"
[email protected]21d3a882012-05-31 14:41:5599#endif // defined(ENABLE_CONFIGURATION_POLICY)
100
[email protected]b112a4c2009-02-01 20:24:01101#if defined(OS_WIN)
[email protected]770c6d82012-09-06 22:21:32102#include "base/win/windows_version.h"
[email protected]477ae052011-11-18 23:53:57103#include "ui/views/focus/view_storage.h"
[email protected]03d8d3e92011-09-20 06:07:11104#elif defined(OS_MACOSX)
105#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]86230b92009-11-23 20:38:38106#endif
107
[email protected]4189bc222012-03-29 23:11:47108#if defined(USE_AURA)
109#include "ui/aura/env.h"
110#endif
111
[email protected]8b60ca722013-07-19 01:29:02112#if !defined(OS_ANDROID) && !defined(OS_IOS)
[email protected]e8262a52013-04-24 02:02:51113#include "chrome/browser/media_galleries/media_file_system_registry.h"
[email protected]e4c5f97b2014-02-17 18:57:17114#include "components/storage_monitor/storage_monitor.h"
[email protected]e8262a52013-04-24 02:02:51115#endif
116
[email protected]2366a3a2012-10-02 20:41:14117#if defined(ENABLE_PLUGIN_INSTALLATION)
[email protected]97eddfe2013-02-12 19:16:30118#include "chrome/browser/plugins/plugins_resource_service.h"
[email protected]2366a3a2012-10-02 20:41:14119#endif
120
[email protected]bbf32c52013-06-03 14:05:52121#if defined(ENABLE_WEBRTC)
122#include "chrome/browser/media/webrtc_log_uploader.h"
123#endif
124
[email protected]3cdacd42010-04-30 18:55:53125#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
126// How often to check if the persistent instance of Chrome needs to restart
127// to install an update.
128static const int kUpdateCheckIntervalHours = 6;
129#endif
130
[email protected]6ef01ac2014-02-19 02:06:40131#if defined(USE_X11) || defined(OS_WIN)
132// How long to wait for the File thread to complete during EndSession, on Linux
133// and Windows. We have a timeout here because we're unable to run the UI
134// messageloop and there's some deadlock risk. Our only option is to exit
135// anyway.
[email protected]c6032e82010-09-13 20:06:05136static const int kEndSessionTimeoutSeconds = 10;
137#endif
138
[email protected]631bb742011-11-02 11:29:39139using content::BrowserThread;
[email protected]b9535422012-02-09 01:47:59140using content::ChildProcessSecurityPolicy;
[email protected]3a5180ae2011-12-21 02:39:38141using content::PluginService;
[email protected]ea114722012-03-12 01:11:25142using content::ResourceDispatcherHost;
[email protected]631bb742011-11-02 11:29:39143
[email protected]0de615a2012-11-08 04:40:59144BrowserProcessImpl::BrowserProcessImpl(
145 base::SequencedTaskRunner* local_state_task_runner,
146 const CommandLine& command_line)
[email protected]99907362012-01-11 05:41:40147 : created_metrics_service_(false),
[email protected]0b565182011-03-02 18:11:15148 created_watchdog_thread_(false),
[email protected]663831822012-05-23 10:19:21149 created_browser_policy_connector_(false),
initial.commit09911bf2008-07-26 23:55:29150 created_profile_manager_(false),
151 created_local_state_(false),
[email protected]b112a4c2009-02-01 20:24:01152 created_icon_manager_(false),
[email protected]29672ab2009-10-30 03:44:03153 created_notification_ui_manager_(false),
[email protected]462a0ff2011-06-02 17:15:34154 created_safe_browsing_service_(false),
initial.commit09911bf2008-07-26 23:55:29155 module_ref_count_(0),
[email protected]afd20c022010-06-10 00:48:20156 did_start_(false),
[email protected]0de615a2012-11-08 04:40:59157 download_status_updater_(new DownloadStatusUpdater),
158 local_state_task_runner_(local_state_task_runner) {
initial.commit09911bf2008-07-26 23:55:29159 g_browser_process = this;
[email protected]7cad6b0d2013-04-25 20:29:32160 platform_part_.reset(new BrowserProcessPlatformPart());
initial.commit09911bf2008-07-26 23:55:29161
[email protected]658677f2012-06-09 06:04:02162#if defined(ENABLE_PRINTING)
initial.commit09911bf2008-07-26 23:55:29163 // Must be created after the NotificationService.
164 print_job_manager_.reset(new printing::PrintJobManager);
[email protected]058e5732012-03-01 22:48:03165#endif
initial.commit09911bf2008-07-26 23:55:29166
[email protected]b2fcd0e2010-12-01 15:19:40167 net_log_.reset(new ChromeNetLog);
[email protected]3ce02412011-03-01 12:01:15168
[email protected]8add5412011-10-01 21:02:14169 ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeScheme(
[email protected]885c0e92012-11-13 20:27:42170 extensions::kExtensionScheme);
[email protected]b23b1b42012-05-18 19:09:16171 ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeScheme(
[email protected]2f3cf692013-12-19 00:51:24172 extensions::kExtensionResourceScheme);
[email protected]672c8c12013-03-07 12:30:06173 ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeScheme(
174 chrome::kChromeSearchScheme);
[email protected]8add5412011-10-01 21:02:14175
[email protected]91901092013-01-31 01:53:59176#if defined(OS_MACOSX)
177 InitIdleMonitor();
178#endif
179
[email protected]01996a592013-09-13 06:55:04180 apps::AppsClient::Set(ChromeAppsClient::GetInstance());
[email protected]ad8b4ba2013-08-09 19:52:44181 extensions::ExtensionsClient::Set(
182 extensions::ChromeExtensionsClient::GetInstance());
[email protected]aa3dd492013-11-05 17:09:09183
184 extensions_browser_client_.reset(
185 new extensions::ChromeExtensionsBrowserClient);
186 extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get());
187
[email protected]5a38dfd2012-07-23 23:22:10188 extension_event_router_forwarder_ = new extensions::EventRouterForwarder;
[email protected]d5570942013-01-24 01:42:43189 ExtensionRendererState::GetInstance()->Init();
[email protected]356530722013-03-05 19:10:19190
[email protected]356530722013-03-05 19:10:19191 message_center::MessageCenter::Initialize();
initial.commit09911bf2008-07-26 23:55:29192}
193
194BrowserProcessImpl::~BrowserProcessImpl() {
[email protected]2e5b60a22011-11-28 15:56:41195 tracked_objects::ThreadData::EnsureCleanupWasCalled(4);
196
197 g_browser_process = NULL;
198}
199
200void BrowserProcessImpl::StartTearDown() {
[email protected]89af4002013-09-06 07:47:07201 TRACE_EVENT0("shutdown", "BrowserProcessImpl::StartTearDown");
[email protected]d393a0fd2009-05-13 23:32:01202 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
203 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
204 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
205 // any pending URLFetchers, and avoid creating any more.
[email protected]cf956b982011-12-02 12:00:45206 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
207 base::Bind(&SdchDictionaryFetcher::Shutdown));
[email protected]d393a0fd2009-05-13 23:32:01208
[email protected]16ab7a02014-02-24 23:30:46209 // We need to destroy the MetricsService, RapporService, VariationsService,
[email protected]ed304482013-01-04 04:45:32210 // IntranetRedirectDetector, PromoResourceService, and SafeBrowsing
211 // ClientSideDetectionService (owned by the SafeBrowsingService) before the
212 // io_thread_ gets destroyed, since their destructors can call the URLFetcher
213 // destructor, which does a PostDelayedTask operation on the IO thread. (The
214 // IO thread will handle that URLFetcher operation before going away.)
initial.commit09911bf2008-07-26 23:55:29215 metrics_service_.reset();
[email protected]16ab7a02014-02-24 23:30:46216 rappor_service_.reset();
[email protected]54e26c122012-05-17 15:36:21217 variations_service_.reset();
[email protected]c4ff4952010-01-08 19:12:47218 intranet_redirect_detector_.reset();
[email protected]6c521fed2012-11-29 17:00:03219#if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
[email protected]ed304482013-01-04 04:45:32220 if (safe_browsing_service_.get())
[email protected]9efb46692011-08-23 12:56:05221 safe_browsing_service()->ShutDown();
[email protected]9efb46692011-08-23 12:56:05222#endif
initial.commit09911bf2008-07-26 23:55:29223
[email protected]d8a899c2010-09-21 04:50:33224 // Need to clear the desktop notification balloons before the io_thread_ and
225 // before the profiles, since if there are any still showing we will access
226 // those things during teardown.
227 notification_ui_manager_.reset();
228
initial.commit09911bf2008-07-26 23:55:29229 // Need to clear profiles (download managers) before the io_thread_.
[email protected]89af4002013-09-06 07:47:07230 {
231 TRACE_EVENT0("shutdown",
232 "BrowserProcessImpl::StartTearDown:ProfileManager");
[email protected]94840bb2013-12-17 19:43:38233 // The desktop User Manager needs to be closed before the guest profile
234 // can be destroyed.
[email protected]4de75262013-12-18 23:16:12235 if (switches::IsNewProfileManagement())
[email protected]94840bb2013-12-17 19:43:38236 chrome::HideUserManager();
[email protected]89af4002013-09-06 07:47:07237 profile_manager_.reset();
238 }
initial.commit09911bf2008-07-26 23:55:29239
[email protected]81054f812012-08-30 00:47:09240#if !defined(OS_ANDROID)
initial.commit09911bf2008-07-26 23:55:29241 // Debugger must be cleaned up before IO thread and NotificationService.
[email protected]4475d232011-07-27 15:29:20242 remote_debugging_server_.reset();
[email protected]81054f812012-08-30 00:47:09243#endif
[email protected]4475d232011-07-27 15:29:20244
[email protected]d5570942013-01-24 01:42:43245 ExtensionRendererState::GetInstance()->Shutdown();
[email protected]fc4facd2011-03-22 23:18:50246
[email protected]8b60ca722013-07-19 01:29:02247#if !defined(OS_ANDROID) && !defined(OS_IOS)
248 media_file_system_registry_.reset();
[email protected]e4c5f97b2014-02-17 18:57:17249 // Remove the global instance of the Storage Monitor now. Otherwise the
250 // FILE thread would be gone when we try to release it in the dtor and
251 // Valgrind would report a leak on almost every single browser_test.
[email protected]8b60ca722013-07-19 01:29:02252 // TODO(gbillock): Make this unnecessary.
[email protected]7bfe94602014-02-25 10:22:39253 storage_monitor::StorageMonitor::Destroy();
[email protected]8b60ca722013-07-19 01:29:02254#endif
255
[email protected]356530722013-03-05 19:10:19256 message_center::MessageCenter::Shutdown();
[email protected]356530722013-03-05 19:10:19257
[email protected]3b19e8e2012-10-17 19:15:49258#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]985655a2011-02-23 09:54:25259 // The policy providers managed by |browser_policy_connector_| need to shut
260 // down while the IO and FILE threads are still alive.
[email protected]3b19e8e2012-10-17 19:15:49261 if (browser_policy_connector_)
262 browser_policy_connector_->Shutdown();
263#endif
[email protected]f2a893c2011-01-05 09:38:07264
[email protected]8fd11832011-07-14 20:01:13265 // Stop the watchdog thread before stopping other threads.
266 watchdog_thread_.reset();
[email protected]4189bc222012-03-29 23:11:47267
268#if defined(USE_AURA)
269 // Delete aura after the metrics service has been deleted as it accesses
270 // monitor information.
271 aura::Env::DeleteInstance();
272#endif
[email protected]acd2121c2013-03-18 05:54:50273
[email protected]7cad6b0d2013-04-25 20:29:32274 platform_part()->StartTearDown();
[email protected]ab8973da2013-11-25 19:32:38275
[email protected]f3724cf2014-03-04 11:21:10276#if defined(ENABLE_WEBRTC)
[email protected]969ebea2014-03-28 16:50:26277 // Cancel any uploads to release the system url request context references.
278 if (webrtc_log_uploader_)
279 webrtc_log_uploader_->StartShutdown();
[email protected]f3724cf2014-03-04 11:21:10280#endif
281
[email protected]b4a269b2014-01-14 04:48:48282 if (local_state())
283 local_state()->CommitPendingWrite();
[email protected]2e5b60a22011-11-28 15:56:41284}
[email protected]8fd11832011-07-14 20:01:13285
[email protected]99907362012-01-11 05:41:40286void BrowserProcessImpl::PostDestroyThreads() {
287 // With the file_thread_ flushed, we can release any icon resources.
288 icon_manager_.reset();
initial.commit09911bf2008-07-26 23:55:29289
[email protected]969ebea2014-03-28 16:50:26290#if defined(ENABLE_WEBRTC)
291 // Must outlive the file thread.
292 webrtc_log_uploader_.reset();
293#endif
294
[email protected]99907362012-01-11 05:41:40295 // Reset associated state right after actual thread is stopped,
296 // as io_thread_.global_ cleanup happens in CleanUp on the IO
297 // thread, i.e. as the thread exits its message loop.
298 //
299 // This is important also because in various places, the
300 // IOThread object being NULL is considered synonymous with the
301 // IO thread having stopped.
302 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29303}
304
[email protected]6ef01ac2014-02-19 02:06:40305#if defined(USE_X11) || defined(OS_WIN)
[email protected]c6032e82010-09-13 20:06:05306static void Signal(base::WaitableEvent* event) {
307 event->Signal();
308}
309#endif
initial.commit09911bf2008-07-26 23:55:29310
[email protected]b443cb042009-12-15 22:05:09311unsigned int BrowserProcessImpl::AddRefModule() {
312 DCHECK(CalledOnValidThread());
[email protected]6b4e6852012-02-14 04:02:48313
314 // CHECK(!IsShuttingDown());
315 if (IsShuttingDown()) {
316 // Copy the stacktrace which released the final reference onto our stack so
317 // it will be available in the crash report for inspection.
318 base::debug::StackTrace callstack = release_last_reference_callstack_;
319 base::debug::Alias(&callstack);
320 CHECK(false);
321 }
322
[email protected]afd20c022010-06-10 00:48:20323 did_start_ = true;
[email protected]b443cb042009-12-15 22:05:09324 module_ref_count_++;
325 return module_ref_count_;
326}
327
328unsigned int BrowserProcessImpl::ReleaseModule() {
329 DCHECK(CalledOnValidThread());
[email protected]760d970a2010-05-18 00:39:18330 DCHECK_NE(0u, module_ref_count_);
[email protected]b443cb042009-12-15 22:05:09331 module_ref_count_--;
332 if (0 == module_ref_count_) {
[email protected]6b4e6852012-02-14 04:02:48333 release_last_reference_callstack_ = base::debug::StackTrace();
334
[email protected]658677f2012-06-09 06:04:02335#if defined(ENABLE_PRINTING)
[email protected]6869771f2012-05-19 00:30:57336 // Wait for the pending print jobs to finish. Don't do this later, since
337 // this might cause a nested message loop to run, and we don't want pending
338 // tasks to run once teardown has started.
[email protected]3222c3262013-09-18 10:26:14339 print_job_manager_->Shutdown();
[email protected]6869771f2012-05-19 00:30:57340#endif
341
[email protected]69c019472013-10-15 05:03:47342#if defined(LEAK_SANITIZER)
343 // Check for memory leaks now, before we start shutting down threads. Doing
344 // this early means we won't report any shutdown-only leaks (as they have
345 // not yet happened at this point).
346 // If leaks are found, this will make the process exit immediately.
347 __lsan_do_leak_check();
348#endif
349
[email protected]b3a25092013-05-28 22:08:16350 CHECK(base::MessageLoop::current()->is_running());
[email protected]03d8d3e92011-09-20 06:07:11351
352#if defined(OS_MACOSX)
[email protected]b3a25092013-05-28 22:08:16353 base::MessageLoop::current()->PostTask(
[email protected]03d8d3e92011-09-20 06:07:11354 FROM_HERE,
[email protected]b3cc0542011-11-19 22:43:44355 base::Bind(ChromeBrowserMainPartsMac::DidEndMainMessageLoop));
[email protected]03d8d3e92011-09-20 06:07:11356#endif
[email protected]b3a25092013-05-28 22:08:16357 base::MessageLoop::current()->Quit();
[email protected]b443cb042009-12-15 22:05:09358 }
359 return module_ref_count_;
360}
361
initial.commit09911bf2008-07-26 23:55:29362void BrowserProcessImpl::EndSession() {
initial.commit09911bf2008-07-26 23:55:29363 // Mark all the profiles as clean.
364 ProfileManager* pm = profile_manager();
[email protected]844a1002011-04-19 11:37:21365 std::vector<Profile*> profiles(pm->GetLoadedProfiles());
366 for (size_t i = 0; i < profiles.size(); ++i)
[email protected]6c0ca7fc2012-10-05 16:27:22367 profiles[i]->SetExitType(Profile::EXIT_SESSION_ENDED);
initial.commit09911bf2008-07-26 23:55:29368
369 // Tell the metrics service it was cleanly shutdown.
370 MetricsService* metrics = g_browser_process->metrics_service();
371 if (metrics && local_state()) {
initial.commit09911bf2008-07-26 23:55:29372 metrics->RecordStartOfSessionEnd();
[email protected]a6aa7542013-10-19 10:24:35373#if !defined(OS_CHROMEOS)
initial.commit09911bf2008-07-26 23:55:29374 // MetricsService lazily writes to prefs, force it to write now.
[email protected]a6aa7542013-10-19 10:24:35375 // On ChromeOS, chrome gets killed when hangs, so no need to
376 // commit prefs::kStabilitySessionEndCompleted change immediately.
[email protected]fbe17c8a2011-12-27 16:41:48377 local_state()->CommitPendingWrite();
[email protected]a6aa7542013-10-19 10:24:35378#endif
initial.commit09911bf2008-07-26 23:55:29379 }
380
[email protected]79a75b02012-04-26 18:03:58381 // http://crbug.com/125207
382 base::ThreadRestrictions::ScopedAllowWait allow_wait;
383
initial.commit09911bf2008-07-26 23:55:29384 // We must write that the profile and metrics service shutdown cleanly,
385 // otherwise on startup we'll think we crashed. So we block until done and
386 // then proceed with normal shutdown.
[email protected]6ef01ac2014-02-19 02:06:40387#if defined(USE_X11) || defined(OS_WIN)
388 // Create a waitable event to block on file writing being complete.
389 //
390 // On Windows, we previously posted a message to FILE and then ran a nested
391 // message loop, waiting for that message to be processed until quitting.
392 // However, doing so means that other messages will also be processed. In
393 // particular, if the GPU process host notices that the GPU has been killed
394 // during shutdown, it races exiting the nested loop with the process host
395 // blocking the message loop attempting to re-establish a connection to the
396 // GPU process synchronously. Because the system may not be allowing
397 // processes to launch, this can result in a hang. See
398 // http://crbug.com/318527.
[email protected]0bfbcdb2011-09-15 21:28:04399 scoped_ptr<base::WaitableEvent> done_writing(
400 new base::WaitableEvent(false, false));
[email protected]d04e7662010-10-10 22:24:48401 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]b3cc0542011-11-19 22:43:44402 base::Bind(Signal, done_writing.get()));
[email protected]0bfbcdb2011-09-15 21:28:04403 // If all file writes haven't cleared in the timeout, leak the WaitableEvent
404 // so that there's no race to reference it in Signal().
405 if (!done_writing->TimedWait(
[email protected]ed304482013-01-04 04:45:32406 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds))) {
[email protected]0bfbcdb2011-09-15 21:28:04407 ignore_result(done_writing.release());
[email protected]ed304482013-01-04 04:45:32408 }
[email protected]c6032e82010-09-13 20:06:05409#else
410 NOTIMPLEMENTED();
411#endif
initial.commit09911bf2008-07-26 23:55:29412}
413
[email protected]e13ad79b2010-07-22 21:36:50414MetricsService* BrowserProcessImpl::metrics_service() {
415 DCHECK(CalledOnValidThread());
416 if (!created_metrics_service_)
417 CreateMetricsService();
418 return metrics_service_.get();
419}
420
[email protected]2a172e42014-02-21 04:06:10421rappor::RapporService* BrowserProcessImpl::rappor_service() {
422 DCHECK(CalledOnValidThread());
423 if (!rappor_service_.get())
424 rappor_service_.reset(new rappor::RapporService());
425 return rappor_service_.get();
426}
427
[email protected]e13ad79b2010-07-22 21:36:50428IOThread* BrowserProcessImpl::io_thread() {
429 DCHECK(CalledOnValidThread());
[email protected]2e5b60a22011-11-28 15:56:41430 DCHECK(io_thread_.get());
[email protected]e13ad79b2010-07-22 21:36:50431 return io_thread_.get();
432}
433
[email protected]0b565182011-03-02 18:11:15434WatchDogThread* BrowserProcessImpl::watchdog_thread() {
435 DCHECK(CalledOnValidThread());
436 if (!created_watchdog_thread_)
437 CreateWatchdogThread();
438 DCHECK(watchdog_thread_.get() != NULL);
439 return watchdog_thread_.get();
440}
441
[email protected]e13ad79b2010-07-22 21:36:50442ProfileManager* BrowserProcessImpl::profile_manager() {
443 DCHECK(CalledOnValidThread());
444 if (!created_profile_manager_)
445 CreateProfileManager();
446 return profile_manager_.get();
447}
448
[email protected]b1de2c72013-02-06 02:45:47449PrefService* BrowserProcessImpl::local_state() {
[email protected]e13ad79b2010-07-22 21:36:50450 DCHECK(CalledOnValidThread());
451 if (!created_local_state_)
452 CreateLocalState();
453 return local_state_.get();
454}
455
[email protected]abe2c032011-03-31 18:49:34456net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() {
[email protected]db0e86dd2011-03-16 14:47:21457 DCHECK(CalledOnValidThread());
458 return io_thread()->system_url_request_context_getter();
459}
460
[email protected]04811242012-07-06 18:04:29461chrome_variations::VariationsService* BrowserProcessImpl::variations_service() {
[email protected]54e26c122012-05-17 15:36:21462 DCHECK(CalledOnValidThread());
[email protected]7e6b753f2013-02-15 16:21:38463 if (!variations_service_.get()) {
464 variations_service_.reset(
465 chrome_variations::VariationsService::Create(local_state()));
466 }
[email protected]54e26c122012-05-17 15:36:21467 return variations_service_.get();
468}
469
[email protected]7cad6b0d2013-04-25 20:29:32470BrowserProcessPlatformPart* BrowserProcessImpl::platform_part() {
471 return platform_part_.get();
[email protected]5b869962011-09-20 19:49:33472}
[email protected]db0e86dd2011-03-16 14:47:21473
[email protected]5a38dfd2012-07-23 23:22:10474extensions::EventRouterForwarder*
[email protected]3ce02412011-03-01 12:01:15475BrowserProcessImpl::extension_event_router_forwarder() {
476 return extension_event_router_forwarder_.get();
477}
478
[email protected]e13ad79b2010-07-22 21:36:50479NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
480 DCHECK(CalledOnValidThread());
481 if (!created_notification_ui_manager_)
482 CreateNotificationUIManager();
483 return notification_ui_manager_.get();
484}
485
[email protected]8393aa62013-01-23 19:40:10486message_center::MessageCenter* BrowserProcessImpl::message_center() {
487 DCHECK(CalledOnValidThread());
[email protected]356530722013-03-05 19:10:19488 return message_center::MessageCenter::Get();
[email protected]8393aa62013-01-23 19:40:10489}
[email protected]8393aa62013-01-23 19:40:10490
[email protected]985655a2011-02-23 09:54:25491policy::BrowserPolicyConnector* BrowserProcessImpl::browser_policy_connector() {
[email protected]f2a893c2011-01-05 09:38:07492 DCHECK(CalledOnValidThread());
[email protected]f31e2e52011-07-14 16:01:19493#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]3b19e8e2012-10-17 19:15:49494 if (!created_browser_policy_connector_) {
[email protected]3b19e8e2012-10-17 19:15:49495 DCHECK(!browser_policy_connector_);
[email protected]97275822014-01-21 19:30:36496 browser_policy_connector_ = platform_part_->CreateBrowserPolicyConnector();
[email protected]371e3ed2012-05-23 18:04:28497 created_browser_policy_connector_ = true;
[email protected]f2a893c2011-01-05 09:38:07498 }
[email protected]985655a2011-02-23 09:54:25499 return browser_policy_connector_.get();
[email protected]3b19e8e2012-10-17 19:15:49500#else
501 return NULL;
502#endif
[email protected]f2a893c2011-01-05 09:38:07503}
504
[email protected]a4179c2a2012-02-09 18:14:21505policy::PolicyService* BrowserProcessImpl::policy_service() {
506#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]3b19e8e2012-10-17 19:15:49507 return browser_policy_connector()->GetPolicyService();
[email protected]a4179c2a2012-02-09 18:14:21508#else
[email protected]3b19e8e2012-10-17 19:15:49509 if (!policy_service_.get())
[email protected]243ec0782012-02-14 21:03:02510 policy_service_.reset(new policy::PolicyServiceStub());
[email protected]8d6b2432012-03-31 12:11:18511 return policy_service_.get();
[email protected]3b19e8e2012-10-17 19:15:49512#endif
[email protected]a4179c2a2012-02-09 18:14:21513}
514
[email protected]e13ad79b2010-07-22 21:36:50515IconManager* BrowserProcessImpl::icon_manager() {
516 DCHECK(CalledOnValidThread());
517 if (!created_icon_manager_)
518 CreateIconManager();
519 return icon_manager_.get();
520}
521
[email protected]a9830b52012-12-17 23:30:36522GLStringManager* BrowserProcessImpl::gl_string_manager() {
523 DCHECK(CalledOnValidThread());
524 if (!gl_string_manager_.get())
525 gl_string_manager_.reset(new GLStringManager());
526 return gl_string_manager_.get();
527}
528
[email protected]e6933d2a2013-03-12 22:32:21529GpuModeManager* BrowserProcessImpl::gpu_mode_manager() {
[email protected]8bbe3a92013-05-12 00:58:35530 DCHECK(CalledOnValidThread());
531 if (!gpu_mode_manager_.get())
532 gpu_mode_manager_.reset(new GpuModeManager());
[email protected]e6933d2a2013-03-12 22:32:21533 return gpu_mode_manager_.get();
534}
535
[email protected]76698ea2012-08-24 20:50:37536void BrowserProcessImpl::CreateDevToolsHttpProtocolHandler(
[email protected]55d342402013-02-22 11:28:06537 chrome::HostDesktopType host_desktop_type,
[email protected]01000cf12011-02-04 11:39:22538 const std::string& ip,
[email protected]d9ce37d22014-03-12 05:06:29539 int port) {
[email protected]e13ad79b2010-07-22 21:36:50540 DCHECK(CalledOnValidThread());
[email protected]81054f812012-08-30 00:47:09541#if !defined(OS_ANDROID)
[email protected]76698ea2012-08-24 20:50:37542 // StartupBrowserCreator::LaunchBrowser can be run multiple times when browser
543 // is started with several profiles or existing browser process is reused.
544 if (!remote_debugging_server_.get()) {
545 remote_debugging_server_.reset(
[email protected]d9ce37d22014-03-12 05:06:29546 new RemoteDebuggingServer(host_desktop_type, ip, port));
[email protected]76698ea2012-08-24 20:50:37547 }
[email protected]81054f812012-08-30 00:47:09548#endif
[email protected]5613126e2011-01-31 15:27:55549}
550
[email protected]e13ad79b2010-07-22 21:36:50551bool BrowserProcessImpl::IsShuttingDown() {
552 DCHECK(CalledOnValidThread());
553 return did_start_ && 0 == module_ref_count_;
554}
555
initial.commit09911bf2008-07-26 23:55:29556printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
[email protected]3222c3262013-09-18 10:26:14557 DCHECK(CalledOnValidThread());
initial.commit09911bf2008-07-26 23:55:29558 return print_job_manager_.get();
559}
560
[email protected]d8ce31e2012-12-19 05:09:21561printing::PrintPreviewDialogController*
562 BrowserProcessImpl::print_preview_dialog_controller() {
[email protected]1e54c1c2013-08-12 17:16:05563#if defined(ENABLE_FULL_PRINTING)
[email protected]dbeebd52010-11-16 20:34:16564 DCHECK(CalledOnValidThread());
[email protected]d8ce31e2012-12-19 05:09:21565 if (!print_preview_dialog_controller_.get())
566 CreatePrintPreviewDialogController();
567 return print_preview_dialog_controller_.get();
[email protected]658677f2012-06-09 06:04:02568#else
569 NOTIMPLEMENTED();
570 return NULL;
[email protected]058e5732012-03-01 22:48:03571#endif
[email protected]dbeebd52010-11-16 20:34:16572}
573
[email protected]68f88b992011-05-07 02:01:39574printing::BackgroundPrintingManager*
575 BrowserProcessImpl::background_printing_manager() {
[email protected]1e54c1c2013-08-12 17:16:05576#if defined(ENABLE_FULL_PRINTING)
[email protected]68f88b992011-05-07 02:01:39577 DCHECK(CalledOnValidThread());
578 if (!background_printing_manager_.get())
579 CreateBackgroundPrintingManager();
580 return background_printing_manager_.get();
[email protected]658677f2012-06-09 06:04:02581#else
582 NOTIMPLEMENTED();
583 return NULL;
[email protected]058e5732012-03-01 22:48:03584#endif
[email protected]68f88b992011-05-07 02:01:39585}
586
[email protected]e13ad79b2010-07-22 21:36:50587IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
588 DCHECK(CalledOnValidThread());
589 if (!intranet_redirect_detector_.get())
590 CreateIntranetRedirectDetector();
591 return intranet_redirect_detector_.get();
592}
593
594const std::string& BrowserProcessImpl::GetApplicationLocale() {
595 DCHECK(!locale_.empty());
596 return locale_;
597}
598
599void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
600 locale_ = locale;
601 extension_l10n_util::SetProcessLocale(locale);
[email protected]eabbfb12013-04-05 23:28:35602 chrome::ChromeContentBrowserClient::SetApplicationLocale(locale);
[email protected]bb1c86cd2014-01-29 18:22:18603 TranslateDownloadManager::GetInstance()->set_application_locale(locale);
[email protected]e13ad79b2010-07-22 21:36:50604}
605
[email protected]073ed7b2010-09-27 09:20:02606DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
[email protected]7a0e72f2011-09-20 19:59:11607 return download_status_updater_.get();
[email protected]073ed7b2010-09-27 09:20:02608}
609
[email protected]195c99c2012-10-31 06:24:51610BookmarkPromptController* BrowserProcessImpl::bookmark_prompt_controller() {
611#if defined(OS_ANDROID)
612 return NULL;
613#else
614 return bookmark_prompt_controller_.get();
615#endif
616}
617
[email protected]95951992013-09-13 00:37:54618MediaFileSystemRegistry* BrowserProcessImpl::media_file_system_registry() {
[email protected]8b60ca722013-07-19 01:29:02619#if defined(OS_ANDROID) || defined(OS_IOS)
[email protected]e8262a52013-04-24 02:02:51620 return NULL;
621#else
[email protected]42aec8df2012-12-12 06:03:57622 if (!media_file_system_registry_)
[email protected]95951992013-09-13 00:37:54623 media_file_system_registry_.reset(new MediaFileSystemRegistry());
[email protected]42aec8df2012-12-12 06:03:57624 return media_file_system_registry_.get();
[email protected]e8262a52013-04-24 02:02:51625#endif
[email protected]42aec8df2012-12-12 06:03:57626}
627
[email protected]16951ead2013-03-27 06:44:44628bool BrowserProcessImpl::created_local_state() const {
629 return created_local_state_;
630}
631
[email protected]bbf32c52013-06-03 14:05:52632#if defined(ENABLE_WEBRTC)
633WebRtcLogUploader* BrowserProcessImpl::webrtc_log_uploader() {
634 if (!webrtc_log_uploader_.get())
635 webrtc_log_uploader_.reset(new WebRtcLogUploader());
636 return webrtc_log_uploader_.get();
637}
638#endif
639
[email protected]b1de2c72013-02-06 02:45:47640// static
641void BrowserProcessImpl::RegisterPrefs(PrefRegistrySimple* registry) {
642 registry->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled,
643 false);
644 // This policy needs to be defined before the net subsystem is initialized,
645 // so we do it here.
646 registry->RegisterIntegerPref(prefs::kMaxConnectionsPerProxy,
647 net::kDefaultMaxSocketsPerProxyServer);
648
[email protected]b1de2c72013-02-06 02:45:47649 registry->RegisterBooleanPref(prefs::kAllowCrossOriginAuthPrompt, false);
650
[email protected]b4b709a2013-04-19 21:08:14651#if defined(OS_CHROMEOS) || defined(OS_ANDROID) || defined(OS_IOS)
652 registry->RegisterBooleanPref(prefs::kEulaAccepted, false);
653#endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) || defined(OS_IOS)
[email protected]b1de2c72013-02-06 02:45:47654#if defined(OS_WIN)
[email protected]d51373d2013-10-31 15:22:00655 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
656 registry->RegisterStringPref(prefs::kRelaunchMode,
657 upgrade_util::kRelaunchModeDefault);
658 }
[email protected]b1de2c72013-02-06 02:45:47659#endif
660
661 // TODO(brettw,*): this comment about ResourceBundle was here since
662 // initial commit. This comment seems unrelated, bit-rotten and
663 // a candidate for removal.
664 // Initialize ResourceBundle which handles files loaded from external
665 // sources. This has to be done before uninstall code path and before prefs
666 // are registered.
667 registry->RegisterStringPref(prefs::kApplicationLocale, std::string());
668#if defined(OS_CHROMEOS)
669 registry->RegisterStringPref(prefs::kOwnerLocale, std::string());
670 registry->RegisterStringPref(prefs::kHardwareKeyboardLayout,
671 std::string());
672#endif // defined(OS_CHROMEOS)
673#if !defined(OS_CHROMEOS)
674 registry->RegisterBooleanPref(
675 prefs::kMetricsReportingEnabled,
676 GoogleUpdateSettings::GetCollectStatsConsent());
677#endif // !defined(OS_CHROMEOS)
[email protected]1505e012013-05-09 23:23:47678
679#if defined(OS_ANDROID)
680 registry->RegisterBooleanPref(
681 prefs::kCrashReportingEnabled, false);
[email protected]ffaf7322013-05-15 00:26:11682#endif // defined(OS_ANDROID)
[email protected]b1de2c72013-02-06 02:45:47683}
684
[email protected]254ed742011-08-16 18:45:27685DownloadRequestLimiter* BrowserProcessImpl::download_request_limiter() {
686 DCHECK(CalledOnValidThread());
[email protected]dc24976f2013-06-02 21:15:09687 if (!download_request_limiter_.get())
[email protected]254ed742011-08-16 18:45:27688 download_request_limiter_ = new DownloadRequestLimiter();
[email protected]dc24976f2013-06-02 21:15:09689 return download_request_limiter_.get();
[email protected]254ed742011-08-16 18:45:27690}
691
[email protected]9e7f015f2011-05-28 00:24:25692BackgroundModeManager* BrowserProcessImpl::background_mode_manager() {
693 DCHECK(CalledOnValidThread());
[email protected]7cee1902012-08-23 00:02:45694#if defined(ENABLE_BACKGROUND)
[email protected]9e7f015f2011-05-28 00:24:25695 if (!background_mode_manager_.get())
696 CreateBackgroundModeManager();
697 return background_mode_manager_.get();
[email protected]7cee1902012-08-23 00:02:45698#else
699 NOTIMPLEMENTED();
700 return NULL;
701#endif
[email protected]9e7f015f2011-05-28 00:24:25702}
703
[email protected]e178ad92013-06-28 02:29:25704void BrowserProcessImpl::set_background_mode_manager_for_test(
705 scoped_ptr<BackgroundModeManager> manager) {
706 background_mode_manager_ = manager.Pass();
707}
708
[email protected]9e7f015f2011-05-28 00:24:25709StatusTray* BrowserProcessImpl::status_tray() {
710 DCHECK(CalledOnValidThread());
711 if (!status_tray_.get())
712 CreateStatusTray();
713 return status_tray_.get();
714}
715
[email protected]462a0ff2011-06-02 17:15:34716
717SafeBrowsingService* BrowserProcessImpl::safe_browsing_service() {
718 DCHECK(CalledOnValidThread());
719 if (!created_safe_browsing_service_)
720 CreateSafeBrowsingService();
721 return safe_browsing_service_.get();
722}
723
[email protected]a7a5e992010-12-09 23:39:51724safe_browsing::ClientSideDetectionService*
725 BrowserProcessImpl::safe_browsing_detection_service() {
726 DCHECK(CalledOnValidThread());
[email protected]9efb46692011-08-23 12:56:05727 if (safe_browsing_service())
728 return safe_browsing_service()->safe_browsing_detection_service();
729 return NULL;
[email protected]a7a5e992010-12-09 23:39:51730}
731
[email protected]e13ad79b2010-07-22 21:36:50732#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
733void BrowserProcessImpl::StartAutoupdateTimer() {
[email protected]d323a172011-09-02 18:23:02734 autoupdate_timer_.Start(FROM_HERE,
[email protected]e13ad79b2010-07-22 21:36:50735 base::TimeDelta::FromHours(kUpdateCheckIntervalHours),
736 this,
737 &BrowserProcessImpl::OnAutoupdateTimer);
738}
739#endif
740
[email protected]d6f37fc2011-02-13 23:58:41741ChromeNetLog* BrowserProcessImpl::net_log() {
742 return net_log_.get();
743}
744
[email protected]1459fb62011-05-25 19:03:27745prerender::PrerenderTracker* BrowserProcessImpl::prerender_tracker() {
746 if (!prerender_tracker_.get())
747 prerender_tracker_.reset(new prerender::PrerenderTracker);
748
749 return prerender_tracker_.get();
750}
751
[email protected]055981f2014-01-17 20:22:32752component_updater::ComponentUpdateService*
753BrowserProcessImpl::component_updater() {
[email protected]c1adf5a2011-08-03 22:11:37754 if (!component_updater_.get()) {
[email protected]ad94f722013-11-02 01:57:36755 if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
756 return NULL;
[email protected]055981f2014-01-17 20:22:32757 component_updater::ComponentUpdateService::Configurator* configurator =
758 component_updater::MakeChromeComponentUpdaterConfigurator(
[email protected]c1adf5a2011-08-03 22:11:37759 CommandLine::ForCurrentProcess(),
760 io_thread()->system_url_request_context_getter());
761 // Creating the component updater does not do anything, components
762 // need to be registered and Start() needs to be called.
763 component_updater_.reset(ComponentUpdateServiceFactory(configurator));
764 }
765 return component_updater_.get();
[email protected]aafbcb572011-08-03 22:22:32766}
[email protected]c1adf5a2011-08-03 22:11:37767
[email protected]ca167a32011-09-30 15:19:11768CRLSetFetcher* BrowserProcessImpl::crl_set_fetcher() {
[email protected]ed304482013-01-04 04:45:32769 if (!crl_set_fetcher_.get())
[email protected]ca167a32011-09-30 15:19:11770 crl_set_fetcher_ = new CRLSetFetcher();
[email protected]ca167a32011-09-30 15:19:11771 return crl_set_fetcher_.get();
[email protected]9f108f22013-04-09 00:39:56772}
773
[email protected]055981f2014-01-17 20:22:32774component_updater::PnaclComponentInstaller*
775BrowserProcessImpl::pnacl_component_installer() {
776 if (!pnacl_component_installer_.get()) {
777 pnacl_component_installer_.reset(
778 new component_updater::PnaclComponentInstaller());
779 }
[email protected]9f108f22013-04-09 00:39:56780 return pnacl_component_installer_.get();
[email protected]ca167a32011-09-30 15:19:11781}
782
[email protected]99907362012-01-11 05:41:40783void BrowserProcessImpl::ResourceDispatcherHostCreated() {
[email protected]8bcdf072011-06-03 16:52:15784 resource_dispatcher_host_delegate_.reset(
[email protected]ea114722012-03-12 01:11:25785 new ChromeResourceDispatcherHostDelegate(prerender_tracker()));
786 ResourceDispatcherHost::Get()->SetDelegate(
787 resource_dispatcher_host_delegate_.get());
[email protected]40850a52011-05-26 22:07:35788
[email protected]cf5a95822012-11-13 14:44:01789 pref_change_registrar_.Add(
790 prefs::kAllowCrossOriginAuthPrompt,
791 base::Bind(&BrowserProcessImpl::ApplyAllowCrossOriginAuthPromptPolicy,
792 base::Unretained(this)));
[email protected]40850a52011-05-26 22:07:35793 ApplyAllowCrossOriginAuthPromptPolicy();
initial.commit09911bf2008-07-26 23:55:29794}
795
796void BrowserProcessImpl::CreateMetricsService() {
797 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
798 created_metrics_service_ = true;
799
800 metrics_service_.reset(new MetricsService);
801}
802
[email protected]0b565182011-03-02 18:11:15803void BrowserProcessImpl::CreateWatchdogThread() {
804 DCHECK(!created_watchdog_thread_ && watchdog_thread_.get() == NULL);
805 created_watchdog_thread_ = true;
806
807 scoped_ptr<WatchDogThread> thread(new WatchDogThread());
808 if (!thread->Start())
809 return;
810 watchdog_thread_.swap(thread);
811}
812
initial.commit09911bf2008-07-26 23:55:29813void BrowserProcessImpl::CreateProfileManager() {
814 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
815 created_profile_manager_ = true;
816
[email protected]650b2d52013-02-10 03:41:45817 base::FilePath user_data_dir;
[email protected]49a25632011-08-31 17:03:48818 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
819 profile_manager_.reset(new ProfileManager(user_data_dir));
initial.commit09911bf2008-07-26 23:55:29820}
821
822void BrowserProcessImpl::CreateLocalState() {
823 DCHECK(!created_local_state_ && local_state_.get() == NULL);
824 created_local_state_ = true;
825
[email protected]650b2d52013-02-10 03:41:45826 base::FilePath local_state_path;
[email protected]0de615a2012-11-08 04:40:59827 CHECK(PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path));
[email protected]b1de2c72013-02-06 02:45:47828 scoped_refptr<PrefRegistrySimple> pref_registry = new PrefRegistrySimple;
[email protected]4082306d92013-02-21 14:51:01829
830 // Register local state preferences.
[email protected]dc24976f2013-06-02 21:15:09831 chrome::RegisterLocalState(pref_registry.get());
[email protected]4082306d92013-02-21 14:51:01832
[email protected]e90a01f2013-11-19 04:22:12833 local_state_ =
[email protected]5b199522012-12-22 17:24:44834 chrome_prefs::CreateLocalState(local_state_path,
[email protected]dc24976f2013-06-02 21:15:09835 local_state_task_runner_.get(),
[email protected]5b199522012-12-22 17:24:44836 policy_service(),
[email protected]b1de2c72013-02-06 02:45:47837 pref_registry,
[email protected]e90a01f2013-11-19 04:22:12838 false).Pass();
[email protected]492d2142010-09-10 13:55:18839
[email protected]2a7e7c152010-10-01 20:12:09840 pref_change_registrar_.Init(local_state_.get());
841
[email protected]e450fa62011-02-01 12:52:56842 // Initialize the notification for the default browser setting policy.
[email protected]cf5a95822012-11-13 14:44:01843 pref_change_registrar_.Add(
844 prefs::kDefaultBrowserSettingEnabled,
845 base::Bind(&BrowserProcessImpl::ApplyDefaultBrowserPolicy,
846 base::Unretained(this)));
[email protected]8b08a47f2011-02-25 12:36:37847
[email protected]459158c2013-11-14 00:25:15848 // This preference must be kept in sync with external values; update them
849 // whenever the preference or its controlling policy changes.
850#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
851 pref_change_registrar_.Add(
852 prefs::kMetricsReportingEnabled,
853 base::Bind(&BrowserProcessImpl::ApplyMetricsReportingPolicy,
854 base::Unretained(this)));
[email protected]459158c2013-11-14 00:25:15855#endif
856
[email protected]12c84e22011-07-11 09:35:45857 int max_per_proxy = local_state_->GetInteger(prefs::kMaxConnectionsPerProxy);
858 net::ClientSocketPoolManager::set_max_sockets_per_proxy_server(
[email protected]a8af2152012-03-21 20:29:52859 net::HttpNetworkSession::NORMAL_SOCKET_POOL,
[email protected]12c84e22011-07-11 09:35:45860 std::max(std::min(max_per_proxy, 99),
[email protected]a8af2152012-03-21 20:29:52861 net::ClientSocketPoolManager::max_sockets_per_group(
862 net::HttpNetworkSession::NORMAL_SOCKET_POOL)));
[email protected]fd6159a2010-09-03 09:38:39863}
initial.commit09911bf2008-07-26 23:55:29864
[email protected]99907362012-01-11 05:41:40865void BrowserProcessImpl::PreCreateThreads() {
[email protected]77305422012-11-29 16:51:39866 io_thread_.reset(new IOThread(local_state(), policy_service(), net_log_.get(),
867 extension_event_router_forwarder_.get()));
[email protected]99907362012-01-11 05:41:40868}
869
[email protected]d2caaa22011-12-12 03:04:15870void BrowserProcessImpl::PreMainMessageLoopRun() {
[email protected]362d694f2013-02-28 09:07:24871#if defined(ENABLE_CONFIGURATION_POLICY)
872 // browser_policy_connector() is created very early because local_state()
873 // needs policy to be initialized with the managed preference values.
874 // However, policy fetches from the network and loading of disk caches
875 // requires that threads are running; this Init() call lets the connector
876 // resume its initialization now that the loops are spinning and the
877 // system request context is available for the fetchers.
878 browser_policy_connector()->Init(local_state(), system_request_context());
879#endif
880
[email protected]0ca957872013-01-03 20:24:04881 if (local_state_->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled))
882 ApplyDefaultBrowserPolicy();
883
[email protected]fc0cd312014-01-13 14:25:54884#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
885 ApplyMetricsReportingPolicy();
886#endif
887
[email protected]ebd71962012-12-20 02:56:55888#if defined(ENABLE_PLUGINS)
[email protected]99907362012-01-11 05:41:40889 PluginService* plugin_service = PluginService::GetInstance();
890 plugin_service->SetFilter(ChromePluginServiceFilter::GetInstance());
891 plugin_service->StartWatchingPlugins();
892
[email protected]99907362012-01-11 05:41:40893#if defined(OS_POSIX)
894 // Also find plugins in a user-specific plugins dir,
895 // e.g. ~/.config/chromium/Plugins.
[email protected]e87ce862013-06-12 17:30:48896 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
897 if (!cmd_line.HasSwitch(switches::kDisablePluginsDiscovery)) {
898 base::FilePath user_data_dir;
899 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
900 plugin_service->AddExtraPluginDir(user_data_dir.Append("Plugins"));
901 }
[email protected]99907362012-01-11 05:41:40902#endif
903
[email protected]de75c702012-09-25 23:06:02904 // Triggers initialization of the singleton instance on UI thread.
905 PluginFinder::GetInstance()->Init();
[email protected]2366a3a2012-10-02 20:41:14906
907#if defined(ENABLE_PLUGIN_INSTALLATION)
[email protected]ed304482013-01-04 04:45:32908 DCHECK(!plugins_resource_service_.get());
909 plugins_resource_service_ = new PluginsResourceService(local_state());
[email protected]97eddfe2013-02-12 19:16:30910 plugins_resource_service_->Init();
[email protected]2366a3a2012-10-02 20:41:14911#endif
[email protected]cd34acd2013-01-04 05:04:49912#endif // defined(ENABLE_PLUGINS)
[email protected]ed304482013-01-04 04:45:32913
914 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
915 if (!command_line.HasSwitch(switches::kDisableWebResources)) {
916 DCHECK(!promo_resource_service_.get());
917 promo_resource_service_ = new PromoResourceService;
918 promo_resource_service_->StartAfterDelay();
919 }
[email protected]195c99c2012-10-31 06:24:51920
921#if !defined(OS_ANDROID)
[email protected]87227592012-11-16 08:41:05922 if (browser_defaults::bookmarks_enabled &&
[email protected]ed304482013-01-04 04:45:32923 BookmarkPromptController::IsEnabled()) {
[email protected]195c99c2012-10-31 06:24:51924 bookmark_prompt_controller_.reset(new BookmarkPromptController());
[email protected]ed304482013-01-04 04:45:32925 }
[email protected]195c99c2012-10-31 06:24:51926#endif
[email protected]acd2121c2013-03-18 05:54:50927
[email protected]8b60ca722013-07-19 01:29:02928#if !defined(OS_ANDROID) && !defined(OS_IOS)
[email protected]7bfe94602014-02-25 10:22:39929 storage_monitor::StorageMonitor::Create();
[email protected]8b60ca722013-07-19 01:29:02930#endif
931
[email protected]90a4b9d2013-07-31 12:14:40932 platform_part_->PreMainMessageLoopRun();
[email protected]d2caaa22011-12-12 03:04:15933}
934
initial.commit09911bf2008-07-26 23:55:29935void BrowserProcessImpl::CreateIconManager() {
936 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
937 created_icon_manager_ = true;
938 icon_manager_.reset(new IconManager);
939}
940
[email protected]c4ff4952010-01-08 19:12:47941void BrowserProcessImpl::CreateIntranetRedirectDetector() {
942 DCHECK(intranet_redirect_detector_.get() == NULL);
943 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
944 new IntranetRedirectDetector);
945 intranet_redirect_detector_.swap(intranet_redirect_detector);
946}
947
[email protected]29672ab2009-10-30 03:44:03948void BrowserProcessImpl::CreateNotificationUIManager() {
[email protected]29cebbd2012-06-06 21:43:42949#if defined(ENABLE_NOTIFICATIONS)
[email protected]29672ab2009-10-30 03:44:03950 DCHECK(notification_ui_manager_.get() == NULL);
[email protected]b0b2a3dd2011-01-06 00:30:05951 notification_ui_manager_.reset(NotificationUIManager::Create(local_state()));
[email protected]29672ab2009-10-30 03:44:03952 created_notification_ui_manager_ = true;
[email protected]29cebbd2012-06-06 21:43:42953#endif
[email protected]29672ab2009-10-30 03:44:03954}
955
[email protected]9e7f015f2011-05-28 00:24:25956void BrowserProcessImpl::CreateBackgroundModeManager() {
957 DCHECK(background_mode_manager_.get() == NULL);
958 background_mode_manager_.reset(
[email protected]279170832011-10-12 23:38:03959 new BackgroundModeManager(CommandLine::ForCurrentProcess(),
960 &profile_manager()->GetProfileInfoCache()));
[email protected]9e7f015f2011-05-28 00:24:25961}
962
963void BrowserProcessImpl::CreateStatusTray() {
964 DCHECK(status_tray_.get() == NULL);
965 status_tray_.reset(StatusTray::Create());
966}
967
[email protected]d8ce31e2012-12-19 05:09:21968void BrowserProcessImpl::CreatePrintPreviewDialogController() {
[email protected]1e54c1c2013-08-12 17:16:05969#if defined(ENABLE_FULL_PRINTING)
[email protected]d8ce31e2012-12-19 05:09:21970 DCHECK(print_preview_dialog_controller_.get() == NULL);
971 print_preview_dialog_controller_ =
972 new printing::PrintPreviewDialogController();
[email protected]658677f2012-06-09 06:04:02973#else
974 NOTIMPLEMENTED();
[email protected]058e5732012-03-01 22:48:03975#endif
[email protected]dbeebd52010-11-16 20:34:16976}
977
[email protected]68f88b992011-05-07 02:01:39978void BrowserProcessImpl::CreateBackgroundPrintingManager() {
[email protected]1e54c1c2013-08-12 17:16:05979#if defined(ENABLE_FULL_PRINTING)
[email protected]68f88b992011-05-07 02:01:39980 DCHECK(background_printing_manager_.get() == NULL);
981 background_printing_manager_.reset(new printing::BackgroundPrintingManager());
[email protected]658677f2012-06-09 06:04:02982#else
983 NOTIMPLEMENTED();
984#endif
[email protected]68f88b992011-05-07 02:01:39985}
986
[email protected]462a0ff2011-06-02 17:15:34987void BrowserProcessImpl::CreateSafeBrowsingService() {
988 DCHECK(safe_browsing_service_.get() == NULL);
[email protected]8c40da62011-07-13 22:58:46989 // Set this flag to true so that we don't retry indefinitely to
990 // create the service class if there was an error.
[email protected]462a0ff2011-06-02 17:15:34991 created_safe_browsing_service_ = true;
[email protected]6c521fed2012-11-29 17:00:03992#if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
[email protected]462a0ff2011-06-02 17:15:34993 safe_browsing_service_ = SafeBrowsingService::CreateSafeBrowsingService();
994 safe_browsing_service_->Initialize();
[email protected]4b58e7d2011-07-11 10:22:56995#endif
[email protected]462a0ff2011-06-02 17:15:34996}
997
[email protected]b61f62a2011-11-01 02:02:10998void BrowserProcessImpl::ApplyDefaultBrowserPolicy() {
[email protected]ed304482013-01-04 04:45:32999 if (local_state()->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) {
[email protected]b61f62a2011-11-01 02:02:101000 scoped_refptr<ShellIntegration::DefaultWebClientWorker>
1001 set_browser_worker = new ShellIntegration::DefaultBrowserWorker(NULL);
1002 set_browser_worker->StartSetAsDefault();
1003 }
1004}
1005
[email protected]40850a52011-05-26 22:07:351006void BrowserProcessImpl::ApplyAllowCrossOriginAuthPromptPolicy() {
1007 bool value = local_state()->GetBoolean(prefs::kAllowCrossOriginAuthPrompt);
[email protected]ea114722012-03-12 01:11:251008 ResourceDispatcherHost::Get()->SetAllowCrossOriginAuthPrompt(value);
[email protected]40850a52011-05-26 22:07:351009}
1010
[email protected]459158c2013-11-14 00:25:151011void BrowserProcessImpl::ApplyMetricsReportingPolicy() {
1012#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
[email protected]fc0cd312014-01-13 14:25:541013 CHECK(BrowserThread::PostTask(
[email protected]a178ed22013-11-17 15:55:391014 BrowserThread::FILE, FROM_HERE,
1015 base::Bind(
1016 base::IgnoreResult(&GoogleUpdateSettings::SetCollectStatsConsent),
[email protected]fc0cd312014-01-13 14:25:541017 local_state()->GetBoolean(prefs::kMetricsReportingEnabled))));
[email protected]459158c2013-11-14 00:25:151018#endif
1019}
1020
[email protected]3cdacd42010-04-30 18:55:531021// Mac is currently not supported.
1022#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:421023
1024bool BrowserProcessImpl::CanAutorestartForUpdate() const {
1025 // Check if browser is in the background and if it needs to be restarted to
1026 // apply a pending update.
[email protected]0665ebe2013-02-13 09:53:191027 return chrome::GetTotalBrowserCount() == 0 && chrome::WillKeepAlive() &&
[email protected]815856722011-04-13 17:19:191028 upgrade_util::IsUpdatePendingRestart();
[email protected]bd48c2b02010-04-09 20:32:421029}
1030
[email protected]5c08f222010-09-22 09:37:211031// Switches to add when auto-restarting Chrome.
[email protected]6c10c972010-08-11 04:15:471032const char* const kSwitchesToAddOnAutorestart[] = {
[email protected]f9a06842010-08-21 00:32:401033 switches::kNoStartupWindow
[email protected]bd48c2b02010-04-09 20:32:421034};
1035
[email protected]f6e6d2e2011-10-28 18:39:221036void BrowserProcessImpl::RestartBackgroundInstance() {
[email protected]bd48c2b02010-04-09 20:32:421037 CommandLine* old_cl = CommandLine::ForCurrentProcess();
[email protected]3cdacd42010-04-30 18:55:531038 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram()));
[email protected]bd48c2b02010-04-09 20:32:421039
1040 std::map<std::string, CommandLine::StringType> switches =
1041 old_cl->GetSwitches();
1042
[email protected]5c08f222010-09-22 09:37:211043 switches::RemoveSwitchesForAutostart(&switches);
[email protected]bd48c2b02010-04-09 20:32:421044
1045 // Append the rest of the switches (along with their values, if any)
1046 // to the new command line
1047 for (std::map<std::string, CommandLine::StringType>::const_iterator i =
1048 switches.begin(); i != switches.end(); ++i) {
1049 CommandLine::StringType switch_value = i->second;
1050 if (switch_value.length() > 0) {
[email protected]05076ba22010-07-30 05:59:571051 new_cl->AppendSwitchNative(i->first, i->second);
[email protected]bd48c2b02010-04-09 20:32:421052 } else {
[email protected]3cdacd42010-04-30 18:55:531053 new_cl->AppendSwitch(i->first);
[email protected]bd48c2b02010-04-09 20:32:421054 }
1055 }
1056
[email protected]6c10c972010-08-11 04:15:471057 // Ensure that our desired switches are set on the new process.
[email protected]5c08f222010-09-22 09:37:211058 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) {
[email protected]6c10c972010-08-11 04:15:471059 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i]))
1060 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
1061 }
[email protected]bd48c2b02010-04-09 20:32:421062
[email protected]3cdacd42010-04-30 18:55:531063 DLOG(WARNING) << "Shutting down current instance of the browser.";
[email protected]0c98ab652013-02-18 00:39:371064 chrome::AttemptExit();
[email protected]3cdacd42010-04-30 18:55:531065
1066 // Transfer ownership to Upgrade.
[email protected]815856722011-04-13 17:19:191067 upgrade_util::SetNewCommandLine(new_cl.release());
[email protected]bd48c2b02010-04-09 20:32:421068}
1069
1070void BrowserProcessImpl::OnAutoupdateTimer() {
1071 if (CanAutorestartForUpdate()) {
[email protected]3cdacd42010-04-30 18:55:531072 DLOG(WARNING) << "Detected update. Restarting browser.";
[email protected]f6e6d2e2011-10-28 18:39:221073 RestartBackgroundInstance();
[email protected]bd48c2b02010-04-09 20:32:421074 }
1075}
1076
[email protected]3cdacd42010-04-30 18:55:531077#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)