1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // When each service is created, we set a flag indicating this. At this point,
6 // the service initialization could fail or succeed. This allows us to remember
7 // if we tried to create a service, and not try creating it over and over if
8 // the creation failed.
10 #ifndef CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_
11 #define CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_
15 #include "base/basictypes.h"
16 #include "base/debug/stack_trace.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/prefs/pref_change_registrar.h"
20 #include "base/threading/non_thread_safe.h"
21 #include "base/timer/timer.h"
22 #include "chrome/browser/browser_process.h"
24 class ChromeDeviceClient
;
26 class ChromeResourceDispatcherHostDelegate
;
27 class RemoteDebuggingServer
;
28 class PrefRegistrySimple
;
29 class PromoResourceService
;
31 #if defined(ENABLE_PLUGIN_INSTALLATION)
32 class PluginsResourceService
;
37 class SequencedTaskRunner
;
40 namespace extensions
{
41 class ExtensionsBrowserClient
;
49 class BrowserPolicyConnector
;
53 // Real implementation of BrowserProcess that creates and returns the services.
54 class BrowserProcessImpl
: public BrowserProcess
,
55 public base::NonThreadSafe
{
57 // |local_state_task_runner| must be a shutdown-blocking task runner.
58 BrowserProcessImpl(base::SequencedTaskRunner
* local_state_task_runner
,
59 const base::CommandLine
& command_line
);
60 ~BrowserProcessImpl() override
;
62 // Called before the browser threads are created.
63 void PreCreateThreads();
65 // Called after the threads have been created but before the message loops
66 // starts running. Allows the browser process to do any initialization that
67 // requires all threads running.
68 void PreMainMessageLoopRun();
70 // Most cleanup is done by these functions, driven from
71 // ChromeBrowserMain based on notifications from the content
72 // framework, rather than in the destructor, so that we can
73 // interleave cleanup with threads being stopped.
75 void PostDestroyThreads();
77 // BrowserProcess implementation.
78 void ResourceDispatcherHostCreated() override
;
79 void EndSession() override
;
80 MetricsServicesManager
* GetMetricsServicesManager() override
;
81 metrics::MetricsService
* metrics_service() override
;
82 rappor::RapporService
* rappor_service() override
;
83 IOThread
* io_thread() override
;
84 WatchDogThread
* watchdog_thread() override
;
85 ProfileManager
* profile_manager() override
;
86 PrefService
* local_state() override
;
87 net::URLRequestContextGetter
* system_request_context() override
;
88 chrome_variations::VariationsService
* variations_service() override
;
89 BrowserProcessPlatformPart
* platform_part() override
;
90 extensions::EventRouterForwarder
* extension_event_router_forwarder() override
;
91 NotificationUIManager
* notification_ui_manager() override
;
92 message_center::MessageCenter
* message_center() override
;
93 policy::BrowserPolicyConnector
* browser_policy_connector() override
;
94 policy::PolicyService
* policy_service() override
;
95 IconManager
* icon_manager() override
;
96 GLStringManager
* gl_string_manager() override
;
97 GpuModeManager
* gpu_mode_manager() override
;
98 void CreateDevToolsHttpProtocolHandler(
99 chrome::HostDesktopType host_desktop_type
,
100 const std::string
& ip
,
101 uint16 port
) override
;
102 unsigned int AddRefModule() override
;
103 unsigned int ReleaseModule() override
;
104 bool IsShuttingDown() override
;
105 printing::PrintJobManager
* print_job_manager() override
;
106 printing::PrintPreviewDialogController
* print_preview_dialog_controller()
108 printing::BackgroundPrintingManager
* background_printing_manager() override
;
109 IntranetRedirectDetector
* intranet_redirect_detector() override
;
110 const std::string
& GetApplicationLocale() override
;
111 void SetApplicationLocale(const std::string
& locale
) override
;
112 DownloadStatusUpdater
* download_status_updater() override
;
113 DownloadRequestLimiter
* download_request_limiter() override
;
114 BackgroundModeManager
* background_mode_manager() override
;
115 void set_background_mode_manager_for_test(
116 scoped_ptr
<BackgroundModeManager
> manager
) override
;
117 StatusTray
* status_tray() override
;
118 SafeBrowsingService
* safe_browsing_service() override
;
119 safe_browsing::ClientSideDetectionService
* safe_browsing_detection_service()
122 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
123 void StartAutoupdateTimer() override
;
126 ChromeNetLog
* net_log() override
;
127 prerender::PrerenderTracker
* prerender_tracker() override
;
128 component_updater::ComponentUpdateService
* component_updater() override
;
129 CRLSetFetcher
* crl_set_fetcher() override
;
130 component_updater::PnaclComponentInstaller
* pnacl_component_installer()
132 component_updater::SupervisedUserWhitelistInstaller
*
133 supervised_user_whitelist_installer() override
;
134 MediaFileSystemRegistry
* media_file_system_registry() override
;
135 bool created_local_state() const override
;
136 #if defined(ENABLE_WEBRTC)
137 WebRtcLogUploader
* webrtc_log_uploader() override
;
139 network_time::NetworkTimeTracker
* network_time_tracker() override
;
140 gcm::GCMDriver
* gcm_driver() override
;
142 static void RegisterPrefs(PrefRegistrySimple
* registry
);
145 void CreateWatchdogThread();
146 void CreateProfileManager();
147 void CreateLocalState();
148 void CreateViewedPageTracker();
149 void CreateIconManager();
150 void CreateIntranetRedirectDetector();
151 void CreateNotificationUIManager();
152 void CreateStatusTrayManager();
153 void CreatePrintPreviewDialogController();
154 void CreateBackgroundPrintingManager();
155 void CreateSafeBrowsingService();
156 void CreateSafeBrowsingDetectionService();
157 void CreateStatusTray();
158 void CreateBackgroundModeManager();
159 void CreateGCMDriver();
161 void ApplyAllowCrossOriginAuthPromptPolicy();
162 void ApplyDefaultBrowserPolicy();
163 void ApplyMetricsReportingPolicy();
165 scoped_ptr
<MetricsServicesManager
> metrics_services_manager_
;
167 scoped_ptr
<IOThread
> io_thread_
;
169 bool created_watchdog_thread_
;
170 scoped_ptr
<WatchDogThread
> watchdog_thread_
;
172 bool created_browser_policy_connector_
;
173 #if defined(ENABLE_CONFIGURATION_POLICY)
174 // Must be destroyed after |local_state_|.
175 scoped_ptr
<policy::BrowserPolicyConnector
> browser_policy_connector_
;
177 // Must be destroyed after |local_state_|.
178 // This is a stub when policy is not enabled. Otherwise, the PolicyService
179 // is owned by the |browser_policy_connector_| and this is not used.
180 scoped_ptr
<policy::PolicyService
> policy_service_
;
183 bool created_profile_manager_
;
184 scoped_ptr
<ProfileManager
> profile_manager_
;
186 bool created_local_state_
;
187 scoped_ptr
<PrefService
> local_state_
;
189 bool created_icon_manager_
;
190 scoped_ptr
<IconManager
> icon_manager_
;
192 scoped_ptr
<GLStringManager
> gl_string_manager_
;
194 scoped_ptr
<GpuModeManager
> gpu_mode_manager_
;
196 #if defined(ENABLE_EXTENSIONS)
197 scoped_ptr
<extensions::ExtensionsBrowserClient
> extensions_browser_client_
;
199 scoped_refptr
<extensions::EventRouterForwarder
>
200 extension_event_router_forwarder_
;
202 scoped_ptr
<MediaFileSystemRegistry
> media_file_system_registry_
;
205 #if !defined(OS_ANDROID)
206 scoped_ptr
<RemoteDebuggingServer
> remote_debugging_server_
;
209 #if defined(ENABLE_PRINT_PREVIEW)
210 scoped_refptr
<printing::PrintPreviewDialogController
>
211 print_preview_dialog_controller_
;
213 scoped_ptr
<printing::BackgroundPrintingManager
> background_printing_manager_
;
216 // Manager for desktop notification UI.
217 bool created_notification_ui_manager_
;
218 scoped_ptr
<NotificationUIManager
> notification_ui_manager_
;
220 scoped_ptr
<IntranetRedirectDetector
> intranet_redirect_detector_
;
222 scoped_ptr
<StatusTray
> status_tray_
;
224 #if defined(ENABLE_BACKGROUND)
225 scoped_ptr
<BackgroundModeManager
> background_mode_manager_
;
228 bool created_safe_browsing_service_
;
229 scoped_refptr
<SafeBrowsingService
> safe_browsing_service_
;
231 unsigned int module_ref_count_
;
234 // Ensures that all the print jobs are finished before closing the browser.
235 scoped_ptr
<printing::PrintJobManager
> print_job_manager_
;
239 // Download status updates (like a changing application icon on dock/taskbar)
240 // are global per-application. DownloadStatusUpdater does no work in the ctor
241 // so we don't have to worry about lazy initialization.
242 scoped_ptr
<DownloadStatusUpdater
> download_status_updater_
;
244 scoped_refptr
<DownloadRequestLimiter
> download_request_limiter_
;
246 // Sequenced task runner for local state related I/O tasks.
247 const scoped_refptr
<base::SequencedTaskRunner
> local_state_task_runner_
;
249 // Ensures that the observers of plugin/print disable/enable state
250 // notifications are properly added and removed.
251 PrefChangeRegistrar pref_change_registrar_
;
253 // Lives here so can safely log events on shutdown.
254 scoped_ptr
<ChromeNetLog
> net_log_
;
256 // Ordered before resource_dispatcher_host_delegate_ due to destruction
258 scoped_ptr
<prerender::PrerenderTracker
> prerender_tracker_
;
260 scoped_ptr
<ChromeResourceDispatcherHostDelegate
>
261 resource_dispatcher_host_delegate_
;
263 scoped_ptr
<PromoResourceService
> promo_resource_service_
;
265 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
266 base::RepeatingTimer
<BrowserProcessImpl
> autoupdate_timer_
;
268 // Gets called by autoupdate timer to see if browser needs restart and can be
269 // restarted, and if that's the case, restarts the browser.
270 void OnAutoupdateTimer();
271 bool CanAutorestartForUpdate() const;
272 void RestartBackgroundInstance();
273 #endif // defined(OS_WIN) || defined(OS_LINUX) && !defined(OS_CHROMEOS)
275 // component updater is normally not used under ChromeOS due
276 // to concerns over integrity of data shared between profiles,
277 // but some users of component updater only install per-user.
278 scoped_ptr
<component_updater::ComponentUpdateService
> component_updater_
;
279 scoped_refptr
<CRLSetFetcher
> crl_set_fetcher_
;
281 #if !defined(DISABLE_NACL)
282 scoped_refptr
<component_updater::PnaclComponentInstaller
>
283 pnacl_component_installer_
;
286 scoped_ptr
<component_updater::SupervisedUserWhitelistInstaller
>
287 supervised_user_whitelist_installer_
;
289 #if defined(ENABLE_PLUGIN_INSTALLATION)
290 scoped_ptr
<PluginsResourceService
> plugins_resource_service_
;
293 scoped_ptr
<BrowserProcessPlatformPart
> platform_part_
;
295 // TODO(eroman): Remove this when done debugging 113031. This tracks
296 // the callstack which released the final module reference count.
297 base::debug::StackTrace release_last_reference_callstack_
;
299 #if defined(ENABLE_WEBRTC)
300 // Lazily initialized.
301 scoped_ptr
<WebRtcLogUploader
> webrtc_log_uploader_
;
304 scoped_ptr
<network_time::NetworkTimeTracker
> network_time_tracker_
;
306 scoped_ptr
<gcm::GCMDriver
> gcm_driver_
;
308 #if !defined(OS_ANDROID)
309 scoped_ptr
<ChromeDeviceClient
> device_client_
;
312 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl
);
315 #endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_