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