Home | History | Annotate | Download | only in browser
      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/memory/scoped_ptr.h"
     18 #include "base/message_loop.h"
     19 #include "base/threading/non_thread_safe.h"
     20 #include "base/timer.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/prefs/pref_member.h"
     25 #include "chrome/browser/tab_contents/thumbnail_generator.h"
     26 #include "content/common/notification_observer.h"
     27 #include "content/common/notification_registrar.h"
     28 #include "ipc/ipc_message.h"
     29 
     30 class ChromeNetLog;
     31 class CommandLine;
     32 class DevToolsHttpProtocolHandler;
     33 class DevToolsProtocolHandler;
     34 class FilePath;
     35 class NotificationService;
     36 class PluginDataRemover;
     37 class TabCloseableStateWatcher;
     38 
     39 // Real implementation of BrowserProcess that creates and returns the services.
     40 class BrowserProcessImpl : public BrowserProcess,
     41                            public base::NonThreadSafe,
     42                            public NotificationObserver {
     43  public:
     44   explicit BrowserProcessImpl(const CommandLine& command_line);
     45   virtual ~BrowserProcessImpl();
     46 
     47   virtual void EndSession();
     48 
     49   // BrowserProcess methods
     50   virtual ResourceDispatcherHost* resource_dispatcher_host();
     51   virtual MetricsService* metrics_service();
     52   virtual IOThread* io_thread();
     53   virtual base::Thread* file_thread();
     54   virtual base::Thread* db_thread();
     55   virtual base::Thread* process_launcher_thread();
     56   virtual base::Thread* cache_thread();
     57   virtual base::Thread* gpu_thread();
     58 #if defined(USE_X11)
     59   virtual base::Thread* background_x11_thread();
     60 #endif
     61   virtual WatchDogThread* watchdog_thread();
     62   virtual ProfileManager* profile_manager();
     63   virtual PrefService* local_state();
     64   virtual DevToolsManager* devtools_manager();
     65   virtual SidebarManager* sidebar_manager();
     66   virtual ui::Clipboard* clipboard();
     67   virtual net::URLRequestContextGetter* system_request_context();
     68 #if defined(OS_CHROMEOS)
     69   virtual chromeos::ProxyConfigServiceImpl*
     70       chromeos_proxy_config_service_impl();
     71 #endif  // defined(OS_CHROMEOS)
     72   virtual ExtensionEventRouterForwarder* extension_event_router_forwarder();
     73   virtual NotificationUIManager* notification_ui_manager();
     74   virtual policy::BrowserPolicyConnector* browser_policy_connector();
     75   virtual IconManager* icon_manager();
     76   virtual ThumbnailGenerator* GetThumbnailGenerator();
     77   virtual AutomationProviderList* InitAutomationProviderList();
     78   virtual void InitDevToolsHttpProtocolHandler(
     79       const std::string& ip,
     80       int port,
     81       const std::string& frontend_url);
     82   virtual void InitDevToolsLegacyProtocolHandler(int port);
     83   virtual unsigned int AddRefModule();
     84   virtual unsigned int ReleaseModule();
     85   virtual bool IsShuttingDown();
     86   virtual printing::PrintJobManager* print_job_manager();
     87   virtual printing::PrintPreviewTabController* print_preview_tab_controller();
     88   virtual GoogleURLTracker* google_url_tracker();
     89   virtual IntranetRedirectDetector* intranet_redirect_detector();
     90   virtual const std::string& GetApplicationLocale();
     91   virtual void SetApplicationLocale(const std::string& locale);
     92   virtual DownloadStatusUpdater* download_status_updater();
     93   virtual base::WaitableEvent* shutdown_event();
     94   virtual TabCloseableStateWatcher* tab_closeable_state_watcher();
     95   virtual safe_browsing::ClientSideDetectionService*
     96       safe_browsing_detection_service();
     97   virtual bool plugin_finder_disabled() const;
     98 
     99   // NotificationObserver methods
    100   virtual void Observe(NotificationType type,
    101                        const NotificationSource& source,
    102                        const NotificationDetails& details);
    103 
    104 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
    105   virtual void StartAutoupdateTimer();
    106 #endif
    107 
    108   virtual ChromeNetLog* net_log();
    109 
    110 #if defined(IPC_MESSAGE_LOG_ENABLED)
    111   virtual void SetIPCLoggingEnabled(bool enable);
    112 #endif
    113 
    114  private:
    115   void ClearLocalState(const FilePath& profile_path);
    116   bool ShouldClearLocalState(FilePath* profile_path);
    117 
    118   void CreateResourceDispatcherHost();
    119   void CreateMetricsService();
    120 
    121   void CreateIOThread();
    122   static void CleanupOnIOThread();
    123 
    124   void WaitForPluginDataRemoverToFinish();
    125 
    126   void CreateFileThread();
    127   void CreateDBThread();
    128   void CreateProcessLauncherThread();
    129   void CreateCacheThread();
    130   void CreateGpuThread();
    131   void CreateWatchdogThread();
    132   void CreateTemplateURLModel();
    133   void CreateProfileManager();
    134   void CreateWebDataService();
    135   void CreateLocalState();
    136   void CreateViewedPageTracker();
    137   void CreateIconManager();
    138   void CreateDevToolsManager();
    139   void CreateSidebarManager();
    140   void CreateGoogleURLTracker();
    141   void CreateIntranetRedirectDetector();
    142   void CreateNotificationUIManager();
    143   void CreateStatusTrayManager();
    144   void CreateTabCloseableStateWatcher();
    145   void CreatePrintPreviewTabController();
    146   void CreateSafeBrowsingDetectionService();
    147 
    148   bool IsSafeBrowsingDetectionServiceEnabled();
    149 
    150   void ApplyDisabledSchemesPolicy();
    151 
    152 #if defined(IPC_MESSAGE_LOG_ENABLED)
    153   void SetIPCLoggingEnabledForChildProcesses(bool enabled);
    154 #endif
    155 
    156   bool created_resource_dispatcher_host_;
    157   scoped_ptr<ResourceDispatcherHost> resource_dispatcher_host_;
    158 
    159   bool created_metrics_service_;
    160   scoped_ptr<MetricsService> metrics_service_;
    161 
    162   bool created_io_thread_;
    163   scoped_ptr<IOThread> io_thread_;
    164 #if defined(USE_X11)
    165   // This shares a created flag with the IO thread.
    166   scoped_ptr<base::Thread> background_x11_thread_;
    167 #endif
    168 
    169   bool created_file_thread_;
    170   scoped_ptr<base::Thread> file_thread_;
    171 
    172   bool created_db_thread_;
    173   scoped_ptr<base::Thread> db_thread_;
    174 
    175   bool created_process_launcher_thread_;
    176   scoped_ptr<base::Thread> process_launcher_thread_;
    177 
    178   bool created_cache_thread_;
    179   scoped_ptr<base::Thread> cache_thread_;
    180 
    181   bool created_gpu_thread_;
    182   scoped_ptr<base::Thread> gpu_thread_;
    183 
    184   bool created_watchdog_thread_;
    185   scoped_ptr<WatchDogThread> watchdog_thread_;
    186 
    187   bool created_profile_manager_;
    188   scoped_ptr<ProfileManager> profile_manager_;
    189 
    190   bool created_local_state_;
    191   scoped_ptr<PrefService> local_state_;
    192 
    193   bool created_icon_manager_;
    194   scoped_ptr<IconManager> icon_manager_;
    195 
    196   scoped_refptr<ExtensionEventRouterForwarder>
    197       extension_event_router_forwarder_;
    198 
    199   scoped_refptr<DevToolsHttpProtocolHandler> devtools_http_handler_;
    200 
    201   scoped_refptr<DevToolsProtocolHandler> devtools_legacy_handler_;
    202 
    203   bool created_devtools_manager_;
    204   scoped_refptr<DevToolsManager> devtools_manager_;
    205 
    206   bool created_sidebar_manager_;
    207   scoped_refptr<SidebarManager> sidebar_manager_;
    208 
    209   bool created_browser_policy_connector_;
    210   scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_;
    211 
    212   scoped_refptr<printing::PrintPreviewTabController>
    213       print_preview_tab_controller_;
    214 
    215   scoped_ptr<ui::Clipboard> clipboard_;
    216 
    217   // Manager for desktop notification UI.
    218   bool created_notification_ui_manager_;
    219   scoped_ptr<NotificationUIManager> notification_ui_manager_;
    220 
    221   scoped_ptr<AutomationProviderList> automation_provider_list_;
    222 
    223   scoped_ptr<GoogleURLTracker> google_url_tracker_;
    224   scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector_;
    225 
    226   scoped_ptr<NotificationService> main_notification_service_;
    227 
    228   scoped_ptr<TabCloseableStateWatcher> tab_closeable_state_watcher_;
    229 
    230   bool created_safe_browsing_detection_service_;
    231   scoped_ptr<safe_browsing::ClientSideDetectionService>
    232      safe_browsing_detection_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 thumbnails for tabs. It does
    246   // nothing in the constructor so we don't have to worry about lazy init.
    247   ThumbnailGenerator thumbnail_generator_;
    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   DownloadStatusUpdater download_status_updater_;
    253 
    254   // An event that notifies when we are shutting-down.
    255   scoped_ptr<base::WaitableEvent> shutdown_event_;
    256 
    257   // Ensures that the observers of plugin/print disable/enable state
    258   // notifications are properly added and removed.
    259   PrefChangeRegistrar pref_change_registrar_;
    260 
    261   // Lives here so can safely log events on shutdown.
    262   scoped_ptr<ChromeNetLog> net_log_;
    263 
    264   NotificationRegistrar notification_registrar_;
    265   scoped_refptr<PluginDataRemover> plugin_data_remover_;
    266 
    267   // Monitors the state of the 'DisablePluginFinder' policy.
    268   BooleanPrefMember plugin_finder_disabled_pref_;
    269 
    270   // Monitors the list of disabled schemes policy.
    271   ListPrefMember disabled_schemes_pref_;
    272 
    273 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
    274   base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_;
    275 
    276   // Gets called by autoupdate timer to see if browser needs restart and can be
    277   // restarted, and if that's the case, restarts the browser.
    278   void OnAutoupdateTimer();
    279   bool CanAutorestartForUpdate() const;
    280   void RestartPersistentInstance();
    281 #endif  // defined(OS_WIN) || defined(OS_LINUX)
    282 
    283 #if defined(OS_CHROMEOS)
    284   scoped_refptr<chromeos::ProxyConfigServiceImpl>
    285       chromeos_proxy_config_service_impl_;
    286 #endif
    287 
    288   DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl);
    289 };
    290 
    291 #endif  // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_
    292