blob: 5a19629ad5083333fec84b808dac3b104c64fdb5 [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(
71 int port,
72 const std::string& frontend_url);
73 virtual void InitDevToolsLegacyProtocolHandler(int port);
[email protected]b443cb042009-12-15 22:05:0974 virtual unsigned int AddRefModule();
[email protected]b443cb042009-12-15 22:05:0975 virtual unsigned int ReleaseModule();
[email protected]e13ad79b2010-07-22 21:36:5076 virtual bool IsShuttingDown();
initial.commit09911bf2008-07-26 23:55:2977 virtual printing::PrintJobManager* print_job_manager();
[email protected]dbeebd52010-11-16 20:34:1678 virtual printing::PrintPreviewTabController* print_preview_tab_controller();
[email protected]e13ad79b2010-07-22 21:36:5079 virtual GoogleURLTracker* google_url_tracker();
80 virtual IntranetRedirectDetector* intranet_redirect_detector();
81 virtual const std::string& GetApplicationLocale();
[email protected]f1b6de22010-03-06 12:13:4782 virtual void SetApplicationLocale(const std::string& locale);
[email protected]073ed7b2010-09-27 09:20:0283 virtual DownloadStatusUpdater* download_status_updater();
[email protected]e13ad79b2010-07-22 21:36:5084 virtual base::WaitableEvent* shutdown_event();
85 virtual TabCloseableStateWatcher* tab_closeable_state_watcher();
[email protected]a7a5e992010-12-09 23:39:5186 virtual safe_browsing::ClientSideDetectionService*
87 safe_browsing_detection_service();
[email protected]6641bf662009-08-21 00:34:0988 virtual void CheckForInspectorFiles();
89
[email protected]6618d1d2010-12-15 21:18:4790 // NotificationObserver methods
91 virtual void Observe(NotificationType type,
92 const NotificationSource& source,
93 const NotificationDetails& details);
94
[email protected]3cdacd42010-04-30 18:55:5395#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]78994ab02010-12-08 18:06:4496 virtual void StartAutoupdateTimer();
[email protected]3cdacd42010-04-30 18:55:5397#endif
[email protected]bd48c2b02010-04-09 20:32:4298
[email protected]e13ad79b2010-07-22 21:36:5099 virtual bool have_inspector_files() const;
[email protected]6641bf662009-08-21 00:34:09100
[email protected]d55aaa132009-09-28 21:08:04101#if defined(IPC_MESSAGE_LOG_ENABLED)
102 virtual void SetIPCLoggingEnabled(bool enable);
103#endif
104
initial.commit09911bf2008-07-26 23:55:29105 private:
[email protected]4ef795df2010-02-03 02:35:08106 void ClearLocalState(const FilePath& profile_path);
107 bool ShouldClearLocalState(FilePath* profile_path);
108
initial.commit09911bf2008-07-26 23:55:29109 void CreateResourceDispatcherHost();
110 void CreatePrefService();
111 void CreateMetricsService();
[email protected]48ca9012009-08-11 21:38:54112
initial.commit09911bf2008-07-26 23:55:29113 void CreateIOThread();
[email protected]48ca9012009-08-11 21:38:54114 static void CleanupOnIOThread();
115
[email protected]6618d1d2010-12-15 21:18:47116 void WaitForPluginDataRemoverToFinish();
117
initial.commit09911bf2008-07-26 23:55:29118 void CreateFileThread();
119 void CreateDBThread();
[email protected]914511712009-11-23 19:42:33120 void CreateProcessLauncherThread();
[email protected]875ee822010-05-18 20:58:01121 void CreateCacheThread();
initial.commit09911bf2008-07-26 23:55:29122 void CreateTemplateURLModel();
123 void CreateProfileManager();
124 void CreateWebDataService();
125 void CreateLocalState();
126 void CreateViewedPageTracker();
127 void CreateIconManager();
[email protected]40ecc902009-03-16 13:42:47128 void CreateDevToolsManager();
[email protected]8b8e7c92010-08-19 18:05:56129 void CreateSidebarManager();
initial.commit09911bf2008-07-26 23:55:29130 void CreateGoogleURLTracker();
[email protected]c4ff4952010-01-08 19:12:47131 void CreateIntranetRedirectDetector();
[email protected]29672ab2009-10-30 03:44:03132 void CreateNotificationUIManager();
[email protected]ccb55cf52010-03-06 22:02:04133 void CreateStatusTrayManager();
[email protected]0b4d3382010-07-14 16:13:04134 void CreateTabCloseableStateWatcher();
[email protected]dbeebd52010-11-16 20:34:16135 void CreatePrintPreviewTabController();
[email protected]a7a5e992010-12-09 23:39:51136 void CreateSafeBrowsingDetectionService();
137
138 bool IsSafeBrowsingDetectionServiceEnabled();
initial.commit09911bf2008-07-26 23:55:29139
[email protected]d55aaa132009-09-28 21:08:04140#if defined(IPC_MESSAGE_LOG_ENABLED)
141 void SetIPCLoggingEnabledForChildProcesses(bool enabled);
142#endif
143
initial.commit09911bf2008-07-26 23:55:29144 bool created_resource_dispatcher_host_;
145 scoped_ptr<ResourceDispatcherHost> resource_dispatcher_host_;
146
147 bool created_metrics_service_;
148 scoped_ptr<MetricsService> metrics_service_;
149
150 bool created_io_thread_;
[email protected]0ac83682010-01-22 17:46:27151 scoped_ptr<IOThread> io_thread_;
[email protected]25d47c7b2010-02-03 20:13:06152#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06153 // This shares a created flag with the IO thread.
154 scoped_ptr<base::Thread> background_x11_thread_;
155#endif
initial.commit09911bf2008-07-26 23:55:29156
157 bool created_file_thread_;
[email protected]ab820df2008-08-26 05:55:10158 scoped_ptr<base::Thread> file_thread_;
initial.commit09911bf2008-07-26 23:55:29159
160 bool created_db_thread_;
[email protected]ab820df2008-08-26 05:55:10161 scoped_ptr<base::Thread> db_thread_;
initial.commit09911bf2008-07-26 23:55:29162
[email protected]914511712009-11-23 19:42:33163 bool created_process_launcher_thread_;
164 scoped_ptr<base::Thread> process_launcher_thread_;
165
[email protected]875ee822010-05-18 20:58:01166 bool created_cache_thread_;
167 scoped_ptr<base::Thread> cache_thread_;
168
initial.commit09911bf2008-07-26 23:55:29169 bool created_profile_manager_;
170 scoped_ptr<ProfileManager> profile_manager_;
171
172 bool created_local_state_;
173 scoped_ptr<PrefService> local_state_;
174
initial.commit09911bf2008-07-26 23:55:29175 bool created_icon_manager_;
176 scoped_ptr<IconManager> icon_manager_;
177
[email protected]5613126e2011-01-31 15:27:55178 scoped_refptr<DevToolsHttpProtocolHandler> devtools_http_handler_;
179
180 scoped_refptr<DevToolsProtocolHandler> devtools_legacy_handler_;
initial.commit09911bf2008-07-26 23:55:29181
[email protected]40ecc902009-03-16 13:42:47182 bool created_devtools_manager_;
[email protected]73ee01522009-06-05 10:13:44183 scoped_refptr<DevToolsManager> devtools_manager_;
[email protected]40ecc902009-03-16 13:42:47184
[email protected]8b8e7c92010-08-19 18:05:56185 bool created_sidebar_manager_;
186 scoped_refptr<SidebarManager> sidebar_manager_;
187
[email protected]f2a893c2011-01-05 09:38:07188 bool created_configuration_policy_provider_keeper_;
189 scoped_ptr<policy::ConfigurationPolicyProviderKeeper>
190 configuration_policy_provider_keeper_;
191
[email protected]dbeebd52010-11-16 20:34:16192 scoped_refptr<printing::PrintPreviewTabController>
193 print_preview_tab_controller_;
194
[email protected]2dfeaf92011-01-10 21:08:21195 scoped_ptr<ui::Clipboard> clipboard_;
initial.commit09911bf2008-07-26 23:55:29196
[email protected]29672ab2009-10-30 03:44:03197 // Manager for desktop notification UI.
198 bool created_notification_ui_manager_;
199 scoped_ptr<NotificationUIManager> notification_ui_manager_;
200
initial.commit09911bf2008-07-26 23:55:29201 scoped_ptr<AutomationProviderList> automation_provider_list_;
202
initial.commit09911bf2008-07-26 23:55:29203 scoped_ptr<GoogleURLTracker> google_url_tracker_;
[email protected]c4ff4952010-01-08 19:12:47204 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector_;
initial.commit09911bf2008-07-26 23:55:29205
206 scoped_ptr<NotificationService> main_notification_service_;
207
[email protected]0b4d3382010-07-14 16:13:04208 scoped_ptr<TabCloseableStateWatcher> tab_closeable_state_watcher_;
209
[email protected]a7a5e992010-12-09 23:39:51210 bool created_safe_browsing_detection_service_;
211 scoped_ptr<safe_browsing::ClientSideDetectionService>
212 safe_browsing_detection_service_;
213
initial.commit09911bf2008-07-26 23:55:29214 unsigned int module_ref_count_;
[email protected]afd20c022010-06-10 00:48:20215 bool did_start_;
initial.commit09911bf2008-07-26 23:55:29216
217 // Ensures that all the print jobs are finished before closing the browser.
218 scoped_ptr<printing::PrintJobManager> print_job_manager_;
219
[email protected]d70539de2009-06-24 22:17:06220 std::string locale_;
initial.commit09911bf2008-07-26 23:55:29221
[email protected]1b2db1a2008-08-08 17:46:13222 bool checked_for_new_frames_;
223 bool using_new_frames_;
224
[email protected]cb85aba2010-09-22 18:34:15225 // This service just sits around and makes thumbnails for tabs. It does
226 // nothing in the constructor so we don't have to worry about lazy init.
[email protected]67a46b7f2009-06-16 21:41:02227 ThumbnailGenerator thumbnail_generator_;
[email protected]67a46b7f2009-06-16 21:41:02228
[email protected]073ed7b2010-09-27 09:20:02229 // Download status updates (like a changing application icon on dock/taskbar)
230 // are global per-application. DownloadStatusUpdater does no work in the ctor
231 // so we don't have to worry about lazy initialization.
232 DownloadStatusUpdater download_status_updater_;
233
[email protected]d65cab7a2008-08-12 01:25:41234 // An event that notifies when we are shutting-down.
[email protected]b797e152009-01-23 16:06:14235 scoped_ptr<base::WaitableEvent> shutdown_event_;
[email protected]d65cab7a2008-08-12 01:25:41236
[email protected]6641bf662009-08-21 00:34:09237 // Runs on the file thread and stats the inspector's directory, filling in
238 // have_inspector_files_ with the result.
239 void DoInspectorFilesCheck();
240 // Our best estimate about the existence of the inspector directory.
241 bool have_inspector_files_;
242
[email protected]2a7e7c152010-10-01 20:12:09243 // Ensures that the observers of plugin/print disable/enable state
[email protected]492d2142010-09-10 13:55:18244 // notifications are properly added and removed.
[email protected]2a7e7c152010-10-01 20:12:09245 PrefChangeRegistrar pref_change_registrar_;
[email protected]492d2142010-09-10 13:55:18246
[email protected]b2fcd0e2010-12-01 15:19:40247 // Lives here so can safely log events on shutdown.
248 scoped_ptr<ChromeNetLog> net_log_;
249
[email protected]6618d1d2010-12-15 21:18:47250 NotificationRegistrar notification_registrar_;
251 scoped_refptr<PluginDataRemover> plugin_data_remover_;
252
[email protected]3cdacd42010-04-30 18:55:53253#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:42254 base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_;
255
256 // Gets called by autoupdate timer to see if browser needs restart and can be
257 // restarted, and if that's the case, restarts the browser.
258 void OnAutoupdateTimer();
259 bool CanAutorestartForUpdate() const;
260 void RestartPersistentInstance();
[email protected]3cdacd42010-04-30 18:55:53261#endif // defined(OS_WIN) || defined(OS_LINUX)
[email protected]bd48c2b02010-04-09 20:32:42262
[email protected]58dca552009-06-17 00:35:02263 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl);
initial.commit09911bf2008-07-26 23:55:29264};
265
[email protected]58dca552009-06-17 00:35:02266#endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_