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.h"
22 #include "chrome/browser/browser_process.h"
25 class ChromeResourceDispatcherHostDelegate
;
27 class RemoteDebuggingServer
;
28 class PrefRegistrySimple
;
29 class PromoResourceService
;
31 #if defined(ENABLE_PLUGIN_INSTALLATION)
32 class PluginsResourceService
;
36 class SequencedTaskRunner
;
40 class BrowserPolicyConnector
;
44 #if defined(OS_WIN) && defined(USE_AURA)
45 class MetroViewerProcessHost
;
48 #if defined(OS_MACOSX)
49 class AppShimHostManager
;
52 // Real implementation of BrowserProcess that creates and returns the services.
53 class BrowserProcessImpl
: public BrowserProcess
,
54 public base::NonThreadSafe
{
56 // |local_state_task_runner| must be a shutdown-blocking task runner.
57 BrowserProcessImpl(base::SequencedTaskRunner
* local_state_task_runner
,
58 const CommandLine
& command_line
);
59 virtual ~BrowserProcessImpl();
61 // Called before the browser threads are created.
62 void PreCreateThreads();
64 // Called after the threads have been created but before the message loops
65 // starts running. Allows the browser process to do any initialization that
66 // requires all threads running.
67 void PreMainMessageLoopRun();
69 // Most cleanup is done by these functions, driven from
70 // ChromeBrowserMain based on notifications from the content
71 // framework, rather than in the destructor, so that we can
72 // interleave cleanup with threads being stopped.
74 void PostDestroyThreads();
76 // BrowserProcess implementation.
77 virtual void ResourceDispatcherHostCreated() OVERRIDE
;
78 virtual void EndSession() OVERRIDE
;
79 virtual MetricsService
* metrics_service() OVERRIDE
;
80 virtual IOThread
* io_thread() OVERRIDE
;
81 virtual WatchDogThread
* watchdog_thread() OVERRIDE
;
82 virtual ProfileManager
* profile_manager() OVERRIDE
;
83 virtual PrefService
* local_state() OVERRIDE
;
84 virtual net::URLRequestContextGetter
* system_request_context() OVERRIDE
;
85 virtual chrome_variations::VariationsService
* variations_service() OVERRIDE
;
86 #if defined(OS_CHROMEOS)
87 virtual chromeos::OomPriorityManager
* oom_priority_manager() OVERRIDE
;
88 #endif // defined(OS_CHROMEOS)
89 virtual extensions::EventRouterForwarder
*
90 extension_event_router_forwarder() OVERRIDE
;
91 virtual NotificationUIManager
* notification_ui_manager() OVERRIDE
;
92 #if defined(ENABLE_MESSAGE_CENTER)
93 virtual message_center::MessageCenter
* message_center() OVERRIDE
;
95 virtual policy::BrowserPolicyConnector
* browser_policy_connector() OVERRIDE
;
96 virtual policy::PolicyService
* policy_service() OVERRIDE
;
97 virtual IconManager
* icon_manager() OVERRIDE
;
98 virtual GLStringManager
* gl_string_manager() OVERRIDE
;
99 virtual GpuModeManager
* gpu_mode_manager() OVERRIDE
;
100 virtual RenderWidgetSnapshotTaker
* GetRenderWidgetSnapshotTaker() OVERRIDE
;
101 virtual AutomationProviderList
* GetAutomationProviderList() OVERRIDE
;
102 virtual void CreateDevToolsHttpProtocolHandler(
104 chrome::HostDesktopType host_desktop_type
,
105 const std::string
& ip
,
107 const std::string
& frontend_url
) OVERRIDE
;
108 virtual unsigned int AddRefModule() OVERRIDE
;
109 virtual unsigned int ReleaseModule() OVERRIDE
;
110 virtual bool IsShuttingDown() OVERRIDE
;
111 virtual printing::PrintJobManager
* print_job_manager() OVERRIDE
;
112 virtual printing::PrintPreviewDialogController
*
113 print_preview_dialog_controller() OVERRIDE
;
114 virtual printing::BackgroundPrintingManager
*
115 background_printing_manager() OVERRIDE
;
116 virtual IntranetRedirectDetector
* intranet_redirect_detector() OVERRIDE
;
117 virtual const std::string
& GetApplicationLocale() OVERRIDE
;
118 virtual void SetApplicationLocale(const std::string
& locale
) OVERRIDE
;
119 virtual DownloadStatusUpdater
* download_status_updater() OVERRIDE
;
120 virtual DownloadRequestLimiter
* download_request_limiter() OVERRIDE
;
121 virtual BackgroundModeManager
* background_mode_manager() OVERRIDE
;
122 virtual StatusTray
* status_tray() OVERRIDE
;
123 virtual SafeBrowsingService
* safe_browsing_service() OVERRIDE
;
124 virtual safe_browsing::ClientSideDetectionService
*
125 safe_browsing_detection_service() OVERRIDE
;
127 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
128 virtual void StartAutoupdateTimer() OVERRIDE
;
131 virtual ChromeNetLog
* net_log() OVERRIDE
;
132 virtual prerender::PrerenderTracker
* prerender_tracker() OVERRIDE
;
133 virtual ComponentUpdateService
* component_updater() OVERRIDE
;
134 virtual CRLSetFetcher
* crl_set_fetcher() OVERRIDE
;
135 virtual PnaclComponentInstaller
* pnacl_component_installer() OVERRIDE
;
136 virtual BookmarkPromptController
* bookmark_prompt_controller() OVERRIDE
;
137 virtual chrome::MediaFileSystemRegistry
*
138 media_file_system_registry() OVERRIDE
;
139 virtual void PlatformSpecificCommandLineProcessing(
140 const CommandLine
& command_line
) OVERRIDE
;
141 virtual bool created_local_state() const OVERRIDE
;
143 static void RegisterPrefs(PrefRegistrySimple
* registry
);
146 void CreateMetricsService();
147 void CreateWatchdogThread();
148 #if defined(OS_CHROMEOS)
149 void InitializeWebSocketProxyThread();
151 void CreateProfileManager();
152 void CreateLocalState();
153 void CreateViewedPageTracker();
154 void CreateIconManager();
155 void CreateIntranetRedirectDetector();
156 void CreateNotificationUIManager();
157 void CreateStatusTrayManager();
158 void CreatePrintPreviewDialogController();
159 void CreateBackgroundPrintingManager();
160 void CreateSafeBrowsingService();
161 void CreateSafeBrowsingDetectionService();
162 void CreateStatusTray();
163 void CreateBackgroundModeManager();
165 void ApplyDisabledSchemesPolicy();
166 void ApplyAllowCrossOriginAuthPromptPolicy();
167 void ApplyDefaultBrowserPolicy();
169 bool created_metrics_service_
;
170 scoped_ptr
<MetricsService
> metrics_service_
;
172 scoped_ptr
<IOThread
> io_thread_
;
174 bool created_watchdog_thread_
;
175 scoped_ptr
<WatchDogThread
> watchdog_thread_
;
177 bool created_browser_policy_connector_
;
178 #if defined(ENABLE_CONFIGURATION_POLICY)
179 // Must be destroyed after |local_state_|.
180 scoped_ptr
<policy::BrowserPolicyConnector
> browser_policy_connector_
;
183 // Must be destroyed after |local_state_|.
184 // This is a stub when policy is not enabled. Otherwise, the PolicyService
185 // is owned by the |browser_policy_connector_| and this is not used.
186 scoped_ptr
<policy::PolicyService
> policy_service_
;
188 bool created_profile_manager_
;
189 scoped_ptr
<ProfileManager
> profile_manager_
;
191 bool created_local_state_
;
192 scoped_ptr
<PrefService
> local_state_
;
194 bool created_icon_manager_
;
195 scoped_ptr
<IconManager
> icon_manager_
;
197 scoped_ptr
<GLStringManager
> gl_string_manager_
;
199 scoped_ptr
<GpuModeManager
> gpu_mode_manager_
;
201 scoped_refptr
<extensions::EventRouterForwarder
>
202 extension_event_router_forwarder_
;
204 #if !defined(OS_ANDROID)
205 scoped_ptr
<RemoteDebuggingServer
> remote_debugging_server_
;
207 // Bookmark prompt controller displays the prompt for frequently visited URL.
208 scoped_ptr
<BookmarkPromptController
> bookmark_prompt_controller_
;
211 scoped_ptr
<chrome::MediaFileSystemRegistry
> media_file_system_registry_
;
213 scoped_refptr
<printing::PrintPreviewDialogController
>
214 print_preview_dialog_controller_
;
216 scoped_ptr
<printing::BackgroundPrintingManager
> background_printing_manager_
;
218 scoped_ptr
<chrome_variations::VariationsService
> variations_service_
;
220 // Manager for desktop notification UI.
221 bool created_notification_ui_manager_
;
222 scoped_ptr
<NotificationUIManager
> notification_ui_manager_
;
224 #if defined(ENABLE_AUTOMATION)
225 scoped_ptr
<AutomationProviderList
> automation_provider_list_
;
228 scoped_ptr
<IntranetRedirectDetector
> intranet_redirect_detector_
;
230 scoped_ptr
<StatusTray
> status_tray_
;
232 scoped_ptr
<BackgroundModeManager
> background_mode_manager_
;
234 bool created_safe_browsing_service_
;
235 scoped_refptr
<SafeBrowsingService
> safe_browsing_service_
;
237 unsigned int module_ref_count_
;
240 // Ensures that all the print jobs are finished before closing the browser.
241 scoped_ptr
<printing::PrintJobManager
> print_job_manager_
;
245 bool checked_for_new_frames_
;
246 bool using_new_frames_
;
248 // This service just sits around and makes snapshots for renderers. It does
249 // nothing in the constructor so we don't have to worry about lazy init.
250 scoped_ptr
<RenderWidgetSnapshotTaker
> render_widget_snapshot_taker_
;
252 // Download status updates (like a changing application icon on dock/taskbar)
253 // are global per-application. DownloadStatusUpdater does no work in the ctor
254 // so we don't have to worry about lazy initialization.
255 scoped_ptr
<DownloadStatusUpdater
> download_status_updater_
;
257 scoped_refptr
<DownloadRequestLimiter
> download_request_limiter_
;
259 // Sequenced task runner for local state related I/O tasks.
260 const scoped_refptr
<base::SequencedTaskRunner
> local_state_task_runner_
;
262 // Ensures that the observers of plugin/print disable/enable state
263 // notifications are properly added and removed.
264 PrefChangeRegistrar pref_change_registrar_
;
266 // Lives here so can safely log events on shutdown.
267 scoped_ptr
<ChromeNetLog
> net_log_
;
269 // Ordered before resource_dispatcher_host_delegate_ due to destruction
271 scoped_ptr
<prerender::PrerenderTracker
> prerender_tracker_
;
273 scoped_ptr
<ChromeResourceDispatcherHostDelegate
>
274 resource_dispatcher_host_delegate_
;
276 scoped_refptr
<PromoResourceService
> promo_resource_service_
;
278 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
279 base::RepeatingTimer
<BrowserProcessImpl
> autoupdate_timer_
;
281 // Gets called by autoupdate timer to see if browser needs restart and can be
282 // restarted, and if that's the case, restarts the browser.
283 void OnAutoupdateTimer();
284 bool CanAutorestartForUpdate() const;
285 void RestartBackgroundInstance();
286 #endif // defined(OS_WIN) || defined(OS_LINUX) && !defined(OS_CHROMEOS)
288 #if defined(OS_CHROMEOS)
289 scoped_ptr
<chromeos::OomPriorityManager
> oom_priority_manager_
;
291 // component updater is normally not used under ChromeOS due
292 // to concerns over integrity of data shared between profiles,
293 // but some users of component updater only install per-user.
294 scoped_ptr
<ComponentUpdateService
> component_updater_
;
295 scoped_refptr
<CRLSetFetcher
> crl_set_fetcher_
;
296 scoped_ptr
<PnaclComponentInstaller
> pnacl_component_installer_
;
298 #if defined(ENABLE_PLUGIN_INSTALLATION)
299 scoped_refptr
<PluginsResourceService
> plugins_resource_service_
;
302 #if defined(OS_WIN) && defined(USE_AURA)
303 void PerformInitForWindowsAura(const CommandLine
& command_line
);
305 // Hosts the channel for the Windows 8 metro viewer process which runs in
306 // the ASH environment.
307 scoped_ptr
<MetroViewerProcessHost
> metro_viewer_process_host_
;
310 #if defined(OS_MACOSX)
311 // Hosts the IPC channel factory that App Shims connect to on Mac.
312 scoped_ptr
<AppShimHostManager
> app_shim_host_manager_
;
315 // TODO(eroman): Remove this when done debugging 113031. This tracks
316 // the callstack which released the final module reference count.
317 base::debug::StackTrace release_last_reference_callstack_
;
319 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl
);
322 #endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_