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 ChromeChildProcessWatcher
;
25 class ChromeDeviceClient
;
26 class ChromeResourceDispatcherHostDelegate
;
27 class RemoteDebuggingServer
;
28 class PrefRegistrySimple
;
30 #if defined(ENABLE_PLUGIN_INSTALLATION)
31 class PluginsResourceService
;
36 class SequencedTaskRunner
;
39 namespace extensions
{
40 class ExtensionsBrowserClient
;
52 class BrowserPolicyConnector
;
56 namespace web_resource
{
57 class PromoResourceService
;
60 // Real implementation of BrowserProcess that creates and returns the services.
61 class BrowserProcessImpl
: public BrowserProcess
,
62 public base::NonThreadSafe
{
64 // |local_state_task_runner| must be a shutdown-blocking task runner.
65 BrowserProcessImpl(base::SequencedTaskRunner
* local_state_task_runner
,
66 const base::CommandLine
& command_line
);
67 ~BrowserProcessImpl() override
;
69 // Called before the browser threads are created.
70 void PreCreateThreads();
72 // Called after the threads have been created but before the message loops
73 // starts running. Allows the browser process to do any initialization that
74 // requires all threads running.
75 void PreMainMessageLoopRun();
77 // Most cleanup is done by these functions, driven from
78 // ChromeBrowserMain based on notifications from the content
79 // framework, rather than in the destructor, so that we can
80 // interleave cleanup with threads being stopped.
82 void PostDestroyThreads();
84 // BrowserProcess implementation.
85 void ResourceDispatcherHostCreated() override
;
86 void EndSession() override
;
87 MetricsServicesManager
* GetMetricsServicesManager() override
;
88 metrics::MetricsService
* metrics_service() override
;
89 rappor::RapporService
* rappor_service() override
;
90 IOThread
* io_thread() override
;
91 WatchDogThread
* watchdog_thread() override
;
92 ProfileManager
* profile_manager() override
;
93 PrefService
* local_state() override
;
94 net::URLRequestContextGetter
* system_request_context() override
;
95 variations::VariationsService
* variations_service() override
;
96 web_resource::PromoResourceService
* promo_resource_service() override
;
97 BrowserProcessPlatformPart
* platform_part() override
;
98 extensions::EventRouterForwarder
* extension_event_router_forwarder() override
;
99 NotificationUIManager
* notification_ui_manager() override
;
100 message_center::MessageCenter
* message_center() override
;
101 policy::BrowserPolicyConnector
* browser_policy_connector() override
;
102 policy::PolicyService
* policy_service() override
;
103 IconManager
* icon_manager() override
;
104 GLStringManager
* gl_string_manager() override
;
105 GpuModeManager
* gpu_mode_manager() override
;
106 void CreateDevToolsHttpProtocolHandler(
107 chrome::HostDesktopType host_desktop_type
,
108 const std::string
& ip
,
109 uint16 port
) override
;
110 unsigned int AddRefModule() override
;
111 unsigned int ReleaseModule() override
;
112 bool IsShuttingDown() override
;
113 printing::PrintJobManager
* print_job_manager() override
;
114 printing::PrintPreviewDialogController
* print_preview_dialog_controller()
116 printing::BackgroundPrintingManager
* background_printing_manager() override
;
117 IntranetRedirectDetector
* intranet_redirect_detector() override
;
118 const std::string
& GetApplicationLocale() override
;
119 void SetApplicationLocale(const std::string
& locale
) override
;
120 DownloadStatusUpdater
* download_status_updater() override
;
121 DownloadRequestLimiter
* download_request_limiter() override
;
122 BackgroundModeManager
* background_mode_manager() override
;
123 void set_background_mode_manager_for_test(
124 scoped_ptr
<BackgroundModeManager
> manager
) override
;
125 StatusTray
* status_tray() override
;
126 SafeBrowsingService
* safe_browsing_service() override
;
127 safe_browsing::ClientSideDetectionService
* safe_browsing_detection_service()
130 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
131 void StartAutoupdateTimer() override
;
134 net_log::ChromeNetLog
* net_log() override
;
135 component_updater::ComponentUpdateService
* component_updater() override
;
136 CRLSetFetcher
* crl_set_fetcher() override
;
137 component_updater::PnaclComponentInstaller
* pnacl_component_installer()
139 component_updater::SupervisedUserWhitelistInstaller
*
140 supervised_user_whitelist_installer() override
;
141 MediaFileSystemRegistry
* media_file_system_registry() override
;
142 bool created_local_state() const override
;
143 #if defined(ENABLE_WEBRTC)
144 WebRtcLogUploader
* webrtc_log_uploader() override
;
146 network_time::NetworkTimeTracker
* network_time_tracker() override
;
147 gcm::GCMDriver
* gcm_driver() override
;
148 memory::OomPriorityManager
* GetOomPriorityManager() override
;
149 ShellIntegration::DefaultWebClientState
CachedDefaultWebClientState()
152 static void RegisterPrefs(PrefRegistrySimple
* registry
);
155 void CreateWatchdogThread();
156 void CreateProfileManager();
157 void CreateLocalState();
158 void CreateViewedPageTracker();
159 void CreateIconManager();
160 void CreateIntranetRedirectDetector();
161 void CreateNotificationUIManager();
162 void CreateStatusTrayManager();
163 void CreatePrintPreviewDialogController();
164 void CreateBackgroundPrintingManager();
165 void CreateSafeBrowsingService();
166 void CreateSafeBrowsingDetectionService();
167 void CreateStatusTray();
168 void CreateBackgroundModeManager();
169 void CreateGCMDriver();
171 void ApplyAllowCrossOriginAuthPromptPolicy();
172 void ApplyDefaultBrowserPolicy();
173 void ApplyMetricsReportingPolicy();
175 void CacheDefaultWebClientState();
177 scoped_ptr
<MetricsServicesManager
> metrics_services_manager_
;
179 scoped_ptr
<IOThread
> io_thread_
;
181 bool created_watchdog_thread_
;
182 scoped_ptr
<WatchDogThread
> watchdog_thread_
;
184 bool created_browser_policy_connector_
;
185 #if defined(ENABLE_CONFIGURATION_POLICY)
186 // Must be destroyed after |local_state_|.
187 scoped_ptr
<policy::BrowserPolicyConnector
> browser_policy_connector_
;
189 // Must be destroyed after |local_state_|.
190 // This is a stub when policy is not enabled. Otherwise, the PolicyService
191 // is owned by the |browser_policy_connector_| and this is not used.
192 scoped_ptr
<policy::PolicyService
> policy_service_
;
195 bool created_profile_manager_
;
196 scoped_ptr
<ProfileManager
> profile_manager_
;
198 bool created_local_state_
;
199 scoped_ptr
<PrefService
> local_state_
;
201 bool created_icon_manager_
;
202 scoped_ptr
<IconManager
> icon_manager_
;
204 scoped_ptr
<GLStringManager
> gl_string_manager_
;
206 scoped_ptr
<GpuModeManager
> gpu_mode_manager_
;
208 #if defined(ENABLE_EXTENSIONS)
209 scoped_ptr
<extensions::ExtensionsBrowserClient
> extensions_browser_client_
;
211 scoped_refptr
<extensions::EventRouterForwarder
>
212 extension_event_router_forwarder_
;
214 scoped_ptr
<MediaFileSystemRegistry
> media_file_system_registry_
;
217 #if !defined(OS_ANDROID)
218 scoped_ptr
<RemoteDebuggingServer
> remote_debugging_server_
;
221 #if defined(ENABLE_PRINT_PREVIEW)
222 scoped_refptr
<printing::PrintPreviewDialogController
>
223 print_preview_dialog_controller_
;
225 scoped_ptr
<printing::BackgroundPrintingManager
> background_printing_manager_
;
228 // Manager for desktop notification UI.
229 bool created_notification_ui_manager_
;
230 scoped_ptr
<NotificationUIManager
> notification_ui_manager_
;
232 scoped_ptr
<IntranetRedirectDetector
> intranet_redirect_detector_
;
234 scoped_ptr
<StatusTray
> status_tray_
;
236 #if defined(ENABLE_BACKGROUND)
237 scoped_ptr
<BackgroundModeManager
> background_mode_manager_
;
240 bool created_safe_browsing_service_
;
241 scoped_refptr
<SafeBrowsingService
> safe_browsing_service_
;
243 unsigned int module_ref_count_
;
246 // Ensures that all the print jobs are finished before closing the browser.
247 scoped_ptr
<printing::PrintJobManager
> print_job_manager_
;
251 // Download status updates (like a changing application icon on dock/taskbar)
252 // are global per-application. DownloadStatusUpdater does no work in the ctor
253 // so we don't have to worry about lazy initialization.
254 scoped_ptr
<DownloadStatusUpdater
> download_status_updater_
;
256 scoped_refptr
<DownloadRequestLimiter
> download_request_limiter_
;
258 // Sequenced task runner for local state related I/O tasks.
259 const scoped_refptr
<base::SequencedTaskRunner
> local_state_task_runner_
;
261 // Ensures that the observers of plugin/print disable/enable state
262 // notifications are properly added and removed.
263 PrefChangeRegistrar pref_change_registrar_
;
265 // Lives here so can safely log events on shutdown.
266 scoped_ptr
<net_log::ChromeNetLog
> net_log_
;
268 scoped_ptr
<ChromeResourceDispatcherHostDelegate
>
269 resource_dispatcher_host_delegate_
;
271 scoped_ptr
<web_resource::PromoResourceService
> promo_resource_service_
;
273 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
274 base::RepeatingTimer
<BrowserProcessImpl
> autoupdate_timer_
;
276 // Gets called by autoupdate timer to see if browser needs restart and can be
277 // restarted, and if that's the case, restarts the browser.
278 void OnAutoupdateTimer();
279 bool CanAutorestartForUpdate() const;
280 void RestartBackgroundInstance();
281 #endif // defined(OS_WIN) || defined(OS_LINUX) && !defined(OS_CHROMEOS)
283 // component updater is normally not used under ChromeOS due
284 // to concerns over integrity of data shared between profiles,
285 // but some users of component updater only install per-user.
286 scoped_ptr
<component_updater::ComponentUpdateService
> component_updater_
;
287 scoped_refptr
<CRLSetFetcher
> crl_set_fetcher_
;
289 #if !defined(DISABLE_NACL)
290 scoped_refptr
<component_updater::PnaclComponentInstaller
>
291 pnacl_component_installer_
;
294 scoped_ptr
<component_updater::SupervisedUserWhitelistInstaller
>
295 supervised_user_whitelist_installer_
;
297 #if defined(ENABLE_PLUGIN_INSTALLATION)
298 scoped_ptr
<PluginsResourceService
> plugins_resource_service_
;
301 scoped_ptr
<BrowserProcessPlatformPart
> platform_part_
;
303 // TODO(eroman): Remove this when done debugging 113031. This tracks
304 // the callstack which released the final module reference count.
305 base::debug::StackTrace release_last_reference_callstack_
;
307 #if defined(ENABLE_WEBRTC)
308 // Lazily initialized.
309 scoped_ptr
<WebRtcLogUploader
> webrtc_log_uploader_
;
312 scoped_ptr
<network_time::NetworkTimeTracker
> network_time_tracker_
;
314 scoped_ptr
<gcm::GCMDriver
> gcm_driver_
;
316 scoped_ptr
<ChromeChildProcessWatcher
> child_process_watcher_
;
318 #if !defined(OS_ANDROID)
319 scoped_ptr
<ChromeDeviceClient
> device_client_
;
322 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
323 // Any change to this #ifdef must be reflected as well in
324 // chrome/browser/memory/oom_priority_manager_browsertest.cc
325 scoped_ptr
<memory::OomPriorityManager
> oom_priority_manager_
;
328 ShellIntegration::DefaultWebClientState cached_default_web_client_state_
;
330 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl
);
333 #endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_