Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / sessions / session_restore.h
blobd38828494ea579628f45e016003d13d27dbbd072
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 "base/callback_list.h"
12 #include "chrome/browser/ui/host_desktop.h"
13 #include "components/history/core/browser/history_service.h"
14 #include "components/sessions/session_types.h"
15 #include "ui/base/window_open_disposition.h"
17 class Browser;
18 class Profile;
20 namespace content {
21 class WebContents;
24 // SessionRestore handles restoring either the last or saved session. Session
25 // restore come in two variants, asynchronous or synchronous. The synchronous
26 // variety is meant for startup and blocks until restore is complete.
27 class SessionRestore {
28 public:
29 enum Behavior {
30 // Indicates the active tab of the supplied browser should be closed.
31 CLOBBER_CURRENT_TAB = 1 << 0,
33 // Indicates that if there is a problem restoring the last session then a
34 // new tabbed browser should be created.
35 ALWAYS_CREATE_TABBED_BROWSER = 1 << 1,
37 // Restore blocks until complete. This is intended for use during startup
38 // when we want to block until restore is complete.
39 SYNCHRONOUS = 1 << 2,
42 // Notification callback list.
43 using CallbackList = base::CallbackList<void(int)>;
45 // Used by objects calling RegisterOnSessionRestoredCallback() to de-register
46 // themselves when they are destroyed.
47 using CallbackSubscription =
48 scoped_ptr<base::CallbackList<void(int)>::Subscription>;
50 // Restores the last session. |behavior| is a bitmask of Behaviors, see it
51 // for details. If |browser| is non-null the tabs for the first window are
52 // added to it. Returns the last active browser.
53 // Every additional browser created will be created on the desktop specified
54 // by |host_desktop_type|, if |browser| is non-null it should have the same
55 // desktop type.
57 // If |urls_to_open| is non-empty, a tab is added for each of the URLs.
58 static Browser* RestoreSession(Profile* profile,
59 Browser* browser,
60 chrome::HostDesktopType host_desktop_type,
61 uint32 behavior,
62 const std::vector<GURL>& urls_to_open);
64 // Restores the last session when the last session crashed. It's a wrapper
65 // of function RestoreSession.
66 static void RestoreSessionAfterCrash(Browser* browser);
68 // Specifically used in the restoration of a foreign session. This function
69 // restores the given session windows to multiple browsers all of which
70 // will be created on the desktop specified by |host_desktop_type|. Returns
71 // the created Browsers.
72 static std::vector<Browser*> RestoreForeignSessionWindows(
73 Profile* profile,
74 chrome::HostDesktopType host_desktop_type,
75 std::vector<const sessions::SessionWindow*>::const_iterator begin,
76 std::vector<const sessions::SessionWindow*>::const_iterator end);
78 // Specifically used in the restoration of a foreign session. This method
79 // restores the given session tab to the browser of |source_web_contents| if
80 // the disposition is not NEW_WINDOW. Returns the WebContents corresponding
81 // to the restored tab. If |disposition| is CURRENT_TAB, |source_web_contents|
82 // may be destroyed.
83 static content::WebContents* RestoreForeignSessionTab(
84 content::WebContents* source_web_contents,
85 const sessions::SessionTab& tab,
86 WindowOpenDisposition disposition);
88 // Returns true if we're in the process of restoring |profile|.
89 static bool IsRestoring(const Profile* profile);
91 // Returns true if synchronously restoring a session.
92 static bool IsRestoringSynchronously();
94 // Registers a callback that is notified every time session restore completes.
95 // Note that 'complete' means all the browsers and tabs have been created but
96 // have not necessarily finished loading. The integer supplied to the callback
97 // indicates the number of tabs that were created.
98 static CallbackSubscription RegisterOnSessionRestoredCallback(
99 const base::Callback<void(int)>& callback);
101 // The max number of non-selected tabs SessionRestore loads when restoring
102 // a session. A value of 0 indicates all tabs are loaded at once.
103 static size_t num_tabs_to_load_;
105 private:
106 SessionRestore();
108 // Accessor for |*on_session_restored_callbacks_|. Creates a new object the
109 // first time so that it always returns a valid object.
110 static CallbackList* on_session_restored_callbacks() {
111 if (!on_session_restored_callbacks_)
112 on_session_restored_callbacks_ = new CallbackList();
113 return on_session_restored_callbacks_;
116 // Contains all registered callbacks for session restore notifications.
117 static CallbackList* on_session_restored_callbacks_;
119 DISALLOW_COPY_AND_ASSIGN(SessionRestore);
122 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_