browser_process_impl.h revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
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// 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#pragma once 13 14#include <string> 15 16#include "base/basictypes.h" 17#include "base/message_loop.h" 18#include "base/threading/non_thread_safe.h" 19#include "base/timer.h" 20#include "base/scoped_ptr.h" 21#include "chrome/browser/browser_process.h" 22#include "chrome/browser/download/download_status_updater.h" 23#include "chrome/browser/prefs/pref_change_registrar.h" 24#include "chrome/browser/tab_contents/thumbnail_generator.h" 25#include "chrome/common/notification_observer.h" 26#include "chrome/common/notification_registrar.h" 27#include "ipc/ipc_message.h" 28 29class ChromeNetLog; 30class CommandLine; 31class DevToolsHttpProtocolHandler; 32class DevToolsProtocolHandler; 33class FilePath; 34class NotificationService; 35class PluginDataRemover; 36class TabCloseableStateWatcher; 37 38// Real implementation of BrowserProcess that creates and returns the services. 39class BrowserProcessImpl : public BrowserProcess, 40 public base::NonThreadSafe, 41 public NotificationObserver { 42 public: 43 explicit BrowserProcessImpl(const CommandLine& command_line); 44 virtual ~BrowserProcessImpl(); 45 46 virtual void EndSession(); 47 48 // BrowserProcess methods 49 virtual ResourceDispatcherHost* resource_dispatcher_host(); 50 virtual MetricsService* metrics_service(); 51 virtual IOThread* io_thread(); 52 virtual base::Thread* file_thread(); 53 virtual base::Thread* db_thread(); 54 virtual base::Thread* process_launcher_thread(); 55 virtual base::Thread* cache_thread(); 56#if defined(USE_X11) 57 virtual base::Thread* background_x11_thread(); 58#endif 59 virtual ProfileManager* profile_manager(); 60 virtual PrefService* local_state(); 61 virtual DevToolsManager* devtools_manager(); 62 virtual SidebarManager* sidebar_manager(); 63 virtual ui::Clipboard* clipboard(); 64 virtual NotificationUIManager* notification_ui_manager(); 65 virtual policy::ConfigurationPolicyProviderKeeper* 66 configuration_policy_provider_keeper(); 67 virtual IconManager* icon_manager(); 68 virtual ThumbnailGenerator* GetThumbnailGenerator(); 69 virtual AutomationProviderList* InitAutomationProviderList(); 70 virtual void InitDevToolsHttpProtocolHandler( 71 const std::string& ip, 72 int port, 73 const std::string& frontend_url); 74 virtual void InitDevToolsLegacyProtocolHandler(int port); 75 virtual unsigned int AddRefModule(); 76 virtual unsigned int ReleaseModule(); 77 virtual bool IsShuttingDown(); 78 virtual printing::PrintJobManager* print_job_manager(); 79 virtual printing::PrintPreviewTabController* print_preview_tab_controller(); 80 virtual GoogleURLTracker* google_url_tracker(); 81 virtual IntranetRedirectDetector* intranet_redirect_detector(); 82 virtual const std::string& GetApplicationLocale(); 83 virtual void SetApplicationLocale(const std::string& locale); 84 virtual DownloadStatusUpdater* download_status_updater(); 85 virtual base::WaitableEvent* shutdown_event(); 86 virtual TabCloseableStateWatcher* tab_closeable_state_watcher(); 87 virtual safe_browsing::ClientSideDetectionService* 88 safe_browsing_detection_service(); 89 virtual void CheckForInspectorFiles(); 90 91 // NotificationObserver methods 92 virtual void Observe(NotificationType type, 93 const NotificationSource& source, 94 const NotificationDetails& details); 95 96#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 97 virtual void StartAutoupdateTimer(); 98#endif 99 100 virtual bool have_inspector_files() const; 101 102 virtual ChromeNetLog* net_log(); 103 104#if defined(IPC_MESSAGE_LOG_ENABLED) 105 virtual void SetIPCLoggingEnabled(bool enable); 106#endif 107 108 private: 109 void ClearLocalState(const FilePath& profile_path); 110 bool ShouldClearLocalState(FilePath* profile_path); 111 112 void CreateResourceDispatcherHost(); 113 void CreatePrefService(); 114 void CreateMetricsService(); 115 116 void CreateIOThread(); 117 static void CleanupOnIOThread(); 118 119 void WaitForPluginDataRemoverToFinish(); 120 121 void CreateFileThread(); 122 void CreateDBThread(); 123 void CreateProcessLauncherThread(); 124 void CreateCacheThread(); 125 void CreateTemplateURLModel(); 126 void CreateProfileManager(); 127 void CreateWebDataService(); 128 void CreateLocalState(); 129 void CreateViewedPageTracker(); 130 void CreateIconManager(); 131 void CreateDevToolsManager(); 132 void CreateSidebarManager(); 133 void CreateGoogleURLTracker(); 134 void CreateIntranetRedirectDetector(); 135 void CreateNotificationUIManager(); 136 void CreateStatusTrayManager(); 137 void CreateTabCloseableStateWatcher(); 138 void CreatePrintPreviewTabController(); 139 void CreateSafeBrowsingDetectionService(); 140 141 bool IsSafeBrowsingDetectionServiceEnabled(); 142 143#if defined(IPC_MESSAGE_LOG_ENABLED) 144 void SetIPCLoggingEnabledForChildProcesses(bool enabled); 145#endif 146 147 bool created_resource_dispatcher_host_; 148 scoped_ptr<ResourceDispatcherHost> resource_dispatcher_host_; 149 150 bool created_metrics_service_; 151 scoped_ptr<MetricsService> metrics_service_; 152 153 bool created_io_thread_; 154 scoped_ptr<IOThread> io_thread_; 155#if defined(USE_X11) 156 // This shares a created flag with the IO thread. 157 scoped_ptr<base::Thread> background_x11_thread_; 158#endif 159 160 bool created_file_thread_; 161 scoped_ptr<base::Thread> file_thread_; 162 163 bool created_db_thread_; 164 scoped_ptr<base::Thread> db_thread_; 165 166 bool created_process_launcher_thread_; 167 scoped_ptr<base::Thread> process_launcher_thread_; 168 169 bool created_cache_thread_; 170 scoped_ptr<base::Thread> cache_thread_; 171 172 bool created_profile_manager_; 173 scoped_ptr<ProfileManager> profile_manager_; 174 175 bool created_local_state_; 176 scoped_ptr<PrefService> local_state_; 177 178 bool created_icon_manager_; 179 scoped_ptr<IconManager> icon_manager_; 180 181 scoped_refptr<DevToolsHttpProtocolHandler> devtools_http_handler_; 182 183 scoped_refptr<DevToolsProtocolHandler> devtools_legacy_handler_; 184 185 bool created_devtools_manager_; 186 scoped_refptr<DevToolsManager> devtools_manager_; 187 188 bool created_sidebar_manager_; 189 scoped_refptr<SidebarManager> sidebar_manager_; 190 191 bool created_configuration_policy_provider_keeper_; 192 scoped_ptr<policy::ConfigurationPolicyProviderKeeper> 193 configuration_policy_provider_keeper_; 194 195 scoped_refptr<printing::PrintPreviewTabController> 196 print_preview_tab_controller_; 197 198 scoped_ptr<ui::Clipboard> clipboard_; 199 200 // Manager for desktop notification UI. 201 bool created_notification_ui_manager_; 202 scoped_ptr<NotificationUIManager> notification_ui_manager_; 203 204 scoped_ptr<AutomationProviderList> automation_provider_list_; 205 206 scoped_ptr<GoogleURLTracker> google_url_tracker_; 207 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector_; 208 209 scoped_ptr<NotificationService> main_notification_service_; 210 211 scoped_ptr<TabCloseableStateWatcher> tab_closeable_state_watcher_; 212 213 bool created_safe_browsing_detection_service_; 214 scoped_ptr<safe_browsing::ClientSideDetectionService> 215 safe_browsing_detection_service_; 216 217 unsigned int module_ref_count_; 218 bool did_start_; 219 220 // Ensures that all the print jobs are finished before closing the browser. 221 scoped_ptr<printing::PrintJobManager> print_job_manager_; 222 223 std::string locale_; 224 225 bool checked_for_new_frames_; 226 bool using_new_frames_; 227 228 // This service just sits around and makes thumbnails for tabs. It does 229 // nothing in the constructor so we don't have to worry about lazy init. 230 ThumbnailGenerator thumbnail_generator_; 231 232 // Download status updates (like a changing application icon on dock/taskbar) 233 // are global per-application. DownloadStatusUpdater does no work in the ctor 234 // so we don't have to worry about lazy initialization. 235 DownloadStatusUpdater download_status_updater_; 236 237 // An event that notifies when we are shutting-down. 238 scoped_ptr<base::WaitableEvent> shutdown_event_; 239 240 // Runs on the file thread and stats the inspector's directory, filling in 241 // have_inspector_files_ with the result. 242 void DoInspectorFilesCheck(); 243 // Our best estimate about the existence of the inspector directory. 244 bool have_inspector_files_; 245 246 // Ensures that the observers of plugin/print disable/enable state 247 // notifications are properly added and removed. 248 PrefChangeRegistrar pref_change_registrar_; 249 250 // Lives here so can safely log events on shutdown. 251 scoped_ptr<ChromeNetLog> net_log_; 252 253 NotificationRegistrar notification_registrar_; 254 scoped_refptr<PluginDataRemover> plugin_data_remover_; 255 256#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 257 base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_; 258 259 // Gets called by autoupdate timer to see if browser needs restart and can be 260 // restarted, and if that's the case, restarts the browser. 261 void OnAutoupdateTimer(); 262 bool CanAutorestartForUpdate() const; 263 void RestartPersistentInstance(); 264#endif // defined(OS_WIN) || defined(OS_LINUX) 265 266 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl); 267}; 268 269#endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_ 270