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 // This interface is for managing the global services of the application. Each 6 // service is lazily created when requested the first time. The service getters 7 // will return NULL if the service is not available, so callers must check for 8 // this condition. 9 10 #ifndef CHROME_BROWSER_BROWSER_PROCESS_H_ 11 #define CHROME_BROWSER_BROWSER_PROCESS_H_ 12 13 #include <stdint.h> 14 15 #include <memory> 16 #include <string> 17 18 #include "base/callback_forward.h" 19 #include "base/macros.h" 20 #include "base/memory/scoped_refptr.h" 21 #include "build/build_config.h" 22 #include "chrome/common/buildflags.h" 23 #include "media/media_buildflags.h" 24 25 class BackgroundModeManager; 26 class BrowserProcessPlatformPart; 27 class BuildState; 28 class DownloadRequestLimiter; 29 class DownloadStatusUpdater; 30 class GpuModeManager; 31 class IconManager; 32 class MediaFileSystemRegistry; 33 class NotificationPlatformBridge; 34 class NotificationUIManager; 35 class PrefService; 36 class ProfileManager; 37 class StatusTray; 38 class SystemNetworkContextManager; 39 class WatchDogThread; 40 class WebRtcLogUploader; 41 class StartupData; 42 43 #if !defined(OS_ANDROID) 44 class IntranetRedirectDetector; 45 #endif 46 47 namespace network { 48 class NetworkQualityTracker; 49 class SharedURLLoaderFactory; 50 } 51 52 namespace safe_browsing { 53 class SafeBrowsingService; 54 } 55 56 namespace subresource_filter { 57 class RulesetService; 58 } 59 60 namespace federated_learning { 61 class FlocSortingLshClustersService; 62 } 63 64 namespace variations { 65 class VariationsService; 66 } 67 68 namespace component_updater { 69 class ComponentUpdateService; 70 class SupervisedUserWhitelistInstaller; 71 } 72 73 namespace extensions { 74 class EventRouterForwarder; 75 } 76 77 namespace gcm { 78 class GCMDriver; 79 } 80 81 namespace metrics { 82 class MetricsService; 83 } 84 85 namespace metrics_services_manager { 86 class MetricsServicesManager; 87 } 88 89 namespace network_time { 90 class NetworkTimeTracker; 91 } 92 93 namespace optimization_guide { 94 class OptimizationGuideService; 95 } 96 97 namespace policy { 98 class ChromeBrowserPolicyConnector; 99 class PolicyService; 100 } 101 102 namespace printing { 103 class BackgroundPrintingManager; 104 class PrintJobManager; 105 class PrintPreviewDialogController; 106 } 107 108 namespace rappor { 109 class RapporServiceImpl; 110 } 111 112 namespace resource_coordinator { 113 class ResourceCoordinatorParts; 114 class TabManager; 115 } 116 117 // NOT THREAD SAFE, call only from the main thread. 118 // These functions shouldn't return NULL unless otherwise noted. 119 class BrowserProcess { 120 public: 121 BrowserProcess(); 122 virtual ~BrowserProcess(); 123 124 // Invoked when the user is logging out/shutting down. When logging off we may 125 // not have enough time to do a normal shutdown. This method is invoked prior 126 // to normal shutdown and saves any state that must be saved before system 127 // shutdown. 128 virtual void EndSession() = 0; 129 130 // Ensures |local_state()| was flushed to disk and then posts |reply| back on 131 // the current sequence. 132 virtual void FlushLocalStateAndReply(base::OnceClosure reply) = 0; 133 134 // Gets the manager for the various metrics-related services, constructing it 135 // if necessary. 136 virtual metrics_services_manager::MetricsServicesManager* 137 GetMetricsServicesManager() = 0; 138 139 // Services: any of these getters may return NULL 140 virtual metrics::MetricsService* metrics_service() = 0; 141 virtual rappor::RapporServiceImpl* rappor_service() = 0; 142 virtual ProfileManager* profile_manager() = 0; 143 virtual PrefService* local_state() = 0; 144 virtual scoped_refptr<network::SharedURLLoaderFactory> 145 shared_url_loader_factory() = 0; 146 virtual variations::VariationsService* variations_service() = 0; 147 148 virtual BrowserProcessPlatformPart* platform_part() = 0; 149 150 virtual extensions::EventRouterForwarder* 151 extension_event_router_forwarder() = 0; 152 153 // Returns the manager for desktop notifications. 154 // TODO(miguelg) This is in the process of being deprecated in favour of 155 // NotificationPlatformBridge + NotificationDisplayService 156 virtual NotificationUIManager* notification_ui_manager() = 0; 157 virtual NotificationPlatformBridge* notification_platform_bridge() = 0; 158 159 // Replacement for IOThread. It owns and manages the 160 // NetworkContext which will use the network service when the network service 161 // is enabled. When the network service is not enabled, its NetworkContext is 162 // backed by the IOThread's URLRequestContext. 163 virtual SystemNetworkContextManager* system_network_context_manager() = 0; 164 165 // Returns a NetworkQualityTracker that can be used to subscribe for 166 // network quality change events. 167 virtual network::NetworkQualityTracker* network_quality_tracker() = 0; 168 169 // Returns the thread that is used for health check of all browser threads. 170 virtual WatchDogThread* watchdog_thread() = 0; 171 172 // Starts and manages the policy system. 173 virtual policy::ChromeBrowserPolicyConnector* browser_policy_connector() = 0; 174 175 // This is the main interface for chromium components to retrieve policy 176 // information from the policy system. 177 virtual policy::PolicyService* policy_service() = 0; 178 179 virtual IconManager* icon_manager() = 0; 180 181 virtual GpuModeManager* gpu_mode_manager() = 0; 182 183 virtual void CreateDevToolsProtocolHandler() = 0; 184 185 virtual void CreateDevToolsAutoOpener() = 0; 186 187 virtual bool IsShuttingDown() = 0; 188 189 virtual printing::PrintJobManager* print_job_manager() = 0; 190 virtual printing::PrintPreviewDialogController* 191 print_preview_dialog_controller() = 0; 192 virtual printing::BackgroundPrintingManager* 193 background_printing_manager() = 0; 194 195 #if !defined(OS_ANDROID) 196 virtual IntranetRedirectDetector* intranet_redirect_detector() = 0; 197 #endif 198 199 // Returns the locale used by the application. It is the IETF language tag, 200 // defined in BCP 47. The region subtag is not included when it adds no 201 // distinguishing information to the language tag (e.g. both "en-US" and "fr" 202 // are correct here). 203 virtual const std::string& GetApplicationLocale() = 0; 204 virtual void SetApplicationLocale(const std::string& actual_locale) = 0; 205 206 virtual DownloadStatusUpdater* download_status_updater() = 0; 207 virtual DownloadRequestLimiter* download_request_limiter() = 0; 208 209 // Returns the object that manages background applications. 210 virtual BackgroundModeManager* background_mode_manager() = 0; 211 virtual void set_background_mode_manager_for_test( 212 std::unique_ptr<BackgroundModeManager> manager) = 0; 213 214 // Returns the StatusTray, which provides an API for displaying status icons 215 // in the system status tray. Returns NULL if status icons are not supported 216 // on this platform (or this is a unit test). 217 virtual StatusTray* status_tray() = 0; 218 219 // Returns the SafeBrowsing service. 220 virtual safe_browsing::SafeBrowsingService* safe_browsing_service() = 0; 221 222 // Returns the service providing versioned storage for rules used by the Safe 223 // Browsing subresource filter. 224 virtual subresource_filter::RulesetService* 225 subresource_filter_ruleset_service() = 0; 226 227 // Returns the service providing versioned storage for a list of limit values 228 // for calculating the floc based on SortingLSH. 229 virtual federated_learning::FlocSortingLshClustersService* 230 floc_sorting_lsh_clusters_service() = 0; 231 232 // Returns the service used to provide hints for what optimizations can be 233 // performed on slow page loads. 234 virtual optimization_guide::OptimizationGuideService* 235 optimization_guide_service() = 0; 236 237 // Returns the StartupData which owns any pre-created objects in //chrome 238 // before the full browser starts. 239 virtual StartupData* startup_data() = 0; 240 241 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 242 // This will start a timer that, if Chrome is in persistent mode, will check 243 // whether an update is available, and if that's the case, restart the 244 // browser. Note that restart code will strip some of the command line keys 245 // and all loose values from the cl this instance of Chrome was launched with, 246 // and add the command line key that will force Chrome to start in the 247 // background mode. For the full list of "blacklisted" keys, refer to 248 // |kSwitchesToRemoveOnAutorestart| array in browser_process_impl.cc. 249 virtual void StartAutoupdateTimer() = 0; 250 #endif 251 252 virtual component_updater::ComponentUpdateService* component_updater() = 0; 253 254 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) 255 virtual component_updater::SupervisedUserWhitelistInstaller* 256 supervised_user_whitelist_installer() = 0; 257 #endif 258 259 virtual MediaFileSystemRegistry* media_file_system_registry() = 0; 260 261 virtual WebRtcLogUploader* webrtc_log_uploader() = 0; 262 263 virtual network_time::NetworkTimeTracker* network_time_tracker() = 0; 264 265 #if !defined(OS_ANDROID) 266 // Avoid using this. Prefer using GCMProfileServiceFactory. 267 virtual gcm::GCMDriver* gcm_driver() = 0; 268 #endif 269 270 // Returns the tab manager. On non-supported platforms, this returns null. 271 // TODO(sebmarchand): Update callers to 272 // resource_coordinator_parts()->tab_manager() and remove this. 273 virtual resource_coordinator::TabManager* GetTabManager() = 0; 274 275 virtual resource_coordinator::ResourceCoordinatorParts* 276 resource_coordinator_parts() = 0; 277 278 virtual BuildState* GetBuildState() = 0; 279 280 private: 281 DISALLOW_COPY_AND_ASSIGN(BrowserProcess); 282 }; 283 284 extern BrowserProcess* g_browser_process; 285 286 #endif // CHROME_BROWSER_BROWSER_PROCESS_H_ 287