blob: f65c65bca7f1d93ba2773f52e77e664608c12c18 [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]b2fcd0e2010-12-01 15:19:4035#include "chrome/browser/net/chrome_net_log.h"
[email protected]3530cd92010-06-27 06:22:0136#include "chrome/browser/net/predictor_api.h"
[email protected]d393a0fd2009-05-13 23:32:0137#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]29672ab2009-10-30 03:44:0338#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]6618d1d2010-12-15 21:18:4739#include "chrome/browser/plugin_data_remover.h"
[email protected]fd49e2d2009-02-20 17:21:3040#include "chrome/browser/plugin_service.h"
[email protected]492d2142010-09-10 13:55:1841#include "chrome/browser/plugin_updater.h"
[email protected]985655a2011-02-23 09:54:2542#include "chrome/browser/policy/browser_policy_connector.h"
[email protected]37858e52010-08-26 00:22:0243#include "chrome/browser/prefs/pref_service.h"
[email protected]e06131d2010-02-10 18:40:3344#include "chrome/browser/printing/print_job_manager.h"
[email protected]dbeebd52010-11-16 20:34:1645#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]8ecad5e2010-12-02 21:18:3346#include "chrome/browser/profiles/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2647#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]81218f42009-02-05 18:48:0848#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
[email protected]a7a5e992010-12-09 23:39:5149#include "chrome/browser/safe_browsing/client_side_detection_service.h"
[email protected]81218f42009-02-05 18:48:0850#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]e450fa62011-02-01 12:52:5651#include "chrome/browser/shell_integration.h"
[email protected]8b8e7c92010-08-19 18:05:5652#include "chrome/browser/sidebar/sidebar_manager.h"
[email protected]0b4d3382010-07-14 16:13:0453#include "chrome/browser/tab_closeable_state_watcher.h"
[email protected]4ef795df2010-02-03 02:35:0854#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2955#include "chrome/common/chrome_paths.h"
56#include "chrome/common/chrome_switches.h"
[email protected]f1b6de22010-03-06 12:13:4757#include "chrome/common/extensions/extension_l10n_util.h"
[email protected]985655a2011-02-23 09:54:2558#include "chrome/common/extensions/extension_resource.h"
[email protected]ea587b02010-05-21 15:01:3559#include "chrome/common/json_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2960#include "chrome/common/notification_service.h"
61#include "chrome/common/pref_names.h"
[email protected]5c08f222010-09-22 09:37:2162#include "chrome/common/switch_utils.h"
[email protected]985655a2011-02-23 09:54:2563#include "chrome/common/url_constants.h"
[email protected]bd48c2b02010-04-09 20:32:4264#include "chrome/installer/util/google_update_constants.h"
[email protected]d55aaa132009-09-28 21:08:0465#include "ipc/ipc_logging.h"
[email protected]2dfeaf92011-01-10 21:08:2166#include "ui/base/clipboard/clipboard.h"
[email protected]c051a1b2011-01-21 23:30:1767#include "ui/base/l10n/l10n_util.h"
[email protected]4ef795df2010-02-03 02:35:0868#include "webkit/database/database_tracker.h"
[email protected]b112a4c2009-02-01 20:24:0169
70#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0571#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3872#endif
73
[email protected]d55aaa132009-09-28 21:08:0474#if defined(IPC_MESSAGE_LOG_ENABLED)
75#include "chrome/common/plugin_messages.h"
76#include "chrome/common/render_messages.h"
77#endif
78
[email protected]3cdacd42010-04-30 18:55:5379#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
80// How often to check if the persistent instance of Chrome needs to restart
81// to install an update.
82static const int kUpdateCheckIntervalHours = 6;
83#endif
84
[email protected]c6032e82010-09-13 20:06:0585#if defined(USE_X11)
86// How long to wait for the File thread to complete during EndSession, on
87// Linux. We have a timeout here because we're unable to run the UI messageloop
88// and there's some deadlock risk. Our only option is to exit anyway.
89static const int kEndSessionTimeoutSeconds = 10;
90#endif
91
[email protected]bb975362009-01-21 01:00:2292BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:2993 : created_resource_dispatcher_host_(false),
94 created_metrics_service_(false),
95 created_io_thread_(false),
96 created_file_thread_(false),
97 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:3398 created_process_launcher_thread_(false),
[email protected]875ee822010-05-18 20:58:0199 created_cache_thread_(false),
initial.commit09911bf2008-07-26 23:55:29100 created_profile_manager_(false),
101 created_local_state_(false),
[email protected]b112a4c2009-02-01 20:24:01102 created_icon_manager_(false),
[email protected]40ecc902009-03-16 13:42:47103 created_devtools_manager_(false),
[email protected]8b8e7c92010-08-19 18:05:56104 created_sidebar_manager_(false),
[email protected]985655a2011-02-23 09:54:25105 created_browser_policy_connector_(false),
[email protected]29672ab2009-10-30 03:44:03106 created_notification_ui_manager_(false),
[email protected]a7a5e992010-12-09 23:39:51107 created_safe_browsing_detection_service_(false),
initial.commit09911bf2008-07-26 23:55:29108 module_ref_count_(0),
[email protected]afd20c022010-06-10 00:48:20109 did_start_(false),
[email protected]1b2db1a2008-08-08 17:46:13110 checked_for_new_frames_(false),
[email protected]6641bf662009-08-21 00:34:09111 using_new_frames_(false),
112 have_inspector_files_(true) {
initial.commit09911bf2008-07-26 23:55:29113 g_browser_process = this;
[email protected]2dfeaf92011-01-10 21:08:21114 clipboard_.reset(new ui::Clipboard);
initial.commit09911bf2008-07-26 23:55:29115 main_notification_service_.reset(new NotificationService);
116
[email protected]6618d1d2010-12-15 21:18:47117 notification_registrar_.Add(this,
118 NotificationType::APP_TERMINATING,
119 NotificationService::AllSources());
120
initial.commit09911bf2008-07-26 23:55:29121 // Must be created after the NotificationService.
122 print_job_manager_.reset(new printing::PrintJobManager);
123
[email protected]b797e152009-01-23 16:06:14124 shutdown_event_.reset(new base::WaitableEvent(true, false));
[email protected]b2fcd0e2010-12-01 15:19:40125
126 net_log_.reset(new ChromeNetLog);
initial.commit09911bf2008-07-26 23:55:29127}
128
129BrowserProcessImpl::~BrowserProcessImpl() {
[email protected]4ef795df2010-02-03 02:35:08130 FilePath profile_path;
131 bool clear_local_state_on_exit;
132
133 // Store the profile path for clearing local state data on exit.
134 clear_local_state_on_exit = ShouldClearLocalState(&profile_path);
135
initial.commit09911bf2008-07-26 23:55:29136 // Delete the AutomationProviderList before NotificationService,
137 // since it may try to unregister notifications
138 // Both NotificationService and AutomationProvider are singleton instances in
139 // the BrowserProcess. Since AutomationProvider may have some active
140 // notification observers, it is essential that it gets destroyed before the
141 // NotificationService. NotificationService won't be destroyed until after
142 // this destructor is run.
143 automation_provider_list_.reset();
144
[email protected]d393a0fd2009-05-13 23:32:01145 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
146 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
147 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
148 // any pending URLFetchers, and avoid creating any more.
149 SdchDictionaryFetcher::Shutdown();
150
[email protected]51ac040762011-01-20 02:01:04151 // We need to destroy the MetricsService, GoogleURLTracker,
152 // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService
153 // before the io_thread_ gets destroyed, since their destructors can call the
154 // URLFetcher destructor, which does a PostDelayedTask operation on the IO
155 // thread. (The IO thread will handle that URLFetcher operation before going
156 // away.)
initial.commit09911bf2008-07-26 23:55:29157 metrics_service_.reset();
158 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47159 intranet_redirect_detector_.reset();
[email protected]51ac040762011-01-20 02:01:04160 safe_browsing_detection_service_.reset();
initial.commit09911bf2008-07-26 23:55:29161
[email protected]d8a899c2010-09-21 04:50:33162 // Need to clear the desktop notification balloons before the io_thread_ and
163 // before the profiles, since if there are any still showing we will access
164 // those things during teardown.
165 notification_ui_manager_.reset();
166
initial.commit09911bf2008-07-26 23:55:29167 // Need to clear profiles (download managers) before the io_thread_.
168 profile_manager_.reset();
169
170 // Debugger must be cleaned up before IO thread and NotificationService.
[email protected]5613126e2011-01-31 15:27:55171 if (devtools_http_handler_.get()) {
172 devtools_http_handler_->Stop();
173 devtools_http_handler_ = NULL;
174 }
175 if (devtools_legacy_handler_.get()) {
176 devtools_legacy_handler_->Stop();
177 devtools_legacy_handler_ = NULL;
178 }
initial.commit09911bf2008-07-26 23:55:29179
180 if (resource_dispatcher_host_.get()) {
181 // Need to tell Safe Browsing Service that the IO thread is going away
182 // since it cached a pointer to it.
183 if (resource_dispatcher_host()->safe_browsing_service())
184 resource_dispatcher_host()->safe_browsing_service()->ShutDown();
185
186 // Cancel pending requests and prevent new requests.
187 resource_dispatcher_host()->Shutdown();
188 }
189
[email protected]985655a2011-02-23 09:54:25190 // The policy providers managed by |browser_policy_connector_| need to shut
191 // down while the IO and FILE threads are still alive.
192 browser_policy_connector_.reset();
[email protected]f2a893c2011-01-05 09:38:07193
[email protected]753efc42010-03-09 19:52:16194#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06195 // The IO thread must outlive the BACKGROUND_X11 thread.
196 background_x11_thread_.reset();
197#endif
198
[email protected]6618d1d2010-12-15 21:18:47199 // Wait for removing plugin data to finish before shutting down the IO thread.
200 WaitForPluginDataRemoverToFinish();
201
initial.commit09911bf2008-07-26 23:55:29202 // Need to stop io_thread_ before resource_dispatcher_host_, since
203 // io_thread_ may still deref ResourceDispatcherHost and handle resource
204 // request before going away.
[email protected]0ac83682010-01-22 17:46:27205 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29206
[email protected]875ee822010-05-18 20:58:01207 // The IO thread was the only user of this thread.
208 cache_thread_.reset();
209
[email protected]914511712009-11-23 19:42:33210 // Stop the process launcher thread after the IO thread, in case the IO thread
211 // posted a task to terminate a process on the process launcher thread.
212 process_launcher_thread_.reset();
213
initial.commit09911bf2008-07-26 23:55:29214 // Clean up state that lives on the file_thread_ before it goes away.
215 if (resource_dispatcher_host_.get()) {
216 resource_dispatcher_host()->download_file_manager()->Shutdown();
217 resource_dispatcher_host()->save_file_manager()->Shutdown();
218 }
219
220 // Need to stop the file_thread_ here to force it to process messages in its
221 // message loop from the previous call to shutdown the DownloadFileManager,
222 // SaveFileManager and SessionService.
223 file_thread_.reset();
224
225 // With the file_thread_ flushed, we can release any icon resources.
226 icon_manager_.reset();
227
228 // Need to destroy ResourceDispatcherHost before PluginService and
[email protected]49f28bc72010-02-04 00:10:01229 // SafeBrowsingService, since it caches a pointer to it. This also
230 // causes the webkit thread to terminate.
initial.commit09911bf2008-07-26 23:55:29231 resource_dispatcher_host_.reset();
232
233 // Wait for the pending print jobs to finish.
234 print_job_manager_->OnQuit();
235 print_job_manager_.reset();
236
[email protected]0b4d3382010-07-14 16:13:04237 // Destroy TabCloseableStateWatcher before NotificationService since the
238 // former registers for notifications.
239 tab_closeable_state_watcher_.reset();
240
initial.commit09911bf2008-07-26 23:55:29241 // Now OK to destroy NotificationService.
242 main_notification_service_.reset();
243
[email protected]49f28bc72010-02-04 00:10:01244 // Prior to clearing local state, we want to complete tasks pending
245 // on the db thread too.
246 db_thread_.reset();
247
248 // At this point, no render process exist and the file, io, db, and
249 // webkit threads in this process have all terminated, so it's safe
250 // to access local state data such as cookies, database, or local storage.
251 if (clear_local_state_on_exit)
252 ClearLocalState(profile_path);
253
initial.commit09911bf2008-07-26 23:55:29254 g_browser_process = NULL;
255}
256
[email protected]c6032e82010-09-13 20:06:05257#if defined(OS_WIN)
[email protected]295039bd2008-08-15 04:32:57258// Send a QuitTask to the given MessageLoop.
259static void PostQuit(MessageLoop* message_loop) {
260 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
261}
[email protected]c6032e82010-09-13 20:06:05262#elif defined(USE_X11)
263static void Signal(base::WaitableEvent* event) {
264 event->Signal();
265}
266#endif
initial.commit09911bf2008-07-26 23:55:29267
[email protected]b443cb042009-12-15 22:05:09268unsigned int BrowserProcessImpl::AddRefModule() {
269 DCHECK(CalledOnValidThread());
[email protected]afd20c022010-06-10 00:48:20270 did_start_ = true;
[email protected]b443cb042009-12-15 22:05:09271 module_ref_count_++;
272 return module_ref_count_;
273}
274
275unsigned int BrowserProcessImpl::ReleaseModule() {
276 DCHECK(CalledOnValidThread());
[email protected]760d970a2010-05-18 00:39:18277 DCHECK_NE(0u, module_ref_count_);
[email protected]b443cb042009-12-15 22:05:09278 module_ref_count_--;
279 if (0 == module_ref_count_) {
[email protected]7d038c32010-12-14 00:40:00280 // Allow UI and IO threads to do blocking IO on shutdown, since we do a lot
281 // of it on shutdown for valid reasons.
282 base::ThreadRestrictions::SetIOAllowed(true);
283 io_thread()->message_loop()->PostTask(
284 FROM_HERE,
285 NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true));
[email protected]b443cb042009-12-15 22:05:09286 MessageLoop::current()->PostTask(
[email protected]34f73fb2010-03-24 20:50:34287 FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop));
[email protected]b443cb042009-12-15 22:05:09288 MessageLoop::current()->Quit();
289 }
290 return module_ref_count_;
291}
292
initial.commit09911bf2008-07-26 23:55:29293void BrowserProcessImpl::EndSession() {
[email protected]c6032e82010-09-13 20:06:05294#if defined(OS_WIN) || defined(USE_X11)
[email protected]d65cab7a2008-08-12 01:25:41295 // Notify we are going away.
[email protected]c6032e82010-09-13 20:06:05296 shutdown_event_->Signal();
[email protected]b112a4c2009-02-01 20:24:01297#endif
[email protected]d65cab7a2008-08-12 01:25:41298
initial.commit09911bf2008-07-26 23:55:29299 // Mark all the profiles as clean.
300 ProfileManager* pm = profile_manager();
301 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i)
302 (*i)->MarkAsCleanShutdown();
303
304 // Tell the metrics service it was cleanly shutdown.
305 MetricsService* metrics = g_browser_process->metrics_service();
306 if (metrics && local_state()) {
307 metrics->RecordCleanShutdown();
308
309 metrics->RecordStartOfSessionEnd();
310
311 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36312 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29313 }
314
315 // We must write that the profile and metrics service shutdown cleanly,
316 // otherwise on startup we'll think we crashed. So we block until done and
317 // then proceed with normal shutdown.
[email protected]c6032e82010-09-13 20:06:05318#if defined(USE_X11)
319 // Can't run a local loop on linux. Instead create a waitable event.
320 base::WaitableEvent done_writing(false, false);
[email protected]d04e7662010-10-10 22:24:48321 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]c6032e82010-09-13 20:06:05322 NewRunnableFunction(Signal, &done_writing));
323 done_writing.TimedWait(
324 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds));
325#elif defined(OS_WIN)
[email protected]d04e7662010-10-10 22:24:48326 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57327 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29328 MessageLoop::current()->Run();
[email protected]c6032e82010-09-13 20:06:05329#else
330 NOTIMPLEMENTED();
331#endif
initial.commit09911bf2008-07-26 23:55:29332}
333
[email protected]e13ad79b2010-07-22 21:36:50334ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() {
335 DCHECK(CalledOnValidThread());
336 if (!created_resource_dispatcher_host_)
337 CreateResourceDispatcherHost();
338 return resource_dispatcher_host_.get();
339}
340
341MetricsService* BrowserProcessImpl::metrics_service() {
342 DCHECK(CalledOnValidThread());
343 if (!created_metrics_service_)
344 CreateMetricsService();
345 return metrics_service_.get();
346}
347
348IOThread* BrowserProcessImpl::io_thread() {
349 DCHECK(CalledOnValidThread());
350 if (!created_io_thread_)
351 CreateIOThread();
352 return io_thread_.get();
353}
354
355base::Thread* BrowserProcessImpl::file_thread() {
356 DCHECK(CalledOnValidThread());
357 if (!created_file_thread_)
358 CreateFileThread();
359 return file_thread_.get();
360}
361
362base::Thread* BrowserProcessImpl::db_thread() {
363 DCHECK(CalledOnValidThread());
364 if (!created_db_thread_)
365 CreateDBThread();
366 return db_thread_.get();
367}
368
369base::Thread* BrowserProcessImpl::process_launcher_thread() {
370 DCHECK(CalledOnValidThread());
371 if (!created_process_launcher_thread_)
372 CreateProcessLauncherThread();
373 return process_launcher_thread_.get();
374}
375
376base::Thread* BrowserProcessImpl::cache_thread() {
377 DCHECK(CalledOnValidThread());
378 if (!created_cache_thread_)
379 CreateCacheThread();
380 return cache_thread_.get();
381}
382
383#if defined(USE_X11)
384base::Thread* BrowserProcessImpl::background_x11_thread() {
385 DCHECK(CalledOnValidThread());
386 // The BACKGROUND_X11 thread is created when the IO thread is created.
387 if (!created_io_thread_)
388 CreateIOThread();
389 return background_x11_thread_.get();
390}
391#endif
392
393ProfileManager* BrowserProcessImpl::profile_manager() {
394 DCHECK(CalledOnValidThread());
395 if (!created_profile_manager_)
396 CreateProfileManager();
397 return profile_manager_.get();
398}
399
400PrefService* BrowserProcessImpl::local_state() {
401 DCHECK(CalledOnValidThread());
402 if (!created_local_state_)
403 CreateLocalState();
404 return local_state_.get();
405}
406
407DevToolsManager* BrowserProcessImpl::devtools_manager() {
408 DCHECK(CalledOnValidThread());
409 if (!created_devtools_manager_)
410 CreateDevToolsManager();
411 return devtools_manager_.get();
412}
413
[email protected]8b8e7c92010-08-19 18:05:56414SidebarManager* BrowserProcessImpl::sidebar_manager() {
415 DCHECK(CalledOnValidThread());
416 if (!created_sidebar_manager_)
417 CreateSidebarManager();
418 return sidebar_manager_.get();
419}
420
[email protected]2dfeaf92011-01-10 21:08:21421ui::Clipboard* BrowserProcessImpl::clipboard() {
[email protected]e13ad79b2010-07-22 21:36:50422 DCHECK(CalledOnValidThread());
423 return clipboard_.get();
424}
425
426NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
427 DCHECK(CalledOnValidThread());
428 if (!created_notification_ui_manager_)
429 CreateNotificationUIManager();
430 return notification_ui_manager_.get();
431}
432
[email protected]985655a2011-02-23 09:54:25433policy::BrowserPolicyConnector* BrowserProcessImpl::browser_policy_connector() {
[email protected]f2a893c2011-01-05 09:38:07434 DCHECK(CalledOnValidThread());
[email protected]985655a2011-02-23 09:54:25435 if (!created_browser_policy_connector_) {
436 DCHECK(browser_policy_connector_.get() == NULL);
437 created_browser_policy_connector_ = true;
438 browser_policy_connector_.reset(new policy::BrowserPolicyConnector());
[email protected]f2a893c2011-01-05 09:38:07439 }
[email protected]985655a2011-02-23 09:54:25440 return browser_policy_connector_.get();
[email protected]f2a893c2011-01-05 09:38:07441}
442
[email protected]e13ad79b2010-07-22 21:36:50443IconManager* BrowserProcessImpl::icon_manager() {
444 DCHECK(CalledOnValidThread());
445 if (!created_icon_manager_)
446 CreateIconManager();
447 return icon_manager_.get();
448}
449
450ThumbnailGenerator* BrowserProcessImpl::GetThumbnailGenerator() {
451 return &thumbnail_generator_;
452}
453
454AutomationProviderList* BrowserProcessImpl::InitAutomationProviderList() {
455 DCHECK(CalledOnValidThread());
456 if (automation_provider_list_.get() == NULL) {
457 automation_provider_list_.reset(AutomationProviderList::GetInstance());
458 }
459 return automation_provider_list_.get();
460}
461
[email protected]5613126e2011-01-31 15:27:55462void BrowserProcessImpl::InitDevToolsHttpProtocolHandler(
[email protected]01000cf12011-02-04 11:39:22463 const std::string& ip,
[email protected]5613126e2011-01-31 15:27:55464 int port,
465 const std::string& frontend_url) {
[email protected]e13ad79b2010-07-22 21:36:50466 DCHECK(CalledOnValidThread());
[email protected]5613126e2011-01-31 15:27:55467 devtools_http_handler_ =
[email protected]01000cf12011-02-04 11:39:22468 DevToolsHttpProtocolHandler::Start(ip,
469 port,
[email protected]9678cb42011-01-31 18:49:42470 frontend_url,
471 new BrowserListTabContentsProvider());
[email protected]5613126e2011-01-31 15:27:55472}
473
474void BrowserProcessImpl::InitDevToolsLegacyProtocolHandler(int port) {
475 DCHECK(CalledOnValidThread());
476 devtools_legacy_handler_ = DevToolsProtocolHandler::Start(port);
[email protected]e13ad79b2010-07-22 21:36:50477}
478
479bool BrowserProcessImpl::IsShuttingDown() {
480 DCHECK(CalledOnValidThread());
481 return did_start_ && 0 == module_ref_count_;
482}
483
initial.commit09911bf2008-07-26 23:55:29484printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
485 // TODO(abarth): DCHECK(CalledOnValidThread());
[email protected]d8922f22010-05-07 00:57:27486 // http://code.google.com/p/chromium/issues/detail?id=6828
initial.commit09911bf2008-07-26 23:55:29487 // print_job_manager_ is initialized in the constructor and destroyed in the
488 // destructor, so it should always be valid.
489 DCHECK(print_job_manager_.get());
490 return print_job_manager_.get();
491}
492
[email protected]dbeebd52010-11-16 20:34:16493printing::PrintPreviewTabController*
494 BrowserProcessImpl::print_preview_tab_controller() {
495 DCHECK(CalledOnValidThread());
496 if (!print_preview_tab_controller_.get())
497 CreatePrintPreviewTabController();
498 return print_preview_tab_controller_.get();
499}
500
[email protected]e13ad79b2010-07-22 21:36:50501GoogleURLTracker* BrowserProcessImpl::google_url_tracker() {
502 DCHECK(CalledOnValidThread());
503 if (!google_url_tracker_.get())
504 CreateGoogleURLTracker();
505 return google_url_tracker_.get();
506}
507
508IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
509 DCHECK(CalledOnValidThread());
510 if (!intranet_redirect_detector_.get())
511 CreateIntranetRedirectDetector();
512 return intranet_redirect_detector_.get();
513}
514
515const std::string& BrowserProcessImpl::GetApplicationLocale() {
516 DCHECK(!locale_.empty());
517 return locale_;
518}
519
520void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
521 locale_ = locale;
522 extension_l10n_util::SetProcessLocale(locale);
523}
524
[email protected]073ed7b2010-09-27 09:20:02525DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
526 return &download_status_updater_;
527}
528
[email protected]e13ad79b2010-07-22 21:36:50529base::WaitableEvent* BrowserProcessImpl::shutdown_event() {
530 return shutdown_event_.get();
531}
532
533TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() {
534 DCHECK(CalledOnValidThread());
535 if (!tab_closeable_state_watcher_.get())
536 CreateTabCloseableStateWatcher();
537 return tab_closeable_state_watcher_.get();
538}
539
[email protected]a7a5e992010-12-09 23:39:51540safe_browsing::ClientSideDetectionService*
541 BrowserProcessImpl::safe_browsing_detection_service() {
542 DCHECK(CalledOnValidThread());
543 if (!created_safe_browsing_detection_service_) {
544 CreateSafeBrowsingDetectionService();
545 }
546 return safe_browsing_detection_service_.get();
547}
548
[email protected]8b08a47f2011-02-25 12:36:37549bool BrowserProcessImpl::plugin_finder_disabled() const {
550 return *plugin_finder_disabled_pref_;
551}
552
[email protected]e13ad79b2010-07-22 21:36:50553void BrowserProcessImpl::CheckForInspectorFiles() {
554 file_thread()->message_loop()->PostTask
555 (FROM_HERE,
556 NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck));
557}
558
[email protected]6618d1d2010-12-15 21:18:47559void BrowserProcessImpl::Observe(NotificationType type,
560 const NotificationSource& source,
561 const NotificationDetails& details) {
562 if (type == NotificationType::APP_TERMINATING) {
563 Profile* profile = ProfileManager::GetDefaultProfile();
564 if (profile) {
565 PrefService* prefs = profile->GetPrefs();
[email protected]2ffc3c6c2011-01-14 12:50:24566 if (prefs->GetBoolean(prefs::kClearSiteDataOnExit) &&
[email protected]6618d1d2010-12-15 21:18:47567 local_state()->GetBoolean(prefs::kClearPluginLSODataEnabled)) {
568 plugin_data_remover_ = new PluginDataRemover();
[email protected]c7d58d62011-01-21 10:27:18569 if (!plugin_data_remover_mime_type().empty())
570 plugin_data_remover_->set_mime_type(plugin_data_remover_mime_type());
571 plugin_data_remover_->StartRemoving(base::Time());
[email protected]6618d1d2010-12-15 21:18:47572 }
573 }
[email protected]e450fa62011-02-01 12:52:56574 } else if (type == NotificationType::PREF_CHANGED) {
575 std::string* pref = Details<std::string>(details).ptr();
576 if (*pref == prefs::kDefaultBrowserSettingEnabled) {
577 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
578 ShellIntegration::SetAsDefaultBrowser();
579 }
[email protected]6618d1d2010-12-15 21:18:47580 } else {
581 NOTREACHED();
582 }
583}
584
585void BrowserProcessImpl::WaitForPluginDataRemoverToFinish() {
[email protected]c7d58d62011-01-21 10:27:18586 if (plugin_data_remover_.get())
587 plugin_data_remover_->Wait();
[email protected]6618d1d2010-12-15 21:18:47588}
589
[email protected]e13ad79b2010-07-22 21:36:50590#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
591void BrowserProcessImpl::StartAutoupdateTimer() {
592 autoupdate_timer_.Start(
593 base::TimeDelta::FromHours(kUpdateCheckIntervalHours),
594 this,
595 &BrowserProcessImpl::OnAutoupdateTimer);
596}
597#endif
598
599bool BrowserProcessImpl::have_inspector_files() const {
600 return have_inspector_files_;
601}
602
[email protected]d6f37fc2011-02-13 23:58:41603ChromeNetLog* BrowserProcessImpl::net_log() {
604 return net_log_.get();
605}
606
[email protected]4ef795df2010-02-03 02:35:08607void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
[email protected]72cfd90f2010-02-06 03:08:04608 webkit_database::DatabaseTracker::ClearLocalState(profile_path);
[email protected]4ef795df2010-02-03 02:35:08609}
610
611bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
612 FilePath user_data_dir;
613 Profile* profile;
614
[email protected]09584972010-07-03 00:00:59615 // Check for the existence of a profile manager. When quitting early,
[email protected]ed0cf562010-02-05 22:50:41616 // e.g. because another chrome instance is running, or when invoked with
617 // options such as --uninstall or --try-chrome-again=0, the profile manager
618 // does not exist yet.
619 if (!profile_manager_.get())
620 return false;
621
[email protected]4ef795df2010-02-03 02:35:08622 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
623 profile = profile_manager_->GetDefaultProfile(user_data_dir);
[email protected]7bfc674322010-03-05 00:20:57624 if (!profile)
625 return false;
[email protected]4ef795df2010-02-03 02:35:08626 *profile_path = profile->GetPath();
627 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit);
628}
629
initial.commit09911bf2008-07-26 23:55:29630void BrowserProcessImpl::CreateResourceDispatcherHost() {
631 DCHECK(!created_resource_dispatcher_host_ &&
632 resource_dispatcher_host_.get() == NULL);
633 created_resource_dispatcher_host_ = true;
634
[email protected]79084c2d2009-11-03 23:12:42635 resource_dispatcher_host_.reset(new ResourceDispatcherHost());
initial.commit09911bf2008-07-26 23:55:29636 resource_dispatcher_host_->Initialize();
637}
638
639void BrowserProcessImpl::CreateMetricsService() {
640 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
641 created_metrics_service_ = true;
642
643 metrics_service_.reset(new MetricsService);
644}
645
646void BrowserProcessImpl::CreateIOThread() {
647 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
648 created_io_thread_ = true;
649
650 // Prior to starting the io thread, we create the plugin service as
651 // it is predominantly used from the io thread, but must be created
652 // on the main thread. The service ctor is inexpensive and does not
653 // invoke the io_thread() accessor.
654 PluginService::GetInstance();
655
[email protected]753efc42010-03-09 19:52:16656#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06657 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so
658 // we start it now.
659 scoped_ptr<base::Thread> background_x11_thread(
[email protected]d04e7662010-10-10 22:24:48660 new BrowserProcessSubThread(BrowserThread::BACKGROUND_X11));
[email protected]4c3cd7412009-04-22 17:56:06661 if (!background_x11_thread->Start())
662 return;
663 background_x11_thread_.swap(background_x11_thread);
664#endif
665
[email protected]b2fcd0e2010-12-01 15:19:40666 scoped_ptr<IOThread> thread(new IOThread(local_state(), net_log_.get()));
[email protected]ab820df2008-08-26 05:55:10667 base::Thread::Options options;
668 options.message_loop_type = MessageLoop::TYPE_IO;
669 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29670 return;
671 io_thread_.swap(thread);
672}
673
674void BrowserProcessImpl::CreateFileThread() {
675 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
676 created_file_thread_ = true;
677
[email protected]ab820df2008-08-26 05:55:10678 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48679 new BrowserProcessSubThread(BrowserThread::FILE));
[email protected]a1db3842008-09-17 22:04:06680 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39681#if defined(OS_WIN)
682 // On Windows, the FILE thread needs to be have a UI message loop which pumps
683 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06684 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39685#else
686 options.message_loop_type = MessageLoop::TYPE_IO;
687#endif
[email protected]a1db3842008-09-17 22:04:06688 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29689 return;
690 file_thread_.swap(thread);
691}
692
693void BrowserProcessImpl::CreateDBThread() {
694 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
695 created_db_thread_ = true;
696
[email protected]ab820df2008-08-26 05:55:10697 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48698 new BrowserProcessSubThread(BrowserThread::DB));
initial.commit09911bf2008-07-26 23:55:29699 if (!thread->Start())
700 return;
701 db_thread_.swap(thread);
702}
703
[email protected]914511712009-11-23 19:42:33704void BrowserProcessImpl::CreateProcessLauncherThread() {
705 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
706 created_process_launcher_thread_ = true;
707
708 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48709 new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER));
[email protected]914511712009-11-23 19:42:33710 if (!thread->Start())
711 return;
712 process_launcher_thread_.swap(thread);
713}
714
[email protected]875ee822010-05-18 20:58:01715void BrowserProcessImpl::CreateCacheThread() {
716 DCHECK(!created_cache_thread_ && !cache_thread_.get());
717 created_cache_thread_ = true;
718
719 scoped_ptr<base::Thread> thread(
[email protected]75096332010-11-09 03:28:13720 new BrowserThread(BrowserThread::CACHE));
[email protected]875ee822010-05-18 20:58:01721 base::Thread::Options options;
722 options.message_loop_type = MessageLoop::TYPE_IO;
723 if (!thread->StartWithOptions(options))
724 return;
725 cache_thread_.swap(thread);
726}
727
initial.commit09911bf2008-07-26 23:55:29728void BrowserProcessImpl::CreateProfileManager() {
729 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
730 created_profile_manager_ = true;
731
732 profile_manager_.reset(new ProfileManager());
733}
734
735void BrowserProcessImpl::CreateLocalState() {
736 DCHECK(!created_local_state_ && local_state_.get() == NULL);
737 created_local_state_ = true;
738
[email protected]b9636002009-03-04 00:05:25739 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29740 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]f2d1f612010-12-09 15:10:17741 local_state_.reset(
742 PrefService::CreatePrefService(local_state_path, NULL, NULL));
[email protected]492d2142010-09-10 13:55:18743
[email protected]2a7e7c152010-10-01 20:12:09744 pref_change_registrar_.Init(local_state_.get());
745
[email protected]492d2142010-09-10 13:55:18746 // Make sure the the plugin updater gets notifications of changes
747 // in the plugin blacklist.
748 local_state_->RegisterListPref(prefs::kPluginsPluginsBlacklist);
[email protected]2a7e7c152010-10-01 20:12:09749 pref_change_registrar_.Add(prefs::kPluginsPluginsBlacklist,
[email protected]8e8bb6d2010-12-13 08:18:55750 PluginUpdater::GetInstance());
[email protected]2a7e7c152010-10-01 20:12:09751
752 // Initialize and set up notifications for the printing enabled
753 // preference.
754 local_state_->RegisterBooleanPref(prefs::kPrintingEnabled, true);
755 bool printing_enabled =
756 local_state_->GetBoolean(prefs::kPrintingEnabled);
757 print_job_manager_->set_printing_enabled(printing_enabled);
758 pref_change_registrar_.Add(prefs::kPrintingEnabled,
759 print_job_manager_.get());
[email protected]e450fa62011-02-01 12:52:56760
761 // Initialize the notification for the default browser setting policy.
762 local_state_->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled,
763 false);
764 if (local_state_->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled)) {
765 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled))
766 ShellIntegration::SetAsDefaultBrowser();
767 }
768 pref_change_registrar_.Add(prefs::kDefaultBrowserSettingEnabled, this);
[email protected]8b08a47f2011-02-25 12:36:37769
770 // Initialize the preference for the plugin finder policy.
771 // This preference is only needed on the IO thread so make it available there.
772 local_state_->RegisterBooleanPref(prefs::kDisablePluginFinder, false);
773 plugin_finder_disabled_pref_.Init(prefs::kDisablePluginFinder,
774 local_state_.get(), NULL);
775 plugin_finder_disabled_pref_.MoveToThread(BrowserThread::IO);
[email protected]fd6159a2010-09-03 09:38:39776}
initial.commit09911bf2008-07-26 23:55:29777
initial.commit09911bf2008-07-26 23:55:29778void BrowserProcessImpl::CreateIconManager() {
779 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
780 created_icon_manager_ = true;
781 icon_manager_.reset(new IconManager);
782}
783
[email protected]40ecc902009-03-16 13:42:47784void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44785 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47786 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44787 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47788}
789
[email protected]8b8e7c92010-08-19 18:05:56790void BrowserProcessImpl::CreateSidebarManager() {
791 DCHECK(sidebar_manager_.get() == NULL);
792 created_sidebar_manager_ = true;
793 sidebar_manager_ = new SidebarManager();
794}
795
initial.commit09911bf2008-07-26 23:55:29796void BrowserProcessImpl::CreateGoogleURLTracker() {
797 DCHECK(google_url_tracker_.get() == NULL);
798 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
799 google_url_tracker_.swap(google_url_tracker);
800}
[email protected]6641bf662009-08-21 00:34:09801
[email protected]c4ff4952010-01-08 19:12:47802void BrowserProcessImpl::CreateIntranetRedirectDetector() {
803 DCHECK(intranet_redirect_detector_.get() == NULL);
804 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
805 new IntranetRedirectDetector);
806 intranet_redirect_detector_.swap(intranet_redirect_detector);
807}
808
[email protected]29672ab2009-10-30 03:44:03809void BrowserProcessImpl::CreateNotificationUIManager() {
810 DCHECK(notification_ui_manager_.get() == NULL);
[email protected]b0b2a3dd2011-01-06 00:30:05811 notification_ui_manager_.reset(NotificationUIManager::Create(local_state()));
812
[email protected]29672ab2009-10-30 03:44:03813 created_notification_ui_manager_ = true;
814}
815
[email protected]0b4d3382010-07-14 16:13:04816void BrowserProcessImpl::CreateTabCloseableStateWatcher() {
817 DCHECK(tab_closeable_state_watcher_.get() == NULL);
818 tab_closeable_state_watcher_.reset(TabCloseableStateWatcher::Create());
819}
820
[email protected]dbeebd52010-11-16 20:34:16821void BrowserProcessImpl::CreatePrintPreviewTabController() {
822 DCHECK(print_preview_tab_controller_.get() == NULL);
823 print_preview_tab_controller_ = new printing::PrintPreviewTabController();
824}
825
[email protected]a7a5e992010-12-09 23:39:51826void BrowserProcessImpl::CreateSafeBrowsingDetectionService() {
827 DCHECK(safe_browsing_detection_service_.get() == NULL);
828 // Set this flag to true so that we don't retry indefinitely to
829 // create the service class if there was an error.
830 created_safe_browsing_detection_service_ = true;
831
832 FilePath model_file_path;
833 Profile* profile = profile_manager() ?
834 profile_manager()->GetDefaultProfile() : NULL;
835 if (IsSafeBrowsingDetectionServiceEnabled() &&
836 PathService::Get(chrome::DIR_USER_DATA, &model_file_path) &&
837 profile && profile->GetRequestContext()) {
838 safe_browsing_detection_service_.reset(
839 safe_browsing::ClientSideDetectionService::Create(
840 model_file_path.Append(chrome::kSafeBrowsingPhishingModelFilename),
841 profile->GetRequestContext()));
842 }
843}
844
845bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() {
846 // The safe browsing client-side detection is enabled only if the switch is
[email protected]42930de42011-01-13 23:26:28847 // enabled and when safe browsing related stats is allowed to be collected.
848 return CommandLine::ForCurrentProcess()->HasSwitch(
849 switches::kEnableClientSidePhishingDetection) &&
850 resource_dispatcher_host()->safe_browsing_service() &&
851 resource_dispatcher_host()->safe_browsing_service()->CanReportStats();
[email protected]a7a5e992010-12-09 23:39:51852}
853
[email protected]6641bf662009-08-21 00:34:09854// The BrowserProcess object must outlive the file thread so we use traits
855// which don't do any management.
[email protected]c56428f22010-06-16 02:17:23856DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl);
[email protected]6641bf662009-08-21 00:34:09857
[email protected]d55aaa132009-09-28 21:08:04858#if defined(IPC_MESSAGE_LOG_ENABLED)
859
860void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
861 // First enable myself.
862 if (enable)
[email protected]8e8bb6d2010-12-13 08:18:55863 IPC::Logging::GetInstance()->Enable();
[email protected]d55aaa132009-09-28 21:08:04864 else
[email protected]8e8bb6d2010-12-13 08:18:55865 IPC::Logging::GetInstance()->Disable();
[email protected]d55aaa132009-09-28 21:08:04866
867 // Now tell subprocesses. Messages to ChildProcess-derived
868 // processes must be done on the IO thread.
869 io_thread()->message_loop()->PostTask
870 (FROM_HERE,
871 NewRunnableMethod(
872 this,
873 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
874 enable));
875
876 // Finally, tell the renderers which don't derive from ChildProcess.
877 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:27878 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
879 !i.IsAtEnd(); i.Advance())
880 i.GetCurrentValue()->Send(new ViewMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:04881}
882
883// Helper for SetIPCLoggingEnabled.
884void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d04e7662010-10-10 22:24:48885 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d55aaa132009-09-28 21:08:04886
[email protected]d27893f62010-07-03 05:47:42887 BrowserChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:11888 while (!i.Done()) {
889 i->Send(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
890 ++i;
[email protected]d55aaa132009-09-28 21:08:04891 }
892}
893
894#endif // IPC_MESSAGE_LOG_ENABLED
895
[email protected]6641bf662009-08-21 00:34:09896void BrowserProcessImpl::DoInspectorFilesCheck() {
897 // Runs on FILE thread.
898 DCHECK(file_thread_->message_loop() == MessageLoop::current());
899 bool result = false;
900
901 FilePath inspector_dir;
902 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) {
903 result = file_util::PathExists(inspector_dir);
904 }
905
[email protected]308080d2009-11-11 19:19:02906 have_inspector_files_ = result;
[email protected]6641bf662009-08-21 00:34:09907}
[email protected]bd48c2b02010-04-09 20:32:42908
[email protected]3cdacd42010-04-30 18:55:53909// Mac is currently not supported.
910#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:42911
912bool BrowserProcessImpl::CanAutorestartForUpdate() const {
913 // Check if browser is in the background and if it needs to be restarted to
914 // apply a pending update.
[email protected]c10fa3952010-08-24 16:52:53915 return BrowserList::size() == 0 && BrowserList::WillKeepAlive() &&
[email protected]c984d9f2010-07-20 20:52:20916 Upgrade::IsUpdatePendingRestart();
[email protected]bd48c2b02010-04-09 20:32:42917}
918
[email protected]5c08f222010-09-22 09:37:21919// Switches to add when auto-restarting Chrome.
[email protected]6c10c972010-08-11 04:15:47920const char* const kSwitchesToAddOnAutorestart[] = {
[email protected]f9a06842010-08-21 00:32:40921 switches::kNoStartupWindow
[email protected]bd48c2b02010-04-09 20:32:42922};
923
924void BrowserProcessImpl::RestartPersistentInstance() {
925 CommandLine* old_cl = CommandLine::ForCurrentProcess();
[email protected]3cdacd42010-04-30 18:55:53926 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram()));
[email protected]bd48c2b02010-04-09 20:32:42927
928 std::map<std::string, CommandLine::StringType> switches =
929 old_cl->GetSwitches();
930
[email protected]5c08f222010-09-22 09:37:21931 switches::RemoveSwitchesForAutostart(&switches);
[email protected]bd48c2b02010-04-09 20:32:42932
933 // Append the rest of the switches (along with their values, if any)
934 // to the new command line
935 for (std::map<std::string, CommandLine::StringType>::const_iterator i =
936 switches.begin(); i != switches.end(); ++i) {
937 CommandLine::StringType switch_value = i->second;
938 if (switch_value.length() > 0) {
[email protected]05076ba22010-07-30 05:59:57939 new_cl->AppendSwitchNative(i->first, i->second);
[email protected]bd48c2b02010-04-09 20:32:42940 } else {
[email protected]3cdacd42010-04-30 18:55:53941 new_cl->AppendSwitch(i->first);
[email protected]bd48c2b02010-04-09 20:32:42942 }
943 }
944
[email protected]6c10c972010-08-11 04:15:47945 // Ensure that our desired switches are set on the new process.
[email protected]5c08f222010-09-22 09:37:21946 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) {
[email protected]6c10c972010-08-11 04:15:47947 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i]))
948 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
949 }
[email protected]bd48c2b02010-04-09 20:32:42950
[email protected]3cdacd42010-04-30 18:55:53951 DLOG(WARNING) << "Shutting down current instance of the browser.";
952 BrowserList::CloseAllBrowsersAndExit();
953
954 // Transfer ownership to Upgrade.
955 Upgrade::SetNewCommandLine(new_cl.release());
[email protected]bd48c2b02010-04-09 20:32:42956}
957
958void BrowserProcessImpl::OnAutoupdateTimer() {
959 if (CanAutorestartForUpdate()) {
[email protected]3cdacd42010-04-30 18:55:53960 DLOG(WARNING) << "Detected update. Restarting browser.";
[email protected]bd48c2b02010-04-09 20:32:42961 RestartPersistentInstance();
962 }
963}
964
[email protected]3cdacd42010-04-30 18:55:53965#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)