blob: c74dca821c23540919a695d9c771a1a1a1ad9056 [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"
[email protected]2e9d79f2013-08-16 05:45:569#include "base/memory/ref_counted.h"
jackhou75d58b12015-07-07 08:16:0110#include "chrome/browser/ui/browser_list_observer.h"
[email protected]2e9d79f2013-08-16 05:45:5611
12class Browser;
13
14// Manages confirming that browser windows are closeable and closing them at
15// shutdown.
jackhou75d58b12015-07-07 08:16:0116class BrowserCloseManager : public base::RefCounted<BrowserCloseManager>,
17 public chrome::BrowserListObserver {
[email protected]2e9d79f2013-08-16 05:45:5618 public:
19 BrowserCloseManager();
20
21 // Starts closing all browser windows.
22 void StartClosingBrowsers();
23
jackhou75d58b12015-07-07 08:16:0124 // BrowserListObserver:
25 void OnBrowserAdded(Browser* browser) override;
26 void OnBrowserRemoved(Browser* browser) override;
27
[email protected]edfca702013-08-16 08:58:1428 protected:
[email protected]2e9d79f2013-08-16 05:45:5629 friend class base::RefCounted<BrowserCloseManager>;
30
jackhou75d58b12015-07-07 08:16:0131 ~BrowserCloseManager() override;
[email protected]2e9d79f2013-08-16 05:45:5632
[email protected]edfca702013-08-16 08:58:1433 virtual void ConfirmCloseWithPendingDownloads(
34 int download_count,
35 const base::Callback<void(bool)>& callback);
36
37 private:
[email protected]2e9d79f2013-08-16 05:45:5638 // 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]edfca702013-08-16 08:58:1451 // 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]2e9d79f2013-08-16 05:45:5662 // The browser for which we are waiting for a callback to
63 // OnBrowserReportCloseable.
64 Browser* current_browser_;
65
jackhou75d58b12015-07-07 08:16:0166 // 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]2e9d79f2013-08-16 05:45:5673 DISALLOW_COPY_AND_ASSIGN(BrowserCloseManager);
74};
75
76#endif // CHROME_BROWSER_LIFETIME_BROWSER_CLOSE_MANAGER_H_