Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #23738 - Integrate the Contile top sites updater
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielluong committed Feb 22, 2022
1 parent 81d8c38 commit 0eab7c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
30 changes: 15 additions & 15 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ import org.mozilla.fenix.ext.setNavigationIcon
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.intent.CrashReporterIntentProcessor
import org.mozilla.fenix.home.intent.HomeDeepLinkIntentProcessor
import org.mozilla.fenix.home.intent.DefaultBrowserIntentProcessor
import org.mozilla.fenix.home.intent.HomeDeepLinkIntentProcessor
import org.mozilla.fenix.home.intent.OpenBrowserIntentProcessor
import org.mozilla.fenix.home.intent.OpenSpecificTabIntentProcessor
import org.mozilla.fenix.home.intent.SpeechProcessingIntentProcessor
Expand Down Expand Up @@ -279,6 +279,10 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {

components.core.requestInterceptor.setNavigationController(navHost.navController)

if (settings().showContileFeature) {
components.core.contileTopSitesUpdater.startPeriodicWork()
}

if (settings().showPocketRecommendationsFeature) {
components.core.pocketStoriesService.startPeriodicStoriesRefresh()
}
Expand Down Expand Up @@ -332,7 +336,15 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}
}

isFenixTheDefaultBrowser()
lifecycleScope.launch(IO) {
components.core.contileTopSitesProvider.refreshTopSitesIfCacheExpired()

if (settings().checkIfFenixIsDefaultBrowserOnAppResume()) {
metrics.track(Event.ChangedToDefaultBrowser)
}

DefaultBrowserNotificationWorker.setDefaultBrowserNotificationIfNeeded(applicationContext)
}
}

override fun onStart() {
Expand Down Expand Up @@ -435,6 +447,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
)
)

components.core.contileTopSitesUpdater.stopPeriodicWork()
components.core.pocketStoriesService.stopPeriodicStoriesRefresh()
privateNotificationObserver?.stop()
}
Expand Down Expand Up @@ -975,19 +988,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}
}

private fun isFenixTheDefaultBrowser() {
// Launch this on a background thread so as not to affect startup performance
lifecycleScope.launch(IO) {
if (
settings().checkIfFenixIsDefaultBrowserOnAppResume()
) {
metrics.track(Event.ChangedToDefaultBrowser)
}

DefaultBrowserNotificationWorker.setDefaultBrowserNotificationIfNeeded(applicationContext)
}
}

@VisibleForTesting
internal fun isActivityColdStarted(startingIntent: Intent, activityIcicle: Bundle?): Boolean {
// First time opening this activity in the task.
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/org/mozilla/fenix/components/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import mozilla.components.feature.webcompat.reporter.WebCompatReporterFeature
import mozilla.components.feature.webnotifications.WebNotificationFeature
import mozilla.components.lib.dataprotect.SecureAbove22Preferences
import mozilla.components.service.contile.ContileTopSitesProvider
import mozilla.components.service.contile.ContileTopSitesUpdater
import mozilla.components.service.digitalassetlinks.RelationChecker
import mozilla.components.service.digitalassetlinks.local.StatementApi
import mozilla.components.service.digitalassetlinks.local.StatementRelationChecker
Expand Down Expand Up @@ -89,6 +90,7 @@ import org.mozilla.fenix.telemetry.TelemetryMiddleware
import org.mozilla.fenix.utils.getUndoDelay
import org.mozilla.geckoview.GeckoRuntime
import java.util.concurrent.TimeUnit
import mozilla.components.service.contile.Frequency as ContileFrequency

/**
* Component group for all core browser functionality.
Expand Down Expand Up @@ -348,6 +350,15 @@ class Core(
)
}

@Suppress("MagicNumber")
val contileTopSitesUpdater by lazyMonitored {
ContileTopSitesUpdater(
context = context,
provider = contileTopSitesProvider,
frequency = ContileFrequency(3, TimeUnit.HOURS)
)
}

val topSitesStorage by lazyMonitored {
val defaultTopSites = mutableListOf<Pair<String, String>>()

Expand Down

0 comments on commit 0eab7c9

Please sign in to comment.