Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Issue #11605: Add option to include provided top sites in TopSitesConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielluong committed Jan 25, 2022
1 parent c581640 commit b09803e
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 13 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

3 comments on commit b09803e

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

Failed to fetch task artifact public/github/customCheckRunText.md for GitHub integration.
Make sure the artifact exists on the worker or other location.

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

Failed to fetch task artifact public/github/customCheckRunText.md for GitHub integration.
Make sure the artifact exists on the worker or other location.

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

Failed to fetch task artifact public/github/customCheckRunText.md for GitHub integration.
Make sure the artifact exists on the worker or other location.

Please sign in to comment.