Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/lifetime/application_lifetime.cc

Issue 796963002: Instrument some of the exit paths likely to suffer hangs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@end_session_instrument
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/lifetime/application_lifetime.h" 5 #include "chrome/browser/lifetime/application_lifetime.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 30 matching lines...) Expand all
41 #if defined(OS_CHROMEOS) 41 #if defined(OS_CHROMEOS)
42 #include "base/sys_info.h" 42 #include "base/sys_info.h"
43 #include "chrome/browser/chromeos/boot_times_loader.h" 43 #include "chrome/browser/chromeos/boot_times_loader.h"
44 #include "chromeos/dbus/dbus_thread_manager.h" 44 #include "chromeos/dbus/dbus_thread_manager.h"
45 #include "chromeos/dbus/session_manager_client.h" 45 #include "chromeos/dbus/session_manager_client.h"
46 #include "chromeos/dbus/update_engine_client.h" 46 #include "chromeos/dbus/update_engine_client.h"
47 #endif 47 #endif
48 48
49 #if defined(OS_WIN) 49 #if defined(OS_WIN)
50 #include "base/win/win_util.h" 50 #include "base/win/win_util.h"
51 #include "components/browser_watcher/exit_funnel.h"
51 #endif 52 #endif
52 53
53 namespace chrome { 54 namespace chrome {
54 namespace { 55 namespace {
55 56
56 #if !defined(OS_ANDROID) 57 #if !defined(OS_ANDROID)
57 // Returns true if all browsers can be closed without user interaction. 58 // Returns true if all browsers can be closed without user interaction.
58 // This currently checks if there is pending download, or if it needs to 59 // This currently checks if there is pending download, or if it needs to
59 // handle unload handler. 60 // handle unload handler.
60 bool AreAllBrowsersCloseable() { 61 bool AreAllBrowsersCloseable() {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // screen locker. 245 // screen locker.
245 if (!AreAllBrowsersCloseable()) 246 if (!AreAllBrowsersCloseable())
246 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); 247 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION);
247 else 248 else
248 browser_shutdown::OnShutdownStarting(browser_shutdown::BROWSER_EXIT); 249 browser_shutdown::OnShutdownStarting(browser_shutdown::BROWSER_EXIT);
249 AttemptExitInternal(true); 250 AttemptExitInternal(true);
250 } 251 }
251 #endif 252 #endif
252 253
253 void SessionEnding() { 254 void SessionEnding() {
255 #if defined(OS_WIN)
256 browser_watcher::ExitFunnel funnel(kBrowserExitCodesRegistryPath,
257 base::GetCurrentProcessHandle());
258 funnel.RecordEvent(L"SessionEnding");
259 #endif
254 // This is a time-limited shutdown where we need to write as much to 260 // This is a time-limited shutdown where we need to write as much to
255 // disk as we can as soon as we can, and where we must kill the 261 // disk as we can as soon as we can, and where we must kill the
256 // process within a hang timeout to avoid user prompts. 262 // process within a hang timeout to avoid user prompts.
257 263
258 // Start watching for hang during shutdown, and crash it if takes too long. 264 // Start watching for hang during shutdown, and crash it if takes too long.
259 // We disarm when |shutdown_watcher| object is destroyed, which is when we 265 // We disarm when |shutdown_watcher| object is destroyed, which is when we
260 // exit this function. 266 // exit this function.
261 ShutdownWatcherHelper shutdown_watcher; 267 ShutdownWatcherHelper shutdown_watcher;
262 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); 268 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90));
263 269
264 // EndSession is invoked once per frame. Only do something the first time. 270 // EndSession is invoked once per frame. Only do something the first time.
265 static bool already_ended = false; 271 static bool already_ended = false;
266 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 272 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852
267 // In this case, do nothing. 273 // In this case, do nothing.
268 if (already_ended || !content::NotificationService::current()) 274 if (already_ended || !content::NotificationService::current())
269 return; 275 return;
270 already_ended = true; 276 already_ended = true;
271 277
272 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); 278 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION);
273 279
274 content::NotificationService::current()->Notify( 280 content::NotificationService::current()->Notify(
275 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, 281 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
276 content::NotificationService::AllSources(), 282 content::NotificationService::AllSources(),
277 content::NotificationService::NoDetails()); 283 content::NotificationService::NoDetails());
278 284
285 #if defined(OS_WIN)
286 funnel.RecordEvent(L"EndSession");
287 #endif
279 // Write important data first. 288 // Write important data first.
280 g_browser_process->EndSession(); 289 g_browser_process->EndSession();
281 290
282 #if defined(OS_WIN) 291 #if defined(OS_WIN)
283 base::win::SetShouldCrashOnProcessDetach(false); 292 base::win::SetShouldCrashOnProcessDetach(false);
284 #endif 293 #endif
285 294
295 #if defined(OS_WIN)
296 // KillProcess ought to terminate the process without further ado, so if
297 // execution gets to this point, presumably this is normal exit.
298 funnel.RecordEvent(L"KillProcess");
299 #endif
300
286 // On Windows 7 and later, the system will consider the process ripe for 301 // On Windows 7 and later, the system will consider the process ripe for
287 // termination as soon as it hides or destroys its windows. Since any 302 // termination as soon as it hides or destroys its windows. Since any
288 // execution past that point will be non-deterministically cut short, we 303 // execution past that point will be non-deterministically cut short, we
289 // might as well put ourselves out of that misery deterministically. 304 // might as well put ourselves out of that misery deterministically.
290 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); 305 base::KillProcess(base::GetCurrentProcessHandle(), 0, false);
291 } 306 }
292 307
293 void IncrementKeepAliveCount() { 308 void IncrementKeepAliveCount() {
294 // Increment the browser process refcount as long as we're keeping the 309 // Increment the browser process refcount as long as we're keeping the
295 // application alive. 310 // application alive.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // environment is still active. 410 // environment is still active.
396 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) 411 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE)
397 return !ash::Shell::HasInstance(); 412 return !ash::Shell::HasInstance();
398 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) 413 else if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH)
399 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty(); 414 return BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->empty();
400 #endif 415 #endif
401 return true; 416 return true;
402 } 417 }
403 418
404 } // namespace chrome 419 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698