blob: 703d70c58384f04cef73364a5e9db338a58b904e [file] [log] [blame]
[email protected]c4ff4952010-01-08 19:12:471// Copyright (c) 2010 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_
initial.commit09911bf2008-07-26 23:55:2912
13#include <string>
14
15#include "base/basictypes.h"
16#include "base/message_loop.h"
17#include "base/non_thread_safe.h"
[email protected]bd48c2b02010-04-09 20:32:4218#include "base/timer.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/scoped_ptr.h"
[email protected]de246f52009-02-25 18:25:4520#include "chrome/browser/automation/automation_provider_list.h"
initial.commit09911bf2008-07-26 23:55:2921#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0222#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]d55aaa132009-09-28 21:08:0423#include "ipc/ipc_message.h"
[email protected]b112a4c2009-02-01 20:24:0124
initial.commit09911bf2008-07-26 23:55:2925class CommandLine;
[email protected]4ef795df2010-02-03 02:35:0826class FilePath;
initial.commit09911bf2008-07-26 23:55:2927class NotificationService;
28
29// Real implementation of BrowserProcess that creates and returns the services.
30class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe {
31 public:
[email protected]f3a4f302009-08-21 22:35:2932 explicit BrowserProcessImpl(const CommandLine& command_line);
initial.commit09911bf2008-07-26 23:55:2933 virtual ~BrowserProcessImpl();
34
35 virtual void EndSession();
36
37 virtual ResourceDispatcherHost* resource_dispatcher_host() {
38 DCHECK(CalledOnValidThread());
39 if (!created_resource_dispatcher_host_)
40 CreateResourceDispatcherHost();
41 return resource_dispatcher_host_.get();
42 }
43
44 virtual MetricsService* metrics_service() {
45 DCHECK(CalledOnValidThread());
46 if (!created_metrics_service_)
47 CreateMetricsService();
48 return metrics_service_.get();
49 }
50
[email protected]0ac83682010-01-22 17:46:2751 virtual IOThread* io_thread() {
initial.commit09911bf2008-07-26 23:55:2952 DCHECK(CalledOnValidThread());
53 if (!created_io_thread_)
54 CreateIOThread();
55 return io_thread_.get();
56 }
57
[email protected]ab820df2008-08-26 05:55:1058 virtual base::Thread* file_thread() {
initial.commit09911bf2008-07-26 23:55:2959 DCHECK(CalledOnValidThread());
60 if (!created_file_thread_)
61 CreateFileThread();
62 return file_thread_.get();
63 }
64
[email protected]ab820df2008-08-26 05:55:1065 virtual base::Thread* db_thread() {
initial.commit09911bf2008-07-26 23:55:2966 DCHECK(CalledOnValidThread());
67 if (!created_db_thread_)
68 CreateDBThread();
69 return db_thread_.get();
70 }
71
[email protected]914511712009-11-23 19:42:3372 virtual base::Thread* process_launcher_thread() {
73 DCHECK(CalledOnValidThread());
74 if (!created_process_launcher_thread_)
75 CreateProcessLauncherThread();
76 return process_launcher_thread_.get();
77 }
78
[email protected]875ee822010-05-18 20:58:0179 virtual base::Thread* cache_thread() {
80 DCHECK(CalledOnValidThread());
81 if (!created_cache_thread_)
82 CreateCacheThread();
83 return cache_thread_.get();
84 }
85
[email protected]25d47c7b2010-02-03 20:13:0686#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:0687 virtual base::Thread* background_x11_thread() {
88 DCHECK(CalledOnValidThread());
89 // The BACKGROUND_X11 thread is created when the IO thread is created.
90 if (!created_io_thread_)
91 CreateIOThread();
92 return background_x11_thread_.get();
93 }
94#endif
95
initial.commit09911bf2008-07-26 23:55:2996 virtual ProfileManager* profile_manager() {
97 DCHECK(CalledOnValidThread());
98 if (!created_profile_manager_)
99 CreateProfileManager();
100 return profile_manager_.get();
101 }
102
103 virtual PrefService* local_state() {
104 DCHECK(CalledOnValidThread());
105 if (!created_local_state_)
106 CreateLocalState();
107 return local_state_.get();
108 }
109
initial.commit09911bf2008-07-26 23:55:29110 virtual DebuggerWrapper* debugger_wrapper() {
111 DCHECK(CalledOnValidThread());
112 if (!created_debugger_wrapper_)
113 return NULL;
114 return debugger_wrapper_.get();
115 }
116
[email protected]40ecc902009-03-16 13:42:47117 virtual DevToolsManager* devtools_manager() {
118 DCHECK(CalledOnValidThread());
119 if (!created_devtools_manager_)
120 CreateDevToolsManager();
121 return devtools_manager_.get();
122 }
123
[email protected]1b8d02f12009-05-05 04:14:11124 virtual Clipboard* clipboard() {
initial.commit09911bf2008-07-26 23:55:29125 DCHECK(CalledOnValidThread());
[email protected]1b8d02f12009-05-05 04:14:11126 return clipboard_.get();
initial.commit09911bf2008-07-26 23:55:29127 }
128
[email protected]29672ab2009-10-30 03:44:03129 virtual NotificationUIManager* notification_ui_manager() {
130 DCHECK(CalledOnValidThread());
131 if (!created_notification_ui_manager_)
132 CreateNotificationUIManager();
133 return notification_ui_manager_.get();
134 }
135
[email protected]ccb55cf52010-03-06 22:02:04136 virtual StatusTrayManager* status_tray_manager() {
137 DCHECK(CalledOnValidThread());
138 if (!status_tray_manager_.get())
139 CreateStatusTrayManager();
140 return status_tray_manager_.get();
141 }
142
initial.commit09911bf2008-07-26 23:55:29143 virtual IconManager* icon_manager() {
144 DCHECK(CalledOnValidThread());
145 if (!created_icon_manager_)
146 CreateIconManager();
147 return icon_manager_.get();
148 }
149
[email protected]58dca552009-06-17 00:35:02150 virtual ThumbnailGenerator* GetThumbnailGenerator() {
151 return &thumbnail_generator_;
152 }
153
initial.commit09911bf2008-07-26 23:55:29154 virtual AutomationProviderList* InitAutomationProviderList() {
155 DCHECK(CalledOnValidThread());
156 if (automation_provider_list_.get() == NULL) {
157 automation_provider_list_.reset(AutomationProviderList::GetInstance());
158 }
159 return automation_provider_list_.get();
160 }
161
162 virtual void InitDebuggerWrapper(int port) {
163 DCHECK(CalledOnValidThread());
164 if (!created_debugger_wrapper_)
165 CreateDebuggerWrapper(port);
166 }
167
[email protected]b443cb042009-12-15 22:05:09168 virtual unsigned int AddRefModule();
initial.commit09911bf2008-07-26 23:55:29169
[email protected]b443cb042009-12-15 22:05:09170 virtual unsigned int ReleaseModule();
initial.commit09911bf2008-07-26 23:55:29171
172 virtual bool IsShuttingDown() {
173 DCHECK(CalledOnValidThread());
174 return 0 == module_ref_count_;
175 }
176
initial.commit09911bf2008-07-26 23:55:29177 virtual printing::PrintJobManager* print_job_manager();
178
179 virtual GoogleURLTracker* google_url_tracker() {
180 DCHECK(CalledOnValidThread());
181 if (!google_url_tracker_.get())
182 CreateGoogleURLTracker();
183 return google_url_tracker_.get();
184 }
185
[email protected]c4ff4952010-01-08 19:12:47186 virtual IntranetRedirectDetector* intranet_redirect_detector() {
187 DCHECK(CalledOnValidThread());
188 if (!intranet_redirect_detector_.get())
189 CreateIntranetRedirectDetector();
190 return intranet_redirect_detector_.get();
191 }
192
[email protected]ce4b6a92009-12-10 00:04:48193 virtual const std::string& GetApplicationLocale() {
194 DCHECK(!locale_.empty());
195 return locale_;
196 }
[email protected]f1b6de22010-03-06 12:13:47197 virtual void SetApplicationLocale(const std::string& locale);
initial.commit09911bf2008-07-26 23:55:29198
[email protected]b797e152009-01-23 16:06:14199 virtual base::WaitableEvent* shutdown_event() {
200 return shutdown_event_.get();
201 }
[email protected]d65cab7a2008-08-12 01:25:41202
[email protected]6641bf662009-08-21 00:34:09203 virtual void CheckForInspectorFiles();
204
[email protected]3cdacd42010-04-30 18:55:53205#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:42206 void StartAutoupdateTimer();
[email protected]3cdacd42010-04-30 18:55:53207#endif
[email protected]bd48c2b02010-04-09 20:32:42208
[email protected]6641bf662009-08-21 00:34:09209 virtual bool have_inspector_files() const {
210 return have_inspector_files_;
211 }
212
[email protected]d55aaa132009-09-28 21:08:04213#if defined(IPC_MESSAGE_LOG_ENABLED)
214 virtual void SetIPCLoggingEnabled(bool enable);
215#endif
216
initial.commit09911bf2008-07-26 23:55:29217 private:
[email protected]4ef795df2010-02-03 02:35:08218 void ClearLocalState(const FilePath& profile_path);
219 bool ShouldClearLocalState(FilePath* profile_path);
220
initial.commit09911bf2008-07-26 23:55:29221 void CreateResourceDispatcherHost();
222 void CreatePrefService();
223 void CreateMetricsService();
[email protected]48ca9012009-08-11 21:38:54224
initial.commit09911bf2008-07-26 23:55:29225 void CreateIOThread();
[email protected]48ca9012009-08-11 21:38:54226 static void CleanupOnIOThread();
227
initial.commit09911bf2008-07-26 23:55:29228 void CreateFileThread();
229 void CreateDBThread();
[email protected]914511712009-11-23 19:42:33230 void CreateProcessLauncherThread();
[email protected]875ee822010-05-18 20:58:01231 void CreateCacheThread();
initial.commit09911bf2008-07-26 23:55:29232 void CreateTemplateURLModel();
233 void CreateProfileManager();
234 void CreateWebDataService();
235 void CreateLocalState();
236 void CreateViewedPageTracker();
237 void CreateIconManager();
238 void CreateDebuggerWrapper(int port);
[email protected]40ecc902009-03-16 13:42:47239 void CreateDevToolsManager();
initial.commit09911bf2008-07-26 23:55:29240 void CreateGoogleURLTracker();
[email protected]c4ff4952010-01-08 19:12:47241 void CreateIntranetRedirectDetector();
[email protected]29672ab2009-10-30 03:44:03242 void CreateNotificationUIManager();
[email protected]ccb55cf52010-03-06 22:02:04243 void CreateStatusTrayManager();
initial.commit09911bf2008-07-26 23:55:29244
[email protected]d55aaa132009-09-28 21:08:04245#if defined(IPC_MESSAGE_LOG_ENABLED)
246 void SetIPCLoggingEnabledForChildProcesses(bool enabled);
247#endif
248
initial.commit09911bf2008-07-26 23:55:29249 bool created_resource_dispatcher_host_;
250 scoped_ptr<ResourceDispatcherHost> resource_dispatcher_host_;
251
252 bool created_metrics_service_;
253 scoped_ptr<MetricsService> metrics_service_;
254
255 bool created_io_thread_;
[email protected]0ac83682010-01-22 17:46:27256 scoped_ptr<IOThread> io_thread_;
[email protected]25d47c7b2010-02-03 20:13:06257#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06258 // This shares a created flag with the IO thread.
259 scoped_ptr<base::Thread> background_x11_thread_;
260#endif
initial.commit09911bf2008-07-26 23:55:29261
262 bool created_file_thread_;
[email protected]ab820df2008-08-26 05:55:10263 scoped_ptr<base::Thread> file_thread_;
initial.commit09911bf2008-07-26 23:55:29264
265 bool created_db_thread_;
[email protected]ab820df2008-08-26 05:55:10266 scoped_ptr<base::Thread> db_thread_;
initial.commit09911bf2008-07-26 23:55:29267
[email protected]914511712009-11-23 19:42:33268 bool created_process_launcher_thread_;
269 scoped_ptr<base::Thread> process_launcher_thread_;
270
[email protected]875ee822010-05-18 20:58:01271 bool created_cache_thread_;
272 scoped_ptr<base::Thread> cache_thread_;
273
initial.commit09911bf2008-07-26 23:55:29274 bool created_profile_manager_;
275 scoped_ptr<ProfileManager> profile_manager_;
276
277 bool created_local_state_;
278 scoped_ptr<PrefService> local_state_;
279
initial.commit09911bf2008-07-26 23:55:29280 bool created_icon_manager_;
281 scoped_ptr<IconManager> icon_manager_;
282
283 bool created_debugger_wrapper_;
284 scoped_refptr<DebuggerWrapper> debugger_wrapper_;
285
[email protected]40ecc902009-03-16 13:42:47286 bool created_devtools_manager_;
[email protected]73ee01522009-06-05 10:13:44287 scoped_refptr<DevToolsManager> devtools_manager_;
[email protected]40ecc902009-03-16 13:42:47288
[email protected]1b8d02f12009-05-05 04:14:11289 scoped_ptr<Clipboard> clipboard_;
initial.commit09911bf2008-07-26 23:55:29290
[email protected]29672ab2009-10-30 03:44:03291 // Manager for desktop notification UI.
292 bool created_notification_ui_manager_;
293 scoped_ptr<NotificationUIManager> notification_ui_manager_;
294
[email protected]ccb55cf52010-03-06 22:02:04295 // Manager for status tray.
296 scoped_ptr<StatusTrayManager> status_tray_manager_;
297
initial.commit09911bf2008-07-26 23:55:29298 scoped_ptr<AutomationProviderList> automation_provider_list_;
299
initial.commit09911bf2008-07-26 23:55:29300 scoped_ptr<GoogleURLTracker> google_url_tracker_;
[email protected]c4ff4952010-01-08 19:12:47301 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector_;
initial.commit09911bf2008-07-26 23:55:29302
303 scoped_ptr<NotificationService> main_notification_service_;
304
305 unsigned int module_ref_count_;
306
307 // Ensures that all the print jobs are finished before closing the browser.
308 scoped_ptr<printing::PrintJobManager> print_job_manager_;
309
[email protected]d70539de2009-06-24 22:17:06310 std::string locale_;
initial.commit09911bf2008-07-26 23:55:29311
[email protected]1b2db1a2008-08-08 17:46:13312 bool checked_for_new_frames_;
313 bool using_new_frames_;
314
[email protected]58dca552009-06-17 00:35:02315 // This service just sits around and makes thumanails for tabs. It does
316 // nothing in the cosntructor so we don't have to worry about lazy init.
[email protected]67a46b7f2009-06-16 21:41:02317 ThumbnailGenerator thumbnail_generator_;
[email protected]67a46b7f2009-06-16 21:41:02318
[email protected]d65cab7a2008-08-12 01:25:41319 // An event that notifies when we are shutting-down.
[email protected]b797e152009-01-23 16:06:14320 scoped_ptr<base::WaitableEvent> shutdown_event_;
[email protected]d65cab7a2008-08-12 01:25:41321
[email protected]6641bf662009-08-21 00:34:09322 // Runs on the file thread and stats the inspector's directory, filling in
323 // have_inspector_files_ with the result.
324 void DoInspectorFilesCheck();
325 // Our best estimate about the existence of the inspector directory.
326 bool have_inspector_files_;
327
[email protected]3cdacd42010-04-30 18:55:53328#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:42329 base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_;
330
331 // Gets called by autoupdate timer to see if browser needs restart and can be
332 // restarted, and if that's the case, restarts the browser.
333 void OnAutoupdateTimer();
334 bool CanAutorestartForUpdate() const;
335 void RestartPersistentInstance();
[email protected]3cdacd42010-04-30 18:55:53336#endif // defined(OS_WIN) || defined(OS_LINUX)
[email protected]bd48c2b02010-04-09 20:32:42337
[email protected]58dca552009-06-17 00:35:02338 DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl);
initial.commit09911bf2008-07-26 23:55:29339};
340
[email protected]58dca552009-06-17 00:35:02341#endif // CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_