blob: 92a7deb4d8ae1ee88ee27eb01d6c49540ac8e7de [file] [log] [blame]
[email protected]f2a893c2011-01-05 09:38:071// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
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
[email protected]58dca552009-06-17 00:35:0210#ifndef CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_
11#define CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_
[email protected]32b76ef2010-07-26 23:08:2412#pragma once
initial.commit09911bf2008-07-26 23:55:2913
14#include <string>
15
16#include "base/basictypes.h"
17#include "base/message_loop.h"
[email protected]c9177502011-01-01 04:48:4918#include "base/threading/non_thread_safe.h"
[email protected]bd48c2b02010-04-09 20:32:4219#include "base/timer.h"
initial.commit09911bf2008-07-26 23:55:2920#include "base/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2921#include "chrome/browser/browser_process.h"
[email protected]073ed7b2010-09-27 09:20:0222#include "chrome/browser/download/download_status_updater.h"
[email protected]492d2142010-09-10 13:55:1823#include "chrome/browser/prefs/pref_change_registrar.h"
[email protected]67a46b7f2009-06-16 21:41:0224#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]6618d1d2010-12-15 21:18:4725#include "chrome/common/notification_observer.h"
26#include "chrome/common/notification_registrar.h"
[email protected]d55aaa132009-09-28 21:08:0427#include "ipc/ipc_message.h"
[email protected]b112a4c2009-02-01 20:24:0128
[email protected]b2fcd0e2010-12-01 15:19:4029class ChromeNetLog;
initial.commit09911bf2008-07-26 23:55:2930class CommandLine;
[email protected]5613126e2011-01-31 15:27:5531class DevToolsHttpProtocolHandler;
32class DevToolsProtocolHandler;
[email protected]4ef795df2010-02-03 02:35:0833class FilePath;
initial.commit09911bf2008-07-26 23:55:2934class NotificationService;
[email protected]6618d1d2010-12-15 21:18:4735class PluginDataRemover;
[email protected]0b4d3382010-07-14 16:13:0436class TabCloseableStateWatcher;
initial.commit09911bf2008-07-26 23:55:2937
38// Real implementation of BrowserProcess that creates and returns the services.
[email protected]6618d1d2010-12-15 21:18:4739class BrowserProcessImpl : public BrowserProcess,
[email protected]c9177502011-01-01 04:48:4940 public base::NonThreadSafe,
[email protected]6618d1d2010-12-15 21:18:4741 public NotificationObserver {
initial.commit09911bf2008-07-26 23:55:2942 public:
[email protected]f3a4f302009-08-21 22:35:2943 explicit BrowserProcessImpl(const CommandLine& command_line);
initial.commit09911bf2008-07-26 23:55:2944 virtual ~BrowserProcessImpl();
45
46 virtual void EndSession();
47
[email protected]6618d1d2010-12-15 21:18:4748 // BrowserProcess methods
[email protected]e13ad79b2010-07-22 21:36:5049 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();
[email protected]25d47c7b2010-02-03 20:13:0656#if defined(USE_X11)
[email protected]e13ad79b2010-07-22 21:36:5057 virtual base::Thread* background_x11_thread();
[email protected]4c3cd7412009-04-22 17:56:0658#endif
[email protected]e13ad79b2010-07-22 21:36:5059 virtual ProfileManager* profile_manager();
60 virtual PrefService* local_state();
61 virtual DevToolsManager* devtools_manager();
[email protected]8b8e7c92010-08-19 18:05:5662 virtual SidebarManager* sidebar_manager();
[email protected]2dfeaf92011-01-10 21:08:2163 virtual ui::Clipboard* clipboard();
[email protected]e13ad79b2010-07-22 21:36:5064 virtual NotificationUIManager* notification_ui_manager();
[email protected]f2a893c2011-01-05 09:38:0765 virtual policy::ConfigurationPolicyProviderKeeper*
66 configuration_policy_provider_keeper();
[email protected]e13ad79b2010-07-22 21:36:5067 virtual IconManager* icon_manager();
68 virtual ThumbnailGenerator* GetThumbnailGenerator();
69 virtual AutomationProviderList* InitAutomationProviderList();
[email protected]5613126e2011-01-31 15:27:5570 virtual void InitDevToolsHttpProtocolHandler(
[email protected]01000cf12011-02-04 11:39:2271 const std::string& ip,
[email protected]5613126e2011-01-31 15:27:5572 int port,
73 const std::string& frontend_url);
74 virtual void InitDevToolsLegacyProtocolHandler(int port);
[email protected]b443cb042009-12-15 22:05:0975 virtual unsigned int AddRefModule();
[email protected]b443cb042009-12-15 22:05:0976 virtual unsigned int ReleaseModule();
[email protected]e13ad79b2010-07-22 21:36:5077 virtual bool IsShuttingDown();
initial.commit09911bf2008-07-26 23:55:2978 virtual printing::PrintJobManager* print_job_manager();
[email protected]dbeebd52010-11-16 20:34:1679 virtual printing::PrintPreviewTabController* print_preview_tab_controller();
[email protected]e13ad79b2010-07-22 21:36:5080 virtual GoogleURLTracker* google_url_tracker();
81 virtual IntranetRedirectDetector* intranet_redirect_detector();
82 virtual const std::string& GetApplicationLocale();
[email protected]f1b6de22010-03-06 12:13:4783 virtual void SetApplicationLocale(const std::string& locale);
[email protected]073ed7b2010-09-27 09:20:0284 virtual DownloadStatusUpdater* download_status_updater();
[email protected]e13ad79b2010-07-22 21:36:5085 virtual base::WaitableEvent* shutdown_event();
86 virtual TabCloseableStateWatcher* tab_closeable_state_watcher();
[email protected]a7a5e992010-12-09 23:39:5187 virtual safe_browsing::ClientSideDetectionService*
88 safe_browsing_detection_service();
[email protected]6641bf662009-08-21 00:34:0989 virtual void CheckForInspectorFiles();
90
[email protected]6618d1d2010-12-15 21:18:4791 // NotificationObserver methods
92 virtual void Observe(NotificationType type,
93 const NotificationSource& source,
94 const NotificationDetails& details);
95
[email protected]3cdacd42010-04-30 18:55:5396#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]78994ab02010-12-08 18:06:4497 virtual void StartAutoupdateTimer();
[email protected]3cdacd42010-04-30 18:55:5398#endif
[email protected]bd48c2b02010-04-09 20:32:4299
[email protected]e13ad79b2010-07-22 21:36:50100 virtual bool have_inspector_files() const;
[email protected]6641bf662009-08-21 00:34:09101
[email protected]d55aaa132009-09-28 21:08:04102#if defined(IPC_MESSAGE_LOG_ENABLED)
103 virtual void SetIPCLoggingEnabled(bool enable);
104#endif
105
initial.commit09911bf2008-07-26 23:55:29106 private:
[email protected]4ef795df2010-02-03 02:35:08107 void ClearLocalState(const FilePath& profile_path);
108 bool ShouldClearLocalState(FilePath* profile_path);
109
initial.commit09911bf2008-07-26 23:55:29110 void CreateResourceDispatcherHost();
111 void CreatePrefService();
112 void CreateMetricsService();
[email protected]48ca9012009-08-11 21:38:54113
initial.commit09911bf2008-07-26 23:55:29114 void CreateIOThread();
[email protected]48ca9012009-08-11 21:38:54115 static void CleanupOnIOThread();
116
[email protected]6618d1d2010-12-15 21:18:47117 void WaitForPluginDataRemoverToFinish();
118
initial.commit09911bf2008-07-26 23:55:29119 void CreateFileThread();
120 void CreateDBThread();
[email protected]914511712009-11-23 19:42:33121 void CreateProcessLauncherThread();
[email protected]875ee822010-05-18 20:58:01122 void CreateCacheThread();
initial.commit09911bf2008-07-26 23:55:29123 void CreateTemplateURLModel();
124 void CreateProfileManager();
125 void CreateWebDataService();
126 void CreateLocalState();
127 void CreateViewedPageTracker();
128 void CreateIconManager();
[email protected]40ecc902009-03-16 13:42:47129 void CreateDevToolsManager();
[email protected]8b8e7c92010-08-19 18:05:56130 void CreateSidebarManager();
initial.commit09911bf2008-07-26 23:55:29131 void CreateGoogleURLTracker();
[email protected]c4ff4952010-01-08 19:12:47132 void CreateIntranetRedirectDetector();
[email protected]29672ab2009-10-30 03:44:03133 void CreateNotificationUIManager();
[email protected]ccb55cf52010-03-06 22:02:04134 void CreateStatusTrayManager();
[email protected]0b4d3382010-07-14 16:13:04135 void CreateTabCloseableStateWatcher();
[email protected]dbeebd52010-11-16 20:34:16136 void CreatePrintPreviewTabController();
[email protected]a7a5e992010-12-09 23:39:51137 void CreateSafeBrowsingDetectionService();
138
139 bool IsSafeBrowsingDetectionServiceEnabled();
initial.commit09911bf2008-07-26 23:55:29140
[email protected]d55aaa132009-09-28 21:08:04141#if defined(IPC_MESSAGE_LOG_ENABLED)
142 void SetIPCLoggingEnabledForChildProcesses(bool enabled);
143#endif
144
initial.commit09911bf2008-07-26 23:55:29145 bool created_resource_dispatcher_host_;
146 scoped_ptr<ResourceDispatcherHost> resource_dispatcher_host_;
147
148 bool created_metrics_service_;
149 scoped_ptr<MetricsService> metrics_service_;
150
151 bool created_io_thread_;
[email protected]0ac83682010-01-22 17:46:27152 scoped_ptr<IOThread> io_thread_;
[email protected]25d47c7b2010-02-03 20:13:06153#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06154 // This shares a created flag with the IO thread.
155 scoped_ptr<base::Thread> background_x11_thread_;
156#endif
initial.commit09911bf2008-07-26 23:55:29157
158 bool created_file_thread_;
[email protected]ab820df2008-08-26 05:55:10159 scoped_ptr<base::Thread> file_thread_;
initial.commit09911bf2008-07-26 23:55:29160
161 bool created_db_thread_;
[email protected]ab820df2008-08-26 05:55:10162 scoped_ptr<base::Thread> db_thread_;
initial.commit09911bf2008-07-26 23:55:29163
[email protected]914511712009-11-23 19:42:33164 bool created_process_launcher_thread_;
165 scoped_ptr<base::Thread> process_launcher_thread_;
166
[email protected]875ee822010-05-18 20:58:01167 bool created_cache_thread_;
168 scoped_ptr<base::Thread> cache_thread_;
169
initial.commit09911bf2008-07-26 23:55:29170 bool created_profile_manager_;
171 scoped_ptr<ProfileManager> profile_manager_;
172
173 bool created_local_state_;
174 scoped_ptr<PrefService> local_state_;
175
initial.commit09911bf2008-07-26 23:55:29176 bool created_icon_manager_;
177 scoped_ptr<IconManager> icon_manager_;
178
[email protected]5613126e2011-01-31 15:27:55179 scoped_refptr<DevToolsHttpProtocolHandler> devtools_http_handler_;
180
181 scoped_refptr<DevToolsProtocolHandler> devtools_legacy_handler_;
initial.commit09911bf2008-07-26 23:55:29182
[email protected]40ecc902009-03-16 13:42:47183 bool created_devtools_manager_;
[email protected]73ee01522009-06-05 10:13:44184 scoped_refptr<DevToolsManager> devtools_manager_;
[email protected]40ecc902009-03-16 13:42:47185
[email protected]8b8e7c92010-08-19 18:05:56186 bool created_sidebar_manager_;
187 scoped_refptr<SidebarManager> sidebar_manager_;
188
[email protected]f2a893c2011-01-05 09:38:07189 bool created_configuration_policy_provider_keeper_;
190 scoped_ptr<policy::ConfigurationPolicyProviderKeeper>
191 configuration_policy_provider_keeper_;
192
[email protected]dbeebd52010-11-16 20:34:16193 scoped_refptr<printing::PrintPreviewTabController>
194 print_preview_tab_controller_;
195
[email protected]2dfeaf92011-01-10 21:08:21196 scoped_ptr<ui::Clipboard> clipboard_;
initial.commit09911bf2008-07-26 23:55:29197
[email protected]29672ab2009-10-30 03:44:03198 // Manager for desktop notification UI.
199 bool created_notification_ui_manager_;
200 scoped_ptr<NotificationUIManager> notification_ui_manager_;
201
initial.commit09911bf2008-07-26 23:55:29202 scoped_ptr<AutomationProviderList> automation_provider_list_;
203
initial.commit09911bf2008-07-26 23:55:29204 scoped_ptr<GoogleURLTracker> google_url_tracker_;
[email protected]c4ff4952010-01-08 19:12:47205 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector_;
initial.commit09911bf2008-07-26 23:55:29206
207 scoped_ptr<NotificationService> main_notification_service_;
208
[email protected]0b4d3382010-07-14 16:13:04209 scoped_ptr<TabCloseableStateWatcher> tab_closeable_state_watcher_;
210
[email protected]a7a5e992010-12-09 23:39:51211 bool created_safe_browsing_detection_service_;
212 scoped_ptr<safe_browsing::ClientSideDetectionService>
213 safe_browsing_detection_service_;
214
initial.commit09911bf2008-07-26 23:55:29215 unsigned int module_ref_count_;
[email protected]afd20c022010-06-10 00:48:20216 bool did_start_;
initial.commit09911bf2008-07-26 23:55:29217
218 // Ensures that all the print jobs are finished before closing the browser.
219 scoped_ptr<printing::PrintJobManager> print_job_manager_;
220
[email protected]d70539de2009-06-24 22:17:06221 std::string locale_;
initial.commit09911bf2008-07-26 23:55:29222
[email protected]1b2db1a2008-08-08 17:46:13223 bool checked_for_new_frames_;
224 bool using_new_frames_;
225
[email protected]cb85aba2010-09-22 18:34:15226 // This service just sits around and makes thumbnails for tabs. It does
227 // nothing in the constructor so we don't have to worry about lazy init.
[email protected]67a46b7f2009-06-16 21:41:02228 ThumbnailGenerator thumbnail_generator_;
[email protected]67a46b7f2009-06-16 21:41:02229
[email protected]073ed7b2010-09-27 09:20:02230 // Download status updates (like a changing application icon on dock/taskbar)
231 // are global per-application. DownloadStatusUpdater does no work in the ctor
232 // so we don't have to worry about lazy initialization.
233 DownloadStatusUpdater download_status_updater_;
234
[email protected]d65cab7a2008-08-12 01:25:41235 // An event that notifies when we are shutting-down.
[email protected]b797e152009-01-23 16:06:14236 scoped_ptr<base::WaitableEvent> shutdown_event_;
[email protected]d65cab7a2008-08-12 01:25:41237
[email protected]6641bf662009-08-21 00:34:09238 // Runs on the file thread and stats the inspector's directory, filling in
239 // have_inspector_files_ with the result.
240 void DoInspectorFilesCheck();
241 // Our best estimate about the existence of the inspector directory.
242 bool have_inspector_files_;
243
[email protected]2a7e7c152010-10-01 20:12:09244 // Ensures that the observers of plugin/print disable/enable state
[email protected]492d2142010-09-10 13:55:18245 // notifications are properly added and removed.
[email protected]2a7e7c152010-10-01 20:12:09246 PrefChangeRegistrar pref_change_registrar_;
[email protected]492d2142010-09-10 13:55:18247
[email protected]b2fcd0e2010-12-01 15:19:40248 // Lives here so can safely log events on shutdown.
249 scoped_ptr<ChromeNetLog> net_log_;
250
[email protected]6618d1d2010-12-15 21:18:47251 NotificationRegistrar notification_registrar_;
252 scoped_refptr<PluginDataRemover> plugin_data_remover_;
253
[email protected]3cdacd42010-04-30 18:55:53254#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:42255 base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_;
256
257 // Gets called by autoupdate timer to see if browser needs restart and can be
258 // restarted, and if that's the case, restarts the browser.
259 void OnAutoupdateTimer();
260 bool CanAutorestartForUpdate() const;
261 void RestartPersistentInstance();
[email protected]3cdacd42010-04-30 18:55:53262#endif // defined(OS_WIN) || defined(OS_LINUX)
[email protected]bd48c2b02010-04-09 20:32:42263
[email protected]58dca552009-06-17 00:35:02264 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl);
initial.commit09911bf2008-07-26 23:55:29265};
266
[email protected]58dca552009-06-17 00:35:02267#endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_