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/download/download_service.h" | 13 #include "chrome/browser/download/download_service.h" |
14 #include "chrome/browser/metrics/thread_watcher.h" | 14 #include "chrome/browser/metrics/thread_watcher.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/printing/background_printing_manager.h" | 16 #include "chrome/browser/printing/background_printing_manager.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "content/browser/tab_contents/navigation_details.h" | 22 #include "content/browser/tab_contents/navigation_details.h" |
| 23 #include "content/public/browser/browser_shutdown.h" |
23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
24 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
26 #include "content/public/common/result_codes.h" | 27 #include "content/public/common/result_codes.h" |
27 | 28 |
28 #if defined(OS_MACOSX) | 29 #if defined(OS_MACOSX) |
29 #include "chrome/browser/chrome_browser_application_mac.h" | 30 #include "chrome/browser/chrome_browser_application_mac.h" |
30 #endif | 31 #endif |
31 | 32 |
32 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 542 |
542 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() | 543 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() |
543 // can be false in following cases. a) power-off b) signout from | 544 // can be false in following cases. a) power-off b) signout from |
544 // screen locker. | 545 // screen locker. |
545 if (!AreAllBrowsersCloseable()) | 546 if (!AreAllBrowsersCloseable()) |
546 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); | 547 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); |
547 AttemptExitInternal(); | 548 AttemptExitInternal(); |
548 } | 549 } |
549 #endif | 550 #endif |
550 | 551 |
551 static void TimeLimitedSessionEnding() { | 552 // static |
| 553 void BrowserList::SessionEnding() { |
| 554 // This is a time-limited shutdown where we need to write as much to |
| 555 // disk as we can as soon as we can, and where we must kill the |
| 556 // process within a hang timeout to avoid user prompts. |
| 557 |
552 // Start watching for hang during shutdown, and crash it if takes too long. | 558 // Start watching for hang during shutdown, and crash it if takes too long. |
553 // We disarm when |shutdown_watcher| object is destroyed, which is when we | 559 // We disarm when |shutdown_watcher| object is destroyed, which is when we |
554 // exit this function. | 560 // exit this function. |
555 ShutdownWatcherHelper shutdown_watcher; | 561 ShutdownWatcherHelper shutdown_watcher; |
556 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); | 562 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); |
557 | 563 |
558 // EndSession is invoked once per frame. Only do something the first time. | 564 // EndSession is invoked once per frame. Only do something the first time. |
559 static bool already_ended = false; | 565 static bool already_ended = false; |
560 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 | 566 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 |
561 // In this case, do nothing. | 567 // In this case, do nothing. |
(...skipping 13 matching lines...) Expand all Loading... |
575 | 581 |
576 BrowserList::CloseAllBrowsers(); | 582 BrowserList::CloseAllBrowsers(); |
577 | 583 |
578 // Send out notification. This is used during testing so that the test harness | 584 // Send out notification. This is used during testing so that the test harness |
579 // can properly shutdown before we exit. | 585 // can properly shutdown before we exit. |
580 content::NotificationService::current()->Notify( | 586 content::NotificationService::current()->Notify( |
581 chrome::NOTIFICATION_SESSION_END, | 587 chrome::NOTIFICATION_SESSION_END, |
582 content::NotificationService::AllSources(), | 588 content::NotificationService::AllSources(), |
583 content::NotificationService::NoDetails()); | 589 content::NotificationService::NoDetails()); |
584 | 590 |
585 // And shutdown. | 591 // This will end by terminating the process. |
586 browser_shutdown::Shutdown(); | 592 content::ImmediateShutdownAndExitProcess(); |
587 } | 593 } |
588 | 594 |
589 // static | 595 // static |
590 void BrowserList::SessionEnding() { | |
591 TimeLimitedSessionEnding(); | |
592 | |
593 #if defined(OS_WIN) | |
594 // At this point the message loop is still running yet we've shut everything | |
595 // down. If any messages are processed we'll likely crash. Exit now. | |
596 ExitProcess(content::RESULT_CODE_NORMAL_EXIT); | |
597 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | |
598 _exit(content::RESULT_CODE_NORMAL_EXIT); | |
599 #else | |
600 NOTIMPLEMENTED(); | |
601 #endif | |
602 } | |
603 | |
604 // static | |
605 bool BrowserList::HasBrowserWithProfile(Profile* profile) { | 596 bool BrowserList::HasBrowserWithProfile(Profile* profile) { |
606 return FindBrowserMatching(BrowserList::begin(), | 597 return FindBrowserMatching(BrowserList::begin(), |
607 BrowserList::end(), | 598 BrowserList::end(), |
608 profile, | 599 profile, |
609 Browser::FEATURE_NONE, | 600 Browser::FEATURE_NONE, |
610 kMatchAny) != NULL; | 601 kMatchAny) != NULL; |
611 } | 602 } |
612 | 603 |
613 // static | 604 // static |
614 int BrowserList::keep_alive_count_ = 0; | 605 int BrowserList::keep_alive_count_ = 0; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 // If no more TabContents from Browsers, check the BackgroundPrintingManager. | 848 // If no more TabContents from Browsers, check the BackgroundPrintingManager. |
858 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { | 849 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { |
859 cur_ = *bg_printing_iterator_; | 850 cur_ = *bg_printing_iterator_; |
860 CHECK(cur_); | 851 CHECK(cur_); |
861 ++bg_printing_iterator_; | 852 ++bg_printing_iterator_; |
862 return; | 853 return; |
863 } | 854 } |
864 // Reached the end - no more TabContents. | 855 // Reached the end - no more TabContents. |
865 cur_ = NULL; | 856 cur_ = NULL; |
866 } | 857 } |
OLD | NEW |