Commit be131aa5 authored by Mugurell's avatar Mugurell Committed by mergify[bot]
Browse files

For #10470 - Persist and restore lastMediaAccess of TabSessionState

parent 061cebc5
......@@ -164,6 +164,7 @@ private fun JsonReader.tabSession(): RecoverableTab? {
var title: String? = null
var contextId: String? = null
var lastAccess: Long? = null
var lastMediaAccess: Long? = null
var readerStateActive: Boolean? = null
var readerActiveUrl: String? = null
......@@ -187,6 +188,7 @@ private fun JsonReader.tabSession(): RecoverableTab? {
Keys.SESSION_HISTORY_METADATA_SEARCH_TERM -> historyMetadataSearchTerm = nextStringOrNull()
Keys.SESSION_HISTORY_METADATA_REFERRER_URL -> historyMetadataReferrerUrl = nextStringOrNull()
Keys.SESSION_LAST_ACCESS -> lastAccess = nextLong()
Keys.SESSION_LAST_MEDIA_ACCESS -> lastMediaAccess = nextLong()
Keys.SESSION_SOURCE_KEY -> nextString()
else -> throw IllegalArgumentException("Unknown session key: $name")
}
......@@ -215,6 +217,7 @@ private fun JsonReader.tabSession(): RecoverableTab? {
null
},
private = false, // We never serialize private sessions
lastAccess = lastAccess ?: 0
lastAccess = lastAccess ?: 0,
lastMediaAccess = lastMediaAccess ?: 0
)
}
......@@ -91,6 +91,9 @@ private fun JsonWriter.tab(
name(Keys.SESSION_LAST_ACCESS)
value(tab.lastAccess)
name(Keys.SESSION_LAST_MEDIA_ACCESS)
value(tab.lastMediaAccess)
if (tab.readerState.active && tab.readerState.activeUrl != null) {
name(Keys.SESSION_READER_MODE_ACTIVE_URL_KEY)
value(tab.readerState.activeUrl)
......
......@@ -22,6 +22,7 @@ internal object Keys {
const val SESSION_READER_MODE_ACTIVE_URL_KEY = "readerModeArticleUrl"
const val SESSION_TITLE = "title"
const val SESSION_LAST_ACCESS = "lastAccess"
const val SESSION_LAST_MEDIA_ACCESS = "lastMediaAccess"
const val SESSION_SOURCE_KEY = "source"
const val SESSION_HISTORY_METADATA_URL = "historyMetadataUrl"
......
......@@ -145,6 +145,33 @@ class BrowserStateWriterReaderTest {
assertNotNull(restoredTab.historyMetadata)
assertEquals(tab.content.url, restoredTab.historyMetadata!!.url)
}
@Test
fun `Read and write tab with lastMediaAccess`() {
val engineState = createFakeEngineState()
val engine = createFakeEngine(engineState)
val tab = createTab(
url = "https://www.mozilla.org",
title = "Mozilla",
contextId = "work",
lastMediaAccess = 333L
)
val writer = BrowserStateWriter()
val reader = BrowserStateReader()
val file = AtomicFile(
File.createTempFile(UUID.randomUUID().toString(), UUID.randomUUID().toString())
)
assertTrue(writer.writeTab(tab, file))
val restoredTab = reader.readTab(engine, file)
assertNotNull(restoredTab!!)
assertEquals(333L, restoredTab.lastMediaAccess)
}
}
private fun createFakeEngineState(): EngineSessionState {
......
......@@ -26,6 +26,7 @@ import mozilla.components.concept.storage.HistoryMetadataKey
* @property state The [EngineSessionState] needed for restoring the previous state of this tab.
* @property readerState The last [ReaderState] of the tab.
* @property lastAccess The last time this tab was selected.
* @property lastMediaAccess The last time media started playing in this tab.
* @property private If tab was private.
*/
data class RecoverableTab(
......@@ -37,6 +38,7 @@ data class RecoverableTab(
val state: EngineSessionState? = null,
val readerState: ReaderState = ReaderState(),
val lastAccess: Long = 0,
val lastMediaAccess: Long = 0,
val private: Boolean = false,
val historyMetadata: HistoryMetadataKey? = null
)
......@@ -53,6 +55,7 @@ fun TabSessionState.toRecoverableTab() = RecoverableTab(
state = engineState.engineSessionState,
readerState = readerState,
lastAccess = lastAccess,
lastMediaAccess = lastMediaAccess,
private = content.private,
historyMetadata = historyMetadata
)
......@@ -69,6 +72,7 @@ fun RecoverableTab.toTabSessionState() = createTab(
engineSessionState = state,
readerState = readerState,
lastAccess = lastAccess,
lastMediaAccess = lastMediaAccess,
private = private
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment