Commit f8311a48 by olly Committed by Oliver Woodman

Add some convenience constructors for Cronet in V2

- The need to pass a Clock is pretty much only for testing, so
  make the constructor that takes one package private + use
  the system clock for public constructors.
- Add default timeout values.
- Also make sure we set Content-Type in all license requests,
  since when using Cronet the stack requires it to be set.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=131404298
parent 4f670add
...@@ -77,6 +77,8 @@ public final class HttpMediaDrmCallback implements MediaDrmCallback { ...@@ -77,6 +77,8 @@ public final class HttpMediaDrmCallback implements MediaDrmCallback {
private byte[] executePost(String url, byte[] data, Map<String, String> requestProperties) private byte[] executePost(String url, byte[] data, Map<String, String> requestProperties)
throws IOException { throws IOException {
HttpDataSource dataSource = dataSourceFactory.createDataSource(); HttpDataSource dataSource = dataSourceFactory.createDataSource();
// Note: This will be overridden by a Content-Type in requestProperties, if one is set.
dataSource.setRequestProperty("Content-Type", "application/octet-stream");
if (requestProperties != null) { if (requestProperties != null) {
for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) { for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue()); dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
......
...@@ -69,8 +69,8 @@ public final class DefaultDataSourceFactory implements Factory { ...@@ -69,8 +69,8 @@ public final class DefaultDataSourceFactory implements Factory {
*/ */
public DefaultDataSourceFactory(Context context, String userAgent, public DefaultDataSourceFactory(Context context, String userAgent,
TransferListener<? super DataSource> listener, boolean allowCrossProtocolRedirects) { TransferListener<? super DataSource> listener, boolean allowCrossProtocolRedirects) {
this(context, userAgent, listener, DEFAULT_CONNECT_TIMEOUT_MILLIS, this(context, userAgent, listener, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS,
DEFAULT_CONNECT_TIMEOUT_MILLIS, allowCrossProtocolRedirects); allowCrossProtocolRedirects);
} }
/** /**
......
...@@ -86,9 +86,9 @@ public class DefaultHttpDataSource implements HttpDataSource { ...@@ -86,9 +86,9 @@ public class DefaultHttpDataSource implements HttpDataSource {
/** /**
* @param userAgent The User-Agent string that should be used. * @param userAgent The User-Agent string that should be used.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is * predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from
* thrown from {@link #open(DataSpec)}. * {@link #open(DataSpec)}.
*/ */
public DefaultHttpDataSource(String userAgent, Predicate<String> contentTypePredicate) { public DefaultHttpDataSource(String userAgent, Predicate<String> contentTypePredicate) {
this(userAgent, contentTypePredicate, null); this(userAgent, contentTypePredicate, null);
...@@ -96,9 +96,9 @@ public class DefaultHttpDataSource implements HttpDataSource { ...@@ -96,9 +96,9 @@ public class DefaultHttpDataSource implements HttpDataSource {
/** /**
* @param userAgent The User-Agent string that should be used. * @param userAgent The User-Agent string that should be used.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is * predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from
* thrown from {@link #open(DataSpec)}. * {@link #open(DataSpec)}.
* @param listener An optional listener. * @param listener An optional listener.
*/ */
public DefaultHttpDataSource(String userAgent, Predicate<String> contentTypePredicate, public DefaultHttpDataSource(String userAgent, Predicate<String> contentTypePredicate,
...@@ -109,9 +109,9 @@ public class DefaultHttpDataSource implements HttpDataSource { ...@@ -109,9 +109,9 @@ public class DefaultHttpDataSource implements HttpDataSource {
/** /**
* @param userAgent The User-Agent string that should be used. * @param userAgent The User-Agent string that should be used.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is * predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from
* thrown from {@link #open(DataSpec)}. * {@link #open(DataSpec)}.
* @param listener An optional listener. * @param listener An optional listener.
* @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is * @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is
* interpreted as an infinite timeout. * interpreted as an infinite timeout.
...@@ -126,9 +126,9 @@ public class DefaultHttpDataSource implements HttpDataSource { ...@@ -126,9 +126,9 @@ public class DefaultHttpDataSource implements HttpDataSource {
/** /**
* @param userAgent The User-Agent string that should be used. * @param userAgent The User-Agent string that should be used.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is * predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from
* thrown from {@link #open(DataSpec)}. * {@link #open(DataSpec)}.
* @param listener An optional listener. * @param listener An optional listener.
* @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is * @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is
* interpreted as an infinite timeout. Pass {@link #DEFAULT_CONNECT_TIMEOUT_MILLIS} to use * interpreted as an infinite timeout. Pass {@link #DEFAULT_CONNECT_TIMEOUT_MILLIS} to use
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment