Skip to content

Commit

Permalink
Issue mozilla-mobile#11605: Add option to include provided top sites …
Browse files Browse the repository at this point in the history
…in TopSitesConfig
  • Loading branch information
gabrielluong committed Jan 25, 2022
1 parent c581640 commit cd0f1ce
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class DefaultTopSitesStorage(
@Suppress("TooGenericExceptionCaught")
override suspend fun getTopSites(
totalSites: Int,
fetchProvidedTopSites: Boolean,
frecencyConfig: FrecencyThresholdOption?
): List<TopSite> {
val topSites = ArrayList<TopSite>()
Expand All @@ -94,9 +95,9 @@ class DefaultTopSitesStorage(

topSites.addAll(pinnedSites)

topSitesProvider?.let { provider ->
if (fetchProvidedTopSites && topSitesProvider != null) {
try {
val providerTopSites = provider.getTopSites()
val providerTopSites = topSitesProvider.getTopSites()
topSites.addAll(providerTopSites.take(numSitesRequired))
numSitesRequired -= providerTopSites.size
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import mozilla.components.concept.storage.FrecencyThresholdOption
* whether or not to include top frecent sites in the top sites feature.
*
* @property totalSites A total number of sites that will be displayed.
* @property fetchProvidedTopSites Whether or not to fetch top sites from the [TopSitesProvider].
* @property frecencyConfig If [frecencyConfig] is specified, only visited sites with a frecency
* score above the given threshold will be returned. Otherwise, frecent top site results are
* not included.
*/
data class TopSitesConfig(
val totalSites: Int,
val fetchProvidedTopSites: Boolean,
val frecencyConfig: FrecencyThresholdOption?
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package mozilla.components.feature.top.sites

import mozilla.components.browser.storage.sync.PlacesHistoryStorage
import mozilla.components.concept.storage.FrecencyThresholdOption
import mozilla.components.support.base.observer.Observable

Expand Down Expand Up @@ -42,12 +43,14 @@ interface TopSitesStorage : Observable<TopSitesStorage.Observer> {
* If `frecencyConfig` is specified, fill in any missing top sites with frecent top site results.
*
* @param totalSites A total number of sites that will be retrieve if possible.
* @param fetchProvidedTopSites Whether or not to fetch top sites from the [TopSitesProvider].
* @param frecencyConfig If [frecencyConfig] is specified, only visited sites with a frecency
* score above the given threshold will be returned. Otherwise, frecent top site results are
* not included.
*/
suspend fun getTopSites(
totalSites: Int,
fetchProvidedTopSites: Boolean,
frecencyConfig: FrecencyThresholdOption?
): List<TopSite>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal class DefaultTopSitesPresenter(
scope.launch {
val topSites = storage.getTopSites(
innerConfig.totalSites,
innerConfig.fetchProvidedTopSites,
innerConfig.frecencyConfig
)

Expand Down
Loading

0 comments on commit cd0f1ce

Please sign in to comment.