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

Issue #11483: Implement a ContileTopSitesProvider #11525

Merged
merged 3 commits into from
Jan 17, 2022

Conversation

gabrielluong
Copy link
Member

Fixes #11483.

I am taking an incremental approach here. It's best to review commits separately. In followups, I will be looking at adding a WorkManager to periodically fetch along with a disk cache to store the results.

Pull Request checklist

  • Quality: This PR builds and passes detekt/ktlint checks (A pre-push hook is recommended)
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry or does not need one
  • Accessibility: The code in this PR follows accessibility best practices or does not include any user facing features

After merge

  • Milestone: Make sure issues closed by this pull request are added to the milestone of the version currently in development.
  • Breaking Changes: If this is a breaking change, please push a draft PR on Reference Browser to address the breaking issues.

@gabrielluong gabrielluong requested review from grigoryk and a team as code owners January 12, 2022 03:25
@gabrielluong gabrielluong requested review from Amejia481 and csadilek and removed request for grigoryk January 12, 2022 03:25
@gabrielluong gabrielluong added the 🕵️‍♀️ needs review PRs that need to be reviewed label Jan 12, 2022
@gabrielluong gabrielluong force-pushed the 11483 branch 4 times, most recently from 4c540f3 to 57a8d71 Compare January 12, 2022 07:46
Copy link
Contributor

@Amejia481 Amejia481 left a comment

Choose a reason for hiding this comment

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

Great job!
It looks good to me 👍🏽
Should we also link a add a PR for addressing the breaking changes on Fenix?

@mergify
Copy link
Contributor

mergify bot commented Jan 12, 2022

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

Copy link
Contributor

@csadilek csadilek left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Left a few comments and a suggestion below, but your choice :)

@@ -23,17 +23,21 @@ import kotlin.coroutines.CoroutineContext
* @param pinnedSitesStorage An instance of [PinnedSiteStorage], used for storing pinned sites.
* @param historyStorage An instance of [PlacesHistoryStorage], used for retrieving top frecent
* sites from history.
* @param topSitesProvider An optional instance of [TopSitesProvider], used for retrieving top
* sites from a provider.
* @param defaultTopSites A list containing a title to url pair of default top sites to be added
* to the [PinnedSiteStorage].
*/
class DefaultTopSitesStorage(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not for now but we have a confusing design (or at least naming) here. The default storage is composed of other storages (PinnedSiteStorage, PlacesHistoryStorage) and now also a provider (TopSitesProvider). It's not clear to consumers at all how top sites are loaded / stored when using DefaultTopSitesStorage.

I could see us refactoring this into a top-level class TopSitesProvider or TopSitesManager :) that accepts a list of top site sources/services. Right now we're passing the storages and the provider to another storage which is quite confusing.

@gabrielluong gabrielluong added 🛬 needs landing PRs that are ready to land and removed 🕵️‍♀️ needs review PRs that need to be reviewed labels Jan 17, 2022
@mergify mergify bot merged commit a0acc00 into mozilla-mobile:main Jan 17, 2022
@gabrielluong gabrielluong deleted the 11483 branch January 17, 2022 22:44
Copy link
Contributor

@jonalmeida jonalmeida left a comment

Choose a reason for hiding this comment

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

Drive-by 🚗 : I left some comments that you may want to consider for #11529, which I discovered after reviewing mozilla-mobile/fenix#23410

Nothing urgent or required, just suggestions. 🙂


private fun fetchTopSites(): List<TopSite.Provided> {
client.fetch(
Request(url = CONTILE_ENDPOINT_URL)
Copy link
Contributor

Choose a reason for hiding this comment

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

This endpoint could be good as a parameter with CONTILE_ENDPOINT_URL as the default so we aren't tied to this endpoint (say, if we need a separate one for Focus/Fenix).

return try {
JSONObject(responseBody).getTopSites()
} catch (e: JSONException) {
throw IOException(e)
Copy link
Contributor

Choose a reason for hiding this comment

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

For JSONObject.toTopSite() we return null on exception, but for JSONObject.getTopSites() we throw here - it's not clear why we would want to throw it on only this one and then catch it to re-throw it above because the consuming app now needs to try/catch their call as well in order to be safe.

Might be prudent to log the exception and return null/emptyList so that we crash the app if the request is successful but the response has nothing in it.

docs/components.md Show resolved Hide resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🛬 needs landing PRs that are ready to land
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ContileTopSitesProvider
4 participants