Chromium Code Reviews| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_shutdown.h" | 12 #include "chrome/browser/browser_shutdown.h" |
| 13 #include "chrome/browser/metrics/metrics_service.h" | |
| 13 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/printing/background_printing_manager.h" | 15 #include "chrome/browser/printing/background_printing_manager.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "content/browser/renderer_host/render_process_host.h" | 20 #include "content/browser/renderer_host/render_process_host.h" |
| 20 #include "content/browser/tab_contents/navigation_details.h" | 21 #include "content/browser/tab_contents/navigation_details.h" |
| 21 #include "content/common/notification_registrar.h" | 22 #include "content/common/notification_registrar.h" |
| 22 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 | 249 |
| 249 // Send out notifications after add has occurred. Do some basic checking to | 250 // Send out notifications after add has occurred. Do some basic checking to |
| 250 // try to catch evil observers that change the list from under us. | 251 // try to catch evil observers that change the list from under us. |
| 251 size_t original_count = observers_.size(); | 252 size_t original_count = observers_.size(); |
| 252 FOR_EACH_OBSERVER(Observer, observers_, OnBrowserAdded(browser)); | 253 FOR_EACH_OBSERVER(Observer, observers_, OnBrowserAdded(browser)); |
| 253 DCHECK_EQ(original_count, observers_.size()) | 254 DCHECK_EQ(original_count, observers_.size()) |
| 254 << "observer list modified during notification"; | 255 << "observer list modified during notification"; |
| 255 } | 256 } |
| 256 | 257 |
| 257 // static | 258 // static |
| 258 void BrowserList::MarkAsCleanShutdown() { | 259 void BrowserList::MarkAsCleanShutdownInUserProfiles() { |
| 259 for (const_iterator i = begin(); i != end(); ++i) { | 260 for (const_iterator i = begin(); i != end(); ++i) { |
| 260 (*i)->profile()->MarkAsCleanShutdown(); | 261 (*i)->profile()->MarkAsCleanShutdown(); |
| 261 } | 262 } |
| 262 } | 263 } |
| 263 | 264 |
| 264 void BrowserList::AttemptExitInternal() { | 265 void BrowserList::AttemptExitInternal() { |
| 265 NotificationService::current()->Notify( | 266 NotificationService::current()->Notify( |
| 266 NotificationType::APP_EXITING, | 267 NotificationType::APP_EXITING, |
| 267 NotificationService::AllSources(), | 268 NotificationService::AllSources(), |
| 268 NotificationService::NoDetails()); | 269 NotificationService::NoDetails()); |
| 269 | 270 |
| 270 #if !defined(OS_MACOSX) | 271 #if !defined(OS_MACOSX) |
| 271 // On most platforms, closing all windows causes the application to exit. | 272 // On most platforms, closing all windows causes the application to exit. |
| 272 CloseAllBrowsers(); | 273 CloseAllBrowsers(); |
| 273 #else | 274 #else |
| 274 // On the Mac, the application continues to run once all windows are closed. | 275 // On the Mac, the application continues to run once all windows are closed. |
| 275 // Terminate will result in a CloseAllBrowsers() call, and once (and if) | 276 // Terminate will result in a CloseAllBrowsers() call, and once (and if) |
| 276 // that is done, will cause the application to exit cleanly. | 277 // that is done, will cause the application to exit cleanly. |
| 277 chrome_browser_application_mac::Terminate(); | 278 chrome_browser_application_mac::Terminate(); |
| 278 #endif | 279 #endif |
| 279 } | 280 } |
| 280 | 281 |
| 281 // static | 282 // static |
| 282 void BrowserList::NotifyAndTerminate(bool fast_path) { | 283 void BrowserList::NotifyAndTerminate(bool fast_path) { |
| 283 #if defined(OS_CHROMEOS) | 284 #if defined(OS_CHROMEOS) |
| 284 if (!signout) return; | 285 if (!signout) return; |
|
jar (doing other things)
2011/06/29 04:00:09
style nit: put return on next line, to be more con
| |
| 285 NotifyWindowManagerAboutSignout(); | |
| 286 #endif | 286 #endif |
| 287 | 287 |
| 288 if (fast_path) { | 288 if (fast_path) { |
| 289 NotificationService::current()->Notify(NotificationType::APP_TERMINATING, | 289 NotificationService::current()->Notify(NotificationType::APP_TERMINATING, |
| 290 NotificationService::AllSources(), | 290 NotificationService::AllSources(), |
| 291 NotificationService::NoDetails()); | 291 NotificationService::NoDetails()); |
| 292 } | 292 } |
| 293 | 293 |
| 294 #if defined(OS_CHROMEOS) | 294 #if defined(OS_CHROMEOS) |
| 295 NotifyWindowManagerAboutSignout(); | |
| 295 chromeos::CrosLibrary* cros_library = chromeos::CrosLibrary::Get(); | 296 chromeos::CrosLibrary* cros_library = chromeos::CrosLibrary::Get(); |
| 296 if (cros_library->EnsureLoaded()) { | 297 if (cros_library->EnsureLoaded()) { |
| 297 // If update has been installed, reboot, otherwise, sign out. | 298 // If update has been installed, reboot, otherwise, sign out. |
| 298 if (cros_library->GetUpdateLibrary()->status().status == | 299 if (cros_library->GetUpdateLibrary()->status().status == |
| 299 chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT) { | 300 chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT) { |
| 300 cros_library->GetUpdateLibrary()->RebootAfterUpdate(); | 301 cros_library->GetUpdateLibrary()->RebootAfterUpdate(); |
| 301 } else { | 302 } else { |
| 302 cros_library->GetLoginLibrary()->StopSession(""); | 303 cros_library->GetLoginLibrary()->StopSession(""); |
| 303 } | 304 } |
| 304 return; | 305 return; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 PrefService* state = g_browser_process->local_state(); | 433 PrefService* state = g_browser_process->local_state(); |
| 433 if (state) { | 434 if (state) { |
| 434 std::string owner_locale = state->GetString(prefs::kOwnerLocale); | 435 std::string owner_locale = state->GetString(prefs::kOwnerLocale); |
| 435 if (!owner_locale.empty() && | 436 if (!owner_locale.empty() && |
| 436 state->GetString(prefs::kApplicationLocale) != owner_locale && | 437 state->GetString(prefs::kApplicationLocale) != owner_locale && |
| 437 !state->IsManagedPreference(prefs::kApplicationLocale)) { | 438 !state->IsManagedPreference(prefs::kApplicationLocale)) { |
| 438 state->SetString(prefs::kApplicationLocale, owner_locale); | 439 state->SetString(prefs::kApplicationLocale, owner_locale); |
| 439 state->ScheduleSavePersistentPrefs(); | 440 state->ScheduleSavePersistentPrefs(); |
| 440 } | 441 } |
| 441 } | 442 } |
| 442 if (FastShutdown()) { | 443 if (FastShutdown()) |
| 443 return; | 444 return; |
| 444 } | |
| 445 #else | 445 #else |
| 446 // Reset the restart bit that might have been set in cancelled restart | 446 // Reset the restart bit that might have been set in cancelled restart |
| 447 // request. | 447 // request. |
| 448 PrefService* pref_service = g_browser_process->local_state(); | 448 PrefService* pref_service = g_browser_process->local_state(); |
| 449 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); | 449 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, false); |
| 450 #endif | 450 #endif |
| 451 AttemptExitInternal(); | 451 AttemptExitInternal(); |
| 452 } | 452 } |
| 453 | 453 |
| 454 // static | 454 // static |
| 455 void BrowserList::AttemptRestart() { | 455 void BrowserList::AttemptRestart() { |
| 456 #if defined(OS_CHROMEOS) | 456 #if defined(OS_CHROMEOS) |
| 457 // For CrOS instead of browser restart (which is not supported) perform a full | 457 // For CrOS instead of browser restart (which is not supported) perform a full |
| 458 // sign out. Session will be only restored if user has that setting set. | 458 // sign out. Session will be only restored if user has that setting set. |
| 459 // Same session restore behavior happens in case of full restart after update. | 459 // Same session restore behavior happens in case of full restart after update. |
| 460 AttemptUserExit(); | 460 AttemptUserExit(); |
| 461 #else | 461 #else |
| 462 // Set the flag to restore state after the restart. | 462 // Set the flag to restore state after the restart. |
| 463 PrefService* pref_service = g_browser_process->local_state(); | 463 PrefService* pref_service = g_browser_process->local_state(); |
| 464 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); | 464 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); |
| 465 AttemptExit(); | 465 AttemptExit(); |
| 466 #endif | 466 #endif |
| 467 } | 467 } |
| 468 | 468 |
| 469 // static | 469 // static |
| 470 void BrowserList::AttemptExit() { | 470 void BrowserList::AttemptExit() { |
| 471 // If we know that all browsers can be closed without blocking, | 471 // If we know that all browsers can be closed without blocking, |
| 472 // don't notify users of crashes beyond this point. | 472 // don't notify users of crashes beyond this point. Note that |
| 473 // Note that MarkAsCleanShutdown does not set UMA's exit cleanly bit | 473 // MarkAsCleanShutdownInUserProfiles does not set UMA's exit cleanly |
| 474 // so crashes during shutdown are still reported in UMA. | 474 // bit so crashes during shutdown are still reported in UMA. |
| 475 if (AreAllBrowsersCloseable()) | 475 if (AreAllBrowsersCloseable()) |
| 476 MarkAsCleanShutdown(); | 476 MarkAsCleanShutdownInUserProfiles(); |
| 477 AttemptExitInternal(); | 477 AttemptExitInternal(); |
| 478 } | 478 } |
| 479 | 479 |
| 480 #if defined(OS_CHROMEOS) | 480 #if defined(OS_CHROMEOS) |
| 481 // static | 481 // static |
| 482 void BrowserList::ExitCleanly() { | 482 void BrowserList::ExitCleanly() { |
| 483 // We always mark exit cleanly. | 483 // We always mark exit cleanly. |
| 484 MarkAsCleanShutdown(); | 484 MarkAsCleanShutdownInUserProfiles(); |
| 485 // Don't report UMA crash beyond this point. SessionManager may kill | |
| 486 // chrome after this point. | |
| 487 MetricsService* metrics = g_browser_process->metrics_service(); | |
| 488 if (metrics) | |
| 489 metrics->LogCleanShutdown(); | |
| 485 AttemptExitInternal(); | 490 AttemptExitInternal(); |
| 486 } | 491 } |
| 487 #endif | 492 #endif |
| 488 | 493 |
| 489 // static | 494 // static |
| 490 void BrowserList::SessionEnding() { | 495 void BrowserList::SessionEnding() { |
| 491 // EndSession is invoked once per frame. Only do something the first time. | 496 // EndSession is invoked once per frame. Only do something the first time. |
| 492 static bool already_ended = false; | 497 static bool already_ended = false; |
| 493 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 | 498 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 |
| 494 // In this case, do nothing. | 499 // In this case, do nothing. |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 // If no more TabContents from Browsers, check the BackgroundPrintingManager. | 731 // If no more TabContents from Browsers, check the BackgroundPrintingManager. |
| 727 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { | 732 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { |
| 728 cur_ = *bg_printing_iterator_; | 733 cur_ = *bg_printing_iterator_; |
| 729 CHECK(cur_); | 734 CHECK(cur_); |
| 730 ++bg_printing_iterator_; | 735 ++bg_printing_iterator_; |
| 731 return; | 736 return; |
| 732 } | 737 } |
| 733 // Reached the end - no more TabContents. | 738 // Reached the end - no more TabContents. |
| 734 cur_ = NULL; | 739 cur_ = NULL; |
| 735 } | 740 } |
| OLD | NEW |