For #15600 - Move removal of timed out sessions to immediately after restoration

pull/200/head^2
ekager 4 years ago
parent 450caf1e42
commit ec3595d4fc

@ -32,7 +32,6 @@ import kotlinx.android.synthetic.main.activity_home.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
@ -281,16 +280,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}
settings().wasDefaultBrowserOnLastResume = settings().isDefaultBrowser()
if (!settings().manuallyCloseTabs) {
val toClose = components.core.store.state.tabs.filter {
(System.currentTimeMillis() - it.lastAccess) > settings().getTabTimeout()
}
// Removal needs to happen on the main thread.
lifecycleScope.launch(Main) {
toClose.forEach { components.useCases.tabsUseCases.removeTab(it.id) }
}
}
}
}

@ -77,6 +77,7 @@ import java.util.concurrent.TimeUnit
* Component group for all core browser functionality.
*/
@Mockable
@Suppress("LargeClass")
class Core(
private val context: Context,
private val crashReporter: CrashReporting,
@ -218,6 +219,18 @@ class Core(
.periodicallyInForeground(interval = 30, unit = TimeUnit.SECONDS)
.whenGoingToBackground()
.whenSessionsChange()
// Now that we have restored our previous state (if there's one) let's remove timed out tabs
if (!context.settings().manuallyCloseTabs) {
store.state.tabs.filter {
(System.currentTimeMillis() - it.lastAccess) > context.settings().getTabTimeout()
}.forEach {
val session = sessionManager.findSessionById(it.id)
if (session != null) {
sessionManager.remove(session)
}
}
}
}
WebNotificationFeature(
@ -272,11 +285,13 @@ class Core(
val bookmarksStorage by lazy { lazyBookmarksStorage.value }
val passwordsStorage by lazy { lazyPasswordsStorage.value }
val tabCollectionStorage by lazy { TabCollectionStorage(
context,
sessionManager,
strictMode
) }
val tabCollectionStorage by lazy {
TabCollectionStorage(
context,
sessionManager,
strictMode
)
}
/**
* A storage component for persisting thumbnail images of tabs.

Loading…
Cancel
Save