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" | |
24 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
25 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
27 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
28 | 27 |
29 #if defined(OS_MACOSX) | 28 #if defined(OS_MACOSX) |
30 #include "chrome/browser/chrome_browser_application_mac.h" | 29 #include "chrome/browser/chrome_browser_application_mac.h" |
31 #endif | 30 #endif |
32 | 31 |
33 #if defined(OS_CHROMEOS) | 32 #if defined(OS_CHROMEOS) |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 541 |
543 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() | 542 // Don't block when SIGTERM is received. AreaAllBrowsersCloseable() |
544 // can be false in following cases. a) power-off b) signout from | 543 // can be false in following cases. a) power-off b) signout from |
545 // screen locker. | 544 // screen locker. |
546 if (!AreAllBrowsersCloseable()) | 545 if (!AreAllBrowsersCloseable()) |
547 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); | 546 browser_shutdown::OnShutdownStarting(browser_shutdown::END_SESSION); |
548 AttemptExitInternal(); | 547 AttemptExitInternal(); |
549 } | 548 } |
550 #endif | 549 #endif |
551 | 550 |
552 // static | 551 static void TimeLimitedSessionEnding() { |
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 | |
558 // Start watching for hang during shutdown, and crash it if takes too long. | 552 // Start watching for hang during shutdown, and crash it if takes too long. |
559 // We disarm when |shutdown_watcher| object is destroyed, which is when we | 553 // We disarm when |shutdown_watcher| object is destroyed, which is when we |
560 // exit this function. | 554 // exit this function. |
561 ShutdownWatcherHelper shutdown_watcher; | 555 ShutdownWatcherHelper shutdown_watcher; |
562 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); | 556 shutdown_watcher.Arm(base::TimeDelta::FromSeconds(90)); |
563 | 557 |
564 // EndSession is invoked once per frame. Only do something the first time. | 558 // EndSession is invoked once per frame. Only do something the first time. |
565 static bool already_ended = false; | 559 static bool already_ended = false; |
566 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 | 560 // We may get called in the middle of shutdown, e.g. http://crbug.com/70852 |
567 // In this case, do nothing. | 561 // In this case, do nothing. |
(...skipping 13 matching lines...) Expand all Loading... |
581 | 575 |
582 BrowserList::CloseAllBrowsers(); | 576 BrowserList::CloseAllBrowsers(); |
583 | 577 |
584 // Send out notification. This is used during testing so that the test harness | 578 // Send out notification. This is used during testing so that the test harness |
585 // can properly shutdown before we exit. | 579 // can properly shutdown before we exit. |
586 content::NotificationService::current()->Notify( | 580 content::NotificationService::current()->Notify( |
587 chrome::NOTIFICATION_SESSION_END, | 581 chrome::NOTIFICATION_SESSION_END, |
588 content::NotificationService::AllSources(), | 582 content::NotificationService::AllSources(), |
589 content::NotificationService::NoDetails()); | 583 content::NotificationService::NoDetails()); |
590 | 584 |
591 // This will end by terminating the process. | 585 // And shutdown. |
592 content::ImmediateShutdownAndExitProcess(); | 586 browser_shutdown::Shutdown(); |
| 587 } |
| 588 |
| 589 // 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 |
593 } | 602 } |
594 | 603 |
595 // static | 604 // static |
596 bool BrowserList::HasBrowserWithProfile(Profile* profile) { | 605 bool BrowserList::HasBrowserWithProfile(Profile* profile) { |
597 return FindBrowserMatching(BrowserList::begin(), | 606 return FindBrowserMatching(BrowserList::begin(), |
598 BrowserList::end(), | 607 BrowserList::end(), |
599 profile, | 608 profile, |
600 Browser::FEATURE_NONE, | 609 Browser::FEATURE_NONE, |
601 kMatchAny) != NULL; | 610 kMatchAny) != NULL; |
602 } | 611 } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 // If no more TabContents from Browsers, check the BackgroundPrintingManager. | 857 // If no more TabContents from Browsers, check the BackgroundPrintingManager. |
849 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { | 858 while (bg_printing_iterator_ != GetBackgroundPrintingManager()->end()) { |
850 cur_ = *bg_printing_iterator_; | 859 cur_ = *bg_printing_iterator_; |
851 CHECK(cur_); | 860 CHECK(cur_); |
852 ++bg_printing_iterator_; | 861 ++bg_printing_iterator_; |
853 return; | 862 return; |
854 } | 863 } |
855 // Reached the end - no more TabContents. | 864 // Reached the end - no more TabContents. |
856 cur_ = NULL; | 865 cur_ = NULL; |
857 } | 866 } |
OLD | NEW |