OLD | NEW |
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 AttemptExitInternal(true); | 240 AttemptExitInternal(true); |
241 } | 241 } |
242 #endif | 242 #endif |
243 | 243 |
244 #if !defined(OS_ANDROID) | 244 #if !defined(OS_ANDROID) |
245 void SessionEnding() { | 245 void SessionEnding() { |
246 // This is a time-limited shutdown where we need to write as much to | 246 // This is a time-limited shutdown where we need to write as much to |
247 // disk as we can as soon as we can, and where we must kill the | 247 // disk as we can as soon as we can, and where we must kill the |
248 // process within a hang timeout to avoid user prompts. | 248 // process within a hang timeout to avoid user prompts. |
249 | 249 |
250 // Start watching for hang during shutdown, and crash it if takes too long. | |
251 // We disarm when |shutdown_watcher| object is destroyed, which is when we | |
252 // exit this function. | |
253 ShutdownWatcherHelper shutdown_watcher; | |
254 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); | |
255 | |
256 // EndSession is invoked once per frame. Only do something the first time. | 250 // EndSession is invoked once per frame. Only do something the first time. |
257 static bool already_ended = false; | 251 static bool already_ended = false; |
258 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 | 252 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 |
259 // In this case, do nothing. | 253 // In this case, do nothing. |
260 if (already_ended || !content::NotificationService::current()) | 254 if (already_ended || !content::NotificationService::current()) |
261 return; | 255 return; |
262 already_ended = true; | 256 already_ended = true; |
263 | 257 |
| 258 // ~ShutdownWatcherHelper uses IO (it joins a thread). We'll only trigger that |
| 259 // if Terminate() fails, which leaves us in a weird state, or the OS is going |
| 260 // to kill us soon. Either way we don't care about that here. |
| 261 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 262 |
| 263 // Start watching for hang during shutdown, and crash it if takes too long. |
| 264 // We disarm when |shutdown_watcher| object is destroyed, which is when we |
| 265 // exit this function. |
| 266 ShutdownWatcherHelper shutdown_watcher; |
| 267 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); |
| 268 |
264 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); | 269 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); |
265 | 270 |
266 content::NotificationService::current()->Notify( | 271 content::NotificationService::current()->Notify( |
267 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | 272 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
268 content::NotificationService::AllSources(), | 273 content::NotificationService::AllSources(), |
269 content::NotificationService::NoDetails()); | 274 content::NotificationService::NoDetails()); |
270 | 275 |
271 // Write important data first. | 276 // Write important data first. |
272 g_browser_process->EndSession(); | 277 g_browser_process->EndSession(); |
273 | 278 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 void OnAppExiting() { | 348 void OnAppExiting() { |
344 static bool notified = false; | 349 static bool notified = false; |
345 if (notified) | 350 if (notified) |
346 return; | 351 return; |
347 notified = true; | 352 notified = true; |
348 HandleAppExitingForPlatform(); | 353 HandleAppExitingForPlatform(); |
349 } | 354 } |
350 #endif // !defined(OS_ANDROID) | 355 #endif // !defined(OS_ANDROID) |
351 | 356 |
352 } // namespace chrome | 357 } // namespace chrome |
OLD | NEW |