@@ -6,8 +6,6 @@ package mozilla.components.browser.session
6
6
7
7
import android.support.annotation.GuardedBy
8
8
import mozilla.components.browser.session.engine.EngineObserver
9
- import mozilla.components.browser.session.storage.SessionWithState
10
- import mozilla.components.browser.session.storage.SessionsSnapshot
11
9
import mozilla.components.concept.engine.Engine
12
10
import mozilla.components.concept.engine.EngineSession
13
11
import mozilla.components.support.base.observer.Observable
@@ -38,11 +36,11 @@ class SessionManager(
38
36
* Produces a snapshot of this manager's state, suitable for restoring via [SessionManager.restore].
39
37
* Only regular sessions are included in the snapshot. Private and Custom Tab sessions are omitted.
40
38
*
41
- * @return [SessionsSnapshot ] or null if no sessions are present.
39
+ * @return [Snapshot ] or null if no sessions are present.
42
40
*/
43
- fun createSnapshot (): SessionsSnapshot ? = synchronized(values) {
41
+ fun createSnapshot (): Snapshot ? = synchronized(values) {
44
42
if (values.isEmpty()) {
45
- return @synchronized null
43
+ return null
46
44
}
47
45
48
46
// Filter out CustomTab and private sessions.
@@ -51,16 +49,16 @@ class SessionManager(
51
49
.filter { ! it.isCustomTabSession() }
52
50
.filter { ! it.private }
53
51
.map { session ->
54
- SessionWithState (
55
- session,
56
- session.engineSessionHolder.engineSession
52
+ Snapshot . Item (
53
+ session,
54
+ session.engineSessionHolder.engineSession
57
55
)
58
56
}
59
57
.toList()
60
58
61
59
// We might have some sessions (private, custom tab) but none we'd include in the snapshot.
62
60
if (sessionStateTuples.isEmpty()) {
63
- return @synchronized null
61
+ return null
64
62
}
65
63
66
64
// We need to find out the index of our selected session in the filtered list. If we have a
@@ -79,7 +77,7 @@ class SessionManager(
79
77
" Selection index after filtering session must be valid"
80
78
}
81
79
82
- SessionsSnapshot (
80
+ Snapshot (
83
81
sessions = sessionStateTuples,
84
82
selectedSessionIndex = selectedIndexAfterFiltering
85
83
)
@@ -176,17 +174,17 @@ class SessionManager(
176
174
}
177
175
178
176
/* *
179
- * Restores sessions from the provided [SessionsSnapshot ].
177
+ * Restores sessions from the provided [Snapshot ].
180
178
* Notification behaviour is as follows:
181
179
* - onSessionAdded notifications will not fire,
182
180
* - onSessionSelected notification will fire exactly once if the snapshot isn't empty,
183
181
* - once snapshot has been restored, and appropriate session has been selected, onSessionsRestored
184
182
* notification will fire.
185
183
*
186
- * @param snapshot A [SessionsSnapshot ] which may be produced by [createSnapshot].
184
+ * @param snapshot A [Snapshot ] which may be produced by [createSnapshot].
187
185
* @throws IllegalArgumentException if an empty snapshot is passed in.
188
186
*/
189
- fun restore (snapshot : SessionsSnapshot ) = synchronized(values) {
187
+ fun restore (snapshot : Snapshot ) = synchronized(values) {
190
188
require(snapshot.sessions.isNotEmpty()) {
191
189
" Snapshot must contain session state tuples"
192
190
}
@@ -470,4 +468,16 @@ class SessionManager(
470
468
*/
471
469
fun onAllSessionsRemoved () = Unit
472
470
}
471
+
472
+ data class Snapshot (
473
+ val sessions : List <Item >,
474
+ val selectedSessionIndex : Int
475
+ ) {
476
+ fun isEmpty () = sessions.isEmpty()
477
+
478
+ data class Item (
479
+ val session : Session ,
480
+ val engineSession : EngineSession ? = null
481
+ )
482
+ }
473
483
}
0 commit comments