[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / browser_process_impl.h
blob5631a5ec3e927b006116a5e5967a52e15cdd81cd
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_
13 #include <string>
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 ChromeNetLog;
25 class ChromeResourceDispatcherHostDelegate;
26 class MetricsServicesManager;
27 class RemoteDebuggingServer;
28 class PrefRegistrySimple;
29 class PromoResourceService;
31 #if defined(ENABLE_PLUGIN_INSTALLATION)
32 class PluginsResourceService;
33 #endif
35 namespace base {
36 class CommandLine;
37 class SequencedTaskRunner;
40 namespace extensions {
41 class ExtensionsBrowserClient;
44 namespace policy {
45 class BrowserPolicyConnector;
46 class PolicyService;
49 // Real implementation of BrowserProcess that creates and returns the services.
50 class BrowserProcessImpl : public BrowserProcess,
51 public base::NonThreadSafe {
52 public:
53 // |local_state_task_runner| must be a shutdown-blocking task runner.
54 BrowserProcessImpl(base::SequencedTaskRunner* local_state_task_runner,
55 const base::CommandLine& command_line);
56 virtual ~BrowserProcessImpl();
58 // Called before the browser threads are created.
59 void PreCreateThreads();
61 // Called after the threads have been created but before the message loops
62 // starts running. Allows the browser process to do any initialization that
63 // requires all threads running.
64 void PreMainMessageLoopRun();
66 // Most cleanup is done by these functions, driven from
67 // ChromeBrowserMain based on notifications from the content
68 // framework, rather than in the destructor, so that we can
69 // interleave cleanup with threads being stopped.
70 void StartTearDown();
71 void PostDestroyThreads();
73 // BrowserProcess implementation.
74 virtual void ResourceDispatcherHostCreated() OVERRIDE;
75 virtual void EndSession() OVERRIDE;
76 virtual MetricsService* metrics_service() OVERRIDE;
77 virtual rappor::RapporService* rappor_service() OVERRIDE;
78 virtual IOThread* io_thread() OVERRIDE;
79 virtual WatchDogThread* watchdog_thread() OVERRIDE;
80 virtual ProfileManager* profile_manager() OVERRIDE;
81 virtual PrefService* local_state() OVERRIDE;
82 virtual net::URLRequestContextGetter* system_request_context() OVERRIDE;
83 virtual chrome_variations::VariationsService* variations_service() OVERRIDE;
84 virtual BrowserProcessPlatformPart* platform_part() OVERRIDE;
85 virtual extensions::EventRouterForwarder*
86 extension_event_router_forwarder() OVERRIDE;
87 virtual NotificationUIManager* notification_ui_manager() OVERRIDE;
88 virtual message_center::MessageCenter* message_center() OVERRIDE;
89 virtual policy::BrowserPolicyConnector* browser_policy_connector() OVERRIDE;
90 virtual policy::PolicyService* policy_service() OVERRIDE;
91 virtual IconManager* icon_manager() OVERRIDE;
92 virtual GLStringManager* gl_string_manager() OVERRIDE;
93 virtual GpuModeManager* gpu_mode_manager() OVERRIDE;
94 virtual void CreateDevToolsHttpProtocolHandler(
95 chrome::HostDesktopType host_desktop_type,
96 const std::string& ip,
97 int port) OVERRIDE;
98 virtual unsigned int AddRefModule() OVERRIDE;
99 virtual unsigned int ReleaseModule() OVERRIDE;
100 virtual bool IsShuttingDown() OVERRIDE;
101 virtual printing::PrintJobManager* print_job_manager() OVERRIDE;
102 virtual printing::PrintPreviewDialogController*
103 print_preview_dialog_controller() OVERRIDE;
104 virtual printing::BackgroundPrintingManager*
105 background_printing_manager() OVERRIDE;
106 virtual IntranetRedirectDetector* intranet_redirect_detector() OVERRIDE;
107 virtual const std::string& GetApplicationLocale() OVERRIDE;
108 virtual void SetApplicationLocale(const std::string& locale) OVERRIDE;
109 virtual DownloadStatusUpdater* download_status_updater() OVERRIDE;
110 virtual DownloadRequestLimiter* download_request_limiter() OVERRIDE;
111 virtual BackgroundModeManager* background_mode_manager() OVERRIDE;
112 virtual void set_background_mode_manager_for_test(
113 scoped_ptr<BackgroundModeManager> manager) OVERRIDE;
114 virtual StatusTray* status_tray() OVERRIDE;
115 virtual SafeBrowsingService* safe_browsing_service() OVERRIDE;
116 virtual safe_browsing::ClientSideDetectionService*
117 safe_browsing_detection_service() OVERRIDE;
119 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
120 virtual void StartAutoupdateTimer() OVERRIDE;
121 #endif
123 virtual ChromeNetLog* net_log() OVERRIDE;
124 virtual prerender::PrerenderTracker* prerender_tracker() OVERRIDE;
125 virtual component_updater::ComponentUpdateService*
126 component_updater() OVERRIDE;
127 virtual CRLSetFetcher* crl_set_fetcher() OVERRIDE;
128 virtual component_updater::PnaclComponentInstaller*
129 pnacl_component_installer() OVERRIDE;
130 virtual MediaFileSystemRegistry* media_file_system_registry() OVERRIDE;
131 virtual bool created_local_state() const OVERRIDE;
132 #if defined(ENABLE_WEBRTC)
133 virtual WebRtcLogUploader* webrtc_log_uploader() OVERRIDE;
134 #endif
135 virtual NetworkTimeTracker* network_time_tracker() OVERRIDE;
137 static void RegisterPrefs(PrefRegistrySimple* registry);
139 private:
140 void CreateWatchdogThread();
141 void CreateProfileManager();
142 void CreateLocalState();
143 void CreateViewedPageTracker();
144 void CreateIconManager();
145 void CreateIntranetRedirectDetector();
146 void CreateNotificationUIManager();
147 void CreateStatusTrayManager();
148 void CreatePrintPreviewDialogController();
149 void CreateBackgroundPrintingManager();
150 void CreateSafeBrowsingService();
151 void CreateSafeBrowsingDetectionService();
152 void CreateStatusTray();
153 void CreateBackgroundModeManager();
155 MetricsServicesManager* GetMetricsServicesManager();
157 void ApplyAllowCrossOriginAuthPromptPolicy();
158 void ApplyDefaultBrowserPolicy();
159 void ApplyMetricsReportingPolicy();
161 scoped_ptr<MetricsServicesManager> metrics_services_manager_;
163 scoped_ptr<IOThread> io_thread_;
165 bool created_watchdog_thread_;
166 scoped_ptr<WatchDogThread> watchdog_thread_;
168 bool created_browser_policy_connector_;
169 #if defined(ENABLE_CONFIGURATION_POLICY)
170 // Must be destroyed after |local_state_|.
171 scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_;
172 #else
173 // Must be destroyed after |local_state_|.
174 // This is a stub when policy is not enabled. Otherwise, the PolicyService
175 // is owned by the |browser_policy_connector_| and this is not used.
176 scoped_ptr<policy::PolicyService> policy_service_;
177 #endif
179 bool created_profile_manager_;
180 scoped_ptr<ProfileManager> profile_manager_;
182 bool created_local_state_;
183 scoped_ptr<PrefService> local_state_;
185 bool created_icon_manager_;
186 scoped_ptr<IconManager> icon_manager_;
188 scoped_ptr<GLStringManager> gl_string_manager_;
190 scoped_ptr<GpuModeManager> gpu_mode_manager_;
192 scoped_ptr<extensions::ExtensionsBrowserClient> extensions_browser_client_;
193 scoped_refptr<extensions::EventRouterForwarder>
194 extension_event_router_forwarder_;
196 #if !defined(OS_ANDROID)
197 scoped_ptr<RemoteDebuggingServer> remote_debugging_server_;
198 #endif
200 #if !defined(OS_ANDROID) && !defined(OS_IOS)
201 scoped_ptr<MediaFileSystemRegistry> media_file_system_registry_;
202 #endif
204 scoped_refptr<printing::PrintPreviewDialogController>
205 print_preview_dialog_controller_;
207 scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_;
209 // Manager for desktop notification UI.
210 bool created_notification_ui_manager_;
211 scoped_ptr<NotificationUIManager> notification_ui_manager_;
213 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector_;
215 scoped_ptr<StatusTray> status_tray_;
217 scoped_ptr<BackgroundModeManager> background_mode_manager_;
219 bool created_safe_browsing_service_;
220 scoped_refptr<SafeBrowsingService> safe_browsing_service_;
222 unsigned int module_ref_count_;
223 bool did_start_;
225 // Ensures that all the print jobs are finished before closing the browser.
226 scoped_ptr<printing::PrintJobManager> print_job_manager_;
228 std::string locale_;
230 // Download status updates (like a changing application icon on dock/taskbar)
231 // are global per-application. DownloadStatusUpdater does no work in the ctor
232 // so we don't have to worry about lazy initialization.
233 scoped_ptr<DownloadStatusUpdater> download_status_updater_;
235 scoped_refptr<DownloadRequestLimiter> download_request_limiter_;
237 // Sequenced task runner for local state related I/O tasks.
238 const scoped_refptr<base::SequencedTaskRunner> local_state_task_runner_;
240 // Ensures that the observers of plugin/print disable/enable state
241 // notifications are properly added and removed.
242 PrefChangeRegistrar pref_change_registrar_;
244 // Lives here so can safely log events on shutdown.
245 scoped_ptr<ChromeNetLog> net_log_;
247 // Ordered before resource_dispatcher_host_delegate_ due to destruction
248 // ordering.
249 scoped_ptr<prerender::PrerenderTracker> prerender_tracker_;
251 scoped_ptr<ChromeResourceDispatcherHostDelegate>
252 resource_dispatcher_host_delegate_;
254 scoped_refptr<PromoResourceService> promo_resource_service_;
256 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
257 base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_;
259 // Gets called by autoupdate timer to see if browser needs restart and can be
260 // restarted, and if that's the case, restarts the browser.
261 void OnAutoupdateTimer();
262 bool CanAutorestartForUpdate() const;
263 void RestartBackgroundInstance();
264 #endif // defined(OS_WIN) || defined(OS_LINUX) && !defined(OS_CHROMEOS)
266 // component updater is normally not used under ChromeOS due
267 // to concerns over integrity of data shared between profiles,
268 // but some users of component updater only install per-user.
269 scoped_ptr<component_updater::ComponentUpdateService> component_updater_;
270 scoped_refptr<CRLSetFetcher> crl_set_fetcher_;
271 scoped_ptr<component_updater::PnaclComponentInstaller>
272 pnacl_component_installer_;
274 #if defined(ENABLE_PLUGIN_INSTALLATION)
275 scoped_refptr<PluginsResourceService> plugins_resource_service_;
276 #endif
278 scoped_ptr<BrowserProcessPlatformPart> platform_part_;
280 // TODO(eroman): Remove this when done debugging 113031. This tracks
281 // the callstack which released the final module reference count.
282 base::debug::StackTrace release_last_reference_callstack_;
284 #if defined(ENABLE_WEBRTC)
285 // Lazily initialized.
286 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader_;
287 #endif
289 scoped_ptr<NetworkTimeTracker> network_time_tracker_;
291 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl);
294 #endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_