OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/browser_list.h" | 5 #include "chrome/browser/ui/browser_list.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 << "observer list modified during notification"; | 295 << "observer list modified during notification"; |
296 } | 296 } |
297 | 297 |
298 // static | 298 // static |
299 void BrowserList::MarkAsCleanShutdown() { | 299 void BrowserList::MarkAsCleanShutdown() { |
300 for (const_iterator i = begin(); i != end(); ++i) { | 300 for (const_iterator i = begin(); i != end(); ++i) { |
301 (*i)->profile()->MarkAsCleanShutdown(); | 301 (*i)->profile()->MarkAsCleanShutdown(); |
302 } | 302 } |
303 } | 303 } |
304 | 304 |
305 void BrowserList::AttemptExitInternal() { | 305 void BrowserList::AttemptExitInternal(bool restart) { |
| 306 PrefService* pref_service = g_browser_process->local_state(); |
| 307 pref_service->SetBoolean(prefs::kWasRestarted, restart); |
306 content::NotificationService::current()->Notify( | 308 content::NotificationService::current()->Notify( |
307 content::NOTIFICATION_APP_EXITING, | 309 content::NOTIFICATION_APP_EXITING, |
308 content::NotificationService::AllSources(), | 310 content::NotificationService::AllSources(), |
309 content::NotificationService::NoDetails()); | 311 content::NotificationService::NoDetails()); |
310 | 312 |
311 #if !defined(OS_MACOSX) | 313 #if !defined(OS_MACOSX) |
312 // On most platforms, closing all windows causes the application to exit. | 314 // On most platforms, closing all windows causes the application to exit. |
313 CloseAllBrowsers(); | 315 CloseAllBrowsers(); |
314 #else | 316 #else |
315 // On the Mac, the application continues to run once all windows are closed. | 317 // On the Mac, the application continues to run once all windows are closed. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 } | 474 } |
473 } | 475 } |
474 | 476 |
475 for (BrowserVector::const_iterator i = browsers_to_close.begin(); | 477 for (BrowserVector::const_iterator i = browsers_to_close.begin(); |
476 i != browsers_to_close.end(); ++i) { | 478 i != browsers_to_close.end(); ++i) { |
477 (*i)->window()->Close(); | 479 (*i)->window()->Close(); |
478 } | 480 } |
479 } | 481 } |
480 | 482 |
481 // static | 483 // static |
482 void BrowserList::AttemptUserExit() { | 484 void BrowserList::AttemptUserExit(bool restart) { |
483 #if defined(OS_CHROMEOS) | 485 #if defined(OS_CHROMEOS) |
484 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutStarted", false); | 486 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutStarted", false); |
485 // Write /tmp/uptime-logout-started as well. | 487 // Write /tmp/uptime-logout-started as well. |
486 const char kLogoutStarted[] = "logout-started"; | 488 const char kLogoutStarted[] = "logout-started"; |
487 chromeos::BootTimesLoader::Get()->RecordCurrentStats(kLogoutStarted); | 489 chromeos::BootTimesLoader::Get()->RecordCurrentStats(kLogoutStarted); |
488 | 490 |
489 // Login screen should show up in owner's locale. | 491 // Login screen should show up in owner's locale. |
490 PrefService* state = g_browser_process->local_state(); | 492 PrefService* state = g_browser_process->local_state(); |
491 if (state) { | 493 if (state) { |
492 std::string owner_locale = state->GetString(prefs::kOwnerLocale); | 494 std::string owner_locale = state->GetString(prefs::kOwnerLocale); |
493 if (!owner_locale.empty() && | 495 if (!owner_locale.empty() && |
494 state->GetString(prefs::kApplicationLocale) != owner_locale && | 496 state->GetString(prefs::kApplicationLocale) != owner_locale && |
495 !state->IsManagedPreference(prefs::kApplicationLocale)) { | 497 !state->IsManagedPreference(prefs::kApplicationLocale)) { |
496 state->SetString(prefs::kApplicationLocale, owner_locale); | 498 state->SetString(prefs::kApplicationLocale, owner_locale); |
497 state->SavePersistentPrefs(); | 499 state->SavePersistentPrefs(); |
498 } | 500 } |
499 } | 501 } |
500 g_session_manager_requested_shutdown = false; | 502 g_session_manager_requested_shutdown = false; |
501 if (FastShutdown()) | 503 if (FastShutdown()) |
502 return; | 504 return; |
503 #else | 505 #else |
504 // Reset the restart bit that might have been set in cancelled restart | 506 // Reset the restart bit that might have been set in cancelled restart |
505 // request. | 507 // request. |
506 PrefService* pref_service = g_browser_process->local_state(); | 508 PrefService* pref_service = g_browser_process->local_state(); |
507 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); | 509 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); |
508 #endif | 510 #endif |
509 AttemptExitInternal(); | 511 AttemptExitInternal(restart); |
510 } | 512 } |
511 | 513 |
512 // static | 514 // static |
513 void BrowserList::AttemptRestart() { | 515 void BrowserList::AttemptRestart() { |
514 if (CommandLine::ForCurrentProcess()->HasSwitch( | 516 if (CommandLine::ForCurrentProcess()->HasSwitch( |
515 switches::kEnableRestoreSessionState)) { | 517 switches::kEnableRestoreSessionState)) { |
516 BrowserVector::const_iterator it; | 518 BrowserVector::const_iterator it; |
517 for (it = begin(); it != end(); ++it) | 519 for (it = begin(); it != end(); ++it) |
518 (*it)->profile()->SaveSessionState(); | 520 (*it)->profile()->SaveSessionState(); |
519 } | 521 } |
520 | 522 |
521 #if defined(OS_CHROMEOS) | 523 #if defined(OS_CHROMEOS) |
522 // For CrOS instead of browser restart (which is not supported) perform a full | 524 // For CrOS instead of browser restart (which is not supported) perform a full |
523 // sign out. Session will be only restored if user has that setting set. | 525 // sign out. Session will be only restored if user has that setting set. |
524 // Same session restore behavior happens in case of full restart after update. | 526 // Same session restore behavior happens in case of full restart after update. |
525 AttemptUserExit(); | 527 AttemptUserExit(true); |
526 #else | 528 #else |
527 // Set the flag to restore state after the restart. | 529 // Set the flag to restore state after the restart. |
528 PrefService* pref_service = g_browser_process->local_state(); | 530 PrefService* pref_service = g_browser_process->local_state(); |
529 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); | 531 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); |
530 AttemptExit(); | 532 AttemptExit(true); |
531 #endif | 533 #endif |
532 } | 534 } |
533 | 535 |
534 // static | 536 // static |
535 void BrowserList::AttemptExit() { | 537 void BrowserList::AttemptExit(bool restart) { |
536 // If we know that all browsers can be closed without blocking, | 538 // If we know that all browsers can be closed without blocking, |
537 // don't notify users of crashes beyond this point. | 539 // don't notify users of crashes beyond this point. |
538 // Note that MarkAsCleanShutdown does not set UMA's exit cleanly bit | 540 // Note that MarkAsCleanShutdown does not set UMA's exit cleanly bit |
539 // so crashes during shutdown are still reported in UMA. | 541 // so crashes during shutdown are still reported in UMA. |
540 if (AreAllBrowsersCloseable()) | 542 if (AreAllBrowsersCloseable()) |
541 MarkAsCleanShutdown(); | 543 MarkAsCleanShutdown(); |
542 AttemptExitInternal(); | 544 AttemptExitInternal(restart); |
543 } | 545 } |
544 | 546 |
545 #if defined(OS_CHROMEOS) | 547 #if defined(OS_CHROMEOS) |
546 // A function called when SIGTERM is received. | 548 // A function called when SIGTERM is received. |
547 // static | 549 // static |
548 void BrowserList::ExitCleanly() { | 550 void BrowserList::ExitCleanly() { |
549 // We always mark exit cleanly because SessionManager may kill | 551 // We always mark exit cleanly because SessionManager may kill |
550 // chrome in 3 seconds after SIGTERM. | 552 // chrome in 3 seconds after SIGTERM. |
551 g_browser_process->EndSession(); | 553 g_browser_process->EndSession(); |
552 | 554 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 // If no more TabContents from Browsers, check the BackgroundPrintingManager. | 860 // If no more TabContents from Browsers, check the BackgroundPrintingManager. |
859 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { | 861 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { |
860 cur_ = *bg_printing_iterator_; | 862 cur_ = *bg_printing_iterator_; |
861 CHECK(cur_); | 863 CHECK(cur_); |
862 ++bg_printing_iterator_; | 864 ++bg_printing_iterator_; |
863 return; | 865 return; |
864 } | 866 } |
865 // Reached the end - no more TabContents. | 867 // Reached the end - no more TabContents. |
866 cur_ = NULL; | 868 cur_ = NULL; |
867 } | 869 } |
OLD | NEW |