[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_LIFETIME_BROWSER_CLOSE_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_LIFETIME_BROWSER_CLOSE_MANAGER_H_ |
| 7 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 8 | #include "base/callback_forward.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
jackhou | 75d58b1 | 2015-07-07 08:16:01 | [diff] [blame] | 10 | #include "chrome/browser/ui/browser_list_observer.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 11 | |
| 12 | class Browser; |
| 13 | |
| 14 | // Manages confirming that browser windows are closeable and closing them at |
| 15 | // shutdown. |
jackhou | 75d58b1 | 2015-07-07 08:16:01 | [diff] [blame] | 16 | class BrowserCloseManager : public base::RefCounted<BrowserCloseManager>, |
| 17 | public chrome::BrowserListObserver { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 18 | public: |
| 19 | BrowserCloseManager(); |
| 20 | |
| 21 | // Starts closing all browser windows. |
| 22 | void StartClosingBrowsers(); |
| 23 | |
jackhou | 75d58b1 | 2015-07-07 08:16:01 | [diff] [blame] | 24 | // BrowserListObserver: |
| 25 | void OnBrowserAdded(Browser* browser) override; |
| 26 | void OnBrowserRemoved(Browser* browser) override; |
| 27 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 28 | protected: |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 29 | friend class base::RefCounted<BrowserCloseManager>; |
| 30 | |
jackhou | 75d58b1 | 2015-07-07 08:16:01 | [diff] [blame] | 31 | ~BrowserCloseManager() override; |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 32 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 33 | virtual void ConfirmCloseWithPendingDownloads( |
| 34 | int download_count, |
| 35 | const base::Callback<void(bool)>& callback); |
| 36 | |
| 37 | private: |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 38 | // Notifies all browser windows that the close is cancelled. |
| 39 | void CancelBrowserClose(); |
| 40 | |
| 41 | // Checks whether all browser windows are ready to close and closes them if |
| 42 | // they are. |
| 43 | void TryToCloseBrowsers(); |
| 44 | |
| 45 | // Called to report whether a beforeunload dialog was accepted. |
| 46 | void OnBrowserReportCloseable(bool proceed); |
| 47 | |
| 48 | // Closes all browser windows. |
| 49 | void CloseBrowsers(); |
| 50 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 51 | // Checks whether there are any downloads in-progress and prompts the user to |
| 52 | // cancel them. If there are no downloads or the user accepts the cancel |
| 53 | // downloads dialog, CloseBrowsers is called to continue with the shutdown. |
| 54 | // Otherwise, if the user declines to cancel downloads, the shutdown is |
| 55 | // aborted and the downloads page is shown for each profile with in-progress |
| 56 | // downloads. |
| 57 | void CheckForDownloadsInProgress(); |
| 58 | |
| 59 | // Called to report whether downloads may be cancelled during shutdown. |
| 60 | void OnReportDownloadsCancellable(bool proceed); |
| 61 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 62 | // The browser for which we are waiting for a callback to |
| 63 | // OnBrowserReportCloseable. |
| 64 | Browser* current_browser_; |
| 65 | |
jackhou | 75d58b1 | 2015-07-07 08:16:01 | [diff] [blame] | 66 | // Whether we are currently iterating over browsers in CloseBrowsers(). |
| 67 | // No Browsers should be added or removed synchronously or concurrently, |
| 68 | // except explicitly by CloseBrowsers(). |
| 69 | // This was added to investigate http://crbug.com/484951. |
| 70 | // TODO(jackhou): Delete when no longer needed. |
| 71 | bool iterating_over_browsers_during_shutdown_; |
| 72 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 73 | DISALLOW_COPY_AND_ASSIGN(BrowserCloseManager); |
| 74 | }; |
| 75 | |
| 76 | #endif // CHROME_BROWSER_LIFETIME_BROWSER_CLOSE_MANAGER_H_ |