browser_process_impl.h revision 010d83a9304c5a91596085d917d248abff47903a
1ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner// Use of this source code is governed by a BSD-style license that can be 3ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner// found in the LICENSE file. 4ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner 5ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner// When each service is created, we set a flag indicating this. At this point, 6ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner// the service initialization could fail or succeed. This allows us to remember 7ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner// if we tried to create a service, and not try creating it over and over if 8ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner// the creation failed. 9ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner 10ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner#ifndef CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_ 11ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner#define CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_ 12af76e592c7f9deff0e55c13dbb4a34f07f1c7f64Chris Lattner 13892e18239308f8a02a4c83758616be84a459c19dChris Lattner#include <string> 14ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner 15ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner#include "base/basictypes.h" 16892e18239308f8a02a4c83758616be84a459c19dChris Lattner#include "base/debug/stack_trace.h" 17892e18239308f8a02a4c83758616be84a459c19dChris Lattner#include "base/memory/ref_counted.h" 18892e18239308f8a02a4c83758616be84a459c19dChris Lattner#include "base/memory/scoped_ptr.h" 19892e18239308f8a02a4c83758616be84a459c19dChris Lattner#include "base/prefs/pref_change_registrar.h" 20ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner#include "base/threading/non_thread_safe.h" 21ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner#include "base/timer/timer.h" 22ed47a0409b187d5dcd2bddfd054326fc809d00aeChris Lattner#include "chrome/browser/browser_process.h" 23892e18239308f8a02a4c83758616be84a459c19dChris Lattner 24892e18239308f8a02a4c83758616be84a459c19dChris Lattnerclass ChromeNetLog; 25892e18239308f8a02a4c83758616be84a459c19dChris Lattnerclass ChromeResourceDispatcherHostDelegate; 26a1c31b779cdde0090b8efcde87d7d0d898cabd38Chris Lattnerclass MetricsServicesManager; 277c599d056a41262681aa7fcd771eeed53a8e0bd2Chris Lattnerclass RemoteDebuggingServer; 28a1c31b779cdde0090b8efcde87d7d0d898cabd38Chris Lattnerclass PrefRegistrySimple; 2938cff389af1d78bd80df0479ef258493e0c5897eChris Lattnerclass PromoResourceService; 30a1c31b779cdde0090b8efcde87d7d0d898cabd38Chris Lattner 31a1c31b779cdde0090b8efcde87d7d0d898cabd38Chris Lattner#if defined(ENABLE_PLUGIN_INSTALLATION) 32af76e592c7f9deff0e55c13dbb4a34f07f1c7f64Chris Lattnerclass PluginsResourceService; 33892e18239308f8a02a4c83758616be84a459c19dChris Lattner#endif 34892e18239308f8a02a4c83758616be84a459c19dChris Lattner 35892e18239308f8a02a4c83758616be84a459c19dChris Lattnernamespace base { 36892e18239308f8a02a4c83758616be84a459c19dChris Lattnerclass CommandLine; 37892e18239308f8a02a4c83758616be84a459c19dChris Lattnerclass SequencedTaskRunner; 38892e18239308f8a02a4c83758616be84a459c19dChris Lattner} 39892e18239308f8a02a4c83758616be84a459c19dChris Lattner 40892e18239308f8a02a4c83758616be84a459c19dChris Lattnernamespace extensions { 41892e18239308f8a02a4c83758616be84a459c19dChris Lattnerclass ExtensionsBrowserClient; 42892e18239308f8a02a4c83758616be84a459c19dChris Lattner} 43892e18239308f8a02a4c83758616be84a459c19dChris Lattner 44892e18239308f8a02a4c83758616be84a459c19dChris Lattnernamespace policy { 45892e18239308f8a02a4c83758616be84a459c19dChris Lattnerclass BrowserPolicyConnector; 46class PolicyService; 47}; 48 49// Real implementation of BrowserProcess that creates and returns the services. 50class 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(); 57 58 // Called before the browser threads are created. 59 void PreCreateThreads(); 60 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(); 65 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(); 72 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; 118 119#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 120 virtual void StartAutoupdateTimer() OVERRIDE; 121#endif 122 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 136 static void RegisterPrefs(PrefRegistrySimple* registry); 137 138 private: 139 void CreateWatchdogThread(); 140 void CreateProfileManager(); 141 void CreateLocalState(); 142 void CreateViewedPageTracker(); 143 void CreateIconManager(); 144 void CreateIntranetRedirectDetector(); 145 void CreateNotificationUIManager(); 146 void CreateStatusTrayManager(); 147 void CreatePrintPreviewDialogController(); 148 void CreateBackgroundPrintingManager(); 149 void CreateSafeBrowsingService(); 150 void CreateSafeBrowsingDetectionService(); 151 void CreateStatusTray(); 152 void CreateBackgroundModeManager(); 153 154 MetricsServicesManager* GetMetricsServicesManager(); 155 156 void ApplyAllowCrossOriginAuthPromptPolicy(); 157 void ApplyDefaultBrowserPolicy(); 158 void ApplyMetricsReportingPolicy(); 159 160 scoped_ptr<MetricsServicesManager> metrics_services_manager_; 161 162 scoped_ptr<IOThread> io_thread_; 163 164 bool created_watchdog_thread_; 165 scoped_ptr<WatchDogThread> watchdog_thread_; 166 167 bool created_browser_policy_connector_; 168#if defined(ENABLE_CONFIGURATION_POLICY) 169 // Must be destroyed after |local_state_|. 170 scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_; 171#else 172 // Must be destroyed after |local_state_|. 173 // This is a stub when policy is not enabled. Otherwise, the PolicyService 174 // is owned by the |browser_policy_connector_| and this is not used. 175 scoped_ptr<policy::PolicyService> policy_service_; 176#endif 177 178 bool created_profile_manager_; 179 scoped_ptr<ProfileManager> profile_manager_; 180 181 bool created_local_state_; 182 scoped_ptr<PrefService> local_state_; 183 184 bool created_icon_manager_; 185 scoped_ptr<IconManager> icon_manager_; 186 187 scoped_ptr<GLStringManager> gl_string_manager_; 188 189 scoped_ptr<GpuModeManager> gpu_mode_manager_; 190 191 scoped_ptr<extensions::ExtensionsBrowserClient> extensions_browser_client_; 192 scoped_refptr<extensions::EventRouterForwarder> 193 extension_event_router_forwarder_; 194 195#if !defined(OS_ANDROID) 196 scoped_ptr<RemoteDebuggingServer> remote_debugging_server_; 197#endif 198 199#if !defined(OS_ANDROID) && !defined(OS_IOS) 200 scoped_ptr<MediaFileSystemRegistry> media_file_system_registry_; 201#endif 202 203 scoped_refptr<printing::PrintPreviewDialogController> 204 print_preview_dialog_controller_; 205 206 scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_; 207 208 // Manager for desktop notification UI. 209 bool created_notification_ui_manager_; 210 scoped_ptr<NotificationUIManager> notification_ui_manager_; 211 212 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector_; 213 214 scoped_ptr<StatusTray> status_tray_; 215 216 scoped_ptr<BackgroundModeManager> background_mode_manager_; 217 218 bool created_safe_browsing_service_; 219 scoped_refptr<SafeBrowsingService> safe_browsing_service_; 220 221 unsigned int module_ref_count_; 222 bool did_start_; 223 224 // Ensures that all the print jobs are finished before closing the browser. 225 scoped_ptr<printing::PrintJobManager> print_job_manager_; 226 227 std::string locale_; 228 229 // Download status updates (like a changing application icon on dock/taskbar) 230 // are global per-application. DownloadStatusUpdater does no work in the ctor 231 // so we don't have to worry about lazy initialization. 232 scoped_ptr<DownloadStatusUpdater> download_status_updater_; 233 234 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; 235 236 // Sequenced task runner for local state related I/O tasks. 237 const scoped_refptr<base::SequencedTaskRunner> local_state_task_runner_; 238 239 // Ensures that the observers of plugin/print disable/enable state 240 // notifications are properly added and removed. 241 PrefChangeRegistrar pref_change_registrar_; 242 243 // Lives here so can safely log events on shutdown. 244 scoped_ptr<ChromeNetLog> net_log_; 245 246 // Ordered before resource_dispatcher_host_delegate_ due to destruction 247 // ordering. 248 scoped_ptr<prerender::PrerenderTracker> prerender_tracker_; 249 250 scoped_ptr<ChromeResourceDispatcherHostDelegate> 251 resource_dispatcher_host_delegate_; 252 253 scoped_refptr<PromoResourceService> promo_resource_service_; 254 255#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 256 base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_; 257 258 // Gets called by autoupdate timer to see if browser needs restart and can be 259 // restarted, and if that's the case, restarts the browser. 260 void OnAutoupdateTimer(); 261 bool CanAutorestartForUpdate() const; 262 void RestartBackgroundInstance(); 263#endif // defined(OS_WIN) || defined(OS_LINUX) && !defined(OS_CHROMEOS) 264 265 // component updater is normally not used under ChromeOS due 266 // to concerns over integrity of data shared between profiles, 267 // but some users of component updater only install per-user. 268 scoped_ptr<component_updater::ComponentUpdateService> component_updater_; 269 scoped_refptr<CRLSetFetcher> crl_set_fetcher_; 270 scoped_ptr<component_updater::PnaclComponentInstaller> 271 pnacl_component_installer_; 272 273#if defined(ENABLE_PLUGIN_INSTALLATION) 274 scoped_refptr<PluginsResourceService> plugins_resource_service_; 275#endif 276 277 scoped_ptr<BrowserProcessPlatformPart> platform_part_; 278 279 // TODO(eroman): Remove this when done debugging 113031. This tracks 280 // the callstack which released the final module reference count. 281 base::debug::StackTrace release_last_reference_callstack_; 282 283#if defined(ENABLE_WEBRTC) 284 // Lazily initialized. 285 scoped_ptr<WebRtcLogUploader> webrtc_log_uploader_; 286#endif 287 288 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl); 289}; 290 291#endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_ 292