Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / sessions / session_restore.h
blob830feb7a2b64d26e31c6d7f6b88afdfaf08f3fbb
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.
5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_
6 #define CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "chrome/browser/history/history_service.h"
12 #include "chrome/browser/ui/host_desktop.h"
13 #include "components/sessions/session_types.h"
14 #include "ui/base/window_open_disposition.h"
16 class Browser;
17 class Profile;
19 namespace content {
20 class WebContents;
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.
26 class SessionRestore {
27 public:
28 enum Behavior {
29 // Indicates the active tab of the supplied browser should be closed.
30 CLOBBER_CURRENT_TAB = 1 << 0,
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,
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,
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.
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);
55 // Restores the last session when the last session crashed. It's a wrapper
56 // of function RestoreSession.
57 static void RestoreSessionAfterCrash(Browser* browser);
59 // Specifically used in the restoration of a foreign session. This function
60 // restores the given session windows to multiple browsers all of which
61 // will be created on the desktop specified by |host_desktop_type|. Returns
62 // the created Browsers.
63 static std::vector<Browser*> RestoreForeignSessionWindows(
64 Profile* profile,
65 chrome::HostDesktopType host_desktop_type,
66 std::vector<const sessions::SessionWindow*>::const_iterator begin,
67 std::vector<const sessions::SessionWindow*>::const_iterator end);
69 // Specifically used in the restoration of a foreign session. This method
70 // restores the given session tab to the browser of |source_web_contents| if
71 // the disposition is not NEW_WINDOW. Returns the WebContents corresponding
72 // to the restored tab. If |disposition| is CURRENT_TAB, |source_web_contents|
73 // may be destroyed.
74 static content::WebContents* RestoreForeignSessionTab(
75 content::WebContents* source_web_contents,
76 const sessions::SessionTab& tab,
77 WindowOpenDisposition disposition);
79 // Returns true if we're in the process of restoring |profile|.
80 static bool IsRestoring(const Profile* profile);
82 // Returns true if synchronously restoring a session.
83 static bool IsRestoringSynchronously();
85 // The max number of non-selected tabs SessionRestore loads when restoring
86 // a session. A value of 0 indicates all tabs are loaded at once.
87 static size_t num_tabs_to_load_;
89 private:
90 SessionRestore();
92 DISALLOW_COPY_AND_ASSIGN(SessionRestore);
95 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_