blob: 09842340d45afbec3ee2a8e92885887dabca1718 [file] [log] [blame]
[email protected]f2a893c2011-01-05 09:38:071// Copyright (c) 2011 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]3cdacd42010-04-30 18:55:537#include <map>
8
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]985655a2011-02-23 09:54:2512#include "base/synchronization/waitable_event.h"
[email protected]c6032e82010-09-13 20:06:0513#include "base/task.h"
[email protected]34b99632011-01-01 01:01:0614#include "base/threading/thread.h"
15#include "base/threading/thread_restrictions.h"
[email protected]e13ad79b2010-07-22 21:36:5016#include "chrome/browser/automation/automation_provider_list.h"
[email protected]d27893f62010-07-03 05:47:4217#include "chrome/browser/browser_child_process_host.h"
[email protected]bd48c2b02010-04-09 20:32:4218#include "chrome/browser/browser_list.h"
[email protected]b443cb042009-12-15 22:05:0919#include "chrome/browser/browser_main.h"
[email protected]0ac83682010-01-22 17:46:2720#include "chrome/browser/browser_process_sub_thread.h"
[email protected]ed7e6dd2010-10-12 02:02:4521#include "chrome/browser/browser_thread.h"
[email protected]ac262c9f2008-10-19 17:45:2122#include "chrome/browser/browser_trial.h"
[email protected]9678cb42011-01-31 18:49:4223#include "chrome/browser/debugger/browser_list_tabcontents_provider.h"
[email protected]5613126e2011-01-31 15:27:5524#include "chrome/browser/debugger/devtools_http_protocol_handler.h"
[email protected]40ecc902009-03-16 13:42:4725#include "chrome/browser/debugger/devtools_manager.h"
[email protected]5613126e2011-01-31 15:27:5526#include "chrome/browser/debugger/devtools_protocol_handler.h"
[email protected]6c69796d2010-07-16 21:41:1627#include "chrome/browser/download/download_file_manager.h"
[email protected]5ba0a2c2009-02-19 01:19:3428#include "chrome/browser/download/save_file_manager.h"
[email protected]820735792010-07-29 23:40:0129#include "chrome/browser/first_run/first_run.h"
[email protected]f7578f52010-08-30 22:22:4930#include "chrome/browser/google/google_url_tracker.h"
[email protected]dcefa302009-05-20 00:24:3931#include "chrome/browser/icon_manager.h"
[email protected]c4ff4952010-01-08 19:12:4732#include "chrome/browser/intranet_redirect_detector.h"
[email protected]0ac83682010-01-22 17:46:2733#include "chrome/browser/io_thread.h"
[email protected]dc6f4962009-02-13 01:25:5034#include "chrome/browser/metrics/metrics_service.h"
[email protected]3617ea92011-02-23 07:27:0235#include "chrome/browser/metrics/thread_watcher.h"
[email protected]b2fcd0e2010-12-01 15:19:4036#include "chrome/browser/net/chrome_net_log.h"
[email protected]3530cd92010-06-27 06:22:0137#include "chrome/browser/net/predictor_api.h"
[email protected]d393a0fd2009-05-13 23:32:0138#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]29672ab2009-10-30 03:44:0339#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]6618d1d2010-12-15 21:18:4740#include "chrome/browser/plugin_data_remover.h"
[email protected]fd49e2d2009-02-20 17:21:3041#include "chrome/browser/plugin_service.h"
[email protected]492d2142010-09-10 13:55:1842#include "chrome/browser/plugin_updater.h"
[email protected]985655a2011-02-23 09:54:2543#include "chrome/browser/policy/browser_policy_connector.h"
[email protected]37858e52010-08-26 00:22:0244#include "chrome/browser/prefs/pref_service.h"
[email protected]e06131d2010-02-10 18:40:3345#include "chrome/browser/printing/print_job_manager.h"
[email protected]dbeebd52010-11-16 20:34:1646#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]8ecad5e2010-12-02 21:18:3347#include "chrome/browser/profiles/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2648#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]81218f42009-02-05 18:48:0849#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
[email protected]a7a5e992010-12-09 23:39:5150#include "chrome/browser/safe_browsing/client_side_detection_service.h"
[email protected]81218f42009-02-05 18:48:0851#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]e450fa62011-02-01 12:52:5652#include "chrome/browser/shell_integration.h"
[email protected]8b8e7c92010-08-19 18:05:5653#include "chrome/browser/sidebar/sidebar_manager.h"
[email protected]0b4d3382010-07-14 16:13:0454#include "chrome/browser/tab_closeable_state_watcher.h"
[email protected]4ef795df2010-02-03 02:35:0855#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2956#include "chrome/common/chrome_paths.h"
57#include "chrome/common/chrome_switches.h"
[email protected]f1b6de22010-03-06 12:13:4758#include "chrome/common/extensions/extension_l10n_util.h"
[email protected]985655a2011-02-23 09:54:2559#include "chrome/common/extensions/extension_resource.h"
[email protected]ea587b02010-05-21 15:01:3560#include "chrome/common/json_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2961#include "chrome/common/notification_service.h"
62#include "chrome/common/pref_names.h"
[email protected]5c08f222010-09-22 09:37:2163#include "chrome/common/switch_utils.h"
[email protected]985655a2011-02-23 09:54:2564#include "chrome/common/url_constants.h"
[email protected]bd48c2b02010-04-09 20:32:4265#include "chrome/installer/util/google_update_constants.h"
[email protected]d55aaa132009-09-28 21:08:0466#include "ipc/ipc_logging.h"
[email protected]2dfeaf92011-01-10 21:08:2167#include "ui/base/clipboard/clipboard.h"
[email protected]c051a1b2011-01-21 23:30:1768#include "ui/base/l10n/l10n_util.h"
[email protected]4ef795df2010-02-03 02:35:0869#include "webkit/database/database_tracker.h"
[email protected]b112a4c2009-02-01 20:24:0170
71#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0572#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3873#endif
74
[email protected]d55aaa132009-09-28 21:08:0475#if defined(IPC_MESSAGE_LOG_ENABLED)
76#include "chrome/common/plugin_messages.h"
77#include "chrome/common/render_messages.h"
78#endif
79
[email protected]3cdacd42010-04-30 18:55:5380#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
81// How often to check if the persistent instance of Chrome needs to restart
82// to install an update.
83static const int kUpdateCheckIntervalHours = 6;
84#endif
85
[email protected]c6032e82010-09-13 20:06:0586#if defined(USE_X11)
87// How long to wait for the File thread to complete during EndSession, on
88// Linux. We have a timeout here because we're unable to run the UI messageloop
89// and there's some deadlock risk. Our only option is to exit anyway.
90static const int kEndSessionTimeoutSeconds = 10;
91#endif
92
[email protected]bb975362009-01-21 01:00:2293BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:2994 : created_resource_dispatcher_host_(false),
95 created_metrics_service_(false),
96 created_io_thread_(false),
97 created_file_thread_(false),
98 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:3399 created_process_launcher_thread_(false),
[email protected]875ee822010-05-18 20:58:01100 created_cache_thread_(false),
[email protected]3617ea92011-02-23 07:27:02101 created_watchdog_thread_(false),
initial.commit09911bf2008-07-26 23:55:29102 created_profile_manager_(false),
103 created_local_state_(false),
[email protected]b112a4c2009-02-01 20:24:01104 created_icon_manager_(false),
[email protected]40ecc902009-03-16 13:42:47105 created_devtools_manager_(false),
[email protected]8b8e7c92010-08-19 18:05:56106 created_sidebar_manager_(false),
[email protected]985655a2011-02-23 09:54:25107 created_browser_policy_connector_(false),
[email protected]29672ab2009-10-30 03:44:03108 created_notification_ui_manager_(false),
[email protected]a7a5e992010-12-09 23:39:51109 created_safe_browsing_detection_service_(false),
initial.commit09911bf2008-07-26 23:55:29110 module_ref_count_(0),
[email protected]afd20c022010-06-10 00:48:20111 did_start_(false),
[email protected]1b2db1a2008-08-08 17:46:13112 checked_for_new_frames_(false),
[email protected]6641bf662009-08-21 00:34:09113 using_new_frames_(false),
114 have_inspector_files_(true) {
initial.commit09911bf2008-07-26 23:55:29115 g_browser_process = this;
[email protected]2dfeaf92011-01-10 21:08:21116 clipboard_.reset(new ui::Clipboard);
initial.commit09911bf2008-07-26 23:55:29117 main_notification_service_.reset(new NotificationService);
118
[email protected]6618d1d2010-12-15 21:18:47119 notification_registrar_.Add(this,
120 NotificationType::APP_TERMINATING,
121 NotificationService::AllSources());
122
initial.commit09911bf2008-07-26 23:55:29123 // Must be created after the NotificationService.
124 print_job_manager_.reset(new printing::PrintJobManager);
125
[email protected]b797e152009-01-23 16:06:14126 shutdown_event_.reset(new base::WaitableEvent(true, false));
[email protected]b2fcd0e2010-12-01 15:19:40127
128 net_log_.reset(new ChromeNetLog);
initial.commit09911bf2008-07-26 23:55:29129}
130
131BrowserProcessImpl::~BrowserProcessImpl() {
[email protected]4ef795df2010-02-03 02:35:08132 FilePath profile_path;
133 bool clear_local_state_on_exit;
134
135 // Store the profile path for clearing local state data on exit.
136 clear_local_state_on_exit = ShouldClearLocalState(&profile_path);
137
initial.commit09911bf2008-07-26 23:55:29138 // Delete the AutomationProviderList before NotificationService,
139 // since it may try to unregister notifications
140 // Both NotificationService and AutomationProvider are singleton instances in
141 // the BrowserProcess. Since AutomationProvider may have some active
142 // notification observers, it is essential that it gets destroyed before the
143 // NotificationService. NotificationService won't be destroyed until after
144 // this destructor is run.
145 automation_provider_list_.reset();
146
[email protected]d393a0fd2009-05-13 23:32:01147 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
148 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
149 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
150 // any pending URLFetchers, and avoid creating any more.
151 SdchDictionaryFetcher::Shutdown();
152
[email protected]51ac040762011-01-20 02:01:04153 // We need to destroy the MetricsService, GoogleURLTracker,
154 // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService
155 // before the io_thread_ gets destroyed, since their destructors can call the
156 // URLFetcher destructor, which does a PostDelayedTask operation on the IO
157 // thread. (The IO thread will handle that URLFetcher operation before going
158 // away.)
initial.commit09911bf2008-07-26 23:55:29159 metrics_service_.reset();
160 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47161 intranet_redirect_detector_.reset();
[email protected]51ac040762011-01-20 02:01:04162 safe_browsing_detection_service_.reset();
initial.commit09911bf2008-07-26 23:55:29163
[email protected]d8a899c2010-09-21 04:50:33164 // Need to clear the desktop notification balloons before the io_thread_ and
165 // before the profiles, since if there are any still showing we will access
166 // those things during teardown.
167 notification_ui_manager_.reset();
168
initial.commit09911bf2008-07-26 23:55:29169 // Need to clear profiles (download managers) before the io_thread_.
170 profile_manager_.reset();
171
172 // Debugger must be cleaned up before IO thread and NotificationService.
[email protected]5613126e2011-01-31 15:27:55173 if (devtools_http_handler_.get()) {
174 devtools_http_handler_->Stop();
175 devtools_http_handler_ = NULL;
176 }
177 if (devtools_legacy_handler_.get()) {
178 devtools_legacy_handler_->Stop();
179 devtools_legacy_handler_ = NULL;
180 }
initial.commit09911bf2008-07-26 23:55:29181
182 if (resource_dispatcher_host_.get()) {
183 // Need to tell Safe Browsing Service that the IO thread is going away
184 // since it cached a pointer to it.
185 if (resource_dispatcher_host()->safe_browsing_service())
186 resource_dispatcher_host()->safe_browsing_service()->ShutDown();
187
188 // Cancel pending requests and prevent new requests.
189 resource_dispatcher_host()->Shutdown();
190 }
191
[email protected]985655a2011-02-23 09:54:25192 // The policy providers managed by |browser_policy_connector_| need to shut
193 // down while the IO and FILE threads are still alive.
194 browser_policy_connector_.reset();
[email protected]f2a893c2011-01-05 09:38:07195
[email protected]753efc42010-03-09 19:52:16196#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06197 // The IO thread must outlive the BACKGROUND_X11 thread.
198 background_x11_thread_.reset();
199#endif
200
[email protected]6618d1d2010-12-15 21:18:47201 // Wait for removing plugin data to finish before shutting down the IO thread.
202 WaitForPluginDataRemoverToFinish();
203
initial.commit09911bf2008-07-26 23:55:29204 // Need to stop io_thread_ before resource_dispatcher_host_, since
205 // io_thread_ may still deref ResourceDispatcherHost and handle resource
206 // request before going away.
[email protected]0ac83682010-01-22 17:46:27207 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29208
[email protected]875ee822010-05-18 20:58:01209 // The IO thread was the only user of this thread.
210 cache_thread_.reset();
211
[email protected]914511712009-11-23 19:42:33212 // Stop the process launcher thread after the IO thread, in case the IO thread
213 // posted a task to terminate a process on the process launcher thread.
214 process_launcher_thread_.reset();
215
initial.commit09911bf2008-07-26 23:55:29216 // Clean up state that lives on the file_thread_ before it goes away.
217 if (resource_dispatcher_host_.get()) {
218 resource_dispatcher_host()->download_file_manager()->Shutdown();
219 resource_dispatcher_host()->save_file_manager()->Shutdown();
220 }
221
222 // Need to stop the file_thread_ here to force it to process messages in its
223 // message loop from the previous call to shutdown the DownloadFileManager,
224 // SaveFileManager and SessionService.
225 file_thread_.reset();
226
227 // With the file_thread_ flushed, we can release any icon resources.
228 icon_manager_.reset();
229
230 // Need to destroy ResourceDispatcherHost before PluginService and
[email protected]49f28bc72010-02-04 00:10:01231 // SafeBrowsingService, since it caches a pointer to it. This also
232 // causes the webkit thread to terminate.
initial.commit09911bf2008-07-26 23:55:29233 resource_dispatcher_host_.reset();
234
235 // Wait for the pending print jobs to finish.
236 print_job_manager_->OnQuit();
237 print_job_manager_.reset();
238
[email protected]0b4d3382010-07-14 16:13:04239 // Destroy TabCloseableStateWatcher before NotificationService since the
240 // former registers for notifications.
241 tab_closeable_state_watcher_.reset();
242
initial.commit09911bf2008-07-26 23:55:29243 // Now OK to destroy NotificationService.
244 main_notification_service_.reset();
245
[email protected]49f28bc72010-02-04 00:10:01246 // Prior to clearing local state, we want to complete tasks pending
247 // on the db thread too.
248 db_thread_.reset();
249
[email protected]3617ea92011-02-23 07:27:02250 // Stop the watchdog thread after stopping other threads.
251 watchdog_thread_.reset();
252
[email protected]49f28bc72010-02-04 00:10:01253 // At this point, no render process exist and the file, io, db, and
254 // webkit threads in this process have all terminated, so it's safe
255 // to access local state data such as cookies, database, or local storage.
256 if (clear_local_state_on_exit)
257 ClearLocalState(profile_path);
258
initial.commit09911bf2008-07-26 23:55:29259 g_browser_process = NULL;
260}
261
[email protected]c6032e82010-09-13 20:06:05262#if defined(OS_WIN)
[email protected]295039bd2008-08-15 04:32:57263// Send a QuitTask to the given MessageLoop.
264static void PostQuit(MessageLoop* message_loop) {
265 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
266}
[email protected]c6032e82010-09-13 20:06:05267#elif defined(USE_X11)
268static void Signal(base::WaitableEvent* event) {
269 event->Signal();
270}
271#endif
initial.commit09911bf2008-07-26 23:55:29272
[email protected]b443cb042009-12-15 22:05:09273unsigned int BrowserProcessImpl::AddRefModule() {
274 DCHECK(CalledOnValidThread());
[email protected]afd20c022010-06-10 00:48:20275 did_start_ = true;
[email protected]b443cb042009-12-15 22:05:09276 module_ref_count_++;
277 return module_ref_count_;
278}
279
280unsigned int BrowserProcessImpl::ReleaseModule() {
281 DCHECK(CalledOnValidThread());
[email protected]760d970a2010-05-18 00:39:18282 DCHECK_NE(0u, module_ref_count_);
[email protected]b443cb042009-12-15 22:05:09283 module_ref_count_--;
284 if (0 == module_ref_count_) {
[email protected]7d038c32010-12-14 00:40:00285 // Allow UI and IO threads to do blocking IO on shutdown, since we do a lot
286 // of it on shutdown for valid reasons.
287 base::ThreadRestrictions::SetIOAllowed(true);
288 io_thread()->message_loop()->PostTask(
289 FROM_HERE,
290 NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true));
[email protected]b443cb042009-12-15 22:05:09291 MessageLoop::current()->PostTask(
[email protected]34f73fb2010-03-24 20:50:34292 FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop));
[email protected]b443cb042009-12-15 22:05:09293 MessageLoop::current()->Quit();
294 }
295 return module_ref_count_;
296}
297
initial.commit09911bf2008-07-26 23:55:29298void BrowserProcessImpl::EndSession() {
[email protected]c6032e82010-09-13 20:06:05299#if defined(OS_WIN) || defined(USE_X11)
[email protected]d65cab7a2008-08-12 01:25:41300 // Notify we are going away.
[email protected]c6032e82010-09-13 20:06:05301 shutdown_event_->Signal();
[email protected]b112a4c2009-02-01 20:24:01302#endif
[email protected]d65cab7a2008-08-12 01:25:41303
initial.commit09911bf2008-07-26 23:55:29304 // Mark all the profiles as clean.
305 ProfileManager* pm = profile_manager();
306 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i)
307 (*i)->MarkAsCleanShutdown();
308
309 // Tell the metrics service it was cleanly shutdown.
310 MetricsService* metrics = g_browser_process->metrics_service();
311 if (metrics && local_state()) {
312 metrics->RecordCleanShutdown();
313
314 metrics->RecordStartOfSessionEnd();
315
316 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36317 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29318 }
319
320 // We must write that the profile and metrics service shutdown cleanly,
321 // otherwise on startup we'll think we crashed. So we block until done and
322 // then proceed with normal shutdown.
[email protected]c6032e82010-09-13 20:06:05323#if defined(USE_X11)
324 // Can't run a local loop on linux. Instead create a waitable event.
325 base::WaitableEvent done_writing(false, false);
[email protected]d04e7662010-10-10 22:24:48326 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]c6032e82010-09-13 20:06:05327 NewRunnableFunction(Signal, &done_writing));
328 done_writing.TimedWait(
329 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds));
330#elif defined(OS_WIN)
[email protected]d04e7662010-10-10 22:24:48331 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57332 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29333 MessageLoop::current()->Run();
[email protected]c6032e82010-09-13 20:06:05334#else
335 NOTIMPLEMENTED();
336#endif
initial.commit09911bf2008-07-26 23:55:29337}
338
[email protected]e13ad79b2010-07-22 21:36:50339ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() {
340 DCHECK(CalledOnValidThread());
341 if (!created_resource_dispatcher_host_)
342 CreateResourceDispatcherHost();
343 return resource_dispatcher_host_.get();
344}
345
346MetricsService* BrowserProcessImpl::metrics_service() {
347 DCHECK(CalledOnValidThread());
348 if (!created_metrics_service_)
349 CreateMetricsService();
350 return metrics_service_.get();
351}
352
353IOThread* BrowserProcessImpl::io_thread() {
354 DCHECK(CalledOnValidThread());
355 if (!created_io_thread_)
356 CreateIOThread();
357 return io_thread_.get();
358}
359
360base::Thread* BrowserProcessImpl::file_thread() {
361 DCHECK(CalledOnValidThread());
362 if (!created_file_thread_)
363 CreateFileThread();
364 return file_thread_.get();
365}
366
367base::Thread* BrowserProcessImpl::db_thread() {
368 DCHECK(CalledOnValidThread());
369 if (!created_db_thread_)
370 CreateDBThread();
371 return db_thread_.get();
372}
373
374base::Thread* BrowserProcessImpl::process_launcher_thread() {
375 DCHECK(CalledOnValidThread());
376 if (!created_process_launcher_thread_)
377 CreateProcessLauncherThread();
378 return process_launcher_thread_.get();
379}
380
381base::Thread* BrowserProcessImpl::cache_thread() {
382 DCHECK(CalledOnValidThread());
383 if (!created_cache_thread_)
384 CreateCacheThread();
385 return cache_thread_.get();
386}
387
388#if defined(USE_X11)
389base::Thread* BrowserProcessImpl::background_x11_thread() {
390 DCHECK(CalledOnValidThread());
391 // The BACKGROUND_X11 thread is created when the IO thread is created.
392 if (!created_io_thread_)
393 CreateIOThread();
394 return background_x11_thread_.get();
395}
396#endif
397
[email protected]3617ea92011-02-23 07:27:02398WatchDogThread* BrowserProcessImpl::watchdog_thread() {
399 DCHECK(CalledOnValidThread());
400 if (!created_watchdog_thread_)
401 CreateWatchdogThread();
402 DCHECK(watchdog_thread_.get() != NULL);
403 return watchdog_thread_.get();
404}
405
[email protected]e13ad79b2010-07-22 21:36:50406ProfileManager* BrowserProcessImpl::profile_manager() {
407 DCHECK(CalledOnValidThread());
408 if (!created_profile_manager_)
409 CreateProfileManager();
410 return profile_manager_.get();
411}
412
413PrefService* BrowserProcessImpl::local_state() {
414 DCHECK(CalledOnValidThread());
415 if (!created_local_state_)
416 CreateLocalState();
417 return local_state_.get();
418}
419
420DevToolsManager* BrowserProcessImpl::devtools_manager() {
421 DCHECK(CalledOnValidThread());
422 if (!created_devtools_manager_)
423 CreateDevToolsManager();
424 return devtools_manager_.get();
425}
426
[email protected]8b8e7c92010-08-19 18:05:56427SidebarManager* BrowserProcessImpl::sidebar_manager() {
428 DCHECK(CalledOnValidThread());
429 if (!created_sidebar_manager_)
430 CreateSidebarManager();
431 return sidebar_manager_.get();
432}
433
[email protected]2dfeaf92011-01-10 21:08:21434ui::Clipboard* BrowserProcessImpl::clipboard() {
[email protected]e13ad79b2010-07-22 21:36:50435 DCHECK(CalledOnValidThread());
436 return clipboard_.get();
437}
438
439NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
440 DCHECK(CalledOnValidThread());
441 if (!created_notification_ui_manager_)
442 CreateNotificationUIManager();
443 return notification_ui_manager_.get();
444}
445
[email protected]985655a2011-02-23 09:54:25446policy::BrowserPolicyConnector* BrowserProcessImpl::browser_policy_connector() {
[email protected]f2a893c2011-01-05 09:38:07447 DCHECK(CalledOnValidThread());
[email protected]985655a2011-02-23 09:54:25448 if (!created_browser_policy_connector_) {
449 DCHECK(browser_policy_connector_.get() == NULL);
450 created_browser_policy_connector_ = true;
451 browser_policy_connector_.reset(new policy::BrowserPolicyConnector());
[email protected]f2a893c2011-01-05 09:38:07452 }
[email protected]985655a2011-02-23 09:54:25453 return browser_policy_connector_.get();
[email protected]f2a893c2011-01-05 09:38:07454}
455
[email protected]e13ad79b2010-07-22 21:36:50456IconManager* BrowserProcessImpl::icon_manager() {
457 DCHECK(CalledOnValidThread());
458 if (!created_icon_manager_)
459 CreateIconManager();
460 return icon_manager_.get();
461}
462
463ThumbnailGenerator* BrowserProcessImpl::GetThumbnailGenerator() {
464 return &thumbnail_generator_;
465}
466
467AutomationProviderList* BrowserProcessImpl::InitAutomationProviderList() {
468 DCHECK(CalledOnValidThread());
469 if (automation_provider_list_.get() == NULL) {
470 automation_provider_list_.reset(AutomationProviderList::GetInstance());
471 }
472 return automation_provider_list_.get();
473}
474
[email protected]5613126e2011-01-31 15:27:55475void BrowserProcessImpl::InitDevToolsHttpProtocolHandler(
[email protected]01000cf12011-02-04 11:39:22476 const std::string& ip,
[email protected]5613126e2011-01-31 15:27:55477 int port,
478 const std::string& frontend_url) {
[email protected]e13ad79b2010-07-22 21:36:50479 DCHECK(CalledOnValidThread());
[email protected]5613126e2011-01-31 15:27:55480 devtools_http_handler_ =
[email protected]01000cf12011-02-04 11:39:22481 DevToolsHttpProtocolHandler::Start(ip,
482 port,
[email protected]9678cb42011-01-31 18:49:42483 frontend_url,
484 new BrowserListTabContentsProvider());
[email protected]5613126e2011-01-31 15:27:55485}
486
487void BrowserProcessImpl::InitDevToolsLegacyProtocolHandler(int port) {
488 DCHECK(CalledOnValidThread());
489 devtools_legacy_handler_ = DevToolsProtocolHandler::Start(port);
[email protected]e13ad79b2010-07-22 21:36:50490}
491
492bool BrowserProcessImpl::IsShuttingDown() {
493 DCHECK(CalledOnValidThread());
494 return did_start_ && 0 == module_ref_count_;
495}
496
initial.commit09911bf2008-07-26 23:55:29497printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
498 // TODO(abarth): DCHECK(CalledOnValidThread());
[email protected]d8922f22010-05-07 00:57:27499 // http://code.google.com/p/chromium/issues/detail?id=6828
initial.commit09911bf2008-07-26 23:55:29500 // print_job_manager_ is initialized in the constructor and destroyed in the
501 // destructor, so it should always be valid.
502 DCHECK(print_job_manager_.get());
503 return print_job_manager_.get();
504}
505
[email protected]dbeebd52010-11-16 20:34:16506printing::PrintPreviewTabController*
507 BrowserProcessImpl::print_preview_tab_controller() {
508 DCHECK(CalledOnValidThread());
509 if (!print_preview_tab_controller_.get())
510 CreatePrintPreviewTabController();
511 return print_preview_tab_controller_.get();
512}
513
[email protected]e13ad79b2010-07-22 21:36:50514GoogleURLTracker* BrowserProcessImpl::google_url_tracker() {
515 DCHECK(CalledOnValidThread());
516 if (!google_url_tracker_.get())
517 CreateGoogleURLTracker();
518 return google_url_tracker_.get();
519}
520
521IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
522 DCHECK(CalledOnValidThread());
523 if (!intranet_redirect_detector_.get())
524 CreateIntranetRedirectDetector();
525 return intranet_redirect_detector_.get();
526}
527
528const std::string& BrowserProcessImpl::GetApplicationLocale() {
529 DCHECK(!locale_.empty());
530 return locale_;
531}
532
533void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
534 locale_ = locale;
535 extension_l10n_util::SetProcessLocale(locale);
536}
537
[email protected]073ed7b2010-09-27 09:20:02538DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
539 return &download_status_updater_;
540}
541
[email protected]e13ad79b2010-07-22 21:36:50542base::WaitableEvent* BrowserProcessImpl::shutdown_event() {
543 return shutdown_event_.get();
544}
545
546TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() {
547 DCHECK(CalledOnValidThread());
548 if (!tab_closeable_state_watcher_.get())
549 CreateTabCloseableStateWatcher();
550 return tab_closeable_state_watcher_.get();
551}
552
[email protected]a7a5e992010-12-09 23:39:51553safe_browsing::ClientSideDetectionService*
554 BrowserProcessImpl::safe_browsing_detection_service() {
555 DCHECK(CalledOnValidThread());
556 if (!created_safe_browsing_detection_service_) {
557 CreateSafeBrowsingDetectionService();
558 }
559 return safe_browsing_detection_service_.get();
560}
561
[email protected]e13ad79b2010-07-22 21:36:50562void BrowserProcessImpl::CheckForInspectorFiles() {
563 file_thread()->message_loop()->PostTask
564 (FROM_HERE,
565 NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck));
566}
567
[email protected]6618d1d2010-12-15 21:18:47568void BrowserProcessImpl::Observe(NotificationType type,
569 const NotificationSource& source,
570 const NotificationDetails& details) {
571 if (type == NotificationType::APP_TERMINATING) {
572 Profile* profile = ProfileManager::GetDefaultProfile();
573 if (profile) {
574 PrefService* prefs = profile->GetPrefs();
[email protected]2ffc3c6c2011-01-14 12:50:24575 if (prefs->GetBoolean(prefs::kClearSiteDataOnExit) &&
[email protected]6618d1d2010-12-15 21:18:47576 local_state()->GetBoolean(prefs::kClearPluginLSODataEnabled)) {
577 plugin_data_remover_ = new PluginDataRemover();
[email protected]c7d58d62011-01-21 10:27:18578 if (!plugin_data_remover_mime_type().empty())
579 plugin_data_remover_->set_mime_type(plugin_data_remover_mime_type());
580 plugin_data_remover_->StartRemoving(base::Time());
[email protected]6618d1d2010-12-15 21:18:47581 }
582 }
[email protected]e450fa62011-02-01 12:52:56583 } else if (type == NotificationType::PREF_CHANGED) {
584 std::string* pref = Details<std::string>(details).ptr();
585 if (*pref == prefs::kDefaultBrowserSettingEnabled) {
586 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
587 ShellIntegration::SetAsDefaultBrowser();
588 }
[email protected]6618d1d2010-12-15 21:18:47589 } else {
590 NOTREACHED();
591 }
592}
593
594void BrowserProcessImpl::WaitForPluginDataRemoverToFinish() {
[email protected]c7d58d62011-01-21 10:27:18595 if (plugin_data_remover_.get())
596 plugin_data_remover_->Wait();
[email protected]6618d1d2010-12-15 21:18:47597}
598
[email protected]e13ad79b2010-07-22 21:36:50599#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
600void BrowserProcessImpl::StartAutoupdateTimer() {
601 autoupdate_timer_.Start(
602 base::TimeDelta::FromHours(kUpdateCheckIntervalHours),
603 this,
604 &BrowserProcessImpl::OnAutoupdateTimer);
605}
606#endif
607
608bool BrowserProcessImpl::have_inspector_files() const {
609 return have_inspector_files_;
610}
611
[email protected]d6f37fc2011-02-13 23:58:41612ChromeNetLog* BrowserProcessImpl::net_log() {
613 return net_log_.get();
614}
615
[email protected]4ef795df2010-02-03 02:35:08616void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
[email protected]72cfd90f2010-02-06 03:08:04617 webkit_database::DatabaseTracker::ClearLocalState(profile_path);
[email protected]4ef795df2010-02-03 02:35:08618}
619
620bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
621 FilePath user_data_dir;
622 Profile* profile;
623
[email protected]09584972010-07-03 00:00:59624 // Check for the existence of a profile manager. When quitting early,
[email protected]ed0cf562010-02-05 22:50:41625 // e.g. because another chrome instance is running, or when invoked with
626 // options such as --uninstall or --try-chrome-again=0, the profile manager
627 // does not exist yet.
628 if (!profile_manager_.get())
629 return false;
630
[email protected]4ef795df2010-02-03 02:35:08631 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
632 profile = profile_manager_->GetDefaultProfile(user_data_dir);
[email protected]7bfc674322010-03-05 00:20:57633 if (!profile)
634 return false;
[email protected]4ef795df2010-02-03 02:35:08635 *profile_path = profile->GetPath();
636 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit);
637}
638
initial.commit09911bf2008-07-26 23:55:29639void BrowserProcessImpl::CreateResourceDispatcherHost() {
640 DCHECK(!created_resource_dispatcher_host_ &&
641 resource_dispatcher_host_.get() == NULL);
642 created_resource_dispatcher_host_ = true;
643
[email protected]79084c2d2009-11-03 23:12:42644 resource_dispatcher_host_.reset(new ResourceDispatcherHost());
initial.commit09911bf2008-07-26 23:55:29645 resource_dispatcher_host_->Initialize();
646}
647
648void BrowserProcessImpl::CreateMetricsService() {
649 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
650 created_metrics_service_ = true;
651
652 metrics_service_.reset(new MetricsService);
653}
654
655void BrowserProcessImpl::CreateIOThread() {
656 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
657 created_io_thread_ = true;
658
659 // Prior to starting the io thread, we create the plugin service as
660 // it is predominantly used from the io thread, but must be created
661 // on the main thread. The service ctor is inexpensive and does not
662 // invoke the io_thread() accessor.
663 PluginService::GetInstance();
664
[email protected]753efc42010-03-09 19:52:16665#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06666 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so
667 // we start it now.
668 scoped_ptr<base::Thread> background_x11_thread(
[email protected]d04e7662010-10-10 22:24:48669 new BrowserProcessSubThread(BrowserThread::BACKGROUND_X11));
[email protected]4c3cd7412009-04-22 17:56:06670 if (!background_x11_thread->Start())
671 return;
672 background_x11_thread_.swap(background_x11_thread);
673#endif
674
[email protected]b2fcd0e2010-12-01 15:19:40675 scoped_ptr<IOThread> thread(new IOThread(local_state(), net_log_.get()));
[email protected]ab820df2008-08-26 05:55:10676 base::Thread::Options options;
677 options.message_loop_type = MessageLoop::TYPE_IO;
678 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29679 return;
680 io_thread_.swap(thread);
681}
682
683void BrowserProcessImpl::CreateFileThread() {
684 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
685 created_file_thread_ = true;
686
[email protected]ab820df2008-08-26 05:55:10687 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48688 new BrowserProcessSubThread(BrowserThread::FILE));
[email protected]a1db3842008-09-17 22:04:06689 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39690#if defined(OS_WIN)
691 // On Windows, the FILE thread needs to be have a UI message loop which pumps
692 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06693 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39694#else
695 options.message_loop_type = MessageLoop::TYPE_IO;
696#endif
[email protected]a1db3842008-09-17 22:04:06697 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29698 return;
699 file_thread_.swap(thread);
700}
701
702void BrowserProcessImpl::CreateDBThread() {
703 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
704 created_db_thread_ = true;
705
[email protected]ab820df2008-08-26 05:55:10706 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48707 new BrowserProcessSubThread(BrowserThread::DB));
initial.commit09911bf2008-07-26 23:55:29708 if (!thread->Start())
709 return;
710 db_thread_.swap(thread);
711}
712
[email protected]914511712009-11-23 19:42:33713void BrowserProcessImpl::CreateProcessLauncherThread() {
714 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
715 created_process_launcher_thread_ = true;
716
717 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48718 new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER));
[email protected]914511712009-11-23 19:42:33719 if (!thread->Start())
720 return;
721 process_launcher_thread_.swap(thread);
722}
723
[email protected]875ee822010-05-18 20:58:01724void BrowserProcessImpl::CreateCacheThread() {
725 DCHECK(!created_cache_thread_ && !cache_thread_.get());
726 created_cache_thread_ = true;
727
728 scoped_ptr<base::Thread> thread(
[email protected]75096332010-11-09 03:28:13729 new BrowserThread(BrowserThread::CACHE));
[email protected]875ee822010-05-18 20:58:01730 base::Thread::Options options;
731 options.message_loop_type = MessageLoop::TYPE_IO;
732 if (!thread->StartWithOptions(options))
733 return;
734 cache_thread_.swap(thread);
735}
736
[email protected]3617ea92011-02-23 07:27:02737void BrowserProcessImpl::CreateWatchdogThread() {
738 DCHECK(!created_watchdog_thread_ && watchdog_thread_.get() == NULL);
739 created_watchdog_thread_ = true;
740
741 scoped_ptr<WatchDogThread> thread(new WatchDogThread());
742 if (!thread->Start())
743 return;
744 watchdog_thread_.swap(thread);
745}
746
initial.commit09911bf2008-07-26 23:55:29747void BrowserProcessImpl::CreateProfileManager() {
748 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
749 created_profile_manager_ = true;
750
751 profile_manager_.reset(new ProfileManager());
752}
753
754void BrowserProcessImpl::CreateLocalState() {
755 DCHECK(!created_local_state_ && local_state_.get() == NULL);
756 created_local_state_ = true;
757
[email protected]b9636002009-03-04 00:05:25758 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29759 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]f2d1f612010-12-09 15:10:17760 local_state_.reset(
761 PrefService::CreatePrefService(local_state_path, NULL, NULL));
[email protected]492d2142010-09-10 13:55:18762
[email protected]2a7e7c152010-10-01 20:12:09763 pref_change_registrar_.Init(local_state_.get());
764
[email protected]492d2142010-09-10 13:55:18765 // Make sure the the plugin updater gets notifications of changes
766 // in the plugin blacklist.
767 local_state_->RegisterListPref(prefs::kPluginsPluginsBlacklist);
[email protected]2a7e7c152010-10-01 20:12:09768 pref_change_registrar_.Add(prefs::kPluginsPluginsBlacklist,
[email protected]8e8bb6d2010-12-13 08:18:55769 PluginUpdater::GetInstance());
[email protected]2a7e7c152010-10-01 20:12:09770
771 // Initialize and set up notifications for the printing enabled
772 // preference.
773 local_state_->RegisterBooleanPref(prefs::kPrintingEnabled, true);
774 bool printing_enabled =
775 local_state_->GetBoolean(prefs::kPrintingEnabled);
776 print_job_manager_->set_printing_enabled(printing_enabled);
777 pref_change_registrar_.Add(prefs::kPrintingEnabled,
778 print_job_manager_.get());
[email protected]e450fa62011-02-01 12:52:56779
780 // Initialize the notification for the default browser setting policy.
781 local_state_->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled,
782 false);
783 if (local_state_->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled)) {
784 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
785 ShellIntegration::SetAsDefaultBrowser();
786 }
787 pref_change_registrar_.Add(prefs::kDefaultBrowserSettingEnabled, this);
[email protected]fd6159a2010-09-03 09:38:39788}
initial.commit09911bf2008-07-26 23:55:29789
initial.commit09911bf2008-07-26 23:55:29790void BrowserProcessImpl::CreateIconManager() {
791 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
792 created_icon_manager_ = true;
793 icon_manager_.reset(new IconManager);
794}
795
[email protected]40ecc902009-03-16 13:42:47796void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44797 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47798 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44799 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47800}
801
[email protected]8b8e7c92010-08-19 18:05:56802void BrowserProcessImpl::CreateSidebarManager() {
803 DCHECK(sidebar_manager_.get() == NULL);
804 created_sidebar_manager_ = true;
805 sidebar_manager_ = new SidebarManager();
806}
807
initial.commit09911bf2008-07-26 23:55:29808void BrowserProcessImpl::CreateGoogleURLTracker() {
809 DCHECK(google_url_tracker_.get() == NULL);
810 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
811 google_url_tracker_.swap(google_url_tracker);
812}
[email protected]6641bf662009-08-21 00:34:09813
[email protected]c4ff4952010-01-08 19:12:47814void BrowserProcessImpl::CreateIntranetRedirectDetector() {
815 DCHECK(intranet_redirect_detector_.get() == NULL);
816 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
817 new IntranetRedirectDetector);
818 intranet_redirect_detector_.swap(intranet_redirect_detector);
819}
820
[email protected]29672ab2009-10-30 03:44:03821void BrowserProcessImpl::CreateNotificationUIManager() {
822 DCHECK(notification_ui_manager_.get() == NULL);
[email protected]b0b2a3dd2011-01-06 00:30:05823 notification_ui_manager_.reset(NotificationUIManager::Create(local_state()));
824
[email protected]29672ab2009-10-30 03:44:03825 created_notification_ui_manager_ = true;
826}
827
[email protected]0b4d3382010-07-14 16:13:04828void BrowserProcessImpl::CreateTabCloseableStateWatcher() {
829 DCHECK(tab_closeable_state_watcher_.get() == NULL);
830 tab_closeable_state_watcher_.reset(TabCloseableStateWatcher::Create());
831}
832
[email protected]dbeebd52010-11-16 20:34:16833void BrowserProcessImpl::CreatePrintPreviewTabController() {
834 DCHECK(print_preview_tab_controller_.get() == NULL);
835 print_preview_tab_controller_ = new printing::PrintPreviewTabController();
836}
837
[email protected]a7a5e992010-12-09 23:39:51838void BrowserProcessImpl::CreateSafeBrowsingDetectionService() {
839 DCHECK(safe_browsing_detection_service_.get() == NULL);
840 // Set this flag to true so that we don't retry indefinitely to
841 // create the service class if there was an error.
842 created_safe_browsing_detection_service_ = true;
843
844 FilePath model_file_path;
845 Profile* profile = profile_manager() ?
846 profile_manager()->GetDefaultProfile() : NULL;
847 if (IsSafeBrowsingDetectionServiceEnabled() &&
848 PathService::Get(chrome::DIR_USER_DATA, &model_file_path) &&
849 profile && profile->GetRequestContext()) {
850 safe_browsing_detection_service_.reset(
851 safe_browsing::ClientSideDetectionService::Create(
852 model_file_path.Append(chrome::kSafeBrowsingPhishingModelFilename),
853 profile->GetRequestContext()));
854 }
855}
856
857bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() {
858 // The safe browsing client-side detection is enabled only if the switch is
[email protected]42930de42011-01-13 23:26:28859 // enabled and when safe browsing related stats is allowed to be collected.
860 return CommandLine::ForCurrentProcess()->HasSwitch(
861 switches::kEnableClientSidePhishingDetection) &&
862 resource_dispatcher_host()->safe_browsing_service() &&
863 resource_dispatcher_host()->safe_browsing_service()->CanReportStats();
[email protected]a7a5e992010-12-09 23:39:51864}
865
[email protected]6641bf662009-08-21 00:34:09866// The BrowserProcess object must outlive the file thread so we use traits
867// which don't do any management.
[email protected]c56428f22010-06-16 02:17:23868DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl);
[email protected]6641bf662009-08-21 00:34:09869
[email protected]d55aaa132009-09-28 21:08:04870#if defined(IPC_MESSAGE_LOG_ENABLED)
871
872void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
873 // First enable myself.
874 if (enable)
[email protected]8e8bb6d2010-12-13 08:18:55875 IPC::Logging::GetInstance()->Enable();
[email protected]d55aaa132009-09-28 21:08:04876 else
[email protected]8e8bb6d2010-12-13 08:18:55877 IPC::Logging::GetInstance()->Disable();
[email protected]d55aaa132009-09-28 21:08:04878
879 // Now tell subprocesses. Messages to ChildProcess-derived
880 // processes must be done on the IO thread.
881 io_thread()->message_loop()->PostTask
882 (FROM_HERE,
883 NewRunnableMethod(
884 this,
885 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
886 enable));
887
888 // Finally, tell the renderers which don't derive from ChildProcess.
889 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:27890 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
891 !i.IsAtEnd(); i.Advance())
892 i.GetCurrentValue()->Send(new ViewMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:04893}
894
895// Helper for SetIPCLoggingEnabled.
896void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d04e7662010-10-10 22:24:48897 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d55aaa132009-09-28 21:08:04898
[email protected]d27893f62010-07-03 05:47:42899 BrowserChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:11900 while (!i.Done()) {
901 i->Send(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
902 ++i;
[email protected]d55aaa132009-09-28 21:08:04903 }
904}
905
906#endif // IPC_MESSAGE_LOG_ENABLED
907
[email protected]6641bf662009-08-21 00:34:09908void BrowserProcessImpl::DoInspectorFilesCheck() {
909 // Runs on FILE thread.
910 DCHECK(file_thread_->message_loop() == MessageLoop::current());
911 bool result = false;
912
913 FilePath inspector_dir;
914 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) {
915 result = file_util::PathExists(inspector_dir);
916 }
917
[email protected]308080d2009-11-11 19:19:02918 have_inspector_files_ = result;
[email protected]6641bf662009-08-21 00:34:09919}
[email protected]bd48c2b02010-04-09 20:32:42920
[email protected]3cdacd42010-04-30 18:55:53921// Mac is currently not supported.
922#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:42923
924bool BrowserProcessImpl::CanAutorestartForUpdate() const {
925 // Check if browser is in the background and if it needs to be restarted to
926 // apply a pending update.
[email protected]c10fa3952010-08-24 16:52:53927 return BrowserList::size() == 0 && BrowserList::WillKeepAlive() &&
[email protected]c984d9f2010-07-20 20:52:20928 Upgrade::IsUpdatePendingRestart();
[email protected]bd48c2b02010-04-09 20:32:42929}
930
[email protected]5c08f222010-09-22 09:37:21931// Switches to add when auto-restarting Chrome.
[email protected]6c10c972010-08-11 04:15:47932const char* const kSwitchesToAddOnAutorestart[] = {
[email protected]f9a06842010-08-21 00:32:40933 switches::kNoStartupWindow
[email protected]bd48c2b02010-04-09 20:32:42934};
935
936void BrowserProcessImpl::RestartPersistentInstance() {
937 CommandLine* old_cl = CommandLine::ForCurrentProcess();
[email protected]3cdacd42010-04-30 18:55:53938 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram()));
[email protected]bd48c2b02010-04-09 20:32:42939
940 std::map<std::string, CommandLine::StringType> switches =
941 old_cl->GetSwitches();
942
[email protected]5c08f222010-09-22 09:37:21943 switches::RemoveSwitchesForAutostart(&switches);
[email protected]bd48c2b02010-04-09 20:32:42944
945 // Append the rest of the switches (along with their values, if any)
946 // to the new command line
947 for (std::map<std::string, CommandLine::StringType>::const_iterator i =
948 switches.begin(); i != switches.end(); ++i) {
949 CommandLine::StringType switch_value = i->second;
950 if (switch_value.length() > 0) {
[email protected]05076ba22010-07-30 05:59:57951 new_cl->AppendSwitchNative(i->first, i->second);
[email protected]bd48c2b02010-04-09 20:32:42952 } else {
[email protected]3cdacd42010-04-30 18:55:53953 new_cl->AppendSwitch(i->first);
[email protected]bd48c2b02010-04-09 20:32:42954 }
955 }
956
[email protected]6c10c972010-08-11 04:15:47957 // Ensure that our desired switches are set on the new process.
[email protected]5c08f222010-09-22 09:37:21958 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) {
[email protected]6c10c972010-08-11 04:15:47959 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i]))
960 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
961 }
[email protected]bd48c2b02010-04-09 20:32:42962
[email protected]3cdacd42010-04-30 18:55:53963 DLOG(WARNING) << "Shutting down current instance of the browser.";
964 BrowserList::CloseAllBrowsersAndExit();
965
966 // Transfer ownership to Upgrade.
967 Upgrade::SetNewCommandLine(new_cl.release());
[email protected]bd48c2b02010-04-09 20:32:42968}
969
970void BrowserProcessImpl::OnAutoupdateTimer() {
971 if (CanAutorestartForUpdate()) {
[email protected]3cdacd42010-04-30 18:55:53972 DLOG(WARNING) << "Detected update. Restarting browser.";
[email protected]bd48c2b02010-04-09 20:32:42973 RestartPersistentInstance();
974 }
975}
976
[email protected]3cdacd42010-04-30 18:55:53977#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)