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

Side by Side Diff: chrome/browser/ui/browser_list.cc

Issue 8745015: Store the "browser autorestarted, last session must be restored" information in a preference. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
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
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
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
Finnur 2011/11/30 18:32:04 nit: shouldn't we keep this line break? nit: can y
marja 2011/12/02 09:23:41 Done. Braces removed in the not-yet-committed CL (
522 #if defined(OS_CHROMEOS) 523 #if defined(OS_CHROMEOS)
523 // 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
524 // 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.
525 // 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.
526 AttemptUserExit(); 527 AttemptUserExit(true);
527 #else 528 #else
528 // Set the flag to restore state after the restart. 529 // Set the flag to restore state after the restart.
529 PrefService* pref_service = g_browser_process->local_state(); 530 PrefService* pref_service = g_browser_process->local_state();
530 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); 531 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true);
531 AttemptExit(); 532 AttemptExit(true);
532 #endif 533 #endif
533 } 534 }
534 535
535 // static 536 // static
536 void BrowserList::AttemptExit() { 537 void BrowserList::AttemptExit(bool restart) {
537 // If we know that all browsers can be closed without blocking, 538 // If we know that all browsers can be closed without blocking,
538 // don't notify users of crashes beyond this point. 539 // don't notify users of crashes beyond this point.
539 // Note that MarkAsCleanShutdown does not set UMA's exit cleanly bit 540 // Note that MarkAsCleanShutdown does not set UMA's exit cleanly bit
540 // so crashes during shutdown are still reported in UMA. 541 // so crashes during shutdown are still reported in UMA.
541 if (AreAllBrowsersCloseable()) 542 if (AreAllBrowsersCloseable())
542 MarkAsCleanShutdown(); 543 MarkAsCleanShutdown();
543 AttemptExitInternal(); 544 AttemptExitInternal(restart);
544 } 545 }
545 546
546 #if defined(OS_CHROMEOS) 547 #if defined(OS_CHROMEOS)
547 // A function called when SIGTERM is received. 548 // A function called when SIGTERM is received.
548 // static 549 // static
549 void BrowserList::ExitCleanly() { 550 void BrowserList::ExitCleanly() {
550 // We always mark exit cleanly because SessionManager may kill 551 // We always mark exit cleanly because SessionManager may kill
551 // chrome in 3 seconds after SIGTERM. 552 // chrome in 3 seconds after SIGTERM.
552 g_browser_process->EndSession(); 553 g_browser_process->EndSession();
553 554
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 // If no more TabContents from Browsers, check the BackgroundPrintingManager. 860 // If no more TabContents from Browsers, check the BackgroundPrintingManager.
860 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { 861 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) {
861 cur_ = *bg_printing_iterator_; 862 cur_ = *bg_printing_iterator_;
862 CHECK(cur_); 863 CHECK(cur_);
863 ++bg_printing_iterator_; 864 ++bg_printing_iterator_;
864 return; 865 return;
865 } 866 }
866 // Reached the end - no more TabContents. 867 // Reached the end - no more TabContents.
867 cur_ = NULL; 868 cur_ = NULL;
868 } 869 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698