| 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(bool restart) { | 305 void BrowserList::AttemptExitInternal() { |
| 306 PrefService* pref_service = g_browser_process->local_state(); | |
| 307 pref_service->SetBoolean(prefs::kWasRestarted, restart); | |
| 308 content::NotificationService::current()->Notify( | 306 content::NotificationService::current()->Notify( |
| 309 content::NOTIFICATION_APP_EXITING, | 307 content::NOTIFICATION_APP_EXITING, |
| 310 content::NotificationService::AllSources(), | 308 content::NotificationService::AllSources(), |
| 311 content::NotificationService::NoDetails()); | 309 content::NotificationService::NoDetails()); |
| 312 | 310 |
| 313 #if !defined(OS_MACOSX) | 311 #if !defined(OS_MACOSX) |
| 314 // On most platforms, closing all windows causes the application to exit. | 312 // On most platforms, closing all windows causes the application to exit. |
| 315 CloseAllBrowsers(); | 313 CloseAllBrowsers(); |
| 316 #else | 314 #else |
| 317 // On the Mac, the application continues to run once all windows are closed. | 315 // 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... |
| 474 } | 472 } |
| 475 } | 473 } |
| 476 | 474 |
| 477 for (BrowserVector::const_iterator i = browsers_to_close.begin(); | 475 for (BrowserVector::const_iterator i = browsers_to_close.begin(); |
| 478 i != browsers_to_close.end(); ++i) { | 476 i != browsers_to_close.end(); ++i) { |
| 479 (*i)->window()->Close(); | 477 (*i)->window()->Close(); |
| 480 } | 478 } |
| 481 } | 479 } |
| 482 | 480 |
| 483 // static | 481 // static |
| 484 void BrowserList::AttemptUserExit(bool restart) { | 482 void BrowserList::AttemptUserExit() { |
| 485 #if defined(OS_CHROMEOS) | 483 #if defined(OS_CHROMEOS) |
| 486 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutStarted", false); | 484 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutStarted", false); |
| 487 // Write /tmp/uptime-logout-started as well. | 485 // Write /tmp/uptime-logout-started as well. |
| 488 const char kLogoutStarted[] = "logout-started"; | 486 const char kLogoutStarted[] = "logout-started"; |
| 489 chromeos::BootTimesLoader::Get()->RecordCurrentStats(kLogoutStarted); | 487 chromeos::BootTimesLoader::Get()->RecordCurrentStats(kLogoutStarted); |
| 490 | 488 |
| 491 // Login screen should show up in owner's locale. | 489 // Login screen should show up in owner's locale. |
| 492 PrefService* state = g_browser_process->local_state(); | 490 PrefService* state = g_browser_process->local_state(); |
| 493 if (state) { | 491 if (state) { |
| 494 std::string owner_locale = state->GetString(prefs::kOwnerLocale); | 492 std::string owner_locale = state->GetString(prefs::kOwnerLocale); |
| 495 if (!owner_locale.empty() && | 493 if (!owner_locale.empty() && |
| 496 state->GetString(prefs::kApplicationLocale) != owner_locale && | 494 state->GetString(prefs::kApplicationLocale) != owner_locale && |
| 497 !state->IsManagedPreference(prefs::kApplicationLocale)) { | 495 !state->IsManagedPreference(prefs::kApplicationLocale)) { |
| 498 state->SetString(prefs::kApplicationLocale, owner_locale); | 496 state->SetString(prefs::kApplicationLocale, owner_locale); |
| 499 state->SavePersistentPrefs(); | 497 state->SavePersistentPrefs(); |
| 500 } | 498 } |
| 501 } | 499 } |
| 502 g_session_manager_requested_shutdown = false; | 500 g_session_manager_requested_shutdown = false; |
| 503 if (FastShutdown()) | 501 if (FastShutdown()) |
| 504 return; | 502 return; |
| 505 #else | 503 #else |
| 506 // Reset the restart bit that might have been set in cancelled restart | 504 // Reset the restart bit that might have been set in cancelled restart |
| 507 // request. | 505 // request. |
| 508 PrefService* pref_service = g_browser_process->local_state(); | 506 PrefService* pref_service = g_browser_process->local_state(); |
| 509 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); | 507 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); |
| 510 #endif | 508 #endif |
| 511 AttemptExitInternal(restart); | 509 AttemptExitInternal(); |
| 512 } | 510 } |
| 513 | 511 |
| 514 // static | 512 // static |
| 515 void BrowserList::AttemptRestart() { | 513 void BrowserList::AttemptRestart() { |
| 516 if (CommandLine::ForCurrentProcess()->HasSwitch( | 514 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 517 switches::kEnableRestoreSessionState)) { | 515 switches::kEnableRestoreSessionState)) { |
| 518 BrowserVector::const_iterator it; | 516 BrowserVector::const_iterator it; |
| 519 for (it = begin(); it != end(); ++it) | 517 for (it = begin(); it != end(); ++it) |
| 520 (*it)->profile()->SaveSessionState(); | 518 (*it)->profile()->SaveSessionState(); |
| 521 } | 519 } |
| 522 | 520 |
| 521 PrefService* pref_service = g_browser_process->local_state(); |
| 522 pref_service->SetBoolean(prefs::kWasRestarted, true); |
| 523 pref_service->ScheduleSavePersistentPrefs(); |
| 524 |
| 523 #if defined(OS_CHROMEOS) | 525 #if defined(OS_CHROMEOS) |
| 524 // For CrOS instead of browser restart (which is not supported) perform a full | 526 // For CrOS instead of browser restart (which is not supported) perform a full |
| 525 // sign out. Session will be only restored if user has that setting set. | 527 // sign out. Session will be only restored if user has that setting set. |
| 526 // Same session restore behavior happens in case of full restart after update. | 528 // Same session restore behavior happens in case of full restart after update. |
| 527 AttemptUserExit(true); | 529 AttemptUserExit(); |
| 528 #else | 530 #else |
| 529 // Set the flag to restore state after the restart. | 531 // Set the flag to restore state after the restart. |
| 530 PrefService* pref_service = g_browser_process->local_state(); | |
| 531 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); | 532 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); |
| 532 AttemptExit(true); | 533 AttemptExit(); |
| 533 #endif | 534 #endif |
| 534 } | 535 } |
| 535 | 536 |
| 536 // static | 537 // static |
| 537 void BrowserList::AttemptExit(bool restart) { | 538 void BrowserList::AttemptExit() { |
| 538 // If we know that all browsers can be closed without blocking, | 539 // If we know that all browsers can be closed without blocking, |
| 539 // don't notify users of crashes beyond this point. | 540 // don't notify users of crashes beyond this point. |
| 540 // Note that MarkAsCleanShutdown does not set UMA's exit cleanly bit | 541 // Note that MarkAsCleanShutdown does not set UMA's exit cleanly bit |
| 541 // so crashes during shutdown are still reported in UMA. | 542 // so crashes during shutdown are still reported in UMA. |
| 542 if (AreAllBrowsersCloseable()) | 543 if (AreAllBrowsersCloseable()) |
| 543 MarkAsCleanShutdown(); | 544 MarkAsCleanShutdown(); |
| 544 AttemptExitInternal(restart); | 545 AttemptExitInternal(); |
| 545 } | 546 } |
| 546 | 547 |
| 547 #if defined(OS_CHROMEOS) | 548 #if defined(OS_CHROMEOS) |
| 548 // A function called when SIGTERM is received. | 549 // A function called when SIGTERM is received. |
| 549 // static | 550 // static |
| 550 void BrowserList::ExitCleanly() { | 551 void BrowserList::ExitCleanly() { |
| 551 // We always mark exit cleanly because SessionManager may kill | 552 // We always mark exit cleanly because SessionManager may kill |
| 552 // chrome in 3 seconds after SIGTERM. | 553 // chrome in 3 seconds after SIGTERM. |
| 553 g_browser_process->EndSession(); | 554 g_browser_process->EndSession(); |
| 554 | 555 |
| 555 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() | 556 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() |
| 556 // can be false in following cases. a) power-off b) signout from | 557 // can be false in following cases. a) power-off b) signout from |
| 557 // screen locker. | 558 // screen locker. |
| 558 if (!AreAllBrowsersCloseable()) | 559 if (!AreAllBrowsersCloseable()) |
| 559 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); | 560 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); |
| 560 AttemptExitInternal(false); | 561 AttemptExitInternal(); |
| 561 } | 562 } |
| 562 #endif | 563 #endif |
| 563 | 564 |
| 564 // static | 565 // static |
| 565 void BrowserList::SessionEnding() { | 566 void BrowserList::SessionEnding() { |
| 566 // This is a time-limited shutdown where we need to write as much to | 567 // This is a time-limited shutdown where we need to write as much to |
| 567 // disk as we can as soon as we can, and where we must kill the | 568 // disk as we can as soon as we can, and where we must kill the |
| 568 // process within a hang timeout to avoid user prompts. | 569 // process within a hang timeout to avoid user prompts. |
| 569 | 570 |
| 570 // Start watching for hang during shutdown, and crash it if takes too long. | 571 // Start watching for hang during shutdown, and crash it if takes too long. |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 // If no more TabContents from Browsers, check the BackgroundPrintingManager. | 861 // If no more TabContents from Browsers, check the BackgroundPrintingManager. |
| 861 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { | 862 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { |
| 862 cur_ = *bg_printing_iterator_; | 863 cur_ = *bg_printing_iterator_; |
| 863 CHECK(cur_); | 864 CHECK(cur_); |
| 864 ++bg_printing_iterator_; | 865 ++bg_printing_iterator_; |
| 865 return; | 866 return; |
| 866 } | 867 } |
| 867 // Reached the end - no more TabContents. | 868 // Reached the end - no more TabContents. |
| 868 cur_ = NULL; | 869 cur_ = NULL; |
| 869 } | 870 } |
| OLD | NEW |