Package com.google.android.exoplayer2.ext.cronet

## 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` for `CronetDataSource` instances.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Factory​(CronetEngineWrapper cronetEngineWrapper, Executor executor)` | Creates an instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `HttpDataSource` | `createDataSource()` | Creates a `DataSource` instance.
    `HttpDataSource.RequestProperties` | `getDefaultRequestProperties()` | Deprecated. Use `setDefaultRequestProperties(Map)` instead.
    `CronetDataSource.Factory` | `setConnectionTimeoutMs​(int connectTimeoutMs)` | Sets the connect timeout, in milliseconds.
    `CronetDataSource.Factory` | `setContentTypePredicate​(Predicate<String> contentTypePredicate)` | Sets a content type `Predicate`.
    `CronetDataSource.Factory` | `setDefaultRequestProperties​(Map<String,​String> defaultRequestProperties)` | Sets the default request headers for `HttpDataSource` instances created by the factory.
    `CronetDataSource.Factory` | `setFallbackFactory​(HttpDataSource.Factory fallbackFactory)` | Sets the fallback `HttpDataSource.Factory` that is used as a fallback if the `CronetEngineWrapper` fails to provide a `CronetEngine`.
    `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` | `setReadTimeoutMs​(int readTimeoutMs)` | Sets the read timeout, in milliseconds.
    `CronetDataSource.Factory` | `setResetTimeoutOnRedirects​(boolean resetTimeoutOnRedirects)` | Sets whether the connect timeout is reset when a redirect occurs.
    `CronetDataSource.Factory` | `setTransferListener​(TransferListener transferListener)` | Sets the `TransferListener` that will be used.
    `CronetDataSource.Factory` | `setUserAgent​(String userAgent)` | Sets the user agent that will be used.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Factory

          public Factory​(CronetEngineWrapper cronetEngineWrapper,
                         Executor executor)

      Creates an instance.
      Parameters:
        `cronetEngineWrapper` - A `CronetEngineWrapper`.
        `executor` - The `Executor` 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

    - #### getDefaultRequestProperties

          @Deprecated
          public final HttpDataSource.RequestProperties getDefaultRequestProperties()

      Deprecated.
      Use `setDefaultRequestProperties(Map)` instead.
      Specified by:
        `getDefaultRequestProperties` in interface `HttpDataSource.Factory`

    - #### setDefaultRequestProperties

          public final CronetDataSource.Factory setDefaultRequestProperties​(Map<String,​String> defaultRequestProperties)

      Description copied from interface: `HttpDataSource.Factory`
      Sets the default request headers for `HttpDataSource` 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 the `defaultRequestProperties` 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 interface `HttpDataSource.Factory`
      Parameters:
        `defaultRequestProperties` - The default request properties.
      Returns:
        This factory.

    - #### setUserAgent

          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 underlying `CronetEngine` to be used.

      Parameters:
        `userAgent` - The user agent that will be used, or `null` to use the default user agent of the underlying `CronetEngine`.
      Returns:
        This factory.

    - #### setConnectionTimeoutMs

          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

          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

          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

          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

          public CronetDataSource.Factory setContentTypePredicate​(@Nullable
                                                                  Predicate<String> contentTypePredicate)

      Sets a content type `Predicate`. If a content type is rejected by the predicate then a `HttpDataSource.InvalidContentTypeException` is thrown from `DataSource.open(DataSpec)`.

      The default is `null`.

      Parameters:
        `contentTypePredicate` - The content type `Predicate`, or `null` to clear a predicate that was previously set.
      Returns:
        This factory.

    - #### setTransferListener

          public CronetDataSource.Factory setTransferListener​(@Nullable
                                                              TransferListener transferListener)

      Sets the `TransferListener` that will be used.

      The default is `null`.

      See `DataSource.addTransferListener(TransferListener)`.

      Parameters:
        `transferListener` - The listener that will be used.
      Returns:
        This factory.

    - #### setFallbackFactory

          public CronetDataSource.Factory setFallbackFactory​(@Nullable
                                                             HttpDataSource.Factory fallbackFactory)

      Sets the fallback `HttpDataSource.Factory` that is used as a fallback if the `CronetEngineWrapper` fails to provide a `CronetEngine`.

      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 a `DataSource` instance.
      Specified by:
        `createDataSource` in interface `DataSource.Factory`
      Specified by:
        `createDataSource` in interface `HttpDataSource.Factory`