blob: 4f094dd3ef91cb3feafa25460ff7924b99d22a66 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 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.
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"
initial.commit09911bf2008-07-26 23:55:2918#include "base/scoped_ptr.h"
[email protected]de246f52009-02-25 18:25:4519#include "chrome/browser/automation/automation_provider_list.h"
initial.commit09911bf2008-07-26 23:55:2920#include "chrome/browser/browser_process.h"
[email protected]67a46b7f2009-06-16 21:41:0221#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]d55aaa132009-09-28 21:08:0422#include "ipc/ipc_message.h"
[email protected]b112a4c2009-02-01 20:24:0123
24#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:2925#include "sandbox/src/sandbox.h"
[email protected]b112a4c2009-02-01 20:24:0126#else
27#include "chrome/common/temp_scaffolding_stubs.h"
28#endif
initial.commit09911bf2008-07-26 23:55:2929
30class CommandLine;
31class NotificationService;
32
33// Real implementation of BrowserProcess that creates and returns the services.
34class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe {
35 public:
[email protected]f3a4f302009-08-21 22:35:2936 explicit BrowserProcessImpl(const CommandLine& command_line);
initial.commit09911bf2008-07-26 23:55:2937 virtual ~BrowserProcessImpl();
38
39 virtual void EndSession();
40
41 virtual ResourceDispatcherHost* resource_dispatcher_host() {
42 DCHECK(CalledOnValidThread());
43 if (!created_resource_dispatcher_host_)
44 CreateResourceDispatcherHost();
45 return resource_dispatcher_host_.get();
46 }
47
48 virtual MetricsService* metrics_service() {
49 DCHECK(CalledOnValidThread());
50 if (!created_metrics_service_)
51 CreateMetricsService();
52 return metrics_service_.get();
53 }
54
[email protected]ab820df2008-08-26 05:55:1055 virtual base::Thread* io_thread() {
initial.commit09911bf2008-07-26 23:55:2956 DCHECK(CalledOnValidThread());
57 if (!created_io_thread_)
58 CreateIOThread();
59 return io_thread_.get();
60 }
61
[email protected]ab820df2008-08-26 05:55:1062 virtual base::Thread* file_thread() {
initial.commit09911bf2008-07-26 23:55:2963 DCHECK(CalledOnValidThread());
64 if (!created_file_thread_)
65 CreateFileThread();
66 return file_thread_.get();
67 }
68
[email protected]ab820df2008-08-26 05:55:1069 virtual base::Thread* db_thread() {
initial.commit09911bf2008-07-26 23:55:2970 DCHECK(CalledOnValidThread());
71 if (!created_db_thread_)
72 CreateDBThread();
73 return db_thread_.get();
74 }
75
[email protected]4c3cd7412009-04-22 17:56:0676#if defined(OS_LINUX)
77 virtual base::Thread* background_x11_thread() {
78 DCHECK(CalledOnValidThread());
79 // The BACKGROUND_X11 thread is created when the IO thread is created.
80 if (!created_io_thread_)
81 CreateIOThread();
82 return background_x11_thread_.get();
83 }
84#endif
85
initial.commit09911bf2008-07-26 23:55:2986 virtual ProfileManager* profile_manager() {
87 DCHECK(CalledOnValidThread());
88 if (!created_profile_manager_)
89 CreateProfileManager();
90 return profile_manager_.get();
91 }
92
93 virtual PrefService* local_state() {
94 DCHECK(CalledOnValidThread());
95 if (!created_local_state_)
96 CreateLocalState();
97 return local_state_.get();
98 }
99
[email protected]f3a4f302009-08-21 22:35:29100#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29101 virtual sandbox::BrokerServices* broker_services() {
102 // TODO(abarth): DCHECK(CalledOnValidThread());
103 // See <http://b/1287166>.
104 if (!initialized_broker_services_)
105 return NULL;
106 return broker_services_;
107 }
[email protected]f3a4f302009-08-21 22:35:29108#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29109
110 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
129 virtual IconManager* icon_manager() {
130 DCHECK(CalledOnValidThread());
131 if (!created_icon_manager_)
132 CreateIconManager();
133 return icon_manager_.get();
134 }
135
[email protected]58dca552009-06-17 00:35:02136 virtual ThumbnailGenerator* GetThumbnailGenerator() {
137 return &thumbnail_generator_;
138 }
139
initial.commit09911bf2008-07-26 23:55:29140 virtual AutomationProviderList* InitAutomationProviderList() {
141 DCHECK(CalledOnValidThread());
142 if (automation_provider_list_.get() == NULL) {
143 automation_provider_list_.reset(AutomationProviderList::GetInstance());
144 }
145 return automation_provider_list_.get();
146 }
147
148 virtual void InitDebuggerWrapper(int port) {
149 DCHECK(CalledOnValidThread());
150 if (!created_debugger_wrapper_)
151 CreateDebuggerWrapper(port);
152 }
153
154 virtual unsigned int AddRefModule() {
155 DCHECK(CalledOnValidThread());
156 module_ref_count_++;
157 return module_ref_count_;
158 }
159
160 virtual unsigned int ReleaseModule() {
161 DCHECK(CalledOnValidThread());
162 DCHECK(0 != module_ref_count_);
163 module_ref_count_--;
164 if (0 == module_ref_count_) {
165 MessageLoop::current()->Quit();
166 }
167 return module_ref_count_;
168 }
169
170 virtual bool IsShuttingDown() {
171 DCHECK(CalledOnValidThread());
172 return 0 == module_ref_count_;
173 }
174
initial.commit09911bf2008-07-26 23:55:29175 virtual printing::PrintJobManager* print_job_manager();
176
177 virtual GoogleURLTracker* google_url_tracker() {
178 DCHECK(CalledOnValidThread());
179 if (!google_url_tracker_.get())
180 CreateGoogleURLTracker();
181 return google_url_tracker_.get();
182 }
183
[email protected]d70539de2009-06-24 22:17:06184 virtual const std::string& GetApplicationLocale();
initial.commit09911bf2008-07-26 23:55:29185
186 virtual MemoryModel memory_model() {
187 DCHECK(CalledOnValidThread());
188 return memory_model_;
189 }
190
[email protected]b797e152009-01-23 16:06:14191 virtual base::WaitableEvent* shutdown_event() {
192 return shutdown_event_.get();
193 }
[email protected]d65cab7a2008-08-12 01:25:41194
[email protected]6641bf662009-08-21 00:34:09195 virtual void CheckForInspectorFiles();
196
197 virtual bool have_inspector_files() const {
198 return have_inspector_files_;
199 }
200
[email protected]d55aaa132009-09-28 21:08:04201#if defined(IPC_MESSAGE_LOG_ENABLED)
202 virtual void SetIPCLoggingEnabled(bool enable);
203#endif
204
initial.commit09911bf2008-07-26 23:55:29205 private:
206 void CreateResourceDispatcherHost();
207 void CreatePrefService();
208 void CreateMetricsService();
[email protected]48ca9012009-08-11 21:38:54209
initial.commit09911bf2008-07-26 23:55:29210 void CreateIOThread();
[email protected]48ca9012009-08-11 21:38:54211 void ResetIOThread();
212 static void CleanupOnIOThread();
213
initial.commit09911bf2008-07-26 23:55:29214 void CreateFileThread();
215 void CreateDBThread();
initial.commit09911bf2008-07-26 23:55:29216 void CreateTemplateURLModel();
217 void CreateProfileManager();
218 void CreateWebDataService();
219 void CreateLocalState();
220 void CreateViewedPageTracker();
221 void CreateIconManager();
222 void CreateDebuggerWrapper(int port);
[email protected]40ecc902009-03-16 13:42:47223 void CreateDevToolsManager();
initial.commit09911bf2008-07-26 23:55:29224 void CreateGoogleURLTracker();
225
[email protected]f3a4f302009-08-21 22:35:29226#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29227 void InitBrokerServices(sandbox::BrokerServices* broker_services);
[email protected]f3a4f302009-08-21 22:35:29228#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29229
[email protected]d55aaa132009-09-28 21:08:04230#if defined(IPC_MESSAGE_LOG_ENABLED)
231 void SetIPCLoggingEnabledForChildProcesses(bool enabled);
232#endif
233
initial.commit09911bf2008-07-26 23:55:29234 bool created_resource_dispatcher_host_;
235 scoped_ptr<ResourceDispatcherHost> resource_dispatcher_host_;
236
237 bool created_metrics_service_;
238 scoped_ptr<MetricsService> metrics_service_;
239
240 bool created_io_thread_;
[email protected]ab820df2008-08-26 05:55:10241 scoped_ptr<base::Thread> io_thread_;
[email protected]4c3cd7412009-04-22 17:56:06242#if defined(OS_LINUX)
243 // This shares a created flag with the IO thread.
244 scoped_ptr<base::Thread> background_x11_thread_;
245#endif
initial.commit09911bf2008-07-26 23:55:29246
247 bool created_file_thread_;
[email protected]ab820df2008-08-26 05:55:10248 scoped_ptr<base::Thread> file_thread_;
initial.commit09911bf2008-07-26 23:55:29249
250 bool created_db_thread_;
[email protected]ab820df2008-08-26 05:55:10251 scoped_ptr<base::Thread> db_thread_;
initial.commit09911bf2008-07-26 23:55:29252
253 bool created_profile_manager_;
254 scoped_ptr<ProfileManager> profile_manager_;
255
256 bool created_local_state_;
257 scoped_ptr<PrefService> local_state_;
258
[email protected]f3a4f302009-08-21 22:35:29259#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29260 bool initialized_broker_services_;
261 sandbox::BrokerServices* broker_services_;
[email protected]f3a4f302009-08-21 22:35:29