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.FactoryforCronetDataSourceinstances.
-
-
Constructor Summary
Constructors Constructor Description Factory(CronetEngineWrapper cronetEngineWrapper, Executor executor)Deprecated.UseFactory(CronetEngine, Executor)with an instantiatedCronetEngine, orDefaultHttpDataSourcefor 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 HttpDataSourcecreateDataSource()Creates aDataSourceinstance.CronetDataSource.FactorysetConnectionTimeoutMs(int connectTimeoutMs)Sets the connect timeout, in milliseconds.CronetDataSource.FactorysetContentTypePredicate(Predicate<String> contentTypePredicate)Sets a content typePredicate.CronetDataSource.FactorysetDefaultRequestProperties(Map<String,String> defaultRequestProperties)Sets the default request headers forHttpDataSourceinstances created by the factory.CronetDataSource.FactorysetFallbackFactory(HttpDataSource.Factory fallbackFactory)Deprecated.Do not useCronetDataSourceor its factory in cases where a suitableCronetEngineis not available.CronetDataSource.FactorysetHandleSetCookieRequests(boolean handleSetCookieRequests)Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.CronetDataSource.FactorysetKeepPostFor302Redirects(boolean keepPostFor302Redirects)Sets whether we should keep the POST method and body when we have HTTP 302 redirects for a POST request.CronetDataSource.FactorysetReadTimeoutMs(int readTimeoutMs)Sets the read timeout, in milliseconds.CronetDataSource.FactorysetRequestPriority(int requestPriority)Sets the priority of requests made byCronetDataSourceinstances created by this factory.CronetDataSource.FactorysetResetTimeoutOnRedirects(boolean resetTimeoutOnRedirects)Sets whether the connect timeout is reset when a redirect occurs.CronetDataSource.FactorysetTransferListener(TransferListener transferListener)Sets theTransferListenerthat will be used.CronetDataSource.FactorysetUserAgent(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- ACronetEngineto make the requests. This should not be a fallback instance obtained fromJavaCronetProvider. It's more efficient to useDefaultHttpDataSourceinstead in this case.executor- TheExecutorthat 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, orDefaultHttpDataSourcefor cases whereCronetEngineWrapper.getCronetEngine()would have returnednull.Creates an instance.- Parameters:
cronetEngineWrapper- ACronetEngineWrapper.executor- TheExecutorthat 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.FactorySets the default request headers forHttpDataSourceinstances created by the factory.The new request properties will be used for future requests made by
HttpDataSourcescreated by the factory, including instances that have already been created. Modifying thedefaultRequestPropertiesmap 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:
setDefaultRequestPropertiesin 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 underlyingCronetEngineto be used.- Parameters:
userAgent- The user agent that will be used, ornullto 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 byCronetDataSourceinstances 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.InvalidContentTypeExceptionis thrown fromDataSource.open(DataSpec).The default is
null.- Parameters:
contentTypePredicate- The content typePredicate, ornullto 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 theTransferListenerthat 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 useCronetDataSourceor its factory in cases where a suitableCronetEngineis not available. Use the fallback factory directly in such cases.Sets the fallbackHttpDataSource.Factorythat is used as a fallback if theCronetEngineWrapperfails to provide aCronetEngine.By default a
DefaultHttpDataSourceis 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.FactoryCreates aDataSourceinstance.- Specified by:
createDataSourcein interfaceDataSource.Factory- Specified by:
createDataSourcein interfaceHttpDataSource.Factory
-
-