Class CronetDataSource.Factory
- java.lang.Object
-
- com.google.android.exoplayer2.ext.cronet.CronetDataSource.Factory
-
- All Implemented Interfaces:
DataSource.Factory
,HttpDataSource.Factory
- Enclosing class:
- CronetDataSource
public static final class CronetDataSource.Factory extends Object implements HttpDataSource.Factory
DataSource.Factory
forCronetDataSource
instances.
-
-
Constructor Summary
Constructors Constructor Description Factory(CronetEngineWrapper cronetEngineWrapper, Executor executor)
Deprecated.UseFactory(CronetEngine, Executor)
with an instantiatedCronetEngine
, orDefaultHttpDataSource
for cases whereCronetEngineWrapper.getCronetEngine()
would have returnednull
.Factory(org.chromium.net.CronetEngine cronetEngine, Executor executor)
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HttpDataSource
createDataSource()
Creates aDataSource
instance.CronetDataSource.Factory
setConnectionTimeoutMs(int connectTimeoutMs)
Sets the connect timeout, in milliseconds.CronetDataSource.Factory
setContentTypePredicate(Predicate<String> contentTypePredicate)
Sets a content typePredicate
.CronetDataSource.Factory
setDefaultRequestProperties(Map<String,String> defaultRequestProperties)
Sets the default request headers forHttpDataSource
instances created by the factory.CronetDataSource.Factory
setFallbackFactory(HttpDataSource.Factory fallbackFactory)
Deprecated.Do not useCronetDataSource
or its factory in cases where a suitableCronetEngine
is not available.CronetDataSource.Factory
setHandleSetCookieRequests(boolean handleSetCookieRequests)
Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.CronetDataSource.Factory
setKeepPostFor302Redirects(boolean keepPostFor302Redirects)
Sets whether we should keep the POST method and body when we have HTTP 302 redirects for a POST request.CronetDataSource.Factory
setReadTimeoutMs(int readTimeoutMs)
Sets the read timeout, in milliseconds.CronetDataSource.Factory
setRequestPriority(int requestPriority)
Sets the priority of requests made byCronetDataSource
instances created by this factory.CronetDataSource.Factory
setResetTimeoutOnRedirects(boolean resetTimeoutOnRedirects)
Sets whether the connect timeout is reset when a redirect occurs.CronetDataSource.Factory
setTransferListener(TransferListener transferListener)
Sets theTransferListener
that will be used.CronetDataSource.Factory
setUserAgent(String userAgent)
Sets the user agent that will be used.
-
-
-
Constructor Detail
-
Factory
public Factory(org.chromium.net.CronetEngine cronetEngine, Executor executor)
Creates an instance.- Parameters:
cronetEngine
- ACronetEngine
to make the requests. This should not be a fallback instance obtained fromJavaCronetProvider
. It's more efficient to useDefaultHttpDataSource
instead in this case.executor
- TheExecutor
that will handle responses. This may be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread hop from Cronet's internal network thread to the response handling thread. However, to avoid slowing down overall network performance, care must be taken to make sure response handling is a fast operation when using a direct executor.
-
Factory
@Deprecated public Factory(CronetEngineWrapper cronetEngineWrapper, Executor executor)
Deprecated.UseFactory(CronetEngine, Executor)
with an instantiatedCronetEngine
, orDefaultHttpDataSource
for cases whereCronetEngineWrapper.getCronetEngine()
would have returnednull
.Creates an instance.- Parameters:
cronetEngineWrapper
- ACronetEngineWrapper
.executor
- TheExecutor
that will handle responses. This may be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread hop from Cronet's internal network thread to the response handling thread. However, to avoid slowing down overall network performance, care must be taken to make sure response handling is a fast operation when using a direct executor.
-
-
Method Detail
-
setDefaultRequestProperties
@CanIgnoreReturnValue public final CronetDataSource.Factory setDefaultRequestProperties(Map<String,String> defaultRequestProperties)
Description copied from interface:HttpDataSource.Factory
Sets the default request headers forHttpDataSource
instances created by the factory.The new request properties will be used for future requests made by
HttpDataSources
created by the factory, including instances that have already been created. Modifying thedefaultRequestProperties
map after a call to this method will have no effect, and so it's necessary to call this method again each time the request properties need to be updated.- Specified by:
setDefaultRequestProperties
in interfaceHttpDataSource.Factory
- Parameters:
defaultRequestProperties
- The default request properties.- Returns:
- This factory.
-
setUserAgent
@CanIgnoreReturnValue public CronetDataSource.Factory setUserAgent(@Nullable String userAgent)
Sets the user agent that will be used.The default is
null
, which causes the default user agent of the underlyingCronetEngine
to be used.- Parameters:
userAgent
- The user agent that will be used, ornull
to use the default user agent of the underlyingCronetEngine
.- Returns:
- This factory.
-
setRequestPriority
@CanIgnoreReturnValue public CronetDataSource.Factory setRequestPriority(int requestPriority)
Sets the priority of requests made byCronetDataSource
instances created by this factory.The default is
UrlRequest.Builder.REQUEST_PRIORITY_MEDIUM
.- Parameters:
requestPriority
- The request priority, which should be one of Cronet'sUrlRequest.Builder#REQUEST_PRIORITY_*
constants.- Returns:
- This factory.
-
setConnectionTimeoutMs
@CanIgnoreReturnValue public CronetDataSource.Factory setConnectionTimeoutMs(int connectTimeoutMs)
Sets the connect timeout, in milliseconds.The default is
CronetDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS
.- Parameters:
connectTimeoutMs
- The connect timeout, in milliseconds, that will be used.- Returns:
- This factory.
-
setResetTimeoutOnRedirects
@CanIgnoreReturnValue public CronetDataSource.Factory setResetTimeoutOnRedirects(boolean resetTimeoutOnRedirects)
Sets whether the connect timeout is reset when a redirect occurs.The default is
false
.- Parameters:
resetTimeoutOnRedirects
- Whether the connect timeout is reset when a redirect occurs.- Returns:
- This factory.
-
setHandleSetCookieRequests
@CanIgnoreReturnValue public CronetDataSource.Factory setHandleSetCookieRequests(boolean handleSetCookieRequests)
Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.The default is
false
.- Parameters:
handleSetCookieRequests
- Whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.- Returns:
- This factory.
-
setReadTimeoutMs
@CanIgnoreReturnValue public CronetDataSource.Factory setReadTimeoutMs(int readTimeoutMs)
Sets the read timeout, in milliseconds.The default is
CronetDataSource.DEFAULT_READ_TIMEOUT_MILLIS
.- Parameters:
readTimeoutMs
- The connect timeout, in milliseconds, that will be used.- Returns:
- This factory.
-
setContentTypePredicate
@CanIgnoreReturnValue public CronetDataSource.Factory setContentTypePredicate(@Nullable Predicate<String> contentTypePredicate)
Sets a content typePredicate
. If a content type is rejected by the predicate then aHttpDataSource.InvalidContentTypeException
is thrown fromDataSource.open(DataSpec)
.The default is
null
.- Parameters:
contentTypePredicate
- The content typePredicate
, ornull
to clear a predicate that was previously set.- Returns:
- This factory.
-
setKeepPostFor302Redirects
@CanIgnoreReturnValue public CronetDataSource.Factory setKeepPostFor302Redirects(boolean keepPostFor302Redirects)
Sets whether we should keep the POST method and body when we have HTTP 302 redirects for a POST request.
-
setTransferListener
@CanIgnoreReturnValue public CronetDataSource.Factory setTransferListener(@Nullable TransferListener transferListener)
Sets theTransferListener
that will be used.The default is
null
.- Parameters:
transferListener
- The listener that will be used.- Returns:
- This factory.
-
setFallbackFactory
@CanIgnoreReturnValue @Deprecated public CronetDataSource.Factory setFallbackFactory(@Nullable HttpDataSource.Factory fallbackFactory)
Deprecated.Do not useCronetDataSource
or its factory in cases where a suitableCronetEngine
is not available. Use the fallback factory directly in such cases.Sets the fallbackHttpDataSource.Factory
that is used as a fallback if theCronetEngineWrapper
fails to provide aCronetEngine
.By default a
DefaultHttpDataSource
is used as fallback factory.- Parameters:
fallbackFactory
- The fallback factory that will be used.- Returns:
- This factory.
-
createDataSource
public HttpDataSource createDataSource()
Description copied from interface:DataSource.Factory
Creates aDataSource
instance.- Specified by:
createDataSource
in interfaceDataSource.Factory
- Specified by:
createDataSource
in interfaceHttpDataSource.Factory
-
-