Deprecate HttpDataSource.Factory.getDefaultRequestProperties

#exofixit

PiperOrigin-RevId: 347375323
This commit is contained in:
bachinger 2020-12-14 14:48:03 +00:00 committed by Christos Tsilopoulos
parent 5aac1898bb
commit a335c96450
4 changed files with 23 additions and 59 deletions

View File

@ -23,6 +23,8 @@
been handled and the values reported through callbacks are again been handled and the values reported through callbacks are again
completely consistent with the values obtained from the `Player` completely consistent with the values obtained from the `Player`
getters. getters.
* Deprecate `HttpDataSource.Factory.getDefaultRequestProperties` and add
`HttpDataSource.Factory.setDefaultRequestProperties` instead.
* Track selection: * Track selection:
* Add option to specify multiple preferred audio or text languages. * Add option to specify multiple preferred audio or text languages.
* Forward `Timeline` and `MediaPeriodId` to `TrackSelection.Factory`. * Forward `Timeline` and `MediaPeriodId` to `TrackSelection.Factory`.

View File

@ -343,7 +343,7 @@ public final class CronetDataSourceFactory extends BaseFactory {
@Override @Override
protected HttpDataSource createDataSourceInternal(HttpDataSource.RequestProperties protected HttpDataSource createDataSourceInternal(HttpDataSource.RequestProperties
defaultRequestProperties) { defaultRequestProperties) {
CronetEngine cronetEngine = cronetEngineWrapper.getCronetEngine(); @Nullable CronetEngine cronetEngine = cronetEngineWrapper.getCronetEngine();
if (cronetEngine == null) { if (cronetEngine == null) {
return fallbackFactory.createDataSource(); return fallbackFactory.createDataSource();
} }

View File

@ -343,8 +343,7 @@ public final class DataSpec {
* header directly. * header directly.
* <li>Other headers set at the {@link HttpDataSource} layer. I.e., headers set using {@link * <li>Other headers set at the {@link HttpDataSource} layer. I.e., headers set using {@link
* HttpDataSource#setRequestProperty(String, String)}, and using {@link * HttpDataSource#setRequestProperty(String, String)}, and using {@link
* HttpDataSource.RequestProperties#set(String, String)} on the default properties obtained * HttpDataSource.Factory#setDefaultRequestProperties(Map)}.
* from {@link HttpDataSource.Factory#getDefaultRequestProperties()}.
* </ul> * </ul>
*/ */
public final Map<String, String> httpRequestHeaders; public final Map<String, String> httpRequestHeaders;

View File

@ -42,43 +42,23 @@ public interface HttpDataSource extends DataSource {
@Override @Override
HttpDataSource createDataSource(); HttpDataSource createDataSource();
/** /** @deprecated Use {@link #setDefaultRequestProperties(Map)} instead. */
* Gets the default request properties used by all {@link HttpDataSource}s created by the @Deprecated
* factory. Changes to the properties will be reflected in any future requests made by
* {@link HttpDataSource}s created by the factory.
*
* @return The default request properties of the factory.
*/
RequestProperties getDefaultRequestProperties(); RequestProperties getDefaultRequestProperties();
/** /**
* Sets a default request header for {@link HttpDataSource} instances created by the factory. * Sets the default request headers for {@link HttpDataSource} instances created by the factory.
* *
* @deprecated Use {@link #getDefaultRequestProperties} instead. * <p>The new request properties will be used for future requests made by {@link HttpDataSource
* @param name The name of the header field. * HttpDataSources} created by the factory, including instances that have already been created.
* @param value The value of the field. * Modifying the {@code 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
@Deprecated * to be updated.
void setDefaultRequestProperty(String name, String value);
/**
* Clears a default request header for {@link HttpDataSource} instances created by the factory.
* *
* @deprecated Use {@link #getDefaultRequestProperties} instead. * @param defaultRequestProperties The default request properties.
* @param name The name of the header field. * @return This factory.
*/ */
@Deprecated Factory setDefaultRequestProperties(Map<String, String> defaultRequestProperties);
void clearDefaultRequestProperty(String name);
/**
* Clears all default request headers for all {@link HttpDataSource} instances created by the
* factory.
*
* @deprecated Use {@link #getDefaultRequestProperties} instead.
*/
@Deprecated
void clearAllDefaultRequestProperties();
} }
/** /**
@ -159,12 +139,9 @@ public interface HttpDataSource extends DataSource {
} }
return requestPropertiesSnapshot; return requestPropertiesSnapshot;
} }
} }
/** /** Base implementation of {@link Factory} that sets default request properties. */
* Base implementation of {@link Factory} that sets default request properties.
*/
abstract class BaseFactory implements Factory { abstract class BaseFactory implements Factory {
private final RequestProperties defaultRequestProperties; private final RequestProperties defaultRequestProperties;
@ -178,30 +155,17 @@ public interface HttpDataSource extends DataSource {
return createDataSourceInternal(defaultRequestProperties); return createDataSourceInternal(defaultRequestProperties);
} }
/** @deprecated Use {@link #setDefaultRequestProperties(Map)} instead. */
@Deprecated
@Override @Override
public final RequestProperties getDefaultRequestProperties() { public final RequestProperties getDefaultRequestProperties() {
return defaultRequestProperties; return defaultRequestProperties;
} }
/** @deprecated Use {@link #getDefaultRequestProperties} instead. */
@Deprecated
@Override @Override
public final void setDefaultRequestProperty(String name, String value) { public final Factory setDefaultRequestProperties(Map<String, String> defaultRequestProperties) {
defaultRequestProperties.set(name, value); this.defaultRequestProperties.clearAndSet(defaultRequestProperties);
} return this;
/** @deprecated Use {@link #getDefaultRequestProperties} instead. */
@Deprecated
@Override
public final void clearDefaultRequestProperty(String name) {
defaultRequestProperties.remove(name);
}
/** @deprecated Use {@link #getDefaultRequestProperties} instead. */
@Deprecated
@Override
public final void clearAllDefaultRequestProperties() {
defaultRequestProperties.clear();
} }
/** /**
@ -211,9 +175,8 @@ public interface HttpDataSource extends DataSource {
* {@link HttpDataSource} instance. * {@link HttpDataSource} instance.
* @return A {@link HttpDataSource} instance. * @return A {@link HttpDataSource} instance.
*/ */
protected abstract HttpDataSource createDataSourceInternal(RequestProperties protected abstract HttpDataSource createDataSourceInternal(
defaultRequestProperties); RequestProperties defaultRequestProperties);
} }
/** A {@link Predicate} that rejects content types often used for pay-walls. */ /** A {@link Predicate} that rejects content types often used for pay-walls. */