Update V8 to version 4.6.22.
[chromium-blink-merge.git] / chrome / browser / lifetime / browser_close_manager.h
blobc74dca821c23540919a695d9c771a1a1a1ad9056
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.
5 #ifndef CHROME_BROWSER_LIFETIME_BROWSER_CLOSE_MANAGER_H_
6 #define CHROME_BROWSER_LIFETIME_BROWSER_CLOSE_MANAGER_H_
8 #include "base/callback_forward.h"
9 #include "base/memory/ref_counted.h"
10 #include "chrome/browser/ui/browser_list_observer.h"
12 class Browser;
14 // Manages confirming that browser windows are closeable and closing them at
15 // shutdown.
16 class BrowserCloseManager : public base::RefCounted<BrowserCloseManager>,
17 public chrome::BrowserListObserver {
18 public:
19 BrowserCloseManager();
21 // Starts closing all browser windows.
22 void StartClosingBrowsers();
24 // BrowserListObserver:
25 void OnBrowserAdded(Browser* browser) override;
26 void OnBrowserRemoved(Browser* browser) override;
28 protected:
29 friend class base::RefCounted<BrowserCloseManager>;
31 ~BrowserCloseManager() override;
33 virtual void ConfirmCloseWithPendingDownloads(
34 int download_count,
35 const base::Callback<void(bool)>& callback);
37 private:
38 // Notifies all browser windows that the close is cancelled.
39 void CancelBrowserClose();
41 // Checks whether all browser windows are ready to close and closes them if
42 // they are.
43 void TryToCloseBrowsers();
45 // Called to report whether a beforeunload dialog was accepted.
46 void OnBrowserReportCloseable(bool proceed);
48 // Closes all browser windows.
49 void CloseBrowsers();
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();
59 // Called to report whether downloads may be cancelled during shutdown.
60 void OnReportDownloadsCancellable(bool proceed);
62 // The browser for which we are waiting for a callback to
63 // OnBrowserReportCloseable.
64 Browser* current_browser_;
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_;
73 DISALLOW_COPY_AND_ASSIGN(BrowserCloseManager);
76 #endif // CHROME_BROWSER_LIFETIME_BROWSER_CLOSE_MANAGER_H_