blob: 9fecc88775f5eaefdd35cf05f153e5d86b48a9dc [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#include "chrome/browser/browser_process_impl.h"
6
[email protected]90f39902009-10-03 04:25:377#include "app/clipboard/clipboard.h"
[email protected]a92b8642009-05-05 23:38:568#include "app/l10n_util.h"
initial.commit09911bf2008-07-26 23:55:299#include "base/command_line.h"
[email protected]6641bf662009-08-21 00:34:0910#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2911#include "base/path_service.h"
[email protected]ac262c9f2008-10-19 17:45:2112#include "base/thread.h"
[email protected]1c4947f2009-01-15 22:25:1113#include "base/waitable_event.h"
[email protected]b443cb042009-12-15 22:05:0914#include "chrome/browser/browser_main.h"
[email protected]0ac83682010-01-22 17:46:2715#include "chrome/browser/browser_process_sub_thread.h"
[email protected]ac262c9f2008-10-19 17:45:2116#include "chrome/browser/browser_trial.h"
initial.commit09911bf2008-07-26 23:55:2917#include "chrome/browser/chrome_thread.h"
[email protected]4ab4b0f2009-02-10 18:54:5018#include "chrome/browser/debugger/debugger_wrapper.h"
[email protected]40ecc902009-03-16 13:42:4719#include "chrome/browser/debugger/devtools_manager.h"
[email protected]b7f05882009-02-22 01:21:5620#include "chrome/browser/download/download_file.h"
[email protected]5ba0a2c2009-02-19 01:19:3421#include "chrome/browser/download/save_file_manager.h"
initial.commit09911bf2008-07-26 23:55:2922#include "chrome/browser/google_url_tracker.h"
[email protected]dcefa302009-05-20 00:24:3923#include "chrome/browser/icon_manager.h"
[email protected]4ef795df2010-02-03 02:35:0824#include "chrome/browser/in_process_webkit/dom_storage_context.h"
[email protected]c4ff4952010-01-08 19:12:4725#include "chrome/browser/intranet_redirect_detector.h"
[email protected]0ac83682010-01-22 17:46:2726#include "chrome/browser/io_thread.h"
[email protected]dc6f4962009-02-13 01:25:5027#include "chrome/browser/metrics/metrics_service.h"
[email protected]1933eb202009-02-19 18:23:2528#include "chrome/browser/net/dns_global.h"
[email protected]d393a0fd2009-05-13 23:32:0129#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]4ef795df2010-02-03 02:35:0830#include "chrome/browser/net/sqlite_persistent_cookie_store.h"
[email protected]29672ab2009-10-30 03:44:0331#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]fd49e2d2009-02-20 17:21:3032#include "chrome/browser/plugin_service.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2634#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]81218f42009-02-05 18:48:0835#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
36#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]10c934052010-02-04 19:58:3137#include "chrome/common/appcache/chrome_appcache_service.h"
[email protected]b1748b1d82009-11-30 20:32:5638#include "chrome/common/child_process_host.h"
[email protected]4ef795df2010-02-03 02:35:0839#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2940#include "chrome/common/chrome_paths.h"
41#include "chrome/common/chrome_switches.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/common/notification_service.h"
43#include "chrome/common/pref_names.h"
44#include "chrome/common/pref_service.h"
[email protected]4ef795df2010-02-03 02:35:0845#include "chrome/common/url_constants.h"
[email protected]d55aaa132009-09-28 21:08:0446#include "ipc/ipc_logging.h"
[email protected]4ef795df2010-02-03 02:35:0847#include "webkit/database/database_tracker.h"
[email protected]b112a4c2009-02-01 20:24:0148
49#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0550#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3851#endif
52
53#if defined(OS_LINUX)
54// TODO(port): get rid of this.
[email protected]81218f42009-02-05 18:48:0855#include "chrome/common/temp_scaffolding_stubs.h"
[email protected]86230b92009-11-23 20:38:3856#else
57#include "chrome/browser/printing/print_job_manager.h"
[email protected]b112a4c2009-02-01 20:24:0158#endif
initial.commit09911bf2008-07-26 23:55:2959
[email protected]d55aaa132009-09-28 21:08:0460#if defined(IPC_MESSAGE_LOG_ENABLED)
61#include "chrome/common/plugin_messages.h"
62#include "chrome/common/render_messages.h"
63#endif
64
[email protected]bb975362009-01-21 01:00:2265BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:2966 : created_resource_dispatcher_host_(false),
67 created_metrics_service_(false),
68 created_io_thread_(false),
69 created_file_thread_(false),
70 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:3371 created_process_launcher_thread_(false),
initial.commit09911bf2008-07-26 23:55:2972 created_profile_manager_(false),
73 created_local_state_(false),
[email protected]f3a4f302009-08-21 22:35:2974#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:2975 initialized_broker_services_(false),
initial.commit09911bf2008-07-26 23:55:2976 broker_services_(NULL),
[email protected]f3a4f302009-08-21 22:35:2977#endif // defined(OS_WIN)
[email protected]b112a4c2009-02-01 20:24:0178 created_icon_manager_(false),
79 created_debugger_wrapper_(false),
[email protected]40ecc902009-03-16 13:42:4780 created_devtools_manager_(false),
[email protected]29672ab2009-10-30 03:44:0381 created_notification_ui_manager_(false),
initial.commit09911bf2008-07-26 23:55:2982 module_ref_count_(0),
[email protected]1b2db1a2008-08-08 17:46:1383 checked_for_new_frames_(false),
[email protected]6641bf662009-08-21 00:34:0984 using_new_frames_(false),
85 have_inspector_files_(true) {
initial.commit09911bf2008-07-26 23:55:2986 g_browser_process = this;
[email protected]1b8d02f12009-05-05 04:14:1187 clipboard_.reset(new Clipboard);
initial.commit09911bf2008-07-26 23:55:2988 main_notification_service_.reset(new NotificationService);
89
90 // Must be created after the NotificationService.
91 print_job_manager_.reset(new printing::PrintJobManager);
92
[email protected]b797e152009-01-23 16:06:1493 shutdown_event_.reset(new base::WaitableEvent(true, false));
initial.commit09911bf2008-07-26 23:55:2994}
95
96BrowserProcessImpl::~BrowserProcessImpl() {
[email protected]4ef795df2010-02-03 02:35:0897 FilePath profile_path;
98 bool clear_local_state_on_exit;
99
100 // Store the profile path for clearing local state data on exit.
101 clear_local_state_on_exit = ShouldClearLocalState(&profile_path);
102
initial.commit09911bf2008-07-26 23:55:29103 // Delete the AutomationProviderList before NotificationService,
104 // since it may try to unregister notifications
105 // Both NotificationService and AutomationProvider are singleton instances in
106 // the BrowserProcess. Since AutomationProvider may have some active
107 // notification observers, it is essential that it gets destroyed before the
108 // NotificationService. NotificationService won't be destroyed until after
109 // this destructor is run.
110 automation_provider_list_.reset();
111
[email protected]d393a0fd2009-05-13 23:32:01112 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
113 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
114 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
115 // any pending URLFetchers, and avoid creating any more.
116 SdchDictionaryFetcher::Shutdown();
117
[email protected]c4ff4952010-01-08 19:12:47118 // We need to destroy the MetricsService, GoogleURLTracker, and
119 // IntranetRedirectDetector before the io_thread_ gets destroyed, since their
120 // destructors can call the URLFetcher destructor, which does a
121 // PostDelayedTask operation on the IO thread. (The IO thread will handle
122 // that URLFetcher operation before going away.)
initial.commit09911bf2008-07-26 23:55:29123 metrics_service_.reset();
124 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47125 intranet_redirect_detector_.reset();
initial.commit09911bf2008-07-26 23:55:29126
127 // Need to clear profiles (download managers) before the io_thread_.
128 profile_manager_.reset();
129
130 // Debugger must be cleaned up before IO thread and NotificationService.
131 debugger_wrapper_ = NULL;
132
133 if (resource_dispatcher_host_.get()) {
134 // Need to tell Safe Browsing Service that the IO thread is going away
135 // since it cached a pointer to it.
136 if (resource_dispatcher_host()->safe_browsing_service())
137 resource_dispatcher_host()->safe_browsing_service()->ShutDown();
138
139 // Cancel pending requests and prevent new requests.
140 resource_dispatcher_host()->Shutdown();
141 }
142
[email protected]4c3cd7412009-04-22 17:56:06143#if defined(OS_LINUX)
144 // The IO thread must outlive the BACKGROUND_X11 thread.
145 background_x11_thread_.reset();
146#endif
147
initial.commit09911bf2008-07-26 23:55:29148 // Need to stop io_thread_ before resource_dispatcher_host_, since
149 // io_thread_ may still deref ResourceDispatcherHost and handle resource
150 // request before going away.
[email protected]0ac83682010-01-22 17:46:27151 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29152
[email protected]914511712009-11-23 19:42:33153 // Stop the process launcher thread after the IO thread, in case the IO thread
154 // posted a task to terminate a process on the process launcher thread.
155 process_launcher_thread_.reset();
156
initial.commit09911bf2008-07-26 23:55:29157 // Clean up state that lives on the file_thread_ before it goes away.
158 if (resource_dispatcher_host_.get()) {
159 resource_dispatcher_host()->download_file_manager()->Shutdown();
160 resource_dispatcher_host()->save_file_manager()->Shutdown();
161 }
162
163 // Need to stop the file_thread_ here to force it to process messages in its
164 // message loop from the previous call to shutdown the DownloadFileManager,
165 // SaveFileManager and SessionService.
166 file_thread_.reset();
167
168 // With the file_thread_ flushed, we can release any icon resources.
169 icon_manager_.reset();
170
171 // Need to destroy ResourceDispatcherHost before PluginService and
[email protected]49f28bc72010-02-04 00:10:01172 // SafeBrowsingService, since it caches a pointer to it. This also
173 // causes the webkit thread to terminate.
initial.commit09911bf2008-07-26 23:55:29174 resource_dispatcher_host_.reset();
175
176 // Wait for the pending print jobs to finish.
177 print_job_manager_->OnQuit();
178 print_job_manager_.reset();
179
initial.commit09911bf2008-07-26 23:55:29180 // Now OK to destroy NotificationService.
181 main_notification_service_.reset();
182
[email protected]49f28bc72010-02-04 00:10:01183 // Prior to clearing local state, we want to complete tasks pending
184 // on the db thread too.
185 db_thread_.reset();
186
187 // At this point, no render process exist and the file, io, db, and
188 // webkit threads in this process have all terminated, so it's safe
189 // to access local state data such as cookies, database, or local storage.
190 if (clear_local_state_on_exit)
191 ClearLocalState(profile_path);
192
initial.commit09911bf2008-07-26 23:55:29193 g_browser_process = NULL;
194}
195
[email protected]295039bd2008-08-15 04:32:57196// Send a QuitTask to the given MessageLoop.
197static void PostQuit(MessageLoop* message_loop) {
198 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
199}
initial.commit09911bf2008-07-26 23:55:29200
[email protected]b443cb042009-12-15 22:05:09201unsigned int BrowserProcessImpl::AddRefModule() {
202 DCHECK(CalledOnValidThread());
203 module_ref_count_++;
204 return module_ref_count_;
205}
206
207unsigned int BrowserProcessImpl::ReleaseModule() {
208 DCHECK(CalledOnValidThread());
209 DCHECK(0 != module_ref_count_);
210 module_ref_count_--;
211 if (0 == module_ref_count_) {
212 MessageLoop::current()->PostTask(
213 FROM_HERE, NewRunnableFunction(Platform::DidEndMainMessageLoop));
214 MessageLoop::current()->Quit();
215 }
216 return module_ref_count_;
217}
218
initial.commit09911bf2008-07-26 23:55:29219void BrowserProcessImpl::EndSession() {
[email protected]b112a4c2009-02-01 20:24:01220#if defined(OS_WIN)
[email protected]d65cab7a2008-08-12 01:25:41221 // Notify we are going away.
[email protected]b797e152009-01-23 16:06:14222 ::SetEvent(shutdown_event_->handle());
[email protected]b112a4c2009-02-01 20:24:01223#endif
[email protected]d65cab7a2008-08-12 01:25:41224
initial.commit09911bf2008-07-26 23:55:29225 // Mark all the profiles as clean.
226 ProfileManager* pm = profile_manager();
227 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i)
228 (*i)->MarkAsCleanShutdown();
229
230 // Tell the metrics service it was cleanly shutdown.
231 MetricsService* metrics = g_browser_process->metrics_service();
232 if (metrics && local_state()) {
233 metrics->RecordCleanShutdown();
234
235 metrics->RecordStartOfSessionEnd();
236
237 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36238 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29239 }
240
241 // We must write that the profile and metrics service shutdown cleanly,
242 // otherwise on startup we'll think we crashed. So we block until done and
243 // then proceed with normal shutdown.
244 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57245 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29246 MessageLoop::current()->Run();
247}
248
249printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
250 // TODO(abarth): DCHECK(CalledOnValidThread());
251 // See <http://b/1287209>.
252 // print_job_manager_ is initialized in the constructor and destroyed in the
253 // destructor, so it should always be valid.
254 DCHECK(print_job_manager_.get());
255 return print_job_manager_.get();
256}
257
[email protected]4ef795df2010-02-03 02:35:08258void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
259 SQLitePersistentCookieStore::ClearLocalState(profile_path.Append(
260 chrome::kCookieFilename));
261 DOMStorageContext::ClearLocalState(profile_path, chrome::kExtensionScheme);
[email protected]72cfd90f2010-02-06 03:08:04262 webkit_database::DatabaseTracker::ClearLocalState(profile_path);
[email protected]10c934052010-02-04 19:58:31263 ChromeAppCacheService::ClearLocalState(profile_path);
[email protected]4ef795df2010-02-03 02:35:08264}
265
266bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
267 FilePath user_data_dir;
268 Profile* profile;
269
[email protected]ed0cf562010-02-05 22:50:41270 // Check for the existance of a profile manager. When quitting early,
271 // e.g. because another chrome instance is running, or when invoked with
272 // options such as --uninstall or --try-chrome-again=0, the profile manager
273 // does not exist yet.
274 if (!profile_manager_.get())
275 return false;
276
[email protected]4ef795df2010-02-03 02:35:08277 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
278 profile = profile_manager_->GetDefaultProfile(user_data_dir);
279 *profile_path = profile->GetPath();
280 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit);
281}
282
initial.commit09911bf2008-07-26 23:55:29283void BrowserProcessImpl::CreateResourceDispatcherHost() {
284 DCHECK(!created_resource_dispatcher_host_ &&
285 resource_dispatcher_host_.get() == NULL);
286 created_resource_dispatcher_host_ = true;
287
[email protected]79084c2d2009-11-03 23:12:42288 resource_dispatcher_host_.reset(new ResourceDispatcherHost());
initial.commit09911bf2008-07-26 23:55:29289 resource_dispatcher_host_->Initialize();
290}
291
292void BrowserProcessImpl::CreateMetricsService() {
293 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
294 created_metrics_service_ = true;
295
296 metrics_service_.reset(new MetricsService);
297}
298
299void BrowserProcessImpl::CreateIOThread() {
300 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
301 created_io_thread_ = true;
302
303 // Prior to starting the io thread, we create the plugin service as
304 // it is predominantly used from the io thread, but must be created
305 // on the main thread. The service ctor is inexpensive and does not
306 // invoke the io_thread() accessor.
307 PluginService::GetInstance();
308
[email protected]4c3cd7412009-04-22 17:56:06309#if defined(OS_LINUX)
310 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so
311 // we start it now.
312 scoped_ptr<base::Thread> background_x11_thread(
313 new BrowserProcessSubThread(ChromeThread::BACKGROUND_X11));
314 if (!background_x11_thread->Start())
315 return;
316 background_x11_thread_.swap(background_x11_thread);
317#endif
318
[email protected]0ac83682010-01-22 17:46:27319 scoped_ptr<IOThread> thread(new IOThread);
[email protected]ab820df2008-08-26 05:55:10320 base::Thread::Options options;
321 options.message_loop_type = MessageLoop::TYPE_IO;
322 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29323 return;
324 io_thread_.swap(thread);
325}
326
327void BrowserProcessImpl::CreateFileThread() {
328 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
329 created_file_thread_ = true;
330
[email protected]ab820df2008-08-26 05:55:10331 scoped_ptr<base::Thread> thread(
332 new BrowserProcessSubThread(ChromeThread::FILE));
[email protected]a1db3842008-09-17 22:04:06333 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39334#if defined(OS_WIN)
335 // On Windows, the FILE thread needs to be have a UI message loop which pumps
336 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06337 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39338#else
339 options.message_loop_type = MessageLoop::TYPE_IO;
340#endif
[email protected]a1db3842008-09-17 22:04:06341 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29342 return;
343 file_thread_.swap(thread);
344}
345
346void BrowserProcessImpl::CreateDBThread() {
347 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
348 created_db_thread_ = true;
349
[email protected]ab820df2008-08-26 05:55:10350 scoped_ptr<base::Thread> thread(
351 new BrowserProcessSubThread(ChromeThread::DB));
initial.commit09911bf2008-07-26 23:55:29352 if (!thread->Start())
353 return;
354 db_thread_.swap(thread);
355}
356
[email protected]914511712009-11-23 19:42:33357void BrowserProcessImpl::CreateProcessLauncherThread() {
358 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
359 created_process_launcher_thread_ = true;
360
361 scoped_ptr<base::Thread> thread(
362 new BrowserProcessSubThread(ChromeThread::PROCESS_LAUNCHER));
363 if (!thread->Start())
364 return;
365 process_launcher_thread_.swap(thread);
366}
367
initial.commit09911bf2008-07-26 23:55:29368void BrowserProcessImpl::CreateProfileManager() {
369 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
370 created_profile_manager_ = true;
371
372 profile_manager_.reset(new ProfileManager());
373}
374
375void BrowserProcessImpl::CreateLocalState() {
376 DCHECK(!created_local_state_ && local_state_.get() == NULL);
377 created_local_state_ = true;
378
[email protected]b9636002009-03-04 00:05:25379 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29380 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]6fad2632009-11-02 05:59:37381 local_state_.reset(new PrefService(local_state_path));
initial.commit09911bf2008-07-26 23:55:29382}
383
[email protected]f3a4f302009-08-21 22:35:29384#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29385void BrowserProcessImpl::InitBrokerServices(
386 sandbox::BrokerServices* broker_services) {
387 DCHECK(!initialized_broker_services_ && broker_services_ == NULL);
388 broker_services->Init();
389 initialized_broker_services_ = true;
390 broker_services_ = broker_services;
391}
[email protected]f3a4f302009-08-21 22:35:29392#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29393
394void BrowserProcessImpl::CreateIconManager() {
395 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
396 created_icon_manager_ = true;
397 icon_manager_.reset(new IconManager);
398}
399
400void BrowserProcessImpl::CreateDebuggerWrapper(int port) {
401 DCHECK(debugger_wrapper_.get() == NULL);
402 created_debugger_wrapper_ = true;
403
404 debugger_wrapper_ = new DebuggerWrapper(port);
405}
406
[email protected]40ecc902009-03-16 13:42:47407void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44408 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47409 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44410 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47411}
412
initial.commit09911bf2008-07-26 23:55:29413void BrowserProcessImpl::CreateGoogleURLTracker() {
414 DCHECK(google_url_tracker_.get() == NULL);
415 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
416 google_url_tracker_.swap(google_url_tracker);
417}
[email protected]6641bf662009-08-21 00:34:09418
[email protected]c4ff4952010-01-08 19:12:47419void BrowserProcessImpl::CreateIntranetRedirectDetector() {
420 DCHECK(intranet_redirect_detector_.get() == NULL);
421 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
422 new IntranetRedirectDetector);
423 intranet_redirect_detector_.swap(intranet_redirect_detector);
424}
425
[email protected]29672ab2009-10-30 03:44:03426void BrowserProcessImpl::CreateNotificationUIManager() {
427 DCHECK(notification_ui_manager_.get() == NULL);
428 notification_ui_manager_.reset(NotificationUIManager::Create());
429 created_notification_ui_manager_ = true;
430}
431
[email protected]6641bf662009-08-21 00:34:09432// The BrowserProcess object must outlive the file thread so we use traits
433// which don't do any management.
434template <>
435struct RunnableMethodTraits<BrowserProcessImpl> {
[email protected]ee5e3792009-10-13 23:23:47436 void RetainCallee(BrowserProcessImpl* process) {}
437 void ReleaseCallee(BrowserProcessImpl* process) {}
[email protected]6641bf662009-08-21 00:34:09438};
439
440void BrowserProcessImpl::CheckForInspectorFiles() {
441 file_thread()->message_loop()->PostTask
442 (FROM_HERE,
443 NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck));
444}
445
[email protected]d55aaa132009-09-28 21:08:04446#if defined(IPC_MESSAGE_LOG_ENABLED)
447
448void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
449 // First enable myself.
450 if (enable)
451 IPC::Logging::current()->Enable();
452 else
453 IPC::Logging::current()->Disable();
454
455 // Now tell subprocesses. Messages to ChildProcess-derived
456 // processes must be done on the IO thread.
457 io_thread()->message_loop()->PostTask
458 (FROM_HERE,
459 NewRunnableMethod(
460 this,
461 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
462 enable));
463
464 // Finally, tell the renderers which don't derive from ChildProcess.
465 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:27466 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
467 !i.IsAtEnd(); i.Advance())
468 i.GetCurrentValue()->Send(new ViewMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:04469}
470
471// Helper for SetIPCLoggingEnabled.
472void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d85cf072009-10-27 03:59:31473 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
[email protected]d55aaa132009-09-28 21:08:04474
475 ChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:11476 while (!i.Done()) {
477 i->Send(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
478 ++i;
[email protected]d55aaa132009-09-28 21:08:04479 }
480}
481
482#endif // IPC_MESSAGE_LOG_ENABLED
483
[email protected]6641bf662009-08-21 00:34:09484void BrowserProcessImpl::DoInspectorFilesCheck() {
485 // Runs on FILE thread.
486 DCHECK(file_thread_->message_loop() == MessageLoop::current());
487 bool result = false;
488
489 FilePath inspector_dir;
490 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) {
491 result = file_util::PathExists(inspector_dir);
492 }
493
[email protected]308080d2009-11-11 19:19:02494 have_inspector_files_ = result;
[email protected]6641bf662009-08-21 00:34:09495}