blob: 7a14807a7b720d825a7259736ca9503d0a51671a [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
[email protected]a92b8642009-05-05 23:38:569#include "app/l10n_util.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/command_line.h"
[email protected]6641bf662009-08-21 00:34:0911#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/path_service.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]44f9c952011-01-02 06:05:3916#include "base/synchronization/waitable_event.h"
[email protected]e13ad79b2010-07-22 21:36:5017#include "chrome/browser/automation/automation_provider_list.h"
[email protected]d27893f62010-07-03 05:47:4218#include "chrome/browser/browser_child_process_host.h"
[email protected]bd48c2b02010-04-09 20:32:4219#include "chrome/browser/browser_list.h"
[email protected]b443cb042009-12-15 22:05:0920#include "chrome/browser/browser_main.h"
[email protected]0ac83682010-01-22 17:46:2721#include "chrome/browser/browser_process_sub_thread.h"
[email protected]ed7e6dd2010-10-12 02:02:4522#include "chrome/browser/browser_thread.h"
[email protected]ac262c9f2008-10-19 17:45:2123#include "chrome/browser/browser_trial.h"
[email protected]4ab4b0f2009-02-10 18:54:5024#include "chrome/browser/debugger/debugger_wrapper.h"
[email protected]40ecc902009-03-16 13:42:4725#include "chrome/browser/debugger/devtools_manager.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]4ef795df2010-02-03 02:35:0865#include "webkit/database/database_tracker.h"
[email protected]b112a4c2009-02-01 20:24:0166
67#if defined(OS_WIN)
[email protected]2362e4f2009-05-08 00:34:0568#include "views/focus/view_storage.h"
[email protected]86230b92009-11-23 20:38:3869#endif
70
[email protected]d55aaa132009-09-28 21:08:0471#if defined(IPC_MESSAGE_LOG_ENABLED)
72#include "chrome/common/plugin_messages.h"
73#include "chrome/common/render_messages.h"
74#endif
75
[email protected]3cdacd42010-04-30 18:55:5376#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
77// How often to check if the persistent instance of Chrome needs to restart
78// to install an update.
79static const int kUpdateCheckIntervalHours = 6;
80#endif
81
[email protected]c6032e82010-09-13 20:06:0582#if defined(USE_X11)
83// How long to wait for the File thread to complete during EndSession, on
84// Linux. We have a timeout here because we're unable to run the UI messageloop
85// and there's some deadlock risk. Our only option is to exit anyway.
86static const int kEndSessionTimeoutSeconds = 10;
87#endif
88
[email protected]bb975362009-01-21 01:00:2289BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
initial.commit09911bf2008-07-26 23:55:2990 : created_resource_dispatcher_host_(false),
91 created_metrics_service_(false),
92 created_io_thread_(false),
93 created_file_thread_(false),
94 created_db_thread_(false),
[email protected]914511712009-11-23 19:42:3395 created_process_launcher_thread_(false),
[email protected]875ee822010-05-18 20:58:0196 created_cache_thread_(false),
initial.commit09911bf2008-07-26 23:55:2997 created_profile_manager_(false),
98 created_local_state_(false),
[email protected]b112a4c2009-02-01 20:24:0199 created_icon_manager_(false),
100 created_debugger_wrapper_(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]c4ff4952010-01-08 19:12:47149 // We need to destroy the MetricsService, GoogleURLTracker, and
150 // IntranetRedirectDetector before the io_thread_ gets destroyed, since their
151 // destructors can call the URLFetcher destructor, which does a
152 // PostDelayedTask operation on the IO thread. (The IO thread will handle
153 // that URLFetcher operation before going away.)
initial.commit09911bf2008-07-26 23:55:29154 metrics_service_.reset();
155 google_url_tracker_.reset();
[email protected]c4ff4952010-01-08 19:12:47156 intranet_redirect_detector_.reset();
initial.commit09911bf2008-07-26 23:55:29157
[email protected]d8a899c2010-09-21 04:50:33158 // Need to clear the desktop notification balloons before the io_thread_ and
159 // before the profiles, since if there are any still showing we will access
160 // those things during teardown.
161 notification_ui_manager_.reset();
162
initial.commit09911bf2008-07-26 23:55:29163 // Need to clear profiles (download managers) before the io_thread_.
164 profile_manager_.reset();
165
166 // Debugger must be cleaned up before IO thread and NotificationService.
167 debugger_wrapper_ = NULL;
168
169 if (resource_dispatcher_host_.get()) {
170 // Need to tell Safe Browsing Service that the IO thread is going away
171 // since it cached a pointer to it.
172 if (resource_dispatcher_host()->safe_browsing_service())
173 resource_dispatcher_host()->safe_browsing_service()->ShutDown();
174
175 // Cancel pending requests and prevent new requests.
176 resource_dispatcher_host()->Shutdown();
177 }
178
[email protected]f2a893c2011-01-05 09:38:07179 // The policy providers managed by |configuration_policy_provider_keeper_|
180 // need to shut down while the file thread is still alive.
181 configuration_policy_provider_keeper_.reset();
182
[email protected]753efc42010-03-09 19:52:16183#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06184 // The IO thread must outlive the BACKGROUND_X11 thread.
185 background_x11_thread_.reset();
186#endif
187
[email protected]6618d1d2010-12-15 21:18:47188 // Wait for removing plugin data to finish before shutting down the IO thread.
189 WaitForPluginDataRemoverToFinish();
190
initial.commit09911bf2008-07-26 23:55:29191 // Need to stop io_thread_ before resource_dispatcher_host_, since
192 // io_thread_ may still deref ResourceDispatcherHost and handle resource
193 // request before going away.
[email protected]0ac83682010-01-22 17:46:27194 io_thread_.reset();
initial.commit09911bf2008-07-26 23:55:29195
[email protected]875ee822010-05-18 20:58:01196 // The IO thread was the only user of this thread.
197 cache_thread_.reset();
198
[email protected]914511712009-11-23 19:42:33199 // Stop the process launcher thread after the IO thread, in case the IO thread
200 // posted a task to terminate a process on the process launcher thread.
201 process_launcher_thread_.reset();
202
initial.commit09911bf2008-07-26 23:55:29203 // Clean up state that lives on the file_thread_ before it goes away.
204 if (resource_dispatcher_host_.get()) {
205 resource_dispatcher_host()->download_file_manager()->Shutdown();
206 resource_dispatcher_host()->save_file_manager()->Shutdown();
207 }
208
209 // Need to stop the file_thread_ here to force it to process messages in its
210 // message loop from the previous call to shutdown the DownloadFileManager,
211 // SaveFileManager and SessionService.
212 file_thread_.reset();
213
214 // With the file_thread_ flushed, we can release any icon resources.
215 icon_manager_.reset();
216
217 // Need to destroy ResourceDispatcherHost before PluginService and
[email protected]49f28bc72010-02-04 00:10:01218 // SafeBrowsingService, since it caches a pointer to it. This also
219 // causes the webkit thread to terminate.
initial.commit09911bf2008-07-26 23:55:29220 resource_dispatcher_host_.reset();
221
222 // Wait for the pending print jobs to finish.
223 print_job_manager_->OnQuit();
224 print_job_manager_.reset();
225
[email protected]0b4d3382010-07-14 16:13:04226 // Destroy TabCloseableStateWatcher before NotificationService since the
227 // former registers for notifications.
228 tab_closeable_state_watcher_.reset();
229
initial.commit09911bf2008-07-26 23:55:29230 // Now OK to destroy NotificationService.
231 main_notification_service_.reset();
232
[email protected]49f28bc72010-02-04 00:10:01233 // Prior to clearing local state, we want to complete tasks pending
234 // on the db thread too.
235 db_thread_.reset();
236
237 // At this point, no render process exist and the file, io, db, and
238 // webkit threads in this process have all terminated, so it's safe
239 // to access local state data such as cookies, database, or local storage.
240 if (clear_local_state_on_exit)
241 ClearLocalState(profile_path);
242
initial.commit09911bf2008-07-26 23:55:29243 g_browser_process = NULL;
244}
245
[email protected]c6032e82010-09-13 20:06:05246#if defined(OS_WIN)
[email protected]295039bd2008-08-15 04:32:57247// Send a QuitTask to the given MessageLoop.
248static void PostQuit(MessageLoop* message_loop) {
249 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
250}
[email protected]c6032e82010-09-13 20:06:05251#elif defined(USE_X11)
252static void Signal(base::WaitableEvent* event) {
253 event->Signal();
254}
255#endif
initial.commit09911bf2008-07-26 23:55:29256
[email protected]b443cb042009-12-15 22:05:09257unsigned int BrowserProcessImpl::AddRefModule() {
258 DCHECK(CalledOnValidThread());
[email protected]afd20c022010-06-10 00:48:20259 did_start_ = true;
[email protected]b443cb042009-12-15 22:05:09260 module_ref_count_++;
261 return module_ref_count_;
262}
263
264unsigned int BrowserProcessImpl::ReleaseModule() {
265 DCHECK(CalledOnValidThread());
[email protected]760d970a2010-05-18 00:39:18266 DCHECK_NE(0u, module_ref_count_);
[email protected]b443cb042009-12-15 22:05:09267 module_ref_count_--;
268 if (0 == module_ref_count_) {
[email protected]7d038c32010-12-14 00:40:00269 // Allow UI and IO threads to do blocking IO on shutdown, since we do a lot
270 // of it on shutdown for valid reasons.
271 base::ThreadRestrictions::SetIOAllowed(true);
272 io_thread()->message_loop()->PostTask(
273 FROM_HERE,
274 NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true));
[email protected]b443cb042009-12-15 22:05:09275 MessageLoop::current()->PostTask(
[email protected]34f73fb2010-03-24 20:50:34276 FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop));
[email protected]b443cb042009-12-15 22:05:09277 MessageLoop::current()->Quit();
278 }
279 return module_ref_count_;
280}
281
initial.commit09911bf2008-07-26 23:55:29282void BrowserProcessImpl::EndSession() {
[email protected]c6032e82010-09-13 20:06:05283#if defined(OS_WIN) || defined(USE_X11)
[email protected]d65cab7a2008-08-12 01:25:41284 // Notify we are going away.
[email protected]c6032e82010-09-13 20:06:05285 shutdown_event_->Signal();
[email protected]b112a4c2009-02-01 20:24:01286#endif
[email protected]d65cab7a2008-08-12 01:25:41287
initial.commit09911bf2008-07-26 23:55:29288 // Mark all the profiles as clean.
289 ProfileManager* pm = profile_manager();
290 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i)
291 (*i)->MarkAsCleanShutdown();
292
293 // Tell the metrics service it was cleanly shutdown.
294 MetricsService* metrics = g_browser_process->metrics_service();
295 if (metrics && local_state()) {
296 metrics->RecordCleanShutdown();
297
298 metrics->RecordStartOfSessionEnd();
299
300 // MetricsService lazily writes to prefs, force it to write now.
[email protected]6faa0e0d2009-04-28 06:50:36301 local_state()->SavePersistentPrefs();
initial.commit09911bf2008-07-26 23:55:29302 }
303
304 // We must write that the profile and metrics service shutdown cleanly,
305 // otherwise on startup we'll think we crashed. So we block until done and
306 // then proceed with normal shutdown.
[email protected]c6032e82010-09-13 20:06:05307#if defined(USE_X11)
308 // Can't run a local loop on linux. Instead create a waitable event.
309 base::WaitableEvent done_writing(false, false);
[email protected]d04e7662010-10-10 22:24:48310 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]c6032e82010-09-13 20:06:05311 NewRunnableFunction(Signal, &done_writing));
312 done_writing.TimedWait(
313 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds));
314#elif defined(OS_WIN)
[email protected]d04e7662010-10-10 22:24:48315 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
[email protected]295039bd2008-08-15 04:32:57316 NewRunnableFunction(PostQuit, MessageLoop::current()));
initial.commit09911bf2008-07-26 23:55:29317 MessageLoop::current()->Run();
[email protected]c6032e82010-09-13 20:06:05318#else
319 NOTIMPLEMENTED();
320#endif
initial.commit09911bf2008-07-26 23:55:29321}
322
[email protected]e13ad79b2010-07-22 21:36:50323ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() {
324 DCHECK(CalledOnValidThread());
325 if (!created_resource_dispatcher_host_)
326 CreateResourceDispatcherHost();
327 return resource_dispatcher_host_.get();
328}
329
330MetricsService* BrowserProcessImpl::metrics_service() {
331 DCHECK(CalledOnValidThread());
332 if (!created_metrics_service_)
333 CreateMetricsService();
334 return metrics_service_.get();
335}
336
337IOThread* BrowserProcessImpl::io_thread() {
338 DCHECK(CalledOnValidThread());
339 if (!created_io_thread_)
340 CreateIOThread();
341 return io_thread_.get();
342}
343
344base::Thread* BrowserProcessImpl::file_thread() {
345 DCHECK(CalledOnValidThread());
346 if (!created_file_thread_)
347 CreateFileThread();
348 return file_thread_.get();
349}
350
351base::Thread* BrowserProcessImpl::db_thread() {
352 DCHECK(CalledOnValidThread());
353 if (!created_db_thread_)
354 CreateDBThread();
355 return db_thread_.get();
356}
357
358base::Thread* BrowserProcessImpl::process_launcher_thread() {
359 DCHECK(CalledOnValidThread());
360 if (!created_process_launcher_thread_)
361 CreateProcessLauncherThread();
362 return process_launcher_thread_.get();
363}
364
365base::Thread* BrowserProcessImpl::cache_thread() {
366 DCHECK(CalledOnValidThread());
367 if (!created_cache_thread_)
368 CreateCacheThread();
369 return cache_thread_.get();
370}
371
372#if defined(USE_X11)
373base::Thread* BrowserProcessImpl::background_x11_thread() {
374 DCHECK(CalledOnValidThread());
375 // The BACKGROUND_X11 thread is created when the IO thread is created.
376 if (!created_io_thread_)
377 CreateIOThread();
378 return background_x11_thread_.get();
379}
380#endif
381
382ProfileManager* BrowserProcessImpl::profile_manager() {
383 DCHECK(CalledOnValidThread());
384 if (!created_profile_manager_)
385 CreateProfileManager();
386 return profile_manager_.get();
387}
388
389PrefService* BrowserProcessImpl::local_state() {
390 DCHECK(CalledOnValidThread());
391 if (!created_local_state_)
392 CreateLocalState();
393 return local_state_.get();
394}
395
396DevToolsManager* BrowserProcessImpl::devtools_manager() {
397 DCHECK(CalledOnValidThread());
398 if (!created_devtools_manager_)
399 CreateDevToolsManager();
400 return devtools_manager_.get();
401}
402
[email protected]8b8e7c92010-08-19 18:05:56403SidebarManager* BrowserProcessImpl::sidebar_manager() {
404 DCHECK(CalledOnValidThread());
405 if (!created_sidebar_manager_)
406 CreateSidebarManager();
407 return sidebar_manager_.get();
408}
409
[email protected]2dfeaf92011-01-10 21:08:21410ui::Clipboard* BrowserProcessImpl::clipboard() {
[email protected]e13ad79b2010-07-22 21:36:50411 DCHECK(CalledOnValidThread());
412 return clipboard_.get();
413}
414
415NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
416 DCHECK(CalledOnValidThread());
417 if (!created_notification_ui_manager_)
418 CreateNotificationUIManager();
419 return notification_ui_manager_.get();
420}
421
[email protected]f2a893c2011-01-05 09:38:07422policy::ConfigurationPolicyProviderKeeper*
423 BrowserProcessImpl::configuration_policy_provider_keeper() {
424 DCHECK(CalledOnValidThread());
425 if (!created_configuration_policy_provider_keeper_) {
426 DCHECK(configuration_policy_provider_keeper_.get() == NULL);
427 created_configuration_policy_provider_keeper_ = true;
428 configuration_policy_provider_keeper_.reset(
429 new policy::ConfigurationPolicyProviderKeeper());
430 }
431 return configuration_policy_provider_keeper_.get();
432}
433
[email protected]e13ad79b2010-07-22 21:36:50434IconManager* BrowserProcessImpl::icon_manager() {
435 DCHECK(CalledOnValidThread());
436 if (!created_icon_manager_)
437 CreateIconManager();
438 return icon_manager_.get();
439}
440
441ThumbnailGenerator* BrowserProcessImpl::GetThumbnailGenerator() {
442 return &thumbnail_generator_;
443}
444
445AutomationProviderList* BrowserProcessImpl::InitAutomationProviderList() {
446 DCHECK(CalledOnValidThread());
447 if (automation_provider_list_.get() == NULL) {
448 automation_provider_list_.reset(AutomationProviderList::GetInstance());
449 }
450 return automation_provider_list_.get();
451}
452
453void BrowserProcessImpl::InitDebuggerWrapper(int port, bool useHttp) {
454 DCHECK(CalledOnValidThread());
455 if (!created_debugger_wrapper_)
456 CreateDebuggerWrapper(port, useHttp);
457}
458
459bool BrowserProcessImpl::IsShuttingDown() {
460 DCHECK(CalledOnValidThread());
461 return did_start_ && 0 == module_ref_count_;
462}
463
initial.commit09911bf2008-07-26 23:55:29464printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
465 // TODO(abarth): DCHECK(CalledOnValidThread());
[email protected]d8922f22010-05-07 00:57:27466 // http://code.google.com/p/chromium/issues/detail?id=6828
initial.commit09911bf2008-07-26 23:55:29467 // print_job_manager_ is initialized in the constructor and destroyed in the
468 // destructor, so it should always be valid.
469 DCHECK(print_job_manager_.get());
470 return print_job_manager_.get();
471}
472
[email protected]dbeebd52010-11-16 20:34:16473printing::PrintPreviewTabController*
474 BrowserProcessImpl::print_preview_tab_controller() {
475 DCHECK(CalledOnValidThread());
476 if (!print_preview_tab_controller_.get())
477 CreatePrintPreviewTabController();
478 return print_preview_tab_controller_.get();
479}
480
[email protected]e13ad79b2010-07-22 21:36:50481GoogleURLTracker* BrowserProcessImpl::google_url_tracker() {
482 DCHECK(CalledOnValidThread());
483 if (!google_url_tracker_.get())
484 CreateGoogleURLTracker();
485 return google_url_tracker_.get();
486}
487
488IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
489 DCHECK(CalledOnValidThread());
490 if (!intranet_redirect_detector_.get())
491 CreateIntranetRedirectDetector();
492 return intranet_redirect_detector_.get();
493}
494
495const std::string& BrowserProcessImpl::GetApplicationLocale() {
496 DCHECK(!locale_.empty());
497 return locale_;
498}
499
500void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {
501 locale_ = locale;
502 extension_l10n_util::SetProcessLocale(locale);
503}
504
[email protected]073ed7b2010-09-27 09:20:02505DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
506 return &download_status_updater_;
507}
508
[email protected]e13ad79b2010-07-22 21:36:50509base::WaitableEvent* BrowserProcessImpl::shutdown_event() {
510 return shutdown_event_.get();
511}
512
513TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() {
514 DCHECK(CalledOnValidThread());
515 if (!tab_closeable_state_watcher_.get())
516 CreateTabCloseableStateWatcher();
517 return tab_closeable_state_watcher_.get();
518}
519
[email protected]a7a5e992010-12-09 23:39:51520safe_browsing::ClientSideDetectionService*
521 BrowserProcessImpl::safe_browsing_detection_service() {
522 DCHECK(CalledOnValidThread());
523 if (!created_safe_browsing_detection_service_) {
524 CreateSafeBrowsingDetectionService();
525 }
526 return safe_browsing_detection_service_.get();
527}
528
[email protected]e13ad79b2010-07-22 21:36:50529void BrowserProcessImpl::CheckForInspectorFiles() {
530 file_thread()->message_loop()->PostTask
531 (FROM_HERE,
532 NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck));
533}
534
[email protected]6618d1d2010-12-15 21:18:47535void BrowserProcessImpl::Observe(NotificationType type,
536 const NotificationSource& source,
537 const NotificationDetails& details) {
538 if (type == NotificationType::APP_TERMINATING) {
539 Profile* profile = ProfileManager::GetDefaultProfile();
540 if (profile) {
541 PrefService* prefs = profile->GetPrefs();
542 if (prefs->GetBoolean(prefs::kClearPluginLSODataOnExit) &&
543 local_state()->GetBoolean(prefs::kClearPluginLSODataEnabled)) {
544 plugin_data_remover_ = new PluginDataRemover();
545 plugin_data_remover_->StartRemoving(base::Time(), NULL);
546 }
547 }
548 } else {
549 NOTREACHED();
550 }
551}
552
553void BrowserProcessImpl::WaitForPluginDataRemoverToFinish() {
554 if (!plugin_data_remover_.get() || !plugin_data_remover_->is_removing())
555 return;
556 plugin_data_remover_->set_done_task(new MessageLoop::QuitTask());
557 base::Time start_time(base::Time::Now());
558 MessageLoop::current()->Run();
559 UMA_HISTOGRAM_TIMES("ClearPluginData.wait_at_shutdown",
560 base::Time::Now() - start_time);
561}
562
[email protected]e13ad79b2010-07-22 21:36:50563#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
564void BrowserProcessImpl::StartAutoupdateTimer() {
565 autoupdate_timer_.Start(
566 base::TimeDelta::FromHours(kUpdateCheckIntervalHours),
567 this,
568 &BrowserProcessImpl::OnAutoupdateTimer);
569}
570#endif
571
572bool BrowserProcessImpl::have_inspector_files() const {
573 return have_inspector_files_;
574}
575
[email protected]4ef795df2010-02-03 02:35:08576void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) {
[email protected]72cfd90f2010-02-06 03:08:04577 webkit_database::DatabaseTracker::ClearLocalState(profile_path);
[email protected]4ef795df2010-02-03 02:35:08578}
579
580bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) {
581 FilePath user_data_dir;
582 Profile* profile;
583
[email protected]09584972010-07-03 00:00:59584 // Check for the existence of a profile manager. When quitting early,
[email protected]ed0cf562010-02-05 22:50:41585 // e.g. because another chrome instance is running, or when invoked with
586 // options such as --uninstall or --try-chrome-again=0, the profile manager
587 // does not exist yet.
588 if (!profile_manager_.get())
589 return false;
590
[email protected]4ef795df2010-02-03 02:35:08591 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
592 profile = profile_manager_->GetDefaultProfile(user_data_dir);
[email protected]7bfc674322010-03-05 00:20:57593 if (!profile)
594 return false;
[email protected]4ef795df2010-02-03 02:35:08595 *profile_path = profile->GetPath();
596 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit);
597}
598
initial.commit09911bf2008-07-26 23:55:29599void BrowserProcessImpl::CreateResourceDispatcherHost() {
600 DCHECK(!created_resource_dispatcher_host_ &&
601 resource_dispatcher_host_.get() == NULL);
602 created_resource_dispatcher_host_ = true;
603
[email protected]79084c2d2009-11-03 23:12:42604 resource_dispatcher_host_.reset(new ResourceDispatcherHost());
initial.commit09911bf2008-07-26 23:55:29605 resource_dispatcher_host_->Initialize();
606}
607
608void BrowserProcessImpl::CreateMetricsService() {
609 DCHECK(!created_metrics_service_ && metrics_service_.get() == NULL);
610 created_metrics_service_ = true;
611
612 metrics_service_.reset(new MetricsService);
613}
614
615void BrowserProcessImpl::CreateIOThread() {
616 DCHECK(!created_io_thread_ && io_thread_.get() == NULL);
617 created_io_thread_ = true;
618
619 // Prior to starting the io thread, we create the plugin service as
620 // it is predominantly used from the io thread, but must be created
621 // on the main thread. The service ctor is inexpensive and does not
622 // invoke the io_thread() accessor.
623 PluginService::GetInstance();
624
[email protected]753efc42010-03-09 19:52:16625#if defined(USE_X11)
[email protected]4c3cd7412009-04-22 17:56:06626 // The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so
627 // we start it now.
628 scoped_ptr<base::Thread> background_x11_thread(
[email protected]d04e7662010-10-10 22:24:48629 new BrowserProcessSubThread(BrowserThread::BACKGROUND_X11));
[email protected]4c3cd7412009-04-22 17:56:06630 if (!background_x11_thread->Start())
631 return;
632 background_x11_thread_.swap(background_x11_thread);
633#endif
634
[email protected]b2fcd0e2010-12-01 15:19:40635 scoped_ptr<IOThread> thread(new IOThread(local_state(), net_log_.get()));
[email protected]ab820df2008-08-26 05:55:10636 base::Thread::Options options;
637 options.message_loop_type = MessageLoop::TYPE_IO;
638 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29639 return;
640 io_thread_.swap(thread);
641}
642
643void BrowserProcessImpl::CreateFileThread() {
644 DCHECK(!created_file_thread_ && file_thread_.get() == NULL);
645 created_file_thread_ = true;
646
[email protected]ab820df2008-08-26 05:55:10647 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48648 new BrowserProcessSubThread(BrowserThread::FILE));
[email protected]a1db3842008-09-17 22:04:06649 base::Thread::Options options;
[email protected]9e549b582009-02-05 21:13:39650#if defined(OS_WIN)
651 // On Windows, the FILE thread needs to be have a UI message loop which pumps
652 // messages in such a way that Google Update can communicate back to us.
[email protected]a1db3842008-09-17 22:04:06653 options.message_loop_type = MessageLoop::TYPE_UI;
[email protected]9e549b582009-02-05 21:13:39654#else
655 options.message_loop_type = MessageLoop::TYPE_IO;
656#endif
[email protected]a1db3842008-09-17 22:04:06657 if (!thread->StartWithOptions(options))
initial.commit09911bf2008-07-26 23:55:29658 return;
659 file_thread_.swap(thread);
660}
661
662void BrowserProcessImpl::CreateDBThread() {
663 DCHECK(!created_db_thread_ && db_thread_.get() == NULL);
664 created_db_thread_ = true;
665
[email protected]ab820df2008-08-26 05:55:10666 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48667 new BrowserProcessSubThread(BrowserThread::DB));
initial.commit09911bf2008-07-26 23:55:29668 if (!thread->Start())
669 return;
670 db_thread_.swap(thread);
671}
672
[email protected]914511712009-11-23 19:42:33673void BrowserProcessImpl::CreateProcessLauncherThread() {
674 DCHECK(!created_process_launcher_thread_ && !process_launcher_thread_.get());
675 created_process_launcher_thread_ = true;
676
677 scoped_ptr<base::Thread> thread(
[email protected]d04e7662010-10-10 22:24:48678 new BrowserProcessSubThread(BrowserThread::PROCESS_LAUNCHER));
[email protected]914511712009-11-23 19:42:33679 if (!thread->Start())
680 return;
681 process_launcher_thread_.swap(thread);
682}
683
[email protected]875ee822010-05-18 20:58:01684void BrowserProcessImpl::CreateCacheThread() {
685 DCHECK(!created_cache_thread_ && !cache_thread_.get());
686 created_cache_thread_ = true;
687
688 scoped_ptr<base::Thread> thread(
[email protected]75096332010-11-09 03:28:13689 new BrowserThread(BrowserThread::CACHE));
[email protected]875ee822010-05-18 20:58:01690 base::Thread::Options options;
691 options.message_loop_type = MessageLoop::TYPE_IO;
692 if (!thread->StartWithOptions(options))
693 return;
694 cache_thread_.swap(thread);
695}
696
initial.commit09911bf2008-07-26 23:55:29697void BrowserProcessImpl::CreateProfileManager() {
698 DCHECK(!created_profile_manager_ && profile_manager_.get() == NULL);
699 created_profile_manager_ = true;
700
701 profile_manager_.reset(new ProfileManager());
702}
703
704void BrowserProcessImpl::CreateLocalState() {
705 DCHECK(!created_local_state_ && local_state_.get() == NULL);
706 created_local_state_ = true;
707
[email protected]b9636002009-03-04 00:05:25708 FilePath local_state_path;
initial.commit09911bf2008-07-26 23:55:29709 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
[email protected]f2d1f612010-12-09 15:10:17710 local_state_.reset(
711 PrefService::CreatePrefService(local_state_path, NULL, NULL));
[email protected]492d2142010-09-10 13:55:18712
[email protected]2a7e7c152010-10-01 20:12:09713 pref_change_registrar_.Init(local_state_.get());
714
[email protected]492d2142010-09-10 13:55:18715 // Make sure the the plugin updater gets notifications of changes
716 // in the plugin blacklist.
717 local_state_->RegisterListPref(prefs::kPluginsPluginsBlacklist);
[email protected]2a7e7c152010-10-01 20:12:09718 pref_change_registrar_.Add(prefs::kPluginsPluginsBlacklist,
[email protected]8e8bb6d2010-12-13 08:18:55719 PluginUpdater::GetInstance());
[email protected]2a7e7c152010-10-01 20:12:09720
721 // Initialize and set up notifications for the printing enabled
722 // preference.
723 local_state_->RegisterBooleanPref(prefs::kPrintingEnabled, true);
724 bool printing_enabled =
725 local_state_->GetBoolean(prefs::kPrintingEnabled);
726 print_job_manager_->set_printing_enabled(printing_enabled);
727 pref_change_registrar_.Add(prefs::kPrintingEnabled,
728 print_job_manager_.get());
[email protected]fd6159a2010-09-03 09:38:39729}
initial.commit09911bf2008-07-26 23:55:29730
initial.commit09911bf2008-07-26 23:55:29731void BrowserProcessImpl::CreateIconManager() {
732 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL);
733 created_icon_manager_ = true;
734 icon_manager_.reset(new IconManager);
735}
736
[email protected]a9bf67982010-07-06 10:13:00737void BrowserProcessImpl::CreateDebuggerWrapper(int port, bool useHttp) {
initial.commit09911bf2008-07-26 23:55:29738 DCHECK(debugger_wrapper_.get() == NULL);
739 created_debugger_wrapper_ = true;
740
[email protected]a9bf67982010-07-06 10:13:00741 debugger_wrapper_ = new DebuggerWrapper(port, useHttp);
initial.commit09911bf2008-07-26 23:55:29742}
743
[email protected]40ecc902009-03-16 13:42:47744void BrowserProcessImpl::CreateDevToolsManager() {
[email protected]73ee01522009-06-05 10:13:44745 DCHECK(devtools_manager_.get() == NULL);
[email protected]40ecc902009-03-16 13:42:47746 created_devtools_manager_ = true;
[email protected]73ee01522009-06-05 10:13:44747 devtools_manager_ = new DevToolsManager();
[email protected]40ecc902009-03-16 13:42:47748}
749
[email protected]8b8e7c92010-08-19 18:05:56750void BrowserProcessImpl::CreateSidebarManager() {
751 DCHECK(sidebar_manager_.get() == NULL);
752 created_sidebar_manager_ = true;
753 sidebar_manager_ = new SidebarManager();
754}
755
initial.commit09911bf2008-07-26 23:55:29756void BrowserProcessImpl::CreateGoogleURLTracker() {
757 DCHECK(google_url_tracker_.get() == NULL);
758 scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker);
759 google_url_tracker_.swap(google_url_tracker);
760}
[email protected]6641bf662009-08-21 00:34:09761
[email protected]c4ff4952010-01-08 19:12:47762void BrowserProcessImpl::CreateIntranetRedirectDetector() {
763 DCHECK(intranet_redirect_detector_.get() == NULL);
764 scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
765 new IntranetRedirectDetector);
766 intranet_redirect_detector_.swap(intranet_redirect_detector);
767}
768
[email protected]29672ab2009-10-30 03:44:03769void BrowserProcessImpl::CreateNotificationUIManager() {
770 DCHECK(notification_ui_manager_.get() == NULL);
[email protected]b0b2a3dd2011-01-06 00:30:05771 notification_ui_manager_.reset(NotificationUIManager::Create(local_state()));
772
[email protected]29672ab2009-10-30 03:44:03773 created_notification_ui_manager_ = true;
774}
775
[email protected]0b4d3382010-07-14 16:13:04776void BrowserProcessImpl::CreateTabCloseableStateWatcher() {
777 DCHECK(tab_closeable_state_watcher_.get() == NULL);
778 tab_closeable_state_watcher_.reset(TabCloseableStateWatcher::Create());
779}
780
[email protected]dbeebd52010-11-16 20:34:16781void BrowserProcessImpl::CreatePrintPreviewTabController() {
782 DCHECK(print_preview_tab_controller_.get() == NULL);
783 print_preview_tab_controller_ = new printing::PrintPreviewTabController();
784}
785
[email protected]a7a5e992010-12-09 23:39:51786void BrowserProcessImpl::CreateSafeBrowsingDetectionService() {
787 DCHECK(safe_browsing_detection_service_.get() == NULL);
788 // Set this flag to true so that we don't retry indefinitely to
789 // create the service class if there was an error.
790 created_safe_browsing_detection_service_ = true;
791
792 FilePath model_file_path;
793 Profile* profile = profile_manager() ?
794 profile_manager()->GetDefaultProfile() : NULL;
795 if (IsSafeBrowsingDetectionServiceEnabled() &&
796 PathService::Get(chrome::DIR_USER_DATA, &model_file_path) &&
797 profile && profile->GetRequestContext()) {
798 safe_browsing_detection_service_.reset(
799 safe_browsing::ClientSideDetectionService::Create(
800 model_file_path.Append(chrome::kSafeBrowsingPhishingModelFilename),
801 profile->GetRequestContext()));
802 }
803}
804
805bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() {
806 // The safe browsing client-side detection is enabled only if the switch is
807 // enabled, the user has opted in to UMA usage stats and SafeBrowsing
808 // is enabled.
809 Profile* profile = profile_manager() ?
810 profile_manager()->GetDefaultProfile() : NULL;
811 return (CommandLine::ForCurrentProcess()->HasSwitch(
812 switches::kEnableClientSidePhishingDetection) &&
813 metrics_service() && metrics_service()->reporting_active() &&
814 profile && profile->GetPrefs() &&
815 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled));
816}
817
[email protected]6641bf662009-08-21 00:34:09818// The BrowserProcess object must outlive the file thread so we use traits
819// which don't do any management.
[email protected]c56428f22010-06-16 02:17:23820DISABLE_RUNNABLE_METHOD_REFCOUNT(BrowserProcessImpl);
[email protected]6641bf662009-08-21 00:34:09821
[email protected]d55aaa132009-09-28 21:08:04822#if defined(IPC_MESSAGE_LOG_ENABLED)
823
824void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) {
825 // First enable myself.
826 if (enable)
[email protected]8e8bb6d2010-12-13 08:18:55827 IPC::Logging::GetInstance()->Enable();
[email protected]d55aaa132009-09-28 21:08:04828 else
[email protected]8e8bb6d2010-12-13 08:18:55829 IPC::Logging::GetInstance()->Disable();
[email protected]d55aaa132009-09-28 21:08:04830
831 // Now tell subprocesses. Messages to ChildProcess-derived
832 // processes must be done on the IO thread.
833 io_thread()->message_loop()->PostTask
834 (FROM_HERE,
835 NewRunnableMethod(
836 this,
837 &BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses,
838 enable));
839
840 // Finally, tell the renderers which don't derive from ChildProcess.
841 // Messages to the renderers must be done on the UI (main) thread.
[email protected]019191a2009-10-02 20:37:27842 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
843 !i.IsAtEnd(); i.Advance())
844 i.GetCurrentValue()->Send(new ViewMsg_SetIPCLoggingEnabled(enable));
[email protected]d55aaa132009-09-28 21:08:04845}
846
847// Helper for SetIPCLoggingEnabled.
848void BrowserProcessImpl::SetIPCLoggingEnabledForChildProcesses(bool enabled) {
[email protected]d04e7662010-10-10 22:24:48849 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]d55aaa132009-09-28 21:08:04850
[email protected]d27893f62010-07-03 05:47:42851 BrowserChildProcessHost::Iterator i; // default constr references a singleton
[email protected]34cf97d2009-09-29 22:46:11852 while (!i.Done()) {
853 i->Send(new PluginProcessMsg_SetIPCLoggingEnabled(enabled));
854 ++i;
[email protected]d55aaa132009-09-28 21:08:04855 }
856}
857
858#endif // IPC_MESSAGE_LOG_ENABLED
859
[email protected]6641bf662009-08-21 00:34:09860void BrowserProcessImpl::DoInspectorFilesCheck() {
861 // Runs on FILE thread.
862 DCHECK(file_thread_->message_loop() == MessageLoop::current());
863 bool result = false;
864
865 FilePath inspector_dir;
866 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) {
867 result = file_util::PathExists(inspector_dir);
868 }
869
[email protected]308080d2009-11-11 19:19:02870 have_inspector_files_ = result;
[email protected]6641bf662009-08-21 00:34:09871}
[email protected]bd48c2b02010-04-09 20:32:42872
[email protected]3cdacd42010-04-30 18:55:53873// Mac is currently not supported.
874#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:42875
876bool BrowserProcessImpl::CanAutorestartForUpdate() const {
877 // Check if browser is in the background and if it needs to be restarted to
878 // apply a pending update.
[email protected]c10fa3952010-08-24 16:52:53879 return BrowserList::size() == 0 && BrowserList::WillKeepAlive() &&
[email protected]c984d9f2010-07-20 20:52:20880 Upgrade::IsUpdatePendingRestart();
[email protected]bd48c2b02010-04-09 20:32:42881}
882
[email protected]5c08f222010-09-22 09:37:21883// Switches to add when auto-restarting Chrome.
[email protected]6c10c972010-08-11 04:15:47884const char* const kSwitchesToAddOnAutorestart[] = {
[email protected]f9a06842010-08-21 00:32:40885 switches::kNoStartupWindow
[email protected]bd48c2b02010-04-09 20:32:42886};
887
888void BrowserProcessImpl::RestartPersistentInstance() {
889 CommandLine* old_cl = CommandLine::ForCurrentProcess();
[email protected]3cdacd42010-04-30 18:55:53890 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram()));
[email protected]bd48c2b02010-04-09 20:32:42891
892 std::map<std::string, CommandLine::StringType> switches =
893 old_cl->GetSwitches();
894
[email protected]5c08f222010-09-22 09:37:21895 switches::RemoveSwitchesForAutostart(&switches);
[email protected]bd48c2b02010-04-09 20:32:42896
897 // Append the rest of the switches (along with their values, if any)
898 // to the new command line
899 for (std::map<std::string, CommandLine::StringType>::const_iterator i =
900 switches.begin(); i != switches.end(); ++i) {
901 CommandLine::StringType switch_value = i->second;
902 if (switch_value.length() > 0) {
[email protected]05076ba22010-07-30 05:59:57903 new_cl->AppendSwitchNative(i->first, i->second);
[email protected]bd48c2b02010-04-09 20:32:42904 } else {
[email protected]3cdacd42010-04-30 18:55:53905 new_cl->AppendSwitch(i->first);
[email protected]bd48c2b02010-04-09 20:32:42906 }
907 }
908
[email protected]6c10c972010-08-11 04:15:47909 // Ensure that our desired switches are set on the new process.
[email protected]5c08f222010-09-22 09:37:21910 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) {
[email protected]6c10c972010-08-11 04:15:47911 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i]))
912 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
913 }
[email protected]bd48c2b02010-04-09 20:32:42914
[email protected]3cdacd42010-04-30 18:55:53915 DLOG(WARNING) << "Shutting down current instance of the browser.";
916 BrowserList::CloseAllBrowsersAndExit();
917
918 // Transfer ownership to Upgrade.
919 Upgrade::SetNewCommandLine(new_cl.release());
[email protected]bd48c2b02010-04-09 20:32:42920}
921
922void BrowserProcessImpl::OnAutoupdateTimer() {
923 if (CanAutorestartForUpdate()) {
[email protected]3cdacd42010-04-30 18:55:53924 DLOG(WARNING) << "Detected update. Restarting browser.";
[email protected]bd48c2b02010-04-09 20:32:42925 RestartPersistentInstance();
926 }
927}
928
[email protected]3cdacd42010-04-30 18:55:53929#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)