Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
android-components
Commits
be131aa5
Commit
be131aa5
authored
Jul 07, 2021
by
Mugurell
Committed by
mergify[bot]
Jul 08, 2021
Browse files
For #10470 - Persist and restore lastMediaAccess of TabSessionState
parent
061cebc5
Changes
5
Hide whitespace changes
Inline
Side-by-side
components/browser/session-storage/src/main/java/mozilla/components/browser/session/storage/serialize/BrowserStateReader.kt
View file @
be131aa5
...
...
@@ -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
)
}
components/browser/session-storage/src/main/java/mozilla/components/browser/session/storage/serialize/BrowserStateWriter.kt
View file @
be131aa5
...
...
@@ -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
)
...
...
components/browser/session-storage/src/main/java/mozilla/components/browser/session/storage/serialize/Keys.kt
View file @
be131aa5
...
...
@@ -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"
...
...
components/browser/session-storage/src/test/java/mozilla/components/browser/session/storage/serialize/BrowserStateWriterReaderTest.kt
View file @
be131aa5
...
...
@@ -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
{
...
...
components/browser/state/src/main/java/mozilla/components/browser/state/state/recover/RecoverableTab.kt
View file @
be131aa5
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment