Home | History | Annotate | Download | only in sessions
      1 // Copyright (c) 2010 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_SESSIONS_SESSION_RESTORE_H_
      6 #define CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_
      7 #pragma once
      8 
      9 #include <vector>
     10 
     11 #include "chrome/browser/history/history.h"
     12 #include "chrome/browser/sessions/session_types.h"
     13 #include "base/basictypes.h"
     14 
     15 class Browser;
     16 class Profile;
     17 
     18 // SessionRestore handles restoring either the last or saved session. Session
     19 // restore come in two variants, asynchronous or synchronous. The synchronous
     20 // variety is meant for startup, and blocks until restore is complete.
     21 class SessionRestore {
     22  public:
     23   // Asnchronously restores the specified session.
     24   // If |browser| is non-null the tabs for the first window are added to it.
     25   // If clobber_existing_window is true and there is an open browser window,
     26   // it is closed after restoring.
     27   // If always_create_tabbed_browser is true at least one tabbed browser is
     28   // created. For example, if there is an error restoring, or the last session
     29   // session is empty and always_create_tabbed_browser is true, a new empty
     30   // tabbed browser is created.
     31   //
     32   // If urls_to_open is non-empty, a tab is added for each of the URLs.
     33   static void RestoreSession(Profile* profile,
     34                              Browser* browser,
     35                              bool clobber_existing_window,
     36                              bool always_create_tabbed_browser,
     37                              const std::vector<GURL>& urls_to_open);
     38 
     39   // Specifically used in the restoration of a foreign session.  This method
     40   // restores the given session windows to a browser.
     41   static void RestoreForeignSessionWindows(
     42       Profile* profile,
     43       std::vector<SessionWindow*>::const_iterator begin,
     44       std::vector<SessionWindow*>::const_iterator end);
     45 
     46   // Specifically used in the restoration of a foreign session.  This method
     47   // restores the given session tab to a browser.
     48   static void RestoreForeignSessionTab(Profile* profile,
     49       const SessionTab& tab);
     50 
     51   // Synchronously restores the last session. At least one tabbed browser is
     52   // created, even if there is an error in restoring.
     53   //
     54   // If urls_to_open is non-empty, a tab is added for each of the URLs.
     55   //
     56   // Returns the last active Browser (which may have been created by the act of
     57   // restoring).
     58   static Browser* RestoreSessionSynchronously(
     59       Profile* profile,
     60       const std::vector<GURL>& urls_to_open);
     61 
     62   // Returns true if we're in the process of restoring.
     63   static bool IsRestoring();
     64 
     65   // The max number of non-selected tabs SessionRestore loads when restoring
     66   // a session. A value of 0 indicates all tabs are loaded at once.
     67   static size_t num_tabs_to_load_;
     68 
     69  private:
     70   SessionRestore();
     71 
     72   DISALLOW_COPY_AND_ASSIGN(SessionRestore);
     73 };
     74 
     75 #endif  // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_
     76