blob: f3cb9700ef1877703eb5cbb5976de300fec01a7b [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]0082d7e0d2010-02-27 14:34:1214#include "chrome/browser/appcache/chrome_appcache_service.h"
[email protected]b443cb042009-12-15 22:05:0915#include "chrome/browser/browser_main.h"
[email protected]0ac83682010-01-22 17:46:2716#include "chrome/browser/browser_process_sub_thread.h"
[email protected]ac262c9f2008-10-19 17:45:2117#include "chrome/browser/browser_trial.h"
[email protected]dcddcdb02010-02-23 09:10:1318#include "chrome/browser/child_process_host.h"
initial.commit09911bf2008-07-26 23:55:2919#include "chrome/browser/chrome_thread.h"
[email protected]4ab4b0f2009-02-10 18:54:5020#include "chrome/browser/debugger/debugger_wrapper.h"
[email protected]40ecc902009-03-16 13:42:4721#include "chrome/browser/debugger/devtools_manager.h"
[email protected]b7f05882009-02-22 01:21:5622#include "chrome/browser/download/download_file.h"
[email protected]5ba0a2c2009-02-19 01:19:3423#include "chrome/browser/download/save_file_manager.h"
initial.commit09911bf2008-07-26 23:55:2924#include "chrome/browser/google_url_tracker.h"
[email protected]dcefa302009-05-20 00:24:3925#include "chrome/browser/icon_manager.h"
[email protected]4ef795df2010-02-03 02:35:0826#include "chrome/browser/in_process_webkit/dom_storage_context.h"
[email protected]c4ff4952010-01-08 19:12:4727#include "chrome/browser/intranet_redirect_detector.h"
[email protected]0ac83682010-01-22 17:46:2728#include "chrome/browser/io_thread.h"
[email protected]dc6f4962009-02-13 01:25:5029#include "chrome/browser/metrics/metrics_service.h"
[email protected]1933eb202009-02-19 18:23:2530#include "chrome/browser/net/dns_global.h"
[email protected]d393a0fd2009-05-13 23:32:0131#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]4ef795df2010-02-03 02:35:0832#include "chrome/browser/net/sqlite_persistent_cookie_store.h"
[email protected]29672ab2009-10-30 03:44:0333#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]fd49e2d2009-02-20 17:21:3034#include "chrome/browser/plugin_service.h"
[email protected]052313b2010-02-19 09:43:0835#include "chrome/browser/pref_service.h"
[email protected]e06131d2010-02-10 18:40:3336#include "chrome/browser/printing/print_job_manager.h"
initial.commit09911bf2008-07-26 23:55:2937#include "chrome/browser/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2638#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]81218f42009-02-05 18:48:0839#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
40#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]4ef795df2010-02-03 02:35:0841#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/common/chrome_paths.h"
43#include "chrome/common/chrome_switches.h"
[email protected]f1b6de22010-03-06 12:13:4744#include "chrome/common/extensions/extension_l10n_util.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/common/notification_service.h"
46#include "chrome/common/pref_names.h"
[email protected]4ef795df2010-02-03 02:35:0847#include "chrome/common/url_constants.h"
[email protected]d55aaa132009-09-28 21:08:0448#include "ipc/ipc_logging.h"
[email protected]4ef795df2010-02-03 02:35:0849#include "webkit/database/database_tracker.h"
[email protected]b112a4c2009-02-01 20:24:0150
51#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0552#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3853#endif
54
[email protected]d55aaa132009-09-28 21:08:0455#if defined(IPC_MESSAGE_LOG_ENABLED)
56#include "chrome/common/plugin_messages.h"
57#include "chrome/common/render_messages.h"
58#endif
59
[email protected]bb975362009-01-21 01:00:2260BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:2961 : created_resource_dispatcher_host_(false),
62 created_metrics_service_(false),
63 created_io_thread_(false),
64 created_file_thread_(false),
65 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:3366 created_process_launcher_thread_(false),
initial.commit09911bf2008-07-26 23:55:2967 created_profile_manager_(false),
68 created_local_state_(false),
[email protected]f3a4f302009-08-21 22:35:2969#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:2970 initialized_broker_services_(false),
initial.commit09911bf2008-07-26 23:55:2971 broker_services_(NULL),
[email protected]f3a4f302009-08-21 22:35:2972#endif // defined(OS_WIN)
[email protected]b112a4c2009-02-01 20:24:0173 created_icon_manager_(false),
74 created_debugger_wrapper_(false),
[email protected]40ecc902009-03-16 13:42:4775 created_devtools_manager_(false),
[email protected]29672ab2009-10-30 03:44:0376 created_notification_ui_manager_(false),
initial.commit09911bf2008-07-26 23:55:2977 module_ref_count_(0),
[email protected]1b2db1a2008-08-08 17:46:1378 checked_for_new_frames_(false),
[email protected]6641bf662009-08-21 00:34:0979 using_new_frames_(false),
80 have_inspector_files_(true) {
initial.commit09911bf2008-07-26 23:55:2981 g_browser_process = this;
[email protected]1b8d02f12009-05-05 04:14:1182 clipboard_.reset(new Clipboard);
initial.commit09911bf2008-07-26 23:55:2983 main_notification_service_.reset(new NotificationService);
84
85 // Must be created after the NotificationService.
86 print_job_manager_.reset(new printing::PrintJobManager);
87
[email protected]b797e152009-01-23 16:06:1488 shutdown_event_.reset(new base::WaitableEvent(true, false));
initial.commit09911bf2008-07-26 23:55:2989}
90
91BrowserProcessImpl::~BrowserProcessImpl() {
[email protected]4ef795df2010-02-03 02:35:0892 FilePath profile_path;
93 bool clear_local_state_on_exit;
94
95 // Store the profile path for clearing local state data on exit.
96 clear_local_state_on_exit = ShouldClearLocalState(&profile_path);
97
initial.commit09911bf2008-07-26 23:55:2998 // Delete the AutomationProviderList before NotificationService,
99 // since it may try to unregister notifications
100 // Both NotificationService and AutomationProvider are singleton instances in
101 // the BrowserProcess. Since AutomationProvider may have some active
102 // notification observers, it is essential that it gets destroyed before the
103 // NotificationService. NotificationService won't be destroyed until after
104 // this destructor is run.
105 automation_provider_list_.reset();
106
[email protected]d393a0fd2009-05-13 23:32:01107 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
108 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
109 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
110 // any pending URLFetchers, and avoid creating any more.
111 SdchDictionaryFetcher::Shutdown();
112
[email protected]c4ff4952010-01-08 19:12:47113 // We need to destroy the MetricsService, GoogleURLTracker, and
114 // IntranetRedirectDetector before the io_thread_ gets destroyed, since their
115 // destructors can call the URLFetcher destructor, which does a
116 // PostDelayedTask operation on the IO thread. (The IO thread will handle
117 // that URLFetcher operation before going away.)
initial.commit09911bf2008-07-26 23:55:29118 metrics_service_.reset();
119 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47120 intranet_redirect_detector_.reset();
initial.commit09911bf2008-07-26 23:55:29121
122 // Need to clear profiles (download managers) before the io_thread_.
123 profile_manager_.reset();
124
125 // Debugger must be cleaned up before IO thread and NotificationService.
126 debugger_wrapper_ = NULL;
127
128 if (resource_dispatcher_host_.get()) {
129 // Need to tell Safe Browsing Service that the IO thread is going away
130 // since it cached a pointer to it.
131 if (resource_dispatcher_host()->safe_browsing_service())
132 resource_dispatcher_host()->safe_browsing_service()->ShutDown();
133
134 // Cancel pending requests and prevent new requests.
135 resource_dispatcher_host()->Shutdown();
136 }
137
[email protected]4c3cd7412009-04-22 17:56:06138#if defined(OS_LINUX)
139 // The IO thread must outlive the BACKGROUND_X11 thread.
140 background_x11_thread_.reset();
141#endif
142
initial.commit09911bf2008-07-26 23:55:29143 // Need to stop io_thread_ before resource_dispatcher_host_, since
144 // io_thread_ may still deref ResourceDispatcherHost and handle resource
145 // request before going away.
[email protected]0ac83682010-01-22 17:46:27146 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29147
[email protected]914511712009-11-23 19:42:33148 // Stop the process launcher thread after the IO thread, in case the IO thread
149 // posted a task to terminate a process on the process launcher thread.
150 process_launcher_thread_.reset();
151
initial.commit09911bf2008-07-26 23:55:29152 // Clean up state that lives on the file_thread_ before it goes away.
153 if (resource_dispatcher_host_.get()) {
154 resource_dispatcher_host()->download_file_manager()->Shutdown();
155 resource_dispatcher_host()->save_file_manager()->Shutdown();
156 }
157
158 // Need to stop the file_thread_ here to force it to process messages in its
159 // message loop from the previous call to shutdown the DownloadFileManager,
160 // SaveFileManager and SessionService.
161 file_thread_.reset();
162
163 // With the file_thread_ flushed, we can release any icon resources.
164 icon_manager_.reset();
165
166 // Need to destroy ResourceDispatcherHost before PluginService and
[email protected]49f28bc72010-02-04 00:10:01167 // SafeBrowsingService, since it caches a pointer to it. This also
168 // causes the webkit thread to terminate.
initial.commit09911bf2008-07-26 23:55:29169 resource_dispatcher_host_.reset();
170
171 // Wait for the pending print jobs to finish.
172 print_job_manager_->OnQuit();
173 print_job_manager_.reset();
174
initial.commit09911bf2008-07-26 23:55:29175 // Now OK to destroy NotificationService.
176 main_notification_service_.reset();
177
[email protected]49f28bc72010-02-04 00:10:01178 // Prior to clearing local state, we want to complete tasks pending
179 // on the db thread too.
180 db_thread_.reset();
181
182 // At this point, no render process exist and the file, io, db, and
183 // webkit threads in this process have all terminated, so it's safe
184 // to access local state data such as cookies, database, or local storage.
185 if (clear_local_state_on_exit)
186 ClearLocalState(profile_path);
187
initial.commit09911bf2008-07-26 23:55:29188 g_browser_process = NULL;
189}
190
[email protected]295039bd2008-08-15 04:32:57191// Send a QuitTask to the given MessageLoop.
192static void PostQuit(MessageLoop* message_loop) {
193 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
194}
initial.commit09911bf2008-07-26 23:55:29195
[email protected]b443cb042009-12-15 22:05:09196unsigned int BrowserProcessImpl::AddRefModule() {
197 DCHECK(CalledOnValidThread());
198 module_ref_count_++;
199 return module_ref_count_;
200}
201
202unsigned int BrowserProcessImpl::ReleaseModule() {
203 DCHECK(CalledOnValidThread());
204 DCHECK(0 != module_ref_count_);
205 module_ref_count_--;
206 if (0 == module_ref_count_) {
207 MessageLoop::current()->PostTask(
208 FROM_HERE, NewRunnableFunction(Platform::DidEndMainMessageLoop));
209 MessageLoop::current()->Quit();
210 }
211 return module_ref_count_;
212}
213
initial.commit09911bf2008-07-26 23:55:29214void BrowserProcessImpl::EndSession() {
[email protected]b112a4c2009-02-01 20:24:01215#if defined(OS_WIN)
[email protected]d65cab7a2008-08-12 01:25:41216 // Notify we are going away.
[email protected]b797e152009-01-23 16:06:14217 ::SetEvent(shutdown_event_->handle());
[email protected]b112a4c2009-02-01 20:24:01218#endif
[email protected]d65cab7a2008-08-12 01:25:41219
initial.commit09911bf2008-07-26 23:55:29220 // Mark all the profiles as clean.
221 ProfileManager* pm = profile_manager();
222 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i)
223 (*i)->MarkAsCleanShutdown();
224
225 // Tell the metrics service it was cleanly shutdown.
226 MetricsService* metrics = g_browser_process->metrics_service();
227 if (metrics && local_state()) {
228 metrics->RecordCleanShutdown();
229
230 metrics->RecordStartOfSessionEnd();
231
232 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36233 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29234 }
235
236 // We must write that the profile and metrics service shutdown cleanly,
237 // otherwise on startup we'll think we crashed. So we block until done and
238 // then proceed with normal shutdown.
239 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57240 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29241 MessageLoop::current()->Run();
242}
243
244printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
245 // TODO(abarth): DCHECK(CalledOnValidThread());
246 // See <http://b/1287209>.
247 // print_job_manager_ is initialized in the constructor and destroyed in the
248 // destructor, so it should always be valid.
249 DCHECK(print_job_manager_.get());
250 return print_job_manager_.get();
251}
252
[email protected]4ef795df2010-02-03 02:35:08253void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
254 SQLitePersistentCookieStore::ClearLocalState(profile_path.Append(
255 chrome::kCookieFilename));
256 DOMStorageContext::ClearLocalState(profile_path, chrome::kExtensionScheme);
[email protected]72cfd90f2010-02-06 03:08:04257 webkit_database::DatabaseTracker::ClearLocalState(profile_path);
[email protected]10c934052010-02-04 19:58:31258 ChromeAppCacheService::ClearLocalState(profile_path);
[email protected]4ef795df2010-02-03 02:35:08259}
260
261bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
262 FilePath user_data_dir;
263 Profile* profile;
264
[email protected]ed0cf562010-02-05 22:50:41265 // Check for the existance of a profile manager. When quitting early,
266 // e.g. because another chrome instance is running, or when invoked with
267 // options such as --uninstall or --try-chrome-again=0, the profile manager
268 // does not exist yet.
269 if (!profile_manager_.get())
270 return false;
271
[email protected]4ef795df2010-02-03 02:35:08272 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
273 profile = profile_manager_->GetDefaultProfile(user_data_dir);
[email protected]7bfc674322010-03-05 00:20:57274 if (!profile)
275 return false;
[email protected]4ef795df2010-02-03 02:35:08276 *profile_path = profile->GetPath();
277 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit);
278}
279
initial.commit09911bf2008-07-26 23:55:29280void BrowserProcessImpl::CreateResourceDispatcherHost() {
281 DCHECK(!created_resource_dispatcher_host_ &&
282 resource_dispatcher_host_.get() == NULL);
283 created_resource_dispatcher_host_ = true;
284
[email protected]79084c2d2009-11-03 23:12:42285 resource_dispatcher_host_.reset(new ResourceDispatcherHost());
initial.commit09911bf2008-07-26 23:55:29286 resource_dispatcher_host_->Initialize();
287}
288
289void BrowserProcessImpl::CreateMetricsService() {
290 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
291 created_metrics_service_ = true;
292
293 metrics_service_.reset(new MetricsService);
294}
295
296void BrowserProcessImpl::CreateIOThread() {
297 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
298 created_io_thread_ = true;
299
300 // Prior to starting the io thread, we create the plugin service as
301 // it is predominantly used from the io thread, but must be created
302 // on the main thread. The service ctor is inexpensive and does not
303 // invoke the io_thread() accessor.
304 PluginService::GetInstance();
305
[email protected]4c3cd7412009-04-22 17:56:06306#if defined(OS_LINUX)
307 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so
308 // we start it now.
309 scoped_ptr<base::Thread> background_x11_thread(
310 new BrowserProcessSubThread(ChromeThread::BACKGROUND_X11));
311 if (!background_x11_thread->Start())
312 return;
313 background_x11_thread_.swap(background_x11_thread);
314#endif
315
[email protected]0ac83682010-01-22 17:46:27316 scoped_ptr<IOThread> thread(new IOThread);
[email protected]ab820df2008-08-26 05:55:10317 base::Thread::Options options;
318 options.message_loop_type = MessageLoop::TYPE_IO;
319 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29320 return;
321 io_thread_.swap(thread);
322}
323
324void BrowserProcessImpl::CreateFileThread() {
325 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
326 created_file_thread_ = true;
327
[email protected]ab820df2008-08-26 05:55:10328 scoped_ptr<base::Thread> thread(
329 new BrowserProcessSubThread(ChromeThread::FILE));
[email protected]a1db3842008-09-17 22:04:06330 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39331#if defined(OS_WIN)
332 // On Windows, the FILE thread needs to be have a UI message loop which pumps
333 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06334 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39335#else
336 options.message_loop_type = MessageLoop::TYPE_IO;
337#endif
[email protected]a1db3842008-09-17 22:04:06338 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29339 return;
340 file_thread_.swap(thread);
341}
342
343void BrowserProcessImpl::CreateDBThread() {
344 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
345 created_db_thread_ = true;
346
[email protected]ab820df2008-08-26 05:55:10347 scoped_ptr<base::Thread> thread(
348 new BrowserProcessSubThread(ChromeThread::DB));
initial.commit09911bf2008-07-26 23:55:29349 if (!thread->Start())
350 return;
351 db_thread_.swap(thread);
352}
353
[email protected]914511712009-11-23 19:42:33354void BrowserProcessImpl::CreateProcessLauncherThread() {
355 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
356 created_process_launcher_thread_ = true;
357
358 scoped_ptr<base::Thread> thread(
359 new BrowserProcessSubThread(ChromeThread::PROCESS_LAUNCHER));
360 if (!thread->Start())
361 return;
362 process_launcher_thread_.swap(thread);
363}
364
initial.commit09911bf2008-07-26 23:55:29365void BrowserProcessImpl::CreateProfileManager() {
366 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
367 created_profile_manager_ = true;
368
369 profile_manager_.reset(new ProfileManager());
370}
371
372void BrowserProcessImpl::CreateLocalState() {
373 DCHECK(!created_local_state_ && local_state_.get() == NULL);
374 created_local_state_ = true;
375
[email protected]b9636002009-03-04 00:05:25376 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29377 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]6fad2632009-11-02 05:59:37378 local_state_.reset(new PrefService(local_state_path));
initial.commit09911bf2008-07-26 23:55:29379}
380
[email protected]f3a4f302009-08-21 22:35:29381#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29382void BrowserProcessImpl::InitBrokerServices(
383 sandbox::BrokerServices* broker_services) {
384 DCHECK(!initialized_broker_services_ && broker_services_ == NULL);
385 broker_services->Init();
386 initialized_broker_services_ = true;
387 broker_services_ = broker_services;
388}
[email protected]f3a4f302009-08-21 22:35:29389#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29390
391void BrowserProcessImpl::CreateIconManager() {
392 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
393 created_icon_manager_ = true;
394 icon_manager_.reset(new IconManager);
395}
396
397void BrowserProcessImpl::CreateDebuggerWrapper(int port) {
398 DCHECK(debugger_wrapper_.get() == NULL);
399 created_debugger_wrapper_ = true;
400
401 debugger_wrapper_ = new DebuggerWrapper(port);
402}
403
[email protected]40ecc902009-03-16 13:42:47404void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44405 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47406 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44407 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47408}
409
initial.commit09911bf2008-07-26 23:55:29410void BrowserProcessImpl::CreateGoogleURLTracker() {
411 DCHECK(google_url_tracker_.get() == NULL);
412 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
413 google_url_tracker_.swap(google_url_tracker);
414}
[email protected]6641bf662009-08-21 00:34:09415
[email protected]c4ff4952010-01-08 19:12:47416void BrowserProcessImpl::CreateIntranetRedirectDetector() {
417 DCHECK(intranet_redirect_detector_.get() == NULL);
418 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
419 new IntranetRedirectDetector);
420 intranet_redirect_detector_.swap(intranet_redirect_detector);
421}
422
[email protected]29672ab2009-10-30 03:44:03423void BrowserProcessImpl::CreateNotificationUIManager() {
424 DCHECK(notification_ui_manager_.get() == NULL);
425 notification_ui_manager_.reset(NotificationUIManager::Create());
426 created_notification_ui_manager_ = true;
427}
428
[email protected]f1b6de22010-03-06 12:13:47429void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
430 locale_ = locale;
431 extension_l10n_util::SetProcessLocale(locale);
432}
433
[email protected]6641bf662009-08-21 00:34:09434// The BrowserProcess object must outlive the file thread so we use traits
435// which don't do any management.
436template <>
437struct RunnableMethodTraits<BrowserProcessImpl> {
[email protected]ee5e3792009-10-13 23:23:47438 void RetainCallee(BrowserProcessImpl* process) {}
439 void ReleaseCallee(BrowserProcessImpl* process) {}
[email protected]6641bf662009-08-21 00:34:09440};
441
442void BrowserProcessImpl::CheckForInspectorFiles() {
443 file_thread()->message_loop()->PostTask
444 (FROM_HERE,
445 NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck));
446}
447
[email protected]d55aaa132009-09-28 21:08:04448#if defined(IPC_MESSAGE_LOG_ENABLED)
449
450void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
451 // First enable myself.
452 if (enable)
453 IPC::Logging::current()->Enable();
454 else
455 IPC::Logging::current()->Disable();
456
457 // Now tell subprocesses. Messages to ChildProcess-derived
458 // processes must be done on the IO thread.
459 io_thread()->message_loop()->PostTask
460 (FROM_HERE,
461 NewRunnableMethod(
462 this,
463 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
464 enable));
465
466 // Finally, tell the renderers which don't derive from ChildProcess.
467 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:27468 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
469 !i.IsAtEnd(); i.Advance())
470 i.GetCurrentValue()->Send(new ViewMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:04471}
472
473// Helper for SetIPCLoggingEnabled.
474void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d85cf072009-10-27 03:59:31475 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
[email protected]d55aaa132009-09-28 21:08:04476
477 ChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:11478 while (!i.Done()) {
479 i->Send(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
480 ++i;
[email protected]d55aaa132009-09-28 21:08:04481 }
482}
483
484#endif // IPC_MESSAGE_LOG_ENABLED
485
[email protected]6641bf662009-08-21 00:34:09486void BrowserProcessImpl::DoInspectorFilesCheck() {
487 // Runs on FILE thread.
488 DCHECK(file_thread_->message_loop() == MessageLoop::current());
489 bool result = false;
490
491 FilePath inspector_dir;
492 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) {
493 result = file_util::PathExists(inspector_dir);
494 }
495
[email protected]308080d2009-11-11 19:19:02496 have_inspector_files_ = result;
[email protected]6641bf662009-08-21 00:34:09497}