1// Copyright (c) 2012 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
8#include <vector>
9
10#include "base/basictypes.h"
11#include "chrome/browser/history/history_service.h"
12#include "chrome/browser/sessions/session_types.h"
13#include "chrome/browser/ui/host_desktop.h"
14#include "ui/base/window_open_disposition.h"
15
16class Browser;
17class Profile;
18
19namespace content {
20class WebContents;
21}
22
23// SessionRestore handles restoring either the last or saved session. Session
24// restore come in two variants, asynchronous or synchronous. The synchronous
25// variety is meant for startup and blocks until restore is complete.
26class SessionRestore {
27 public:
28  enum Behavior {
29    // Indicates the active tab of the supplied browser should be closed.
30    CLOBBER_CURRENT_TAB          = 1 << 0,
31
32    // Indicates that if there is a problem restoring the last session then a
33    // new tabbed browser should be created.
34    ALWAYS_CREATE_TABBED_BROWSER = 1 << 1,
35
36    // Restore blocks until complete. This is intended for use during startup
37    // when we want to block until restore is complete.
38    SYNCHRONOUS                  = 1 << 2,
39  };
40
41  // Restores the last session. |behavior| is a bitmask of Behaviors, see it
42  // for details. If |browser| is non-null the tabs for the first window are
43  // added to it. Returns the last active browser.
44  // Every additional browser created will be created on the desktop specified
45  // by |host_desktop_type|, if |browser| is non-null it should have the same
46  // desktop type.
47  //
48  // If |urls_to_open| is non-empty, a tab is added for each of the URLs.
49  static Browser* RestoreSession(Profile* profile,
50                                 Browser* browser,
51                                 chrome::HostDesktopType host_desktop_type,
52                                 uint32 behavior,
53                                 const std::vector<GURL>& urls_to_open);
54
55  // Specifically used in the restoration of a foreign session.  This function
56  // restores the given session windows to multiple browsers all of which
57  // will be created on the desktop specified by |host_desktop_type|. Returns
58  // the created Browsers.
59  static std::vector<Browser*> RestoreForeignSessionWindows(
60      Profile* profile,
61      chrome::HostDesktopType host_desktop_type,
62      std::vector<const SessionWindow*>::const_iterator begin,
63      std::vector<const SessionWindow*>::const_iterator end);
64
65  // Specifically used in the restoration of a foreign session.  This method
66  // restores the given session tab to the browser of |source_web_contents| if
67  // the disposition is not NEW_WINDOW. Returns the WebContents corresponding
68  // to the restored tab.
69  static content::WebContents* RestoreForeignSessionTab(
70      content::WebContents* source_web_contents,
71      const SessionTab& tab,
72      WindowOpenDisposition disposition);
73
74  // Returns true if we're in the process of restoring |profile|.
75  static bool IsRestoring(const Profile* profile);
76
77  // Returns true if synchronously restoring a session.
78  static bool IsRestoringSynchronously();
79
80  // The max number of non-selected tabs SessionRestore loads when restoring
81  // a session. A value of 0 indicates all tabs are loaded at once.
82  static size_t num_tabs_to_load_;
83
84 private:
85  SessionRestore();
86
87  DISALLOW_COPY_AND_ASSIGN(SessionRestore);
88};
89
90#endif  // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_
91