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