1 // Copyright (c) 2011 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 #pragma once 13 14 #include <string> 15 #include <vector> 16 17 #include "base/basictypes.h" 18 #include "base/memory/ref_counted.h" 19 #include "ipc/ipc_message.h" 20 21 class AutomationProviderList; 22 23 namespace safe_browsing { 24 class ClientSideDetectionService; 25 } 26 27 class ChromeNetLog; 28 class DevToolsManager; 29 class DownloadRequestLimiter; 30 class DownloadStatusUpdater; 31 class ExtensionEventRouterForwarder; 32 class GoogleURLTracker; 33 class IconManager; 34 class IntranetRedirectDetector; 35 class IOThread; 36 class MetricsService; 37 class NotificationUIManager; 38 class PrefService; 39 class ProfileManager; 40 class ResourceDispatcherHost; 41 class SidebarManager; 42 class TabCloseableStateWatcher; 43 class ThumbnailGenerator; 44 class WatchDogThread; 45 46 namespace base { 47 class Thread; 48 class WaitableEvent; 49 } 50 51 #if defined(OS_CHROMEOS) 52 namespace chromeos { 53 class ProxyConfigServiceImpl; 54 } 55 #endif // defined(OS_CHROMEOS) 56 57 namespace net { 58 class URLRequestContextGetter; 59 } 60 61 namespace printing { 62 class PrintJobManager; 63 class PrintPreviewTabController; 64 } 65 66 namespace policy { 67 class BrowserPolicyConnector; 68 } 69 70 namespace ui { 71 class Clipboard; 72 } 73 74 // NOT THREAD SAFE, call only from the main thread. 75 // These functions shouldn't return NULL unless otherwise noted. 76 class BrowserProcess { 77 public: 78 BrowserProcess(); 79 virtual ~BrowserProcess(); 80 81 // Invoked when the user is logging out/shutting down. When logging off we may 82 // not have enough time to do a normal shutdown. This method is invoked prior 83 // to normal shutdown and saves any state that must be saved before we are 84 // continue shutdown. 85 virtual void EndSession() = 0; 86 87 // Services: any of these getters may return NULL 88 virtual ResourceDispatcherHost* resource_dispatcher_host() = 0; 89 90 virtual MetricsService* metrics_service() = 0; 91 virtual ProfileManager* profile_manager() = 0; 92 virtual PrefService* local_state() = 0; 93 virtual DevToolsManager* devtools_manager() = 0; 94 virtual SidebarManager* sidebar_manager() = 0; 95 virtual ui::Clipboard* clipboard() = 0; 96 virtual net::URLRequestContextGetter* system_request_context() = 0; 97 98 #if defined(OS_CHROMEOS) 99 // Returns ChromeOS's ProxyConfigServiceImpl, creating if not yet created. 100 virtual chromeos::ProxyConfigServiceImpl* 101 chromeos_proxy_config_service_impl() = 0; 102 #endif // defined(OS_CHROMEOS) 103 104 virtual ExtensionEventRouterForwarder* 105 extension_event_router_forwarder() = 0; 106 107 // Returns the manager for desktop notifications. 108 virtual NotificationUIManager* notification_ui_manager() = 0; 109 110 // Returns the thread that we perform I/O coordination on (network requests, 111 // communication with renderers, etc. 112 // NOTE: You should ONLY use this to pass to IPC or other objects which must 113 // need a MessageLoop*. If you just want to post a task, use 114 // BrowserThread::PostTask (or other variants) as they take care of checking 115 // that a thread is still alive, race conditions, lifetime differences etc. 116 // If you still must use this check the return value for NULL. 117 virtual IOThread* io_thread() = 0; 118 119 // Returns the thread that we perform random file operations on. For code 120 // that wants to do I/O operations (not network requests or even file: URL 121 // requests), this is the thread to use to avoid blocking the UI thread. 122 // It might be nicer to have a thread pool for this kind of thing. 123 virtual base::Thread* file_thread() = 0; 124 125 // Returns the thread that is used for database operations such as the web 126 // database. History has its own thread since it has much higher traffic. 127 virtual base::Thread* db_thread() = 0; 128 129 // Returns the thread that is used for background cache operations. 130 virtual base::Thread* cache_thread() = 0; 131 132 // Returns the thread that issues GPU calls. 133 virtual base::Thread* gpu_thread() = 0; 134 135 #if defined(USE_X11) 136 // Returns the thread that is used to process UI requests in cases where 137 // we can't route the request to the UI thread. Note that this thread 138 // should only be used by the IO thread and this method is only safe to call 139 // from the UI thread so, if you've ended up here, something has gone wrong. 140 // This method is only included for uniformity. 141 virtual base::Thread* background_x11_thread() = 0; 142 #endif 143 144 // Returns the thread that is used for health check of all browser threads. 145 virtual WatchDogThread* watchdog_thread() = 0; 146 147 virtual policy::BrowserPolicyConnector* browser_policy_connector() = 0; 148 149 virtual IconManager* icon_manager() = 0; 150 151 virtual ThumbnailGenerator* GetThumbnailGenerator() = 0; 152 153 virtual AutomationProviderList* InitAutomationProviderList() = 0; 154 155 virtual void InitDevToolsHttpProtocolHandler( 156 const std::string& ip, 157 int port, 158 const std::string& frontend_url) = 0; 159 160 virtual void InitDevToolsLegacyProtocolHandler(int port) = 0; 161 162 virtual unsigned int AddRefModule() = 0; 163 virtual unsigned int ReleaseModule() = 0; 164 165 virtual bool IsShuttingDown() = 0; 166 167 virtual printing::PrintJobManager* print_job_manager() = 0; 168 virtual printing::PrintPreviewTabController* 169 print_preview_tab_controller() = 0; 170 171 virtual GoogleURLTracker* google_url_tracker() = 0; 172 virtual IntranetRedirectDetector* intranet_redirect_detector() = 0; 173 174 // Returns the locale used by the application. 175 virtual const std::string& GetApplicationLocale() = 0; 176 virtual void SetApplicationLocale(const std::string& locale) = 0; 177 178 DownloadRequestLimiter* download_request_limiter(); 179 virtual DownloadStatusUpdater* download_status_updater() = 0; 180 181 // Returns an event that is signaled when the browser shutdown. 182 virtual base::WaitableEvent* shutdown_event() = 0; 183 184 // Returns a reference to the user-data-dir based profiles vector. 185 std::vector<std::wstring>& user_data_dir_profiles() { 186 return user_data_dir_profiles_; 187 } 188 189 // Returns the object that watches for changes in the closeable state of tab. 190 virtual TabCloseableStateWatcher* tab_closeable_state_watcher() = 0; 191 192 // Returns an object which handles communication with the SafeBrowsing 193 // client-side detection servers. 194 virtual safe_browsing::ClientSideDetectionService* 195 safe_browsing_detection_service() = 0; 196 197 // Returns the state of the disable plugin finder policy. Callable only on 198 // the IO thread. 199 virtual bool plugin_finder_disabled() const = 0; 200 201 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 202 // This will start a timer that, if Chrome is in persistent mode, will check 203 // whether an update is available, and if that's the case, restart the 204 // browser. Note that restart code will strip some of the command line keys 205 // and all loose values from the cl this instance of Chrome was launched with, 206 // and add the command line key that will force Chrome to start in the 207 // background mode. For the full list of "blacklisted" keys, refer to 208 // |kSwitchesToRemoveOnAutorestart| array in browser_process_impl.cc. 209 virtual void StartAutoupdateTimer() = 0; 210 #endif 211 212 virtual ChromeNetLog* net_log() = 0; 213 214 #if defined(IPC_MESSAGE_LOG_ENABLED) 215 // Enable or disable IPC logging for the browser, all processes 216 // derived from ChildProcess (plugin etc), and all 217 // renderers. 218 virtual void SetIPCLoggingEnabled(bool enable) = 0; 219 #endif 220 221 const std::string& plugin_data_remover_mime_type() const { 222 return plugin_data_remover_mime_type_; 223 } 224 225 void set_plugin_data_remover_mime_type(const std::string& mime_type) { 226 plugin_data_remover_mime_type_ = mime_type; 227 } 228 229 private: 230 // User-data-dir based profiles. 231 std::vector<std::wstring> user_data_dir_profiles_; 232 233 // Used for testing plugin data removal at shutdown. 234 std::string plugin_data_remover_mime_type_; 235 236 DISALLOW_COPY_AND_ASSIGN(BrowserProcess); 237 }; 238 239 extern BrowserProcess* g_browser_process; 240 241 #endif // CHROME_BROWSER_BROWSER_PROCESS_H_ 242