Skip to content

Commit

Permalink
Allow context chain to be passed to FrescoVitoPrefetcher's
Browse files Browse the repository at this point in the history
Reviewed By: oprisnik, defHLT

Differential Revision: D57085974

fbshipit-source-id: 2bcf3728a2e265ab632f78c71e9936e50b775d6c
  • Loading branch information
Veeren Mandalia authored and facebook-github-bot committed May 16, 2024
1 parent 936c013 commit 5f91ddd
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.facebook.fresco.vito.core.impl

import android.net.Uri
import com.facebook.callercontext.CallerContextVerifier
import com.facebook.common.callercontext.ContextChain
import com.facebook.datasource.DataSource
import com.facebook.datasource.DataSources
import com.facebook.fresco.vito.core.FrescoVitoPrefetcher
Expand Down Expand Up @@ -49,6 +50,15 @@ class FrescoVitoPrefetcherImpl(
}
}

override fun prefetch(
prefetchTarget: PrefetchTarget,
uri: Uri,
imageOptions: ImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?> = prefetch(prefetchTarget, uri, imageOptions, callerContext, callsite)

override fun prefetchToBitmapCache(
uri: Uri,
imageOptions: DecodedImageOptions?,
Expand All @@ -59,6 +69,16 @@ class FrescoVitoPrefetcherImpl(
return prefetch(PrefetchTarget.MEMORY_DECODED, imageRequest, callerContext, null)
}

override fun prefetchToBitmapCache(
uri: Uri,
imageOptions: DecodedImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?> {
return prefetchToBitmapCache(uri, imageOptions, callerContext, callsite)
}

override fun prefetchToEncodedCache(
uri: Uri,
imageOptions: EncodedImageOptions?,
Expand All @@ -69,6 +89,14 @@ class FrescoVitoPrefetcherImpl(
return prefetch(PrefetchTarget.MEMORY_ENCODED, imageRequest, callerContext, null)
}

override fun prefetchToEncodedCache(
uri: Uri,
imageOptions: EncodedImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?> = prefetchToEncodedCache(uri, imageOptions, callerContext, callsite)

override fun prefetchToDiskCache(
uri: Uri,
imageOptions: ImageOptions?,
Expand All @@ -79,6 +107,14 @@ class FrescoVitoPrefetcherImpl(
return prefetch(PrefetchTarget.DISK, imageRequest, callerContext, null)
}

override fun prefetchToDiskCache(
uri: Uri,
imageOptions: ImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?> = prefetchToDiskCache(uri, imageOptions, callerContext, callsite)

override fun prefetch(
prefetchTarget: PrefetchTarget,
imageRequest: VitoImageRequest,
Expand All @@ -88,6 +124,16 @@ class FrescoVitoPrefetcherImpl(
): DataSource<Void?> =
prefetch(prefetchTarget, imageRequest.finalImageRequest, callerContext, requestListener)

override fun prefetch(
prefetchTarget: PrefetchTarget,
imageRequest: VitoImageRequest,
callerContext: Any?,
contextChain: ContextChain?,
requestListener: RequestListener?,
callsite: String
): DataSource<Void?> =
prefetch(prefetchTarget, imageRequest, callerContext, requestListener, callsite)

private fun prefetch(
prefetchTarget: PrefetchTarget,
imageRequest: ImageRequest?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.facebook.fresco.vito.core.impl

import android.net.Uri
import com.facebook.common.callercontext.ContextChain
import com.facebook.datasource.DataSource
import com.facebook.datasource.DataSources
import com.facebook.fresco.vito.core.FrescoVitoPrefetcher
Expand All @@ -29,31 +30,73 @@ class NoOpFrescoVitoPrefetcher(private val throwException: Boolean = false) : Fr
callsite: String
): DataSource<Void?> = maybeThrowUnsupportedOperationException()

override fun prefetch(
prefetchTarget: PrefetchTarget,
uri: Uri,
imageOptions: ImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?> = maybeThrowUnsupportedOperationException()

override fun prefetchToBitmapCache(
uri: Uri,
imageOptions: DecodedImageOptions?,
callerContext: Any?,
callsite: String
): DataSource<Void?> = maybeThrowUnsupportedOperationException()

override fun prefetchToBitmapCache(
uri: Uri,
imageOptions: DecodedImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?> = maybeThrowUnsupportedOperationException()

override fun prefetchToEncodedCache(
uri: Uri,
imageOptions: EncodedImageOptions?,
callerContext: Any?,
callsite: String
): DataSource<Void?> = maybeThrowUnsupportedOperationException()

override fun prefetchToEncodedCache(
uri: Uri,
imageOptions: EncodedImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?> = maybeThrowUnsupportedOperationException()

override fun prefetchToDiskCache(
uri: Uri,
imageOptions: ImageOptions?,
callerContext: Any?,
callsite: String
): DataSource<Void?> = maybeThrowUnsupportedOperationException()

override fun prefetchToDiskCache(
uri: Uri,
imageOptions: ImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?> = maybeThrowUnsupportedOperationException()

override fun prefetch(
prefetchTarget: PrefetchTarget,
imageRequest: VitoImageRequest,
callerContext: Any?,
requestListener: RequestListener?,
callsite: String
): DataSource<Void?> = maybeThrowUnsupportedOperationException()

override fun prefetch(
prefetchTarget: PrefetchTarget,
imageRequest: VitoImageRequest,
callerContext: Any?,
contextChain: ContextChain?,
requestListener: RequestListener?,
callsite: String
): DataSource<Void?> = maybeThrowUnsupportedOperationException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.facebook.fresco.vito.core

import android.net.Uri
import com.facebook.common.callercontext.ContextChain
import com.facebook.datasource.DataSource
import com.facebook.fresco.vito.options.DecodedImageOptions
import com.facebook.fresco.vito.options.EncodedImageOptions
Expand Down Expand Up @@ -37,6 +38,29 @@ interface FrescoVitoPrefetcher {
callsite: String
): DataSource<Void?>

/**
* Prefetch an image to the given [PrefetchTarget]
*
* Beware that if your network fetcher doesn't support priorities prefetch requests may slow down
* images which are immediately required on screen.
*
* @param prefetchTarget the target to prefetch to
* @param uri the image URI to prefetch
* @param imageOptions the image options used to display the image
* @param callerContext the caller context for the given image
* @param contextChain the context chain for the given image
* @param callsite the prefetch callsite from which this request is being made, for logging
* @return a DataSource that can safely be ignored.
*/
fun prefetch(
prefetchTarget: PrefetchTarget,
uri: Uri,
imageOptions: ImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?>

/**
* Prefetch an image to the bitmap memory cache (for decoded images). In order to cancel the
* prefetch, close the [DataSource] returned by this method.
Expand All @@ -57,6 +81,48 @@ interface FrescoVitoPrefetcher {
callsite: String
): DataSource<Void?>

/**
* Prefetch an image to the bitmap memory cache (for decoded images). In order to cancel the
* prefetch, close the [DataSource] returned by this method.
*
* Beware that if your network fetcher doesn't support priorities prefetch requests may slow down
* images which are immediately required on screen.
*
* @param uri the image URI to prefetch
* @param imageOptions the image options used to display the image
* @param callerContext the caller context for the given image
* @param contextChain the context chain for the given image
* @param callsite the prefetch callsite from which this request is being made, for logging
* @return a DataSource that can safely be ignored.
*/
fun prefetchToBitmapCache(
uri: Uri,
imageOptions: DecodedImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?>

/**
* Prefetch an image to the encoded memory cache. In order to cancel the prefetch, close the
* [DataSource] returned by this method.
*
* Beware that if your network fetcher doesn't support priorities prefetch requests may slow down
* images which are immediately required on screen.
*
* @param uri the image URI to prefetch
* @param imageOptions the image options used to display the image
* @param callerContext the caller context for the given image
* @param callsite the prefetch callsite from which this request is being made, for logging
* @return a DataSource that can safely be ignored.
*/
fun prefetchToEncodedCache(
uri: Uri,
imageOptions: EncodedImageOptions?,
callerContext: Any?,
callsite: String
): DataSource<Void?>

/**
* Prefetch an image to the encoded memory cache. In order to cancel the prefetch, close the
* [DataSource] returned by this method.
Expand All @@ -67,13 +133,15 @@ interface FrescoVitoPrefetcher {
* @param uri the image URI to prefetch
* @param imageOptions the image options used to display the image
* @param callerContext the caller context for the given image
* @param contextChain the context chain for the given image
* @param callsite the prefetch callsite from which this request is being made, for logging
* @return a DataSource that can safely be ignored.
*/
fun prefetchToEncodedCache(
uri: Uri,
imageOptions: EncodedImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?>

Expand All @@ -97,6 +165,49 @@ interface FrescoVitoPrefetcher {
callsite: String
): DataSource<Void?>

/**
* Prefetch an image to the disk cache. In order to cancel the prefetch, close the [DataSource]
* returned by this method.
*
* Beware that if your network fetcher doesn't support priorities prefetch requests may slow down
* images which are immediately required on screen.
*
* @param uri the image URI to prefetch
* @param imageOptions the image options used to display the image
* @param callerContext the caller context for the given image
* @param contextChain the context chain for the given image
* @param callsite the prefetch callsite from which this request is being made, for logging
* @return a DataSource that can safely be ignored.
*/
fun prefetchToDiskCache(
uri: Uri,
imageOptions: ImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
callsite: String
): DataSource<Void?>

/**
* Prefetch an image to the given [PrefetchTarget] using a [VitoImageRequest]. In order to cancel
* the prefetch, close the [DataSource] returned by this method.
*
* Beware that if your network fetcher doesn't support priorities prefetch requests may slow down
* images which are immediately required on screen.
*
* @param prefetchTarget the target to prefetch to
* @param callerContext the caller context for the given image
* @param requestListener optional request listener
* @param callsite the prefetch callsite from which this request is being made, for logging
* @return a DataSource that can safely be ignored.
*/
fun prefetch(
prefetchTarget: PrefetchTarget,
imageRequest: VitoImageRequest,
callerContext: Any?,
requestListener: RequestListener?,
callsite: String
): DataSource<Void?>

/**
* Prefetch an image to the given [PrefetchTarget] using a [VitoImageRequest]. In order to cancel
* the prefetch, close the [DataSource] returned by this method.
Expand All @@ -106,6 +217,7 @@ interface FrescoVitoPrefetcher {
*
* @param prefetchTarget the target to prefetch to
* @param callerContext the caller context for the given image
* @param contextChain the context chain for the given image
* @param requestListener optional request listener
* @param callsite the prefetch callsite from which this request is being made, for logging
* @return a DataSource that can safely be ignored.
Expand All @@ -114,6 +226,7 @@ interface FrescoVitoPrefetcher {
prefetchTarget: PrefetchTarget,
imageRequest: VitoImageRequest,
callerContext: Any?,
contextChain: ContextChain?,
requestListener: RequestListener?,
callsite: String
): DataSource<Void?>
Expand Down

0 comments on commit 5f91ddd

Please sign in to comment.