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. 4 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. 9 10 #ifndef CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_ 11 #define CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_ 12 13 #include <string> 14 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" 23 24 class ChromeNetLog; 25 class ChromeResourceDispatcherHostDelegate; 26 class MetricsServicesManager; 27 class RemoteDebuggingServer; 28 class PrefRegistrySimple; 29 class PromoResourceService; 30 31 #if defined(ENABLE_PLUGIN_INSTALLATION) 32 class PluginsResourceService; 33 #endif 34 35 namespace base { 36 class CommandLine; 37 class SequencedTaskRunner; 38 } 39 40 namespace extensions { 41 class ExtensionsBrowserClient; 42 } 43 44 namespace gcm { 45 class GCMDriver; 46 } 47 48 namespace policy { 49 class BrowserPolicyConnector; 50 class PolicyService; 51 }; 52 53 // Real implementation of BrowserProcess that creates and returns the services. 54 class BrowserProcessImpl : public BrowserProcess, 55 public base::NonThreadSafe { 56 public: 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 virtual ~BrowserProcessImpl(); 61 62 // Called before the browser threads are created. 63 void PreCreateThreads(); 64 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(); 69 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. 74 void StartTearDown(); 75 void PostDestroyThreads(); 76 77 // BrowserProcess implementation. 78 virtual void ResourceDispatcherHostCreated() OVERRIDE; 79 virtual void EndSession() OVERRIDE; 80 virtual MetricsServicesManager* GetMetricsServicesManager() OVERRIDE; 81 virtual MetricsService* metrics_service() OVERRIDE; 82 virtual rappor::RapporService* rappor_service() OVERRIDE; 83 virtual IOThread* io_thread() OVERRIDE; 84 virtual WatchDogThread* watchdog_thread() OVERRIDE; 85 virtual ProfileManager* profile_manager() OVERRIDE; 86 virtual PrefService* local_state() OVERRIDE; 87 virtual net::URLRequestContextGetter* system_request_context() OVERRIDE; 88 virtual chrome_variations::VariationsService* variations_service() OVERRIDE; 89 virtual BrowserProcessPlatformPart* platform_part() OVERRIDE; 90 virtual extensions::EventRouterForwarder* 91 extension_event_router_forwarder() OVERRIDE; 92 virtual NotificationUIManager* notification_ui_manager() OVERRIDE; 93 virtual message_center::MessageCenter* message_center() OVERRIDE; 94 virtual policy::BrowserPolicyConnector* browser_policy_connector() OVERRIDE; 95 virtual policy::PolicyService* policy_service() OVERRIDE; 96 virtual IconManager* icon_manager() OVERRIDE; 97 virtual GLStringManager* gl_string_manager() OVERRIDE; 98 virtual GpuModeManager* gpu_mode_manager() OVERRIDE; 99 virtual void CreateDevToolsHttpProtocolHandler( 100 chrome::HostDesktopType host_desktop_type, 101 const std::string& ip, 102 int port) OVERRIDE; 103 virtual unsigned int AddRefModule() OVERRIDE; 104 virtual unsigned int ReleaseModule() OVERRIDE; 105 virtual bool IsShuttingDown() OVERRIDE; 106 virtual printing::PrintJobManager* print_job_manager() OVERRIDE; 107 virtual printing::PrintPreviewDialogController* 108 print_preview_dialog_controller() OVERRIDE; 109 virtual printing::BackgroundPrintingManager* 110 background_printing_manager() OVERRIDE; 111 virtual IntranetRedirectDetector* intranet_redirect_detector() OVERRIDE; 112 virtual const std::string& GetApplicationLocale() OVERRIDE; 113 virtual void SetApplicationLocale(const std::string& locale) OVERRIDE; 114 virtual DownloadStatusUpdater* download_status_updater() OVERRIDE; 115 virtual DownloadRequestLimiter* download_request_limiter() OVERRIDE; 116 virtual BackgroundModeManager* background_mode_manager() OVERRIDE; 117 virtual void set_background_mode_manager_for_test( 118 scoped_ptr<BackgroundModeManager> manager) OVERRIDE; 119 virtual StatusTray* status_tray() OVERRIDE; 120 virtual SafeBrowsingService* safe_browsing_service() OVERRIDE; 121 virtual safe_browsing::ClientSideDetectionService* 122 safe_browsing_detection_service() OVERRIDE; 123 124 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 125 virtual void StartAutoupdateTimer() OVERRIDE; 126 #endif 127 128 virtual ChromeNetLog* net_log() OVERRIDE; 129 virtual prerender::PrerenderTracker* prerender_tracker() OVERRIDE; 130 virtual component_updater::ComponentUpdateService* 131 component_updater() OVERRIDE; 132 virtual CRLSetFetcher* crl_set_fetcher() OVERRIDE; 133 virtual component_updater::PnaclComponentInstaller* 134 pnacl_component_installer() OVERRIDE; 135 virtual MediaFileSystemRegistry* media_file_system_registry() OVERRIDE; 136 virtual bool created_local_state() const OVERRIDE; 137 #if defined(ENABLE_WEBRTC) 138 virtual WebRtcLogUploader* webrtc_log_uploader() OVERRIDE; 139 #endif 140 virtual network_time::NetworkTimeTracker* network_time_tracker() OVERRIDE; 141 virtual gcm::GCMDriver* gcm_driver() OVERRIDE; 142 143 static void RegisterPrefs(PrefRegistrySimple* registry); 144 145 private: 146 void CreateWatchdogThread(); 147 void CreateProfileManager(); 148 void CreateLocalState(); 149 void CreateViewedPageTracker(); 150 void CreateIconManager(); 151 void CreateIntranetRedirectDetector(); 152 void CreateNotificationUIManager(); 153 void CreateStatusTrayManager(); 154 void CreatePrintPreviewDialogController(); 155 void CreateBackgroundPrintingManager(); 156 void CreateSafeBrowsingService(); 157 void CreateSafeBrowsingDetectionService(); 158 void CreateStatusTray(); 159 void CreateBackgroundModeManager(); 160 void CreateGCMDriver(); 161 162 void ApplyAllowCrossOriginAuthPromptPolicy(); 163 void ApplyDefaultBrowserPolicy(); 164 void ApplyMetricsReportingPolicy(); 165 166 scoped_ptr<MetricsServicesManager> metrics_services_manager_; 167 168 scoped_ptr<IOThread> io_thread_; 169 170 bool created_watchdog_thread_; 171 scoped_ptr<WatchDogThread> watchdog_thread_; 172 173 bool created_browser_policy_connector_; 174 #if defined(ENABLE_CONFIGURATION_POLICY) 175 // Must be destroyed after |local_state_|. 176 scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_; 177 #else 178 // Must be destroyed after |local_state_|. 179 // This is a stub when policy is not enabled. Otherwise, the PolicyService 180 // is owned by the |browser_policy_connector_| and this is not used. 181 scoped_ptr<policy::PolicyService> policy_service_; 182 #endif 183 184 bool created_profile_manager_; 185 scoped_ptr<ProfileManager> profile_manager_; 186 187 bool created_local_state_; 188 scoped_ptr<PrefService> local_state_; 189 190 bool created_icon_manager_; 191 scoped_ptr<IconManager> icon_manager_; 192 193 scoped_ptr<GLStringManager> gl_string_manager_; 194 195 scoped_ptr<GpuModeManager> gpu_mode_manager_; 196 197 scoped_ptr<extensions::ExtensionsBrowserClient> extensions_browser_client_; 198 scoped_refptr<extensions::EventRouterForwarder> 199 extension_event_router_forwarder_; 200 201 #if !defined(OS_ANDROID) 202 scoped_ptr<RemoteDebuggingServer> remote_debugging_server_; 203 #endif 204 205 #if !defined(OS_ANDROID) && !defined(OS_IOS) 206 scoped_ptr<MediaFileSystemRegistry> media_file_system_registry_; 207 #endif 208 209 scoped_refptr<printing::PrintPreviewDialogController> 210 print_preview_dialog_controller_; 211 212 scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_; 213 214 // Manager for desktop notification UI. 215 bool created_notification_ui_manager_; 216 scoped_ptr<NotificationUIManager> notification_ui_manager_; 217 218 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector_; 219 220 scoped_ptr<StatusTray> status_tray_; 221 222 scoped_ptr<BackgroundModeManager> background_mode_manager_; 223 224 bool created_safe_browsing_service_; 225 scoped_refptr<SafeBrowsingService> safe_browsing_service_; 226 227 unsigned int module_ref_count_; 228 bool did_start_; 229 230 // Ensures that all the print jobs are finished before closing the browser. 231 scoped_ptr<printing::PrintJobManager> print_job_manager_; 232 233 std::string locale_; 234 235 // Download status updates (like a changing application icon on dock/taskbar) 236 // are global per-application. DownloadStatusUpdater does no work in the ctor 237 // so we don't have to worry about lazy initialization. 238 scoped_ptr<DownloadStatusUpdater> download_status_updater_; 239 240 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; 241 242 // Sequenced task runner for local state related I/O tasks. 243 const scoped_refptr<base::SequencedTaskRunner> local_state_task_runner_; 244 245 // Ensures that the observers of plugin/print disable/enable state 246 // notifications are properly added and removed. 247 PrefChangeRegistrar pref_change_registrar_; 248 249 // Lives here so can safely log events on shutdown. 250 scoped_ptr<ChromeNetLog> net_log_; 251 252 // Ordered before resource_dispatcher_host_delegate_ due to destruction 253 // ordering. 254 scoped_ptr<prerender::PrerenderTracker> prerender_tracker_; 255 256 scoped_ptr<ChromeResourceDispatcherHostDelegate> 257 resource_dispatcher_host_delegate_; 258 259 scoped_refptr<PromoResourceService> promo_resource_service_; 260 261 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 262 base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_; 263 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) 270 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_; 276 scoped_ptr<component_updater::PnaclComponentInstaller> 277 pnacl_component_installer_; 278 279 #if defined(ENABLE_PLUGIN_INSTALLATION) 280 scoped_refptr<PluginsResourceService> plugins_resource_service_; 281 #endif 282 283 scoped_ptr<BrowserProcessPlatformPart> platform_part_; 284 285 // TODO(eroman): Remove this when done debugging 113031. This tracks 286 // the callstack which released the final module reference count. 287 base::debug::StackTrace release_last_reference_callstack_; 288 289 #if defined(ENABLE_WEBRTC) 290 // Lazily initialized. 291 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader_; 292 #endif 293 294 scoped_ptr<network_time::NetworkTimeTracker> network_time_tracker_; 295 296 scoped_ptr<gcm::GCMDriver> gcm_driver_; 297 298 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl); 299 }; 300 301 #endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_ 302