blob: 481d2105c08098ccfbad1a95e91e4d5225cd77e8 [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]ac262c9f2008-10-19 17:45:2115#include "chrome/browser/browser_trial.h"
initial.commit09911bf2008-07-26 23:55:2916#include "chrome/browser/chrome_thread.h"
[email protected]4ab4b0f2009-02-10 18:54:5017#include "chrome/browser/debugger/debugger_wrapper.h"
[email protected]40ecc902009-03-16 13:42:4718#include "chrome/browser/debugger/devtools_manager.h"
[email protected]b7f05882009-02-22 01:21:5619#include "chrome/browser/download/download_file.h"
[email protected]5ba0a2c2009-02-19 01:19:3420#include "chrome/browser/download/save_file_manager.h"
initial.commit09911bf2008-07-26 23:55:2921#include "chrome/browser/google_url_tracker.h"
[email protected]dcefa302009-05-20 00:24:3922#include "chrome/browser/icon_manager.h"
[email protected]c4ff4952010-01-08 19:12:4723#include "chrome/browser/intranet_redirect_detector.h"
[email protected]dc6f4962009-02-13 01:25:5024#include "chrome/browser/metrics/metrics_service.h"
[email protected]1933eb202009-02-19 18:23:2525#include "chrome/browser/net/dns_global.h"
[email protected]d393a0fd2009-05-13 23:32:0126#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]29672ab2009-10-30 03:44:0327#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]fd49e2d2009-02-20 17:21:3028#include "chrome/browser/plugin_service.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2630#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]81218f42009-02-05 18:48:0831#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
32#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]b1748b1d82009-11-30 20:32:5633#include "chrome/common/child_process_host.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/common/chrome_paths.h"
35#include "chrome/common/chrome_switches.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/common/notification_service.h"
37#include "chrome/common/pref_names.h"
38#include "chrome/common/pref_service.h"
[email protected]d55aaa132009-09-28 21:08:0439#include "ipc/ipc_logging.h"
[email protected]b112a4c2009-02-01 20:24:0140
41#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0542#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3843#endif
44
45#if defined(OS_LINUX)
46// TODO(port): get rid of this.
[email protected]81218f42009-02-05 18:48:0847#include "chrome/common/temp_scaffolding_stubs.h"
[email protected]86230b92009-11-23 20:38:3848#else
49#include "chrome/browser/printing/print_job_manager.h"
[email protected]b112a4c2009-02-01 20:24:0150#endif
initial.commit09911bf2008-07-26 23:55:2951
[email protected]d55aaa132009-09-28 21:08:0452#if defined(IPC_MESSAGE_LOG_ENABLED)
53#include "chrome/common/plugin_messages.h"
54#include "chrome/common/render_messages.h"
55#endif
56
initial.commit09911bf2008-07-26 23:55:2957namespace {
58
59// ----------------------------------------------------------------------------
60// BrowserProcessSubThread
61//
62// This simple thread object is used for the specialized threads that the
63// BrowserProcess spins up.
64//
65// Applications must initialize the COM library before they can call
66// COM library functions other than CoGetMalloc and memory allocation
67// functions, so this class initializes COM for those users.
68class BrowserProcessSubThread : public ChromeThread {
69 public:
70 explicit BrowserProcessSubThread(ChromeThread::ID identifier)
71 : ChromeThread(identifier) {
72 }
73
[email protected]48ca9012009-08-11 21:38:5474 virtual ~BrowserProcessSubThread() {
initial.commit09911bf2008-07-26 23:55:2975 // We cannot rely on our base class to stop the thread since we want our
76 // CleanUp function to run.
77 Stop();
78 }
79
80 protected:
81 virtual void Init() {
[email protected]b112a4c2009-02-01 20:24:0182#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:2983 // Initializes the COM library on the current thread.
84 CoInitialize(NULL);
[email protected]b112a4c2009-02-01 20:24:0185#endif
initial.commit09911bf2008-07-26 23:55:2986
87 notification_service_ = new NotificationService;
88 }
89
90 virtual void CleanUp() {
91 delete notification_service_;
92 notification_service_ = NULL;
93
[email protected]b112a4c2009-02-01 20:24:0194#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:2995 // Closes the COM library on the current thread. CoInitialize must
96 // be balanced by a corresponding call to CoUninitialize.
97 CoUninitialize();
[email protected]b112a4c2009-02-01 20:24:0198#endif
initial.commit09911bf2008-07-26 23:55:2999 }
100
101 private:
102 // Each specialized thread has its own notification service.
103 // Note: We don't use scoped_ptr because the destructor runs on the wrong
104 // thread.
105 NotificationService* notification_service_;
106};
107
[email protected]48ca9012009-08-11 21:38:54108class IOThread : public BrowserProcessSubThread {
109 public:
110 IOThread() : BrowserProcessSubThread(ChromeThread::IO) {}
111
112 virtual ~IOThread() {
113 // We cannot rely on our base class to stop the thread since we want our
114 // CleanUp function to run.
115 Stop();
116 }
117
118 protected:
119 virtual void CleanUp() {
120 // URLFetcher and URLRequest instances must NOT outlive the IO thread.
[email protected]03a69dc2009-09-22 00:04:59121 //
122 // Strictly speaking, URLFetcher's CheckForLeaks() should be done on the
123 // UI thread. However, since there _shouldn't_ be any instances left
124 // at this point, it shouldn't be a race.
125 //
126 // We check URLFetcher first, since if it has leaked then an associated
127 // URLRequest will also have leaked. However it is more useful to
128 // crash showing the callstack of URLFetcher's allocation than its
129 // URLRequest member.
[email protected]48ca9012009-08-11 21:38:54130 base::LeakTracker<URLFetcher>::CheckForLeaks();
[email protected]03a69dc2009-09-22 00:04:59131 base::LeakTracker<URLRequest>::CheckForLeaks();
[email protected]48ca9012009-08-11 21:38:54132
133 BrowserProcessSubThread::CleanUp();
134 }
135};
136
initial.commit09911bf2008-07-26 23:55:29137} // namespace
138
[email protected]bb975362009-01-21 01:00:22139BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:29140 : created_resource_dispatcher_host_(false),
141 created_metrics_service_(false),
142 created_io_thread_(false),
143 created_file_thread_(false),
144 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:33145 created_process_launcher_thread_(false),
initial.commit09911bf2008-07-26 23:55:29146 created_profile_manager_(false),
147 created_local_state_(false),
[email protected]f3a4f302009-08-21 22:35:29148#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29149 initialized_broker_services_(false),
initial.commit09911bf2008-07-26 23:55:29150 broker_services_(NULL),
[email protected]f3a4f302009-08-21 22:35:29151#endif // defined(OS_WIN)
[email protected]b112a4c2009-02-01 20:24:01152 created_icon_manager_(false),
153 created_debugger_wrapper_(false),
[email protected]40ecc902009-03-16 13:42:47154 created_devtools_manager_(false),
[email protected]29672ab2009-10-30 03:44:03155 created_notification_ui_manager_(false),
initial.commit09911bf2008-07-26 23:55:29156 module_ref_count_(0),
[email protected]1b2db1a2008-08-08 17:46:13157 checked_for_new_frames_(false),
[email protected]6641bf662009-08-21 00:34:09158 using_new_frames_(false),
159 have_inspector_files_(true) {
initial.commit09911bf2008-07-26 23:55:29160 g_browser_process = this;
[email protected]1b8d02f12009-05-05 04:14:11161 clipboard_.reset(new Clipboard);
initial.commit09911bf2008-07-26 23:55:29162 main_notification_service_.reset(new NotificationService);
163
164 // Must be created after the NotificationService.
165 print_job_manager_.reset(new printing::PrintJobManager);
166
[email protected]b797e152009-01-23 16:06:14167 shutdown_event_.reset(new base::WaitableEvent(true, false));
initial.commit09911bf2008-07-26 23:55:29168}
169
170BrowserProcessImpl::~BrowserProcessImpl() {
171 // Delete the AutomationProviderList before NotificationService,
172 // since it may try to unregister notifications
173 // Both NotificationService and AutomationProvider are singleton instances in
174 // the BrowserProcess. Since AutomationProvider may have some active
175 // notification observers, it is essential that it gets destroyed before the
176 // NotificationService. NotificationService won't be destroyed until after
177 // this destructor is run.
178 automation_provider_list_.reset();
179
[email protected]d393a0fd2009-05-13 23:32:01180 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
181 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
182 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
183 // any pending URLFetchers, and avoid creating any more.
184 SdchDictionaryFetcher::Shutdown();
185
[email protected]c4ff4952010-01-08 19:12:47186 // We need to destroy the MetricsService, GoogleURLTracker, and
187 // IntranetRedirectDetector before the io_thread_ gets destroyed, since their
188 // destructors can call the URLFetcher destructor, which does a
189 // PostDelayedTask operation on the IO thread. (The IO thread will handle
190 // that URLFetcher operation before going away.)
initial.commit09911bf2008-07-26 23:55:29191 metrics_service_.reset();
192 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47193 intranet_redirect_detector_.reset();
initial.commit09911bf2008-07-26 23:55:29194
195 // Need to clear profiles (download managers) before the io_thread_.
196 profile_manager_.reset();
197
198 // Debugger must be cleaned up before IO thread and NotificationService.
199 debugger_wrapper_ = NULL;
200
201 if (resource_dispatcher_host_.get()) {
202 // Need to tell Safe Browsing Service that the IO thread is going away
203 // since it cached a pointer to it.
204 if (resource_dispatcher_host()->safe_browsing_service())
205 resource_dispatcher_host()->safe_browsing_service()->ShutDown();
206
207 // Cancel pending requests and prevent new requests.
208 resource_dispatcher_host()->Shutdown();
209 }
210
[email protected]4c3cd7412009-04-22 17:56:06211#if defined(OS_LINUX)
212 // The IO thread must outlive the BACKGROUND_X11 thread.
213 background_x11_thread_.reset();
214#endif
215
initial.commit09911bf2008-07-26 23:55:29216 // Need to stop io_thread_ before resource_dispatcher_host_, since
217 // io_thread_ may still deref ResourceDispatcherHost and handle resource
218 // request before going away.
[email protected]48ca9012009-08-11 21:38:54219 ResetIOThread();
initial.commit09911bf2008-07-26 23:55:29220
[email protected]914511712009-11-23 19:42:33221 // Stop the process launcher thread after the IO thread, in case the IO thread
222 // posted a task to terminate a process on the process launcher thread.
223 process_launcher_thread_.reset();
224
initial.commit09911bf2008-07-26 23:55:29225 // Clean up state that lives on the file_thread_ before it goes away.
226 if (resource_dispatcher_host_.get()) {
227 resource_dispatcher_host()->download_file_manager()->Shutdown();
228 resource_dispatcher_host()->save_file_manager()->Shutdown();
229 }
230
231 // Need to stop the file_thread_ here to force it to process messages in its
232 // message loop from the previous call to shutdown the DownloadFileManager,
233 // SaveFileManager and SessionService.
234 file_thread_.reset();
235
236 // With the file_thread_ flushed, we can release any icon resources.
237 icon_manager_.reset();
238
239 // Need to destroy ResourceDispatcherHost before PluginService and
240 // SafeBrowsingService, since it caches a pointer to it.
241 resource_dispatcher_host_.reset();
242
243 // Wait for the pending print jobs to finish.
244 print_job_manager_->OnQuit();
245 print_job_manager_.reset();
246
initial.commit09911bf2008-07-26 23:55:29247 // Now OK to destroy NotificationService.
248 main_notification_service_.reset();
249
250 g_browser_process = NULL;
251}
252
[email protected]295039bd2008-08-15 04:32:57253// Send a QuitTask to the given MessageLoop.
254static void PostQuit(MessageLoop* message_loop) {
255 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
256}
initial.commit09911bf2008-07-26 23:55:29257
[email protected]b443cb042009-12-15 22:05:09258unsigned int BrowserProcessImpl::AddRefModule() {
259 DCHECK(CalledOnValidThread());
260 module_ref_count_++;
261 return module_ref_count_;
262}
263
264unsigned int BrowserProcessImpl::ReleaseModule() {
265 DCHECK(CalledOnValidThread());
266 DCHECK(0 != module_ref_count_);
267 module_ref_count_--;
268 if (0 == module_ref_count_) {
269 MessageLoop::current()->PostTask(
270 FROM_HERE, NewRunnableFunction(Platform::DidEndMainMessageLoop));
271 MessageLoop::current()->Quit();
272 }
273 return module_ref_count_;
274}
275
initial.commit09911bf2008-07-26 23:55:29276void BrowserProcessImpl::EndSession() {
[email protected]b112a4c2009-02-01 20:24:01277#if defined(OS_WIN)
[email protected]d65cab7a2008-08-12 01:25:41278 // Notify we are going away.
[email protected]b797e152009-01-23 16:06:14279 ::SetEvent(shutdown_event_->handle());
[email protected]b112a4c2009-02-01 20:24:01280#endif
[email protected]d65cab7a2008-08-12 01:25:41281
initial.commit09911bf2008-07-26 23:55:29282 // Mark all the profiles as clean.
283 ProfileManager* pm = profile_manager();
284 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i)
285 (*i)->MarkAsCleanShutdown();
286
287 // Tell the metrics service it was cleanly shutdown.
288 MetricsService* metrics = g_browser_process->metrics_service();
289 if (metrics && local_state()) {
290 metrics->RecordCleanShutdown();
291
292 metrics->RecordStartOfSessionEnd();
293
294 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36295 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29296 }
297
298 // We must write that the profile and metrics service shutdown cleanly,
299 // otherwise on startup we'll think we crashed. So we block until done and
300 // then proceed with normal shutdown.
301 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57302 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29303 MessageLoop::current()->Run();
304}
305
306printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
307 // TODO(abarth): DCHECK(CalledOnValidThread());
308 // See <http://b/1287209>.
309 // print_job_manager_ is initialized in the constructor and destroyed in the
310 // destructor, so it should always be valid.
311 DCHECK(print_job_manager_.get());
312 return print_job_manager_.get();
313}
314
initial.commit09911bf2008-07-26 23:55:29315void BrowserProcessImpl::CreateResourceDispatcherHost() {
316 DCHECK(!created_resource_dispatcher_host_ &&
317 resource_dispatcher_host_.get() == NULL);
318 created_resource_dispatcher_host_ = true;
319
[email protected]79084c2d2009-11-03 23:12:42320 resource_dispatcher_host_.reset(new ResourceDispatcherHost());
initial.commit09911bf2008-07-26 23:55:29321 resource_dispatcher_host_->Initialize();
322}
323
324void BrowserProcessImpl::CreateMetricsService() {
325 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
326 created_metrics_service_ = true;
327
328 metrics_service_.reset(new MetricsService);
329}
330
331void BrowserProcessImpl::CreateIOThread() {
332 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
333 created_io_thread_ = true;
334
335 // Prior to starting the io thread, we create the plugin service as
336 // it is predominantly used from the io thread, but must be created
337 // on the main thread. The service ctor is inexpensive and does not
338 // invoke the io_thread() accessor.
339 PluginService::GetInstance();
340
[email protected]4c3cd7412009-04-22 17:56:06341#if defined(OS_LINUX)
342 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so
343 // we start it now.
344 scoped_ptr<base::Thread> background_x11_thread(
345 new BrowserProcessSubThread(ChromeThread::BACKGROUND_X11));
346 if (!background_x11_thread->Start())
347 return;
348 background_x11_thread_.swap(background_x11_thread);
349#endif
350
[email protected]48ca9012009-08-11 21:38:54351 scoped_ptr<base::Thread> thread(new IOThread);
[email protected]ab820df2008-08-26 05:55:10352 base::Thread::Options options;
353 options.message_loop_type = MessageLoop::TYPE_IO;
354 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29355 return;
356 io_thread_.swap(thread);
357}
358
[email protected]48ca9012009-08-11 21:38:54359void BrowserProcessImpl::ResetIOThread() {
360 if (io_thread_.get()) {
361 io_thread_->message_loop()->PostTask(FROM_HERE,
362 NewRunnableFunction(CleanupOnIOThread));
363 }
364 io_thread_.reset();
365}
366
367// static
368void BrowserProcessImpl::CleanupOnIOThread() {
369 // Shutdown DNS prefetching now to ensure that network stack objects
370 // living on the IO thread get destroyed before the IO thread goes away.
371 chrome_browser_net::EnsureDnsPrefetchShutdown();
372 // TODO(eroman): can this be merged into IOThread::CleanUp() ?
373}
374
initial.commit09911bf2008-07-26 23:55:29375void BrowserProcessImpl::CreateFileThread() {
376 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
377 created_file_thread_ = true;
378
[email protected]ab820df2008-08-26 05:55:10379 scoped_ptr<base::Thread> thread(
380 new BrowserProcessSubThread(ChromeThread::FILE));
[email protected]a1db3842008-09-17 22:04:06381 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39382#if defined(OS_WIN)
383 // On Windows, the FILE thread needs to be have a UI message loop which pumps
384 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06385 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39386#else
387 options.message_loop_type = MessageLoop::TYPE_IO;
388#endif
[email protected]a1db3842008-09-17 22:04:06389 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29390 return;
391 file_thread_.swap(thread);
392}
393
394void BrowserProcessImpl::CreateDBThread() {
395 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
396 created_db_thread_ = true;
397
[email protected]ab820df2008-08-26 05:55:10398 scoped_ptr<base::Thread> thread(
399 new BrowserProcessSubThread(ChromeThread::DB));
initial.commit09911bf2008-07-26 23:55:29400 if (!thread->Start())
401 return;
402 db_thread_.swap(thread);
403}
404
[email protected]914511712009-11-23 19:42:33405void BrowserProcessImpl::CreateProcessLauncherThread() {
406 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
407 created_process_launcher_thread_ = true;
408
409 scoped_ptr<base::Thread> thread(
410 new BrowserProcessSubThread(ChromeThread::PROCESS_LAUNCHER));
411 if (!thread->Start())
412 return;
413 process_launcher_thread_.swap(thread);
414}
415
initial.commit09911bf2008-07-26 23:55:29416void BrowserProcessImpl::CreateProfileManager() {
417 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
418 created_profile_manager_ = true;
419
420 profile_manager_.reset(new ProfileManager());
421}
422
423void BrowserProcessImpl::CreateLocalState() {
424 DCHECK(!created_local_state_ && local_state_.get() == NULL);
425 created_local_state_ = true;
426
[email protected]b9636002009-03-04 00:05:25427 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29428 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]6fad2632009-11-02 05:59:37429 local_state_.reset(new PrefService(local_state_path));
initial.commit09911bf2008-07-26 23:55:29430}
431
[email protected]f3a4f302009-08-21 22:35:29432#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29433void BrowserProcessImpl::InitBrokerServices(
434 sandbox::BrokerServices* broker_services) {
435 DCHECK(!initialized_broker_services_ && broker_services_ == NULL);
436 broker_services->Init();
437 initialized_broker_services_ = true;
438 broker_services_ = broker_services;
439}
[email protected]f3a4f302009-08-21 22:35:29440#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29441
442void BrowserProcessImpl::CreateIconManager() {
443 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
444 created_icon_manager_ = true;
445 icon_manager_.reset(new IconManager);
446}
447
448void BrowserProcessImpl::CreateDebuggerWrapper(int port) {
449 DCHECK(debugger_wrapper_.get() == NULL);
450 created_debugger_wrapper_ = true;
451
452 debugger_wrapper_ = new DebuggerWrapper(port);
453}
454
[email protected]40ecc902009-03-16 13:42:47455void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44456 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47457 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44458 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47459}
460
initial.commit09911bf2008-07-26 23:55:29461void BrowserProcessImpl::CreateGoogleURLTracker() {
462 DCHECK(google_url_tracker_.get() == NULL);
463 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
464 google_url_tracker_.swap(google_url_tracker);
465}
[email protected]6641bf662009-08-21 00:34:09466
[email protected]c4ff4952010-01-08 19:12:47467void BrowserProcessImpl::CreateIntranetRedirectDetector() {
468 DCHECK(intranet_redirect_detector_.get() == NULL);
469 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
470 new IntranetRedirectDetector);
471 intranet_redirect_detector_.swap(intranet_redirect_detector);
472}
473
[email protected]29672ab2009-10-30 03:44:03474void BrowserProcessImpl::CreateNotificationUIManager() {
475 DCHECK(notification_ui_manager_.get() == NULL);
476 notification_ui_manager_.reset(NotificationUIManager::Create());
477 created_notification_ui_manager_ = true;
478}
479
[email protected]6641bf662009-08-21 00:34:09480// The BrowserProcess object must outlive the file thread so we use traits
481// which don't do any management.
482template <>
483struct RunnableMethodTraits<BrowserProcessImpl> {
[email protected]ee5e3792009-10-13 23:23:47484 void RetainCallee(BrowserProcessImpl* process) {}
485 void ReleaseCallee(BrowserProcessImpl* process) {}
[email protected]6641bf662009-08-21 00:34:09486};
487
488void BrowserProcessImpl::CheckForInspectorFiles() {
489 file_thread()->message_loop()->PostTask
490 (FROM_HERE,
491 NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck));
492}
493
[email protected]d55aaa132009-09-28 21:08:04494#if defined(IPC_MESSAGE_LOG_ENABLED)
495
496void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
497 // First enable myself.
498 if (enable)
499 IPC::Logging::current()->Enable();
500 else
501 IPC::Logging::current()->Disable();
502
503 // Now tell subprocesses. Messages to ChildProcess-derived
504 // processes must be done on the IO thread.
505 io_thread()->message_loop()->PostTask
506 (FROM_HERE,
507 NewRunnableMethod(
508 this,
509 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
510 enable));
511
512 // Finally, tell the renderers which don't derive from ChildProcess.
513 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:27514 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
515 !i.IsAtEnd(); i.Advance())
516 i.GetCurrentValue()->Send(new ViewMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:04517}
518
519// Helper for SetIPCLoggingEnabled.
520void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d85cf072009-10-27 03:59:31521 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
[email protected]d55aaa132009-09-28 21:08:04522
523 ChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:11524 while (!i.Done()) {
525 i->Send(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
526 ++i;
[email protected]d55aaa132009-09-28 21:08:04527 }
528}
529
530#endif // IPC_MESSAGE_LOG_ENABLED
531
[email protected]6641bf662009-08-21 00:34:09532void BrowserProcessImpl::DoInspectorFilesCheck() {
533 // Runs on FILE thread.
534 DCHECK(file_thread_->message_loop() == MessageLoop::current());
535 bool result = false;
536
537 FilePath inspector_dir;
538 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) {
539 result = file_util::PathExists(inspector_dir);
540 }
541
[email protected]308080d2009-11-11 19:19:02542 have_inspector_files_ = result;
[email protected]6641bf662009-08-21 00:34:09543}