[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" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 9 | #include "base/macros.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 10 | #include "base/memory/ref_counted.h" |
| 11 | |
| 12 | class Browser; |
| 13 | |
| 14 | // Manages confirming that browser windows are closeable and closing them at |
| 15 | // shutdown. |
jackhou | c722ea13 | 2015-07-29 03:48:48 | [diff] [blame] | 16 | class BrowserCloseManager : public base::RefCounted<BrowserCloseManager> { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 17 | public: |
| 18 | BrowserCloseManager(); |
| 19 | |
| 20 | // Starts closing all browser windows. |
| 21 | void StartClosingBrowsers(); |
| 22 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 23 | protected: |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 24 | friend class base::RefCounted<BrowserCloseManager>; |
| 25 | |
jackhou | c722ea13 | 2015-07-29 03:48:48 | [diff] [blame] | 26 | virtual ~BrowserCloseManager(); |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 27 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 28 | virtual void ConfirmCloseWithPendingDownloads( |
| 29 | int download_count, |
| 30 | const base::Callback<void(bool)>& callback); |
| 31 | |
| 32 | private: |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 33 | // Notifies all browser windows that the close is cancelled. |
| 34 | void CancelBrowserClose(); |
| 35 | |
| 36 | // Checks whether all browser windows are ready to close and closes them if |
| 37 | // they are. |
| 38 | void TryToCloseBrowsers(); |
| 39 | |
| 40 | // Called to report whether a beforeunload dialog was accepted. |
| 41 | void OnBrowserReportCloseable(bool proceed); |
| 42 | |
| 43 | // Closes all browser windows. |
| 44 | void CloseBrowsers(); |
| 45 | |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 46 | // Checks whether there are any downloads in-progress and prompts the user to |
| 47 | // cancel them. If there are no downloads or the user accepts the cancel |
| 48 | // downloads dialog, CloseBrowsers is called to continue with the shutdown. |
| 49 | // Otherwise, if the user declines to cancel downloads, the shutdown is |
| 50 | // aborted and the downloads page is shown for each profile with in-progress |
| 51 | // downloads. |
| 52 | void CheckForDownloadsInProgress(); |
| 53 | |
| 54 | // Called to report whether downloads may be cancelled during shutdown. |
| 55 | void OnReportDownloadsCancellable(bool proceed); |
| 56 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 57 | // The browser for which we are waiting for a callback to |
| 58 | // OnBrowserReportCloseable. |
| 59 | Browser* current_browser_; |
| 60 | |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 61 | DISALLOW_COPY_AND_ASSIGN(BrowserCloseManager); |
| 62 | }; |
| 63 | |
| 64 | #endif // CHROME_BROWSER_LIFETIME_BROWSER_CLOSE_MANAGER_H_ |