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 CommandLine; 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 SequencedTaskRunner; 37 } 38 39 namespace extensions { 40 class ExtensionsBrowserClient; 41 } 42 43 namespace policy { 44 class BrowserPolicyConnector; 45 class PolicyService; 46 }; 47 48 // Real implementation of BrowserProcess that creates and returns the services. 49 class BrowserProcessImpl : public BrowserProcess, 50 public base::NonThreadSafe { 51 public: 52 // |local_state_task_runner| must be a shutdown-blocking task runner. 53 BrowserProcessImpl(base::SequencedTaskRunner* local_state_task_runner, 54 const CommandLine& command_line); 55 virtual ~BrowserProcessImpl(); 56 57 // Called before the browser threads are created. 58 void PreCreateThreads(); 59 60 // Called after the threads have been created but before the message loops 61 // starts running. Allows the browser process to do any initialization that 62 // requires all threads running. 63 void PreMainMessageLoopRun(); 64 65 // Most cleanup is done by these functions, driven from 66 // ChromeBrowserMain based on notifications from the content 67 // framework, rather than in the destructor, so that we can 68 // interleave cleanup with threads being stopped. 69 void StartTearDown(); 70 void PostDestroyThreads(); 71 72 // BrowserProcess implementation. 73 virtual void ResourceDispatcherHostCreated() OVERRIDE; 74 virtual void EndSession() OVERRIDE; 75 virtual MetricsService* metrics_service() OVERRIDE; 76 virtual IOThread* io_thread() OVERRIDE; 77 virtual WatchDogThread* watchdog_thread() OVERRIDE; 78 virtual ProfileManager* profile_manager() OVERRIDE; 79 virtual PrefService* local_state() OVERRIDE; 80 virtual net::URLRequestContextGetter* system_request_context() OVERRIDE; 81 virtual chrome_variations::VariationsService* variations_service() OVERRIDE; 82 virtual BrowserProcessPlatformPart* platform_part() OVERRIDE; 83 virtual extensions::EventRouterForwarder* 84 extension_event_router_forwarder() OVERRIDE; 85 virtual NotificationUIManager* notification_ui_manager() OVERRIDE; 86 virtual message_center::MessageCenter* message_center() OVERRIDE; 87 virtual policy::BrowserPolicyConnector* browser_policy_connector() OVERRIDE; 88 virtual policy::PolicyService* policy_service() OVERRIDE; 89 virtual IconManager* icon_manager() OVERRIDE; 90 virtual GLStringManager* gl_string_manager() OVERRIDE; 91 virtual GpuModeManager* gpu_mode_manager() OVERRIDE; 92 virtual RenderWidgetSnapshotTaker* GetRenderWidgetSnapshotTaker() OVERRIDE; 93 virtual AutomationProviderList* GetAutomationProviderList() OVERRIDE; 94 virtual void CreateDevToolsHttpProtocolHandler( 95 chrome::HostDesktopType host_desktop_type, 96 const std::string& ip, 97 int port, 98 const std::string& frontend_url) OVERRIDE; 99 virtual unsigned int AddRefModule() OVERRIDE; 100 virtual unsigned int ReleaseModule() OVERRIDE; 101 virtual bool IsShuttingDown() OVERRIDE; 102 virtual printing::PrintJobManager* print_job_manager() OVERRIDE; 103 virtual printing::PrintPreviewDialogController* 104 print_preview_dialog_controller() OVERRIDE; 105 virtual printing::BackgroundPrintingManager* 106 background_printing_manager() OVERRIDE; 107 virtual IntranetRedirectDetector* intranet_redirect_detector() OVERRIDE; 108 virtual const std::string& GetApplicationLocale() OVERRIDE; 109 virtual void SetApplicationLocale(const std::string& locale) OVERRIDE; 110 virtual DownloadStatusUpdater* download_status_updater() OVERRIDE; 111 virtual DownloadRequestLimiter* download_request_limiter() OVERRIDE; 112 virtual BackgroundModeManager* background_mode_manager() OVERRIDE; 113 virtual void set_background_mode_manager_for_test( 114 scoped_ptr<BackgroundModeManager> manager) OVERRIDE; 115 virtual StatusTray* status_tray() OVERRIDE; 116 virtual SafeBrowsingService* safe_browsing_service() OVERRIDE; 117 virtual safe_browsing::ClientSideDetectionService* 118 safe_browsing_detection_service() OVERRIDE; 119 120 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 121 virtual void StartAutoupdateTimer() OVERRIDE; 122 #endif 123 124 virtual ChromeNetLog* net_log() OVERRIDE; 125 virtual prerender::PrerenderTracker* prerender_tracker() OVERRIDE; 126 virtual ComponentUpdateService* component_updater() OVERRIDE; 127 virtual CRLSetFetcher* crl_set_fetcher() OVERRIDE; 128 virtual PnaclComponentInstaller* pnacl_component_installer() OVERRIDE; 129 virtual BookmarkPromptController* bookmark_prompt_controller() OVERRIDE; 130 virtual StorageMonitor* storage_monitor() OVERRIDE; 131 void set_storage_monitor_for_test(scoped_ptr<StorageMonitor> monitor); 132 virtual MediaFileSystemRegistry* media_file_system_registry() OVERRIDE; 133 virtual bool created_local_state() const OVERRIDE; 134 #if defined(ENABLE_WEBRTC) 135 virtual WebRtcLogUploader* webrtc_log_uploader() OVERRIDE; 136 #endif 137 138 static void RegisterPrefs(PrefRegistrySimple* registry); 139 140 private: 141 void CreateMetricsService(); 142 void CreateWatchdogThread(); 143 void CreateProfileManager(); 144 void CreateLocalState(); 145 void CreateViewedPageTracker(); 146 void CreateIconManager(); 147 void CreateIntranetRedirectDetector(); 148 void CreateNotificationUIManager(); 149 void CreateStatusTrayManager(); 150 void CreatePrintPreviewDialogController(); 151 void CreateBackgroundPrintingManager(); 152 void CreateSafeBrowsingService(); 153 void CreateSafeBrowsingDetectionService(); 154 void CreateStatusTray(); 155 void CreateBackgroundModeManager(); 156 157 void ApplyAllowCrossOriginAuthPromptPolicy(); 158 void ApplyDefaultBrowserPolicy(); 159 void ApplyMetricsReportingPolicy(); 160 161 bool created_metrics_service_; 162 scoped_ptr<MetricsService> metrics_service_; 163 164 scoped_ptr<IOThread> io_thread_; 165 166 bool created_watchdog_thread_; 167 scoped_ptr<WatchDogThread> watchdog_thread_; 168 169 bool created_browser_policy_connector_; 170 #if defined(ENABLE_CONFIGURATION_POLICY) 171 // Must be destroyed after |local_state_|. 172 scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_; 173 #endif 174 175 // Must be destroyed after |local_state_|. 176 // This is a stub when policy is not enabled. Otherwise, the PolicyService 177 // is owned by the |browser_policy_connector_| and this is not used. 178 scoped_ptr<policy::PolicyService> policy_service_; 179 180 bool created_profile_manager_; 181 scoped_ptr<ProfileManager> profile_manager_; 182 183 bool created_local_state_; 184 scoped_ptr<PrefService> local_state_; 185 186 bool created_icon_manager_; 187 scoped_ptr<IconManager> icon_manager_; 188 189 scoped_ptr<GLStringManager> gl_string_manager_; 190 191 scoped_ptr<GpuModeManager> gpu_mode_manager_; 192 193 scoped_ptr<extensions::ExtensionsBrowserClient> extensions_browser_client_; 194 scoped_refptr<extensions::EventRouterForwarder> 195 extension_event_router_forwarder_; 196 197 #if !defined(OS_ANDROID) 198 scoped_ptr<RemoteDebuggingServer> remote_debugging_server_; 199 200 // Bookmark prompt controller displays the prompt for frequently visited URL. 201 scoped_ptr<BookmarkPromptController> bookmark_prompt_controller_; 202 #endif 203 204 #if !defined(OS_ANDROID) && !defined(OS_IOS) 205 scoped_ptr<StorageMonitor> storage_monitor_; 206 207 scoped_ptr<MediaFileSystemRegistry> media_file_system_registry_; 208 #endif 209 210 scoped_refptr<printing::PrintPreviewDialogController> 211 print_preview_dialog_controller_; 212 213 scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_; 214 215 scoped_ptr<chrome_variations::VariationsService> variations_service_; 216 217 // Manager for desktop notification UI. 218 bool created_notification_ui_manager_; 219 scoped_ptr<NotificationUIManager> notification_ui_manager_; 220 221 #if defined(ENABLE_AUTOMATION) 222 scoped_ptr<AutomationProviderList> automation_provider_list_; 223 #endif 224 225 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector_; 226 227 scoped_ptr<StatusTray> status_tray_; 228 229 scoped_ptr<BackgroundModeManager> background_mode_manager_; 230 231 bool created_safe_browsing_service_; 232 scoped_refptr<SafeBrowsingService> safe_browsing_service_; 233 234 unsigned int module_ref_count_; 235 bool did_start_; 236 237 // Ensures that all the print jobs are finished before closing the browser. 238 scoped_ptr<printing::PrintJobManager> print_job_manager_; 239 240 std::string locale_; 241 242 bool checked_for_new_frames_; 243 bool using_new_frames_; 244 245 // This service just sits around and makes snapshots for renderers. It does 246 // nothing in the constructor so we don't have to worry about lazy init. 247 scoped_ptr<RenderWidgetSnapshotTaker> render_widget_snapshot_taker_; 248 249 // Download status updates (like a changing application icon on dock/taskbar) 250 // are global per-application. DownloadStatusUpdater does no work in the ctor 251 // so we don't have to worry about lazy initialization. 252 scoped_ptr<DownloadStatusUpdater> download_status_updater_; 253 254 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; 255 256 // Sequenced task runner for local state related I/O tasks. 257 const scoped_refptr<base::SequencedTaskRunner> local_state_task_runner_; 258 259 // Ensures that the observers of plugin/print disable/enable state 260 // notifications are properly added and removed. 261 PrefChangeRegistrar pref_change_registrar_; 262 263 // Lives here so can safely log events on shutdown. 264 scoped_ptr<ChromeNetLog> net_log_; 265 266 // Ordered before resource_dispatcher_host_delegate_ due to destruction 267 // ordering. 268 scoped_ptr<prerender::PrerenderTracker> prerender_tracker_; 269 270 scoped_ptr<ChromeResourceDispatcherHostDelegate> 271 resource_dispatcher_host_delegate_; 272 273 scoped_refptr<PromoResourceService> promo_resource_service_; 274 275 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 276 base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_; 277 278 // Gets called by autoupdate timer to see if browser needs restart and can be 279 // restarted, and if that's the case, restarts the browser. 280 void OnAutoupdateTimer(); 281 bool CanAutorestartForUpdate() const; 282 void RestartBackgroundInstance(); 283 #endif // defined(OS_WIN) || defined(OS_LINUX) && !defined(OS_CHROMEOS) 284 285 // component updater is normally not used under ChromeOS due 286 // to concerns over integrity of data shared between profiles, 287 // but some users of component updater only install per-user. 288 scoped_ptr<ComponentUpdateService> component_updater_; 289 scoped_refptr<CRLSetFetcher> crl_set_fetcher_; 290 scoped_ptr<PnaclComponentInstaller> pnacl_component_installer_; 291 292 #if defined(ENABLE_PLUGIN_INSTALLATION) 293 scoped_refptr<PluginsResourceService> plugins_resource_service_; 294 #endif 295 296 scoped_ptr<BrowserProcessPlatformPart> platform_part_; 297 298 // TODO(eroman): Remove this when done debugging 113031. This tracks 299 // the callstack which released the final module reference count. 300 base::debug::StackTrace release_last_reference_callstack_; 301 302 #if defined(ENABLE_WEBRTC) 303 // Lazily initialized. 304 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader_; 305 #endif 306 307 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl); 308 }; 309 310 #endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_ 311