1
0
Fork 0

For #4359: findBookmarkedUrl blocks the main thread (#4362)

master
Colin Lee 2019-07-29 17:01:02 -05:00 committed by GitHub
parent 4c13f45e9e
commit 9bc0122ce3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 8 deletions

View File

@ -30,7 +30,6 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import mozilla.appservices.places.BookmarkRoot import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.session.Session import mozilla.components.browser.session.Session
@ -49,8 +48,8 @@ import mozilla.components.feature.session.ThumbnailsFeature
import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissionsFeature import mozilla.components.feature.sitepermissions.SitePermissionsFeature
import mozilla.components.feature.sitepermissions.SitePermissionsRules import mozilla.components.feature.sitepermissions.SitePermissionsRules
import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.feature.tab.collections.TabCollection import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.base.feature.BackHandler import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.view.exitImmersiveModeIfNeeded import mozilla.components.support.ktx.android.view.exitImmersiveModeIfNeeded
@ -151,7 +150,7 @@ class BrowserFragment : Fragment(), BackHandler {
BrowserState( BrowserState(
quickActionSheetState = QuickActionSheetState( quickActionSheetState = QuickActionSheetState(
readable = getSessionById()?.readerable ?: false, readable = getSessionById()?.readerable ?: false,
bookmarked = findBookmarkedURL(getSessionById()), bookmarked = false,
readerActive = getSessionById()?.readerMode ?: false, readerActive = getSessionById()?.readerMode ?: false,
bounceNeeded = false, bounceNeeded = false,
isAppLink = getSessionById()?.let { appLink.invoke(it.url).hasExternalApp() } ?: false isAppLink = getSessionById()?.let { appLink.invoke(it.url).hasExternalApp() } ?: false
@ -684,9 +683,9 @@ class BrowserFragment : Fragment(), BackHandler {
}.also { requireComponents.core.sessionManager.register(it, this) } }.also { requireComponents.core.sessionManager.register(it, this) }
} }
private fun findBookmarkedURL(session: Session?): Boolean { private suspend fun findBookmarkedURL(session: Session?): Boolean {
session?.let { return withContext(IO) {
return runBlocking { session?.let {
try { try {
val url = URL(it.url).toString() val url = URL(it.url).toString()
val list = requireComponents.core.bookmarksStorage.getBookmarksWithUrl(url) val list = requireComponents.core.bookmarksStorage.getBookmarksWithUrl(url)
@ -694,9 +693,8 @@ class BrowserFragment : Fragment(), BackHandler {
} catch (e: MalformedURLException) { } catch (e: MalformedURLException) {
false false
} }
} } ?: false
} }
return false
} }
private fun updateBookmarkState(session: Session) { private fun updateBookmarkState(session: Session) {