Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / sessions / session_restore.h
bloba0985bea8c61bf33df92791f84d4488264f3a236
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 enum SmartRestoreMode {
43 SMART_RESTORE_MODE_OFF, // No sorting of tabs.
44 SMART_RESTORE_MODE_SIMPLE, // Tabs are sorted using predetermined criteria.
45 SMART_RESTORE_MODE_MRU // Same as above but takes into account MRU.
48 // Notification callback list.
49 using CallbackList = base::CallbackList<void(int)>;
51 // Used by objects calling RegisterOnSessionRestoredCallback() to de-register
52 // themselves when they are destroyed.
53 using CallbackSubscription =
54 scoped_ptr<base::CallbackList<void(int)>::Subscription>;
56 // Restores the last session. |behavior| is a bitmask of Behaviors, see it
57 // for details. If |browser| is non-null the tabs for the first window are
58 // added to it. Returns the last active browser.
59 // Every additional browser created will be created on the desktop specified
60 // by |host_desktop_type|, if |browser| is non-null it should have the same
61 // desktop type.
63 // If |urls_to_open| is non-empty, a tab is added for each of the URLs.
64 static Browser* RestoreSession(Profile* profile,
65 Browser* browser,
66 chrome::HostDesktopType host_desktop_type,
67 uint32 behavior,
68 const std::vector<GURL>& urls_to_open);
70 // Restores the last session when the last session crashed. It's a wrapper
71 // of function RestoreSession.
72 static void RestoreSessionAfterCrash(Browser* browser);
74 // Specifically used in the restoration of a foreign session. This function
75 // restores the given session windows to multiple browsers all of which
76 // will be created on the desktop specified by |host_desktop_type|. Returns
77 // the created Browsers.
78 static std::vector<Browser*> RestoreForeignSessionWindows(
79 Profile* profile,
80 chrome::HostDesktopType host_desktop_type,
81 std::vector<const sessions::SessionWindow*>::const_iterator begin,
82 std::vector<const sessions::SessionWindow*>::const_iterator end);
84 // Specifically used in the restoration of a foreign session. This method
85 // restores the given session tab to the browser of |source_web_contents| if
86 // the disposition is not NEW_WINDOW. Returns the WebContents corresponding
87 // to the restored tab. If |disposition| is CURRENT_TAB, |source_web_contents|
88 // may be destroyed.
89 static content::WebContents* RestoreForeignSessionTab(
90 content::WebContents* source_web_contents,
91 const sessions::SessionTab& tab,
92 WindowOpenDisposition disposition);
94 // Returns true if we're in the process of restoring |profile|.
95 static bool IsRestoring(const Profile* profile);
97 // Returns true if synchronously restoring a session.
98 static bool IsRestoringSynchronously();
100 // Registers a callback that is notified every time session restore completes.
101 // Note that 'complete' means all the browsers and tabs have been created but
102 // have not necessarily finished loading. The integer supplied to the callback
103 // indicates the number of tabs that were created.
104 static CallbackSubscription RegisterOnSessionRestoredCallback(
105 const base::Callback<void(int)>& callback);
107 // Returns true if smart session restore is enabled (ie. background tabs are
108 // sorted before being loaded).
109 static SmartRestoreMode GetSmartRestoreMode();
111 private:
112 SessionRestore();
114 // Accessor for |*on_session_restored_callbacks_|. Creates a new object the
115 // first time so that it always returns a valid object.
116 static CallbackList* on_session_restored_callbacks() {
117 if (!on_session_restored_callbacks_)
118 on_session_restored_callbacks_ = new CallbackList();
119 return on_session_restored_callbacks_;
122 // Contains all registered callbacks for session restore notifications.
123 static CallbackList* on_session_restored_callbacks_;
125 DISALLOW_COPY_AND_ASSIGN(SessionRestore);
128 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_