| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_ | 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_ |
| 6 #define CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_ | 6 #define CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class WebContents; | 23 class WebContents; |
| 24 } | 24 } |
| 25 | 25 |
| 26 // SessionRestore handles restoring either the last or saved session. Session | 26 // SessionRestore handles restoring either the last or saved session. Session |
| 27 // restore come in two variants, asynchronous or synchronous. The synchronous | 27 // restore come in two variants, asynchronous or synchronous. The synchronous |
| 28 // variety is meant for startup and blocks until restore is complete. | 28 // variety is meant for startup and blocks until restore is complete. |
| 29 class SessionRestore { | 29 class SessionRestore { |
| 30 public: | 30 public: |
| 31 enum Behavior { | 31 // Bitmask representing behaviors available when restoring a session. Populate |
| 32 // using the values below. |
| 33 using BehaviorBitmask = uint32_t; |
| 34 |
| 35 enum { |
| 32 // Indicates the active tab of the supplied browser should be closed. | 36 // Indicates the active tab of the supplied browser should be closed. |
| 33 CLOBBER_CURRENT_TAB = 1 << 0, | 37 CLOBBER_CURRENT_TAB = 1 << 0, |
| 34 | 38 |
| 35 // Indicates that if there is a problem restoring the last session then a | 39 // Indicates that if there is a problem restoring the last session then a |
| 36 // new tabbed browser should be created. | 40 // new tabbed browser should be created. |
| 37 ALWAYS_CREATE_TABBED_BROWSER = 1 << 1, | 41 ALWAYS_CREATE_TABBED_BROWSER = 1 << 1, |
| 38 | 42 |
| 39 // Restore blocks until complete. This is intended for use during startup | 43 // Restore blocks until complete. This is intended for use during startup |
| 40 // when we want to block until restore is complete. | 44 // when we want to block until restore is complete. |
| 41 SYNCHRONOUS = 1 << 2, | 45 SYNCHRONOUS = 1 << 2, |
| 42 }; | 46 }; |
| 43 | 47 |
| 44 // Notification callback list. | 48 // Notification callback list. |
| 45 using CallbackList = base::CallbackList<void(int)>; | 49 using CallbackList = base::CallbackList<void(int)>; |
| 46 | 50 |
| 47 // Used by objects calling RegisterOnSessionRestoredCallback() to de-register | 51 // Used by objects calling RegisterOnSessionRestoredCallback() to de-register |
| 48 // themselves when they are destroyed. | 52 // themselves when they are destroyed. |
| 49 using CallbackSubscription = | 53 using CallbackSubscription = |
| 50 std::unique_ptr<base::CallbackList<void(int)>::Subscription>; | 54 std::unique_ptr<base::CallbackList<void(int)>::Subscription>; |
| 51 | 55 |
| 52 // Restores the last session. |behavior| is a bitmask of Behaviors, see it | 56 // Restores the last session. |behavior| is a bitmask of Behaviors, see it |
| 53 // for details. If |browser| is non-null the tabs for the first window are | 57 // for details. If |browser| is non-null the tabs for the first window are |
| 54 // added to it. Returns the last active browser. | 58 // added to it. Returns the last active browser. |
| 55 // | 59 // |
| 56 // If |urls_to_open| is non-empty, a tab is added for each of the URLs. | 60 // If |urls_to_open| is non-empty, a tab is added for each of the URLs. |
| 57 static Browser* RestoreSession(Profile* profile, | 61 static Browser* RestoreSession(Profile* profile, |
| 58 Browser* browser, | 62 Browser* browser, |
| 59 uint32_t behavior, | 63 BehaviorBitmask behavior, |
| 60 const std::vector<GURL>& urls_to_open); | 64 const std::vector<GURL>& urls_to_open); |
| 61 | 65 |
| 62 // Restores the last session when the last session crashed. It's a wrapper | 66 // Restores the last session when the last session crashed. It's a wrapper |
| 63 // of function RestoreSession. | 67 // of function RestoreSession. |
| 64 static void RestoreSessionAfterCrash(Browser* browser); | 68 static void RestoreSessionAfterCrash(Browser* browser); |
| 65 | 69 |
| 66 // Opens the startup pages when the last session crashed. | 70 // Opens the startup pages when the last session crashed. |
| 67 static void OpenStartupPagesAfterCrash(Browser* browser); | 71 static void OpenStartupPagesAfterCrash(Browser* browser); |
| 68 | 72 |
| 69 // Specifically used in the restoration of a foreign session. This function | 73 // Specifically used in the restoration of a foreign session. This function |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 return on_session_restored_callbacks_; | 112 return on_session_restored_callbacks_; |
| 109 } | 113 } |
| 110 | 114 |
| 111 // Contains all registered callbacks for session restore notifications. | 115 // Contains all registered callbacks for session restore notifications. |
| 112 static CallbackList* on_session_restored_callbacks_; | 116 static CallbackList* on_session_restored_callbacks_; |
| 113 | 117 |
| 114 DISALLOW_COPY_AND_ASSIGN(SessionRestore); | 118 DISALLOW_COPY_AND_ASSIGN(SessionRestore); |
| 115 }; | 119 }; |
| 116 | 120 |
| 117 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_ | 121 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_ |
| OLD | NEW |