Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit fbe7289

Browse files
committed
Issue #743: SessionStorage: Customizable UI-independent session storage.
1 parent 40dcef5 commit fbe7289

File tree

15 files changed

+928
-615
lines changed

15 files changed

+928
-615
lines changed

buildSrc/src/main/java/Dependencies.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ private object Versions {
1616
const val support_libraries = "28.0.0"
1717
const val constraint_layout = "1.1.2"
1818
const val workmanager = "1.0.0-alpha09"
19+
const val lifecycle = "1.1.1"
1920

2021
const val dokka = "0.9.16"
2122
const val android_gradle_plugin = "3.1.4"
@@ -56,6 +57,7 @@ object Dependencies {
5657
const val support_compat = "com.android.support:support-compat:${Versions.support_libraries}"
5758

5859
const val arch_workmanager = "android.arch.work:work-runtime:${Versions.workmanager}"
60+
const val arch_lifecycle = "android.arch.lifecycle:extensions:${Versions.lifecycle}"
5961

6062
const val tools_dokka = "org.jetbrains.dokka:dokka-android-gradle-plugin:${Versions.dokka}"
6163
const val tools_androidgradle = "com.android.tools.build:gradle:${Versions.android_gradle_plugin}"

components/browser/session/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ dependencies {
2727
implementation project(':support-ktx')
2828

2929
implementation Dependencies.kotlin_stdlib
30+
implementation Dependencies.kotlin_coroutines
31+
3032
implementation Dependencies.support_customtabs
33+
implementation Dependencies.arch_lifecycle
3134

3235
// We expose this as API because we are using Observable in our public API and do not want every
3336
// consumer to have to manually import "utils".

components/browser/session/src/main/java/mozilla/components/browser/session/SessionManager.kt

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package mozilla.components.browser.session
66

77
import android.support.annotation.GuardedBy
88
import mozilla.components.browser.session.engine.EngineObserver
9-
import mozilla.components.browser.session.storage.SessionWithState
10-
import mozilla.components.browser.session.storage.SessionsSnapshot
119
import mozilla.components.concept.engine.Engine
1210
import mozilla.components.concept.engine.EngineSession
1311
import mozilla.components.support.base.observer.Observable
@@ -38,11 +36,11 @@ class SessionManager(
3836
* Produces a snapshot of this manager's state, suitable for restoring via [SessionManager.restore].
3937
* Only regular sessions are included in the snapshot. Private and Custom Tab sessions are omitted.
4038
*
41-
* @return [SessionsSnapshot] or null if no sessions are present.
39+
* @return [Snapshot] or null if no sessions are present.
4240
*/
43-
fun createSnapshot(): SessionsSnapshot? = synchronized(values) {
41+
fun createSnapshot(): Snapshot? = synchronized(values) {
4442
if (values.isEmpty()) {
45-
return@synchronized null
43+
return null
4644
}
4745

4846
// Filter out CustomTab and private sessions.
@@ -51,16 +49,16 @@ class SessionManager(
5149
.filter { !it.isCustomTabSession() }
5250
.filter { !it.private }
5351
.map { session ->
54-
SessionWithState(
55-
session,
56-
session.engineSessionHolder.engineSession
52+
Snapshot.Item(
53+
session,
54+
session.engineSessionHolder.engineSession
5755
)
5856
}
5957
.toList()
6058

6159
// We might have some sessions (private, custom tab) but none we'd include in the snapshot.
6260
if (sessionStateTuples.isEmpty()) {
63-
return@synchronized null
61+
return null
6462
}
6563

6664
// 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(
7977
"Selection index after filtering session must be valid"
8078
}
8179

82-
SessionsSnapshot(
80+
Snapshot(
8381
sessions = sessionStateTuples,
8482
selectedSessionIndex = selectedIndexAfterFiltering
8583
)
@@ -176,17 +174,17 @@ class SessionManager(
176174
}
177175

178176
/**
179-
* Restores sessions from the provided [SessionsSnapshot].
177+
* Restores sessions from the provided [Snapshot].
180178
* Notification behaviour is as follows:
181179
* - onSessionAdded notifications will not fire,
182180
* - onSessionSelected notification will fire exactly once if the snapshot isn't empty,
183181
* - once snapshot has been restored, and appropriate session has been selected, onSessionsRestored
184182
* notification will fire.
185183
*
186-
* @param snapshot A [SessionsSnapshot] which may be produced by [createSnapshot].
184+
* @param snapshot A [Snapshot] which may be produced by [createSnapshot].
187185
* @throws IllegalArgumentException if an empty snapshot is passed in.
188186
*/
189-
fun restore(snapshot: SessionsSnapshot) = synchronized(values) {
187+
fun restore(snapshot: Snapshot) = synchronized(values) {
190188
require(snapshot.sessions.isNotEmpty()) {
191189
"Snapshot must contain session state tuples"
192190
}
@@ -470,4 +468,16 @@ class SessionManager(
470468
*/
471469
fun onAllSessionsRemoved() = Unit
472470
}
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+
}
473483
}

components/browser/session/src/main/java/mozilla/components/browser/session/storage/DefaultSessionStorage.kt

Lines changed: 0 additions & 229 deletions
This file was deleted.

0 commit comments

Comments
 (0)