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 PromoResourceService
* promo_resource_service() override
;
90 BrowserProcessPlatformPart
* platform_part() override
;
91 extensions::EventRouterForwarder
* extension_event_router_forwarder() override
;
92 NotificationUIManager
* notification_ui_manager() override
;
93 message_center::MessageCenter
* message_center() override
;
94 policy::BrowserPolicyConnector
* browser_policy_connector() override
;
95 policy::PolicyService
* policy_service() override
;
96 IconManager
* icon_manager() override
;
97 GLStringManager
* gl_string_manager() override
;
98 GpuModeManager
* gpu_mode_manager() override
;
99 void CreateDevToolsHttpProtocolHandler(
100 chrome::HostDesktopType host_desktop_type
,
101 const std::string
& ip
,
102 uint16 port
) override
;
103 unsigned int AddRefModule() override
;
104 unsigned int ReleaseModule() override
;
105 bool IsShuttingDown() override
;
106 printing::PrintJobManager
* print_job_manager() override
;
107 printing::PrintPreviewDialogController
* print_preview_dialog_controller()
109 printing::BackgroundPrintingManager
* background_printing_manager() override
;
110 IntranetRedirectDetector
* intranet_redirect_detector() override
;
111 const std::string
& GetApplicationLocale() override
;
112 void SetApplicationLocale(const std::string
& locale
) override
;
113 DownloadStatusUpdater
* download_status_updater() override
;
114 DownloadRequestLimiter
* download_request_limiter() override
;
115 BackgroundModeManager
* background_mode_manager() override
;
116 void set_background_mode_manager_for_test(
117 scoped_ptr
<BackgroundModeManager
> manager
) override
;
118 StatusTray
* status_tray() override
;
119 SafeBrowsingService
* safe_browsing_service() override
;
120 safe_browsing::ClientSideDetectionService
* safe_browsing_detection_service()
123 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
124 void StartAutoupdateTimer() override
;
127 ChromeNetLog
* net_log() 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 scoped_ptr
<ChromeResourceDispatcherHostDelegate
>
257 resource_dispatcher_host_delegate_
;
259 scoped_ptr
<PromoResourceService
> promo_resource_service_
;
261 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
262 base::RepeatingTimer
<BrowserProcessImpl
> autoupdate_timer_
;
264 // Gets called by autoupdate timer to see if browser needs restart and can be
265 // restarted, and if that's the case, restarts the browser.
266 void OnAutoupdateTimer();
267 bool CanAutorestartForUpdate() const;
268 void RestartBackgroundInstance();
269 #endif // defined(OS_WIN) || defined(OS_LINUX) && !defined(OS_CHROMEOS)
271 // component updater is normally not used under ChromeOS due
272 // to concerns over integrity of data shared between profiles,
273 // but some users of component updater only install per-user.
274 scoped_ptr
<component_updater::ComponentUpdateService
> component_updater_
;
275 scoped_refptr
<CRLSetFetcher
> crl_set_fetcher_
;
277 #if !defined(DISABLE_NACL)
278 scoped_refptr
<component_updater::PnaclComponentInstaller
>
279 pnacl_component_installer_
;
282 scoped_ptr
<component_updater::SupervisedUserWhitelistInstaller
>
283 supervised_user_whitelist_installer_
;
285 #if defined(ENABLE_PLUGIN_INSTALLATION)
286 scoped_ptr
<PluginsResourceService
> plugins_resource_service_
;
289 scoped_ptr
<BrowserProcessPlatformPart
> platform_part_
;
291 // TODO(eroman): Remove this when done debugging 113031. This tracks
292 // the callstack which released the final module reference count.
293 base::debug::StackTrace release_last_reference_callstack_
;
295 #if defined(ENABLE_WEBRTC)
296 // Lazily initialized.
297 scoped_ptr
<WebRtcLogUploader
> webrtc_log_uploader_
;
300 scoped_ptr
<network_time::NetworkTimeTracker
> network_time_tracker_
;
302 scoped_ptr
<gcm::GCMDriver
> gcm_driver_
;
304 #if !defined(OS_ANDROID)
305 scoped_ptr
<ChromeDeviceClient
> device_client_
;
308 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl
);
311 #endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_