blob: 6cec9fd9af13de4c62fad4ea09e6de78fe0f5f6f [file] [log] [blame]
[email protected]2e9d79f2013-08-16 05:45:561// 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]edfca702013-08-16 08:58:148#include "base/callback_forward.h"
avi6846aef2015-12-26 01:09:389#include "base/macros.h"
[email protected]2e9d79f2013-08-16 05:45:5610#include "base/memory/ref_counted.h"
11
12class Browser;
13
14// Manages confirming that browser windows are closeable and closing them at
15// shutdown.
jackhouc722ea132015-07-29 03:48:4816class BrowserCloseManager : public base::RefCounted<BrowserCloseManager> {
[email protected]2e9d79f2013-08-16 05:45:5617 public:
18 BrowserCloseManager();
19
20 // Starts closing all browser windows.
21 void StartClosingBrowsers();
22
[email protected]edfca702013-08-16 08:58:1423 protected:
[email protected]2e9d79f2013-08-16 05:45:5624 friend class base::RefCounted<BrowserCloseManager>;
25
jackhouc722ea132015-07-29 03:48:4826 virtual ~BrowserCloseManager();
[email protected]2e9d79f2013-08-16 05:45:5627
[email protected]edfca702013-08-16 08:58:1428 virtual void ConfirmCloseWithPendingDownloads(
29 int download_count,
30 const base::Callback<void(bool)>& callback);
31
32 private:
[email protected]2e9d79f2013-08-16 05:45:5633 // 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]edfca702013-08-16 08:58:1446 // 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]2e9d79f2013-08-16 05:45:5657 // The browser for which we are waiting for a callback to
58 // OnBrowserReportCloseable.
59 Browser* current_browser_;
60
[email protected]2e9d79f2013-08-16 05:45:5661 DISALLOW_COPY_AND_ASSIGN(BrowserCloseManager);
62};
63
64#endif // CHROME_BROWSER_LIFETIME_BROWSER_CLOSE_MANAGER_H_