blob: a8efdb4db9671d774d0b1a2bfbc8edb9959584d2 [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]c6032e82010-09-13 20:06:0512#include "base/task.h"
[email protected]34b99632011-01-01 01:01:0613#include "base/threading/thread.h"
14#include "base/threading/thread_restrictions.h"
[email protected]44f9c952011-01-02 06:05:3915#include "base/synchronization/waitable_event.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]5613126e2011-01-31 15:27:5523#include "chrome/browser/debugger/devtools_http_protocol_handler.h"
[email protected]40ecc902009-03-16 13:42:4724#include "chrome/browser/debugger/devtools_manager.h"
[email protected]5613126e2011-01-31 15:27:5525#include "chrome/browser/debugger/devtools_protocol_handler.h"
[email protected]6c69796d2010-07-16 21:41:1626#include "chrome/browser/download/download_file_manager.h"
[email protected]5ba0a2c2009-02-19 01:19:3427#include "chrome/browser/download/save_file_manager.h"
[email protected]820735792010-07-29 23:40:0128#include "chrome/browser/first_run/first_run.h"
[email protected]f7578f52010-08-30 22:22:4929#include "chrome/browser/google/google_url_tracker.h"
[email protected]dcefa302009-05-20 00:24:3930#include "chrome/browser/icon_manager.h"
[email protected]c4ff4952010-01-08 19:12:4731#include "chrome/browser/intranet_redirect_detector.h"
[email protected]0ac83682010-01-22 17:46:2732#include "chrome/browser/io_thread.h"
[email protected]dc6f4962009-02-13 01:25:5033#include "chrome/browser/metrics/metrics_service.h"
[email protected]b2fcd0e2010-12-01 15:19:4034#include "chrome/browser/net/chrome_net_log.h"
[email protected]3530cd92010-06-27 06:22:0135#include "chrome/browser/net/predictor_api.h"
[email protected]d393a0fd2009-05-13 23:32:0136#include "chrome/browser/net/sdch_dictionary_fetcher.h"
[email protected]29672ab2009-10-30 03:44:0337#include "chrome/browser/notifications/notification_ui_manager.h"
[email protected]6618d1d2010-12-15 21:18:4738#include "chrome/browser/plugin_data_remover.h"
[email protected]fd49e2d2009-02-20 17:21:3039#include "chrome/browser/plugin_service.h"
[email protected]492d2142010-09-10 13:55:1840#include "chrome/browser/plugin_updater.h"
[email protected]f2a893c2011-01-05 09:38:0741#include "chrome/browser/policy/configuration_policy_provider_keeper.h"
[email protected]37858e52010-08-26 00:22:0242#include "chrome/browser/prefs/pref_service.h"
[email protected]e06131d2010-02-10 18:40:3343#include "chrome/browser/printing/print_job_manager.h"
[email protected]dbeebd52010-11-16 20:34:1644#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]8ecad5e2010-12-02 21:18:3345#include "chrome/browser/profiles/profile_manager.h"
[email protected]8c8657d62009-01-16 18:31:2646#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]81218f42009-02-05 18:48:0847#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
[email protected]a7a5e992010-12-09 23:39:5148#include "chrome/browser/safe_browsing/client_side_detection_service.h"
[email protected]81218f42009-02-05 18:48:0849#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]8b8e7c92010-08-19 18:05:5650#include "chrome/browser/sidebar/sidebar_manager.h"
[email protected]0b4d3382010-07-14 16:13:0451#include "chrome/browser/tab_closeable_state_watcher.h"
[email protected]4ef795df2010-02-03 02:35:0852#include "chrome/common/chrome_constants.h"
initial.commit09911bf2008-07-26 23:55:2953#include "chrome/common/chrome_paths.h"
54#include "chrome/common/chrome_switches.h"
[email protected]27fbccc2010-03-25 03:00:4955#include "chrome/common/extensions/extension_resource.h"
[email protected]f1b6de22010-03-06 12:13:4756#include "chrome/common/extensions/extension_l10n_util.h"
[email protected]ea587b02010-05-21 15:01:3557#include "chrome/common/json_pref_store.h"
initial.commit09911bf2008-07-26 23:55:2958#include "chrome/common/notification_service.h"
59#include "chrome/common/pref_names.h"
[email protected]4ef795df2010-02-03 02:35:0860#include "chrome/common/url_constants.h"
[email protected]5c08f222010-09-22 09:37:2161#include "chrome/common/switch_utils.h"
[email protected]bd48c2b02010-04-09 20:32:4262#include "chrome/installer/util/google_update_constants.h"
[email protected]d55aaa132009-09-28 21:08:0463#include "ipc/ipc_logging.h"
[email protected]2dfeaf92011-01-10 21:08:2164#include "ui/base/clipboard/clipboard.h"
[email protected]c051a1b2011-01-21 23:30:1765#include "ui/base/l10n/l10n_util.h"
[email protected]4ef795df2010-02-03 02:35:0866#include "webkit/database/database_tracker.h"
[email protected]b112a4c2009-02-01 20:24:0167
68#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0569#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3870#endif
71
[email protected]d55aaa132009-09-28 21:08:0472#if defined(IPC_MESSAGE_LOG_ENABLED)
73#include "chrome/common/plugin_messages.h"
74#include "chrome/common/render_messages.h"
75#endif
76
[email protected]3cdacd42010-04-30 18:55:5377#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
78// How often to check if the persistent instance of Chrome needs to restart
79// to install an update.
80static const int kUpdateCheckIntervalHours = 6;
81#endif
82
[email protected]c6032e82010-09-13 20:06:0583#if defined(USE_X11)
84// How long to wait for the File thread to complete during EndSession, on
85// Linux. We have a timeout here because we're unable to run the UI messageloop
86// and there's some deadlock risk. Our only option is to exit anyway.
87static const int kEndSessionTimeoutSeconds = 10;
88#endif
89
[email protected]bb975362009-01-21 01:00:2290BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:2991 : created_resource_dispatcher_host_(false),
92 created_metrics_service_(false),
93 created_io_thread_(false),
94 created_file_thread_(false),
95 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:3396 created_process_launcher_thread_(false),
[email protected]875ee822010-05-18 20:58:0197 created_cache_thread_(false),
initial.commit09911bf2008-07-26 23:55:2998 created_profile_manager_(false),
99 created_local_state_(false),
[email protected]b112a4c2009-02-01 20:24:01100 created_icon_manager_(false),
[email protected]40ecc902009-03-16 13:42:47101 created_devtools_manager_(false),
[email protected]8b8e7c92010-08-19 18:05:56102 created_sidebar_manager_(false),
[email protected]f2a893c2011-01-05 09:38:07103 created_configuration_policy_provider_keeper_(false),
[email protected]29672ab2009-10-30 03:44:03104 created_notification_ui_manager_(false),
[email protected]a7a5e992010-12-09 23:39:51105 created_safe_browsing_detection_service_(false),
initial.commit09911bf2008-07-26 23:55:29106 module_ref_count_(0),
[email protected]afd20c022010-06-10 00:48:20107 did_start_(false),
[email protected]1b2db1a2008-08-08 17:46:13108 checked_for_new_frames_(false),
[email protected]6641bf662009-08-21 00:34:09109 using_new_frames_(false),
110 have_inspector_files_(true) {
initial.commit09911bf2008-07-26 23:55:29111 g_browser_process = this;
[email protected]2dfeaf92011-01-10 21:08:21112 clipboard_.reset(new ui::Clipboard);
initial.commit09911bf2008-07-26 23:55:29113 main_notification_service_.reset(new NotificationService);
114
[email protected]6618d1d2010-12-15 21:18:47115 notification_registrar_.Add(this,
116 NotificationType::APP_TERMINATING,
117 NotificationService::AllSources());
118
initial.commit09911bf2008-07-26 23:55:29119 // Must be created after the NotificationService.
120 print_job_manager_.reset(new printing::PrintJobManager);
121
[email protected]b797e152009-01-23 16:06:14122 shutdown_event_.reset(new base::WaitableEvent(true, false));
[email protected]b2fcd0e2010-12-01 15:19:40123
124 net_log_.reset(new ChromeNetLog);
initial.commit09911bf2008-07-26 23:55:29125}
126
127BrowserProcessImpl::~BrowserProcessImpl() {
[email protected]4ef795df2010-02-03 02:35:08128 FilePath profile_path;
129 bool clear_local_state_on_exit;
130
131 // Store the profile path for clearing local state data on exit.
132 clear_local_state_on_exit = ShouldClearLocalState(&profile_path);
133
initial.commit09911bf2008-07-26 23:55:29134 // Delete the AutomationProviderList before NotificationService,
135 // since it may try to unregister notifications
136 // Both NotificationService and AutomationProvider are singleton instances in
137 // the BrowserProcess. Since AutomationProvider may have some active
138 // notification observers, it is essential that it gets destroyed before the
139 // NotificationService. NotificationService won't be destroyed until after
140 // this destructor is run.
141 automation_provider_list_.reset();
142
[email protected]d393a0fd2009-05-13 23:32:01143 // We need to shutdown the SdchDictionaryFetcher as it regularly holds
144 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
145 // a PostDelayedTask onto the IO thread. This shutdown call will both discard
146 // any pending URLFetchers, and avoid creating any more.
147 SdchDictionaryFetcher::Shutdown();
148
[email protected]51ac040762011-01-20 02:01:04149 // We need to destroy the MetricsService, GoogleURLTracker,
150 // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService
151 // before the io_thread_ gets destroyed, since their destructors can call the
152 // URLFetcher destructor, which does a PostDelayedTask operation on the IO
153 // thread. (The IO thread will handle that URLFetcher operation before going
154 // away.)
initial.commit09911bf2008-07-26 23:55:29155 metrics_service_.reset();
156 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47157 intranet_redirect_detector_.reset();
[email protected]51ac040762011-01-20 02:01:04158 safe_browsing_detection_service_.reset();
initial.commit09911bf2008-07-26 23:55:29159
[email protected]d8a899c2010-09-21 04:50:33160 // Need to clear the desktop notification balloons before the io_thread_ and
161 // before the profiles, since if there are any still showing we will access
162 // those things during teardown.
163 notification_ui_manager_.reset();
164
initial.commit09911bf2008-07-26 23:55:29165 // Need to clear profiles (download managers) before the io_thread_.
166 profile_manager_.reset();
167
168 // Debugger must be cleaned up before IO thread and NotificationService.
[email protected]5613126e2011-01-31 15:27:55169 if (devtools_http_handler_.get()) {
170 devtools_http_handler_->Stop();
171 devtools_http_handler_ = NULL;
172 }
173 if (devtools_legacy_handler_.get()) {
174 devtools_legacy_handler_->Stop();
175 devtools_legacy_handler_ = NULL;
176 }
initial.commit09911bf2008-07-26 23:55:29177
178 if (resource_dispatcher_host_.get()) {
179 // Need to tell Safe Browsing Service that the IO thread is going away
180 // since it cached a pointer to it.
181 if (resource_dispatcher_host()->safe_browsing_service())
182 resource_dispatcher_host()->safe_browsing_service()->ShutDown();
183
184 // Cancel pending requests and prevent new requests.
185 resource_dispatcher_host()->Shutdown();
186 }
187
[email protected]f2a893c2011-01-05 09:38:07188 // The policy providers managed by |configuration_policy_provider_keeper_|
189 // need to shut down while the file thread is still alive.
190 configuration_policy_provider_keeper_.reset();
191
[email protected]753efc42010-03-09 19:52:16192#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06193 // The IO thread must outlive the BACKGROUND_X11 thread.
194 background_x11_thread_.reset();
195#endif
196
[email protected]6618d1d2010-12-15 21:18:47197 // Wait for removing plugin data to finish before shutting down the IO thread.
198 WaitForPluginDataRemoverToFinish();
199
initial.commit09911bf2008-07-26 23:55:29200 // Need to stop io_thread_ before resource_dispatcher_host_, since
201 // io_thread_ may still deref ResourceDispatcherHost and handle resource
202 // request before going away.
[email protected]0ac83682010-01-22 17:46:27203 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29204
[email protected]875ee822010-05-18 20:58:01205 // The IO thread was the only user of this thread.
206 cache_thread_.reset();
207
[email protected]914511712009-11-23 19:42:33208 // Stop the process launcher thread after the IO thread, in case the IO thread
209 // posted a task to terminate a process on the process launcher thread.
210 process_launcher_thread_.reset();
211
initial.commit09911bf2008-07-26 23:55:29212 // Clean up state that lives on the file_thread_ before it goes away.
213 if (resource_dispatcher_host_.get()) {
214 resource_dispatcher_host()->download_file_manager()->Shutdown();
215 resource_dispatcher_host()->save_file_manager()->Shutdown();
216 }
217
218 // Need to stop the file_thread_ here to force it to process messages in its
219 // message loop from the previous call to shutdown the DownloadFileManager,
220 // SaveFileManager and SessionService.
221 file_thread_.reset();
222
223 // With the file_thread_ flushed, we can release any icon resources.
224 icon_manager_.reset();
225
226 // Need to destroy ResourceDispatcherHost before PluginService and
[email protected]49f28bc72010-02-04 00:10:01227 // SafeBrowsingService, since it caches a pointer to it. This also
228 // causes the webkit thread to terminate.
initial.commit09911bf2008-07-26 23:55:29229 resource_dispatcher_host_.reset();
230
231 // Wait for the pending print jobs to finish.
232 print_job_manager_->OnQuit();
233 print_job_manager_.reset();
234
[email protected]0b4d3382010-07-14 16:13:04235 // Destroy TabCloseableStateWatcher before NotificationService since the
236 // former registers for notifications.
237 tab_closeable_state_watcher_.reset();
238
initial.commit09911bf2008-07-26 23:55:29239 // Now OK to destroy NotificationService.
240 main_notification_service_.reset();
241
[email protected]49f28bc72010-02-04 00:10:01242 // Prior to clearing local state, we want to complete tasks pending
243 // on the db thread too.
244 db_thread_.reset();
245
246 // At this point, no render process exist and the file, io, db, and
247 // webkit threads in this process have all terminated, so it's safe
248 // to access local state data such as cookies, database, or local storage.
249 if (clear_local_state_on_exit)
250 ClearLocalState(profile_path);
251
initial.commit09911bf2008-07-26 23:55:29252 g_browser_process = NULL;
253}
254
[email protected]c6032e82010-09-13 20:06:05255#if defined(OS_WIN)
[email protected]295039bd2008-08-15 04:32:57256// Send a QuitTask to the given MessageLoop.
257static void PostQuit(MessageLoop* message_loop) {
258 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
259}
[email protected]c6032e82010-09-13 20:06:05260#elif defined(USE_X11)
261static void Signal(base::WaitableEvent* event) {
262 event->Signal();
263}
264#endif
initial.commit09911bf2008-07-26 23:55:29265
[email protected]b443cb042009-12-15 22:05:09266unsigned int BrowserProcessImpl::AddRefModule() {
267 DCHECK(CalledOnValidThread());
[email protected]afd20c022010-06-10 00:48:20268 did_start_ = true;
[email protected]b443cb042009-12-15 22:05:09269 module_ref_count_++;
270 return module_ref_count_;
271}
272
273unsigned int BrowserProcessImpl::ReleaseModule() {
274 DCHECK(CalledOnValidThread());
[email protected]760d970a2010-05-18 00:39:18275 DCHECK_NE(0u, module_ref_count_);
[email protected]b443cb042009-12-15 22:05:09276 module_ref_count_--;
277 if (0 == module_ref_count_) {
[email protected]7d038c32010-12-14 00:40:00278 // Allow UI and IO threads to do blocking IO on shutdown, since we do a lot
279 // of it on shutdown for valid reasons.
280 base::ThreadRestrictions::SetIOAllowed(true);
281 io_thread()->message_loop()->PostTask(
282 FROM_HERE,
283 NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true));
[email protected]b443cb042009-12-15 22:05:09284 MessageLoop::current()->PostTask(
[email protected]34f73fb2010-03-24 20:50:34285 FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop));
[email protected]b443cb042009-12-15 22:05:09286 MessageLoop::current()->Quit();
287 }
288 return module_ref_count_;
289}
290
initial.commit09911bf2008-07-26 23:55:29291void BrowserProcessImpl::EndSession() {
[email protected]c6032e82010-09-13 20:06:05292#if defined(OS_WIN) || defined(USE_X11)
[email protected]d65cab7a2008-08-12 01:25:41293 // Notify we are going away.
[email protected]c6032e82010-09-13 20:06:05294 shutdown_event_->Signal();
[email protected]b112a4c2009-02-01 20:24:01295#endif
[email protected]d65cab7a2008-08-12 01:25:41296
initial.commit09911bf2008-07-26 23:55:29297 // Mark all the profiles as clean.
298 ProfileManager* pm = profile_manager();
299 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i)
300 (*i)->MarkAsCleanShutdown();
301
302 // Tell the metrics service it was cleanly shutdown.
303 MetricsService* metrics = g_browser_process->metrics_service();
304 if (metrics && local_state()) {
305 metrics->RecordCleanShutdown();
306
307 metrics->RecordStartOfSessionEnd();
308
309 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36310 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29311 }
312
313 // We must write that the profile and metrics service shutdown cleanly,
314 // otherwise on startup we'll think we crashed. So we block until done and
315 // then proceed with normal shutdown.
[email protected]c6032e82010-09-13 20:06:05316#if defined(USE_X11)
317 // Can't run a local loop on linux. Instead create a waitable event.
318 base::WaitableEvent done_writing(false, false);
[email protected]d04e7662010-10-10 22:24:48319 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]c6032e82010-09-13 20:06:05320 NewRunnableFunction(Signal, &done_writing));
321 done_writing.TimedWait(
322 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds));
323#elif defined(OS_WIN)
[email protected]d04e7662010-10-10 22:24:48324 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57325 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29326 MessageLoop::current()->Run();
[email protected]c6032e82010-09-13 20:06:05327#else
328 NOTIMPLEMENTED();
329#endif
initial.commit09911bf2008-07-26 23:55:29330}
331
[email protected]e13ad79b2010-07-22 21:36:50332ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() {
333 DCHECK(CalledOnValidThread());
334 if (!created_resource_dispatcher_host_)
335 CreateResourceDispatcherHost();
336 return resource_dispatcher_host_.get();
337}
338
339MetricsService* BrowserProcessImpl::metrics_service() {
340 DCHECK(CalledOnValidThread());
341 if (!created_metrics_service_)
342 CreateMetricsService();
343 return metrics_service_.get();
344}
345
346IOThread* BrowserProcessImpl::io_thread() {
347 DCHECK(CalledOnValidThread());
348 if (!created_io_thread_)
349 CreateIOThread();
350 return io_thread_.get();
351}
352
353base::Thread* BrowserProcessImpl::file_thread() {
354 DCHECK(CalledOnValidThread());
355 if (!created_file_thread_)
356 CreateFileThread();
357 return file_thread_.get();
358}
359
360base::Thread* BrowserProcessImpl::db_thread() {
361 DCHECK(CalledOnValidThread());
362 if (!created_db_thread_)
363 CreateDBThread();
364 return db_thread_.get();
365}
366
367base::Thread* BrowserProcessImpl::process_launcher_thread() {
368 DCHECK(CalledOnValidThread());
369 if (!created_process_launcher_thread_)
370 CreateProcessLauncherThread();
371 return process_launcher_thread_.get();
372}
373
374base::Thread* BrowserProcessImpl::cache_thread() {
375 DCHECK(CalledOnValidThread());
376 if (!created_cache_thread_)
377 CreateCacheThread();
378 return cache_thread_.get();
379}
380
381#if defined(USE_X11)
382base::Thread* BrowserProcessImpl::background_x11_thread() {
383 DCHECK(CalledOnValidThread());
384 // The BACKGROUND_X11 thread is created when the IO thread is created.
385 if (!created_io_thread_)
386 CreateIOThread();
387 return background_x11_thread_.get();
388}
389#endif
390
391ProfileManager* BrowserProcessImpl::profile_manager() {
392 DCHECK(CalledOnValidThread());
393 if (!created_profile_manager_)
394 CreateProfileManager();
395 return profile_manager_.get();
396}
397
398PrefService* BrowserProcessImpl::local_state() {
399 DCHECK(CalledOnValidThread());
400 if (!created_local_state_)
401 CreateLocalState();
402 return local_state_.get();
403}
404
405DevToolsManager* BrowserProcessImpl::devtools_manager() {
406 DCHECK(CalledOnValidThread());
407 if (!created_devtools_manager_)
408 CreateDevToolsManager();
409 return devtools_manager_.get();
410}
411
[email protected]8b8e7c92010-08-19 18:05:56412SidebarManager* BrowserProcessImpl::sidebar_manager() {
413 DCHECK(CalledOnValidThread());
414 if (!created_sidebar_manager_)
415 CreateSidebarManager();
416 return sidebar_manager_.get();
417}
418
[email protected]2dfeaf92011-01-10 21:08:21419ui::Clipboard* BrowserProcessImpl::clipboard() {
[email protected]e13ad79b2010-07-22 21:36:50420 DCHECK(CalledOnValidThread());
421 return clipboard_.get();
422}
423
424NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
425 DCHECK(CalledOnValidThread());
426 if (!created_notification_ui_manager_)
427 CreateNotificationUIManager();
428 return notification_ui_manager_.get();
429}
430
[email protected]f2a893c2011-01-05 09:38:07431policy::ConfigurationPolicyProviderKeeper*
432 BrowserProcessImpl::configuration_policy_provider_keeper() {
433 DCHECK(CalledOnValidThread());
434 if (!created_configuration_policy_provider_keeper_) {
435 DCHECK(configuration_policy_provider_keeper_.get() == NULL);
436 created_configuration_policy_provider_keeper_ = true;
437 configuration_policy_provider_keeper_.reset(
438 new policy::ConfigurationPolicyProviderKeeper());
439 }
440 return configuration_policy_provider_keeper_.get();
441}
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(
463 int port,
464 const std::string& frontend_url) {
[email protected]e13ad79b2010-07-22 21:36:50465 DCHECK(CalledOnValidThread());
[email protected]5613126e2011-01-31 15:27:55466 devtools_http_handler_ =
467 DevToolsHttpProtocolHandler::Start(port, frontend_url);
468}
469
470void BrowserProcessImpl::InitDevToolsLegacyProtocolHandler(int port) {
471 DCHECK(CalledOnValidThread());
472 devtools_legacy_handler_ = DevToolsProtocolHandler::Start(port);
[email protected]e13ad79b2010-07-22 21:36:50473}
474
475bool BrowserProcessImpl::IsShuttingDown() {
476 DCHECK(CalledOnValidThread());
477 return did_start_ && 0 == module_ref_count_;
478}
479
initial.commit09911bf2008-07-26 23:55:29480printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
481 // TODO(abarth): DCHECK(CalledOnValidThread());
[email protected]d8922f22010-05-07 00:57:27482 // http://code.google.com/p/chromium/issues/detail?id=6828
initial.commit09911bf2008-07-26 23:55:29483 // print_job_manager_ is initialized in the constructor and destroyed in the
484 // destructor, so it should always be valid.
485 DCHECK(print_job_manager_.get());
486 return print_job_manager_.get();
487}
488
[email protected]dbeebd52010-11-16 20:34:16489printing::PrintPreviewTabController*
490 BrowserProcessImpl::print_preview_tab_controller() {
491 DCHECK(CalledOnValidThread());
492 if (!print_preview_tab_controller_.get())
493 CreatePrintPreviewTabController();
494 return print_preview_tab_controller_.get();
495}
496
[email protected]e13ad79b2010-07-22 21:36:50497GoogleURLTracker* BrowserProcessImpl::google_url_tracker() {
498 DCHECK(CalledOnValidThread());
499 if (!google_url_tracker_.get())
500 CreateGoogleURLTracker();
501 return google_url_tracker_.get();
502}
503
504IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
505 DCHECK(CalledOnValidThread());
506 if (!intranet_redirect_detector_.get())
507 CreateIntranetRedirectDetector();
508 return intranet_redirect_detector_.get();
509}
510
511const std::string& BrowserProcessImpl::GetApplicationLocale() {
512 DCHECK(!locale_.empty());
513 return locale_;
514}
515
516void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
517 locale_ = locale;
518 extension_l10n_util::SetProcessLocale(locale);
519}
520
[email protected]073ed7b2010-09-27 09:20:02521DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
522 return &download_status_updater_;
523}
524
[email protected]e13ad79b2010-07-22 21:36:50525base::WaitableEvent* BrowserProcessImpl::shutdown_event() {
526 return shutdown_event_.get();
527}
528
529TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() {
530 DCHECK(CalledOnValidThread());
531 if (!tab_closeable_state_watcher_.get())
532 CreateTabCloseableStateWatcher();
533 return tab_closeable_state_watcher_.get();
534}
535
[email protected]a7a5e992010-12-09 23:39:51536safe_browsing::ClientSideDetectionService*
537 BrowserProcessImpl::safe_browsing_detection_service() {
538 DCHECK(CalledOnValidThread());
539 if (!created_safe_browsing_detection_service_) {
540 CreateSafeBrowsingDetectionService();
541 }
542 return safe_browsing_detection_service_.get();
543}
544
[email protected]e13ad79b2010-07-22 21:36:50545void BrowserProcessImpl::CheckForInspectorFiles() {
546 file_thread()->message_loop()->PostTask
547 (FROM_HERE,
548 NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck));
549}
550
[email protected]6618d1d2010-12-15 21:18:47551void BrowserProcessImpl::Observe(NotificationType type,
552 const NotificationSource& source,
553 const NotificationDetails& details) {
554 if (type == NotificationType::APP_TERMINATING) {
555 Profile* profile = ProfileManager::GetDefaultProfile();
556 if (profile) {
557 PrefService* prefs = profile->GetPrefs();
[email protected]2ffc3c6c2011-01-14 12:50:24558 if (prefs->GetBoolean(prefs::kClearSiteDataOnExit) &&
[email protected]6618d1d2010-12-15 21:18:47559 local_state()->GetBoolean(prefs::kClearPluginLSODataEnabled)) {
560 plugin_data_remover_ = new PluginDataRemover();
[email protected]c7d58d62011-01-21 10:27:18561 if (!plugin_data_remover_mime_type().empty())
562 plugin_data_remover_->set_mime_type(plugin_data_remover_mime_type());
563 plugin_data_remover_->StartRemoving(base::Time());
[email protected]6618d1d2010-12-15 21:18:47564 }
565 }
566 } else {
567 NOTREACHED();
568 }
569}
570
571void BrowserProcessImpl::WaitForPluginDataRemoverToFinish() {
[email protected]c7d58d62011-01-21 10:27:18572 if (plugin_data_remover_.get())
573 plugin_data_remover_->Wait();
[email protected]6618d1d2010-12-15 21:18:47574}
575
[email protected]e13ad79b2010-07-22 21:36:50576#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
577void BrowserProcessImpl::StartAutoupdateTimer() {
578 autoupdate_timer_.Start(
579 base::TimeDelta::FromHours(kUpdateCheckIntervalHours),
580 this,
581 &BrowserProcessImpl::OnAutoupdateTimer);
582}
583#endif
584
585bool BrowserProcessImpl::have_inspector_files() const {
586 return have_inspector_files_;
587}
588
[email protected]4ef795df2010-02-03 02:35:08589void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
[email protected]72cfd90f2010-02-06 03:08:04590 webkit_database::DatabaseTracker::ClearLocalState(profile_path);
[email protected]4ef795df2010-02-03 02:35:08591}
592
593bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
594 FilePath user_data_dir;
595 Profile* profile;
596
[email protected]09584972010-07-03 00:00:59597 // Check for the existence of a profile manager. When quitting early,
[email protected]ed0cf562010-02-05 22:50:41598 // e.g. because another chrome instance is running, or when invoked with
599 // options such as --uninstall or --try-chrome-again=0, the profile manager
600 // does not exist yet.
601 if (!profile_manager_.get())
602 return false;
603
[email protected]4ef795df2010-02-03 02:35:08604 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
605 profile = profile_manager_->GetDefaultProfile(user_data_dir);
[email protected]7bfc674322010-03-05 00:20:57606 if (!profile)
607 return false;
[email protected]4ef795df2010-02-03 02:35:08608 *profile_path = profile->GetPath();
609 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit);
610}
611
initial.commit09911bf2008-07-26 23:55:29612void BrowserProcessImpl::CreateResourceDispatcherHost() {
613 DCHECK(!created_resource_dispatcher_host_ &&
614 resource_dispatcher_host_.get() == NULL);
615 created_resource_dispatcher_host_ = true;
616
[email protected]79084c2d2009-11-03 23:12:42617 resource_dispatcher_host_.reset(new ResourceDispatcherHost());
initial.commit09911bf2008-07-26 23:55:29618 resource_dispatcher_host_->Initialize();
619}
620
621void BrowserProcessImpl::CreateMetricsService() {
622 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
623 created_metrics_service_ = true;
624
625 metrics_service_.reset(new MetricsService);
626}
627
628void BrowserProcessImpl::CreateIOThread() {
629 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
630 created_io_thread_ = true;
631
632 // Prior to starting the io thread, we create the plugin service as
633 // it is predominantly used from the io thread, but must be created
634 // on the main thread. The service ctor is inexpensive and does not
635 // invoke the io_thread() accessor.
636 PluginService::GetInstance();
637
[email protected]753efc42010-03-09 19:52:16638#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06639 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so
640 // we start it now.
641 scoped_ptr<base::Thread> background_x11_thread(
[email protected]d04e7662010-10-10 22:24:48642 new BrowserProcessSubThread(BrowserThread::BACKGROUND_X11));
[email protected]4c3cd7412009-04-22 17:56:06643 if (!background_x11_thread->Start())
644 return;
645 background_x11_thread_.swap(background_x11_thread);
646#endif
647
[email protected]b2fcd0e2010-12-01 15:19:40648 scoped_ptr<IOThread> thread(new IOThread(local_state(), net_log_.get()));
[email protected]ab820df2008-08-26 05:55:10649 base::Thread::Options options;
650 options.message_loop_type = MessageLoop::TYPE_IO;
651 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29652 return;
653 io_thread_.swap(thread);
654}
655
656void BrowserProcessImpl::CreateFileThread() {
657 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
658 created_file_thread_ = true;
659
[email protected]ab820df2008-08-26 05:55:10660 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48661 new BrowserProcessSubThread(BrowserThread::FILE));
[email protected]a1db3842008-09-17 22:04:06662 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39663#if defined(OS_WIN)
664 // On Windows, the FILE thread needs to be have a UI message loop which pumps
665 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06666 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39667#else
668 options.message_loop_type = MessageLoop::TYPE_IO;
669#endif
[email protected]a1db3842008-09-17 22:04:06670 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29671 return;
672 file_thread_.swap(thread);
673}
674
675void BrowserProcessImpl::CreateDBThread() {
676 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
677 created_db_thread_ = true;
678
[email protected]ab820df2008-08-26 05:55:10679 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48680 new BrowserProcessSubThread(BrowserThread::DB));
initial.commit09911bf2008-07-26 23:55:29681 if (!thread->Start())
682 return;
683 db_thread_.swap(thread);
684}
685
[email protected]914511712009-11-23 19:42:33686void BrowserProcessImpl::CreateProcessLauncherThread() {
687 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
688 created_process_launcher_thread_ = true;
689
690 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48691 new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER));
[email protected]914511712009-11-23 19:42:33692 if (!thread->Start())
693 return;
694 process_launcher_thread_.swap(thread);
695}
696
[email protected]875ee822010-05-18 20:58:01697void BrowserProcessImpl::CreateCacheThread() {
698 DCHECK(!created_cache_thread_ && !cache_thread_.get());
699 created_cache_thread_ = true;
700
701 scoped_ptr<base::Thread> thread(
[email protected]75096332010-11-09 03:28:13702 new BrowserThread(BrowserThread::CACHE));
[email protected]875ee822010-05-18 20:58:01703 base::Thread::Options options;
704 options.message_loop_type = MessageLoop::TYPE_IO;
705 if (!thread->StartWithOptions(options))
706 return;
707 cache_thread_.swap(thread);
708}
709
initial.commit09911bf2008-07-26 23:55:29710void BrowserProcessImpl::CreateProfileManager() {
711 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
712 created_profile_manager_ = true;
713
714 profile_manager_.reset(new ProfileManager());
715}
716
717void BrowserProcessImpl::CreateLocalState() {
718 DCHECK(!created_local_state_ && local_state_.get() == NULL);
719 created_local_state_ = true;
720
[email protected]b9636002009-03-04 00:05:25721 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29722 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]f2d1f612010-12-09 15:10:17723 local_state_.reset(
724 PrefService::CreatePrefService(local_state_path, NULL, NULL));
[email protected]492d2142010-09-10 13:55:18725
[email protected]2a7e7c152010-10-01 20:12:09726 pref_change_registrar_.Init(local_state_.get());
727
[email protected]492d2142010-09-10 13:55:18728 // Make sure the the plugin updater gets notifications of changes
729 // in the plugin blacklist.
730 local_state_->RegisterListPref(prefs::kPluginsPluginsBlacklist);
[email protected]2a7e7c152010-10-01 20:12:09731 pref_change_registrar_.Add(prefs::kPluginsPluginsBlacklist,
[email protected]8e8bb6d2010-12-13 08:18:55732 PluginUpdater::GetInstance());
[email protected]2a7e7c152010-10-01 20:12:09733
734 // Initialize and set up notifications for the printing enabled
735 // preference.
736 local_state_->RegisterBooleanPref(prefs::kPrintingEnabled, true);
737 bool printing_enabled =
738 local_state_->GetBoolean(prefs::kPrintingEnabled);
739 print_job_manager_->set_printing_enabled(printing_enabled);
740 pref_change_registrar_.Add(prefs::kPrintingEnabled,
741 print_job_manager_.get());
[email protected]fd6159a2010-09-03 09:38:39742}
initial.commit09911bf2008-07-26 23:55:29743
initial.commit09911bf2008-07-26 23:55:29744void BrowserProcessImpl::CreateIconManager() {
745 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
746 created_icon_manager_ = true;
747 icon_manager_.reset(new IconManager);
748}
749
[email protected]40ecc902009-03-16 13:42:47750void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44751 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47752 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44753 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47754}
755
[email protected]8b8e7c92010-08-19 18:05:56756void BrowserProcessImpl::CreateSidebarManager() {
757 DCHECK(sidebar_manager_.get() == NULL);
758 created_sidebar_manager_ = true;
759 sidebar_manager_ = new SidebarManager();
760}
761
initial.commit09911bf2008-07-26 23:55:29762void BrowserProcessImpl::CreateGoogleURLTracker() {
763 DCHECK(google_url_tracker_.get() == NULL);
764 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
765 google_url_tracker_.swap(google_url_tracker);
766}
[email protected]6641bf662009-08-21 00:34:09767
[email protected]c4ff4952010-01-08 19:12:47768void BrowserProcessImpl::CreateIntranetRedirectDetector() {
769 DCHECK(intranet_redirect_detector_.get() == NULL);
770 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
771 new IntranetRedirectDetector);
772 intranet_redirect_detector_.swap(intranet_redirect_detector);
773}
774
[email protected]29672ab2009-10-30 03:44:03775void BrowserProcessImpl::CreateNotificationUIManager() {
776 DCHECK(notification_ui_manager_.get() == NULL);
[email protected]b0b2a3dd2011-01-06 00:30:05777 notification_ui_manager_.reset(NotificationUIManager::Create(local_state()));
778
[email protected]29672ab2009-10-30 03:44:03779 created_notification_ui_manager_ = true;
780}
781
[email protected]0b4d3382010-07-14 16:13:04782void BrowserProcessImpl::CreateTabCloseableStateWatcher() {
783 DCHECK(tab_closeable_state_watcher_.get() == NULL);
784 tab_closeable_state_watcher_.reset(TabCloseableStateWatcher::Create());
785}
786
[email protected]dbeebd52010-11-16 20:34:16787void BrowserProcessImpl::CreatePrintPreviewTabController() {
788 DCHECK(print_preview_tab_controller_.get() == NULL);
789 print_preview_tab_controller_ = new printing::PrintPreviewTabController();
790}
791
[email protected]a7a5e992010-12-09 23:39:51792void BrowserProcessImpl::CreateSafeBrowsingDetectionService() {
793 DCHECK(safe_browsing_detection_service_.get() == NULL);
794 // Set this flag to true so that we don't retry indefinitely to
795 // create the service class if there was an error.
796 created_safe_browsing_detection_service_ = true;
797
798 FilePath model_file_path;
799 Profile* profile = profile_manager() ?
800 profile_manager()->GetDefaultProfile() : NULL;
801 if (IsSafeBrowsingDetectionServiceEnabled() &&
802 PathService::Get(chrome::DIR_USER_DATA, &model_file_path) &&
803 profile && profile->GetRequestContext()) {
804 safe_browsing_detection_service_.reset(
805 safe_browsing::ClientSideDetectionService::Create(
806 model_file_path.Append(chrome::kSafeBrowsingPhishingModelFilename),
807 profile->GetRequestContext()));
808 }
809}
810
811bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() {
812 // The safe browsing client-side detection is enabled only if the switch is
[email protected]42930de42011-01-13 23:26:28813 // enabled and when safe browsing related stats is allowed to be collected.
814 return CommandLine::ForCurrentProcess()->HasSwitch(
815 switches::kEnableClientSidePhishingDetection) &&
816 resource_dispatcher_host()->safe_browsing_service() &&
817 resource_dispatcher_host()->safe_browsing_service()->CanReportStats();
[email protected]a7a5e992010-12-09 23:39:51818}
819
[email protected]6641bf662009-08-21 00:34:09820// The BrowserProcess object must outlive the file thread so we use traits
821// which don't do any management.
[email protected]c56428f22010-06-16 02:17:23822DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl);
[email protected]6641bf662009-08-21 00:34:09823
[email protected]d55aaa132009-09-28 21:08:04824#if defined(IPC_MESSAGE_LOG_ENABLED)
825
826void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
827 // First enable myself.
828 if (enable)
[email protected]8e8bb6d2010-12-13 08:18:55829 IPC::Logging::GetInstance()->Enable();
[email protected]d55aaa132009-09-28 21:08:04830 else
[email protected]8e8bb6d2010-12-13 08:18:55831 IPC::Logging::GetInstance()->Disable();
[email protected]d55aaa132009-09-28 21:08:04832
833 // Now tell subprocesses. Messages to ChildProcess-derived
834 // processes must be done on the IO thread.
835 io_thread()->message_loop()->PostTask
836 (FROM_HERE,
837 NewRunnableMethod(
838 this,
839 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
840 enable));
841
842 // Finally, tell the renderers which don't derive from ChildProcess.
843 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:27844 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
845 !i.IsAtEnd(); i.Advance())
846 i.GetCurrentValue()->Send(new ViewMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:04847}
848
849// Helper for SetIPCLoggingEnabled.
850void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d04e7662010-10-10 22:24:48851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d55aaa132009-09-28 21:08:04852
[email protected]d27893f62010-07-03 05:47:42853 BrowserChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:11854 while (!i.Done()) {
855 i->Send(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
856 ++i;
[email protected]d55aaa132009-09-28 21:08:04857 }
858}
859
860#endif // IPC_MESSAGE_LOG_ENABLED
861
[email protected]6641bf662009-08-21 00:34:09862void BrowserProcessImpl::DoInspectorFilesCheck() {
863 // Runs on FILE thread.
864 DCHECK(file_thread_->message_loop() == MessageLoop::current());
865 bool result = false;
866
867 FilePath inspector_dir;
868 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) {
869 result = file_util::PathExists(inspector_dir);
870 }
871
[email protected]308080d2009-11-11 19:19:02872 have_inspector_files_ = result;
[email protected]6641bf662009-08-21 00:34:09873}
[email protected]bd48c2b02010-04-09 20:32:42874
[email protected]3cdacd42010-04-30 18:55:53875// Mac is currently not supported.
876#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:42877
878bool BrowserProcessImpl::CanAutorestartForUpdate() const {
879 // Check if browser is in the background and if it needs to be restarted to
880 // apply a pending update.
[email protected]c10fa3952010-08-24 16:52:53881 return BrowserList::size() == 0 && BrowserList::WillKeepAlive() &&
[email protected]c984d9f2010-07-20 20:52:20882 Upgrade::IsUpdatePendingRestart();
[email protected]bd48c2b02010-04-09 20:32:42883}
884
[email protected]5c08f222010-09-22 09:37:21885// Switches to add when auto-restarting Chrome.
[email protected]6c10c972010-08-11 04:15:47886const char* const kSwitchesToAddOnAutorestart[] = {
[email protected]f9a06842010-08-21 00:32:40887 switches::kNoStartupWindow
[email protected]bd48c2b02010-04-09 20:32:42888};
889
890void BrowserProcessImpl::RestartPersistentInstance() {
891 CommandLine* old_cl = CommandLine::ForCurrentProcess();
[email protected]3cdacd42010-04-30 18:55:53892 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram()));
[email protected]bd48c2b02010-04-09 20:32:42893
894 std::map<std::string, CommandLine::StringType> switches =
895 old_cl->GetSwitches();
896
[email protected]5c08f222010-09-22 09:37:21897 switches::RemoveSwitchesForAutostart(&switches);
[email protected]bd48c2b02010-04-09 20:32:42898
899 // Append the rest of the switches (along with their values, if any)
900 // to the new command line
901 for (std::map<std::string, CommandLine::StringType>::const_iterator i =
902 switches.begin(); i != switches.end(); ++i) {
903 CommandLine::StringType switch_value = i->second;
904 if (switch_value.length() > 0) {
[email protected]05076ba22010-07-30 05:59:57905 new_cl->AppendSwitchNative(i->first, i->second);
[email protected]bd48c2b02010-04-09 20:32:42906 } else {
[email protected]3cdacd42010-04-30 18:55:53907 new_cl->AppendSwitch(i->first);
[email protected]bd48c2b02010-04-09 20:32:42908 }
909 }
910
[email protected]6c10c972010-08-11 04:15:47911 // Ensure that our desired switches are set on the new process.
[email protected]5c08f222010-09-22 09:37:21912 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) {
[email protected]6c10c972010-08-11 04:15:47913 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i]))
914 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
915 }
[email protected]bd48c2b02010-04-09 20:32:42916
[email protected]3cdacd42010-04-30 18:55:53917 DLOG(WARNING) << "Shutting down current instance of the browser.";
918 BrowserList::CloseAllBrowsersAndExit();
919
920 // Transfer ownership to Upgrade.
921 Upgrade::SetNewCommandLine(new_cl.release());
[email protected]bd48c2b02010-04-09 20:32:42922}
923
924void BrowserProcessImpl::OnAutoupdateTimer() {
925 if (CanAutorestartForUpdate()) {
[email protected]3cdacd42010-04-30 18:55:53926 DLOG(WARNING) << "Detected update. Restarting browser.";
[email protected]bd48c2b02010-04-09 20:32:42927 RestartPersistentInstance();
928 }
929}
930
[email protected]3cdacd42010-04-30 18:55:53931#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)