From ec3595d4fc0eae94f3bf262aa97060099bb254f0 Mon Sep 17 00:00:00 2001 From: ekager Date: Thu, 1 Oct 2020 12:19:20 -0700 Subject: [PATCH] For #15600 - Move removal of timed out sessions to immediately after restoration --- .../java/org/mozilla/fenix/HomeActivity.kt | 11 -------- .../java/org/mozilla/fenix/components/Core.kt | 25 +++++++++++++++---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 333fb7ba5..e73f6a8e5 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -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) } - } - } } } diff --git a/app/src/main/java/org/mozilla/fenix/components/Core.kt b/app/src/main/java/org/mozilla/fenix/components/Core.kt index 69033a78d..4d76715be 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Core.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Core.kt @@ -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.