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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback_list.h" | 13 #include "base/callback_list.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/observer_list.h" | |
16 #include "chrome/browser/sessions/session_restore_observer.h" | |
15 #include "components/history/core/browser/history_service.h" | 17 #include "components/history/core/browser/history_service.h" |
16 #include "components/sessions/core/session_types.h" | 18 #include "components/sessions/core/session_types.h" |
17 #include "ui/base/window_open_disposition.h" | 19 #include "ui/base/window_open_disposition.h" |
18 | 20 |
19 class Browser; | 21 class Browser; |
20 class Profile; | 22 class Profile; |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 class WebContents; | 25 class WebContents; |
24 } | 26 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 // have not necessarily finished loading. The integer supplied to the callback | 101 // have not necessarily finished loading. The integer supplied to the callback |
100 // indicates the number of tabs that were created. | 102 // indicates the number of tabs that were created. |
101 static CallbackSubscription RegisterOnSessionRestoredCallback( | 103 static CallbackSubscription RegisterOnSessionRestoredCallback( |
102 const base::Callback<void(int)>& callback); | 104 const base::Callback<void(int)>& callback); |
103 | 105 |
104 // Add |urls| to URLs-to-open list, so that they will be opened after session | 106 // Add |urls| to URLs-to-open list, so that they will be opened after session |
105 // URLs when session is restored. | 107 // URLs when session is restored. |
106 static void AddURLsToOpen(const Profile* profile, | 108 static void AddURLsToOpen(const Profile* profile, |
107 const std::vector<GURL>& urls); | 109 const std::vector<GURL>& urls); |
108 | 110 |
111 // Add/remove an observer to/from this session restore. | |
112 static void AddObserver(SessionRestoreObserver* observer); | |
113 static void RemoveObserver(SessionRestoreObserver* observer); | |
114 | |
115 // Accessor for the observer list. Create the list the first time to always | |
116 // return a valid reference. | |
117 static base::ObserverList<SessionRestoreObserver>& observers() { | |
118 if (!observers_) | |
119 observers_ = new base::ObserverList<SessionRestoreObserver>(); | |
120 return *observers_; | |
121 } | |
122 | |
109 private: | 123 private: |
110 SessionRestore(); | 124 SessionRestore(); |
111 | 125 |
112 // Accessor for |*on_session_restored_callbacks_|. Creates a new object the | 126 // Accessor for |*on_session_restored_callbacks_|. Creates a new object the |
113 // first time so that it always returns a valid object. | 127 // first time so that it always returns a valid object. |
114 static CallbackList* on_session_restored_callbacks() { | 128 static CallbackList* on_session_restored_callbacks() { |
115 if (!on_session_restored_callbacks_) | 129 if (!on_session_restored_callbacks_) |
116 on_session_restored_callbacks_ = new CallbackList(); | 130 on_session_restored_callbacks_ = new CallbackList(); |
117 return on_session_restored_callbacks_; | 131 return on_session_restored_callbacks_; |
118 } | 132 } |
119 | 133 |
120 // Contains all registered callbacks for session restore notifications. | 134 // Contains all registered callbacks for session restore notifications. |
121 static CallbackList* on_session_restored_callbacks_; | 135 static CallbackList* on_session_restored_callbacks_; |
122 | 136 |
137 // Contains all registered observers for session restore events. | |
138 static base::ObserverList<SessionRestoreObserver>* observers_; | |
chrisha
2017/06/27 17:09:07
Shouldn't this explicitly use a leaky lazy instanc
| |
139 | |
123 DISALLOW_COPY_AND_ASSIGN(SessionRestore); | 140 DISALLOW_COPY_AND_ASSIGN(SessionRestore); |
124 }; | 141 }; |
125 | 142 |
126 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_ | 143 #endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_H_ |
OLD | NEW |