Commit 3a54d744 by olly Committed by Oliver Woodman

Default to respecting the DataSpec cache fragmentation flag

Issue: #4253
PiperOrigin-RevId: 230497544
parent 52f25f6e
...@@ -110,10 +110,8 @@ public final class DownloaderConstructorHelper { ...@@ -110,10 +110,8 @@ public final class DownloaderConstructorHelper {
? cacheReadDataSourceFactory ? cacheReadDataSourceFactory
: new FileDataSourceFactory(); : new FileDataSourceFactory();
if (cacheWriteDataSinkFactory == null) { if (cacheWriteDataSinkFactory == null) {
CacheDataSinkFactory factory = cacheWriteDataSinkFactory =
new CacheDataSinkFactory(cache, CacheDataSink.DEFAULT_FRAGMENT_SIZE); new CacheDataSinkFactory(cache, CacheDataSink.DEFAULT_FRAGMENT_SIZE);
factory.experimental_setRespectCacheFragmentationFlag(true);
cacheWriteDataSinkFactory = factory;
} }
onlineCacheDataSourceFactory = onlineCacheDataSourceFactory =
new CacheDataSourceFactory( new CacheDataSourceFactory(
......
...@@ -50,7 +50,6 @@ public final class CacheDataSink implements DataSink { ...@@ -50,7 +50,6 @@ public final class CacheDataSink implements DataSink {
private final int bufferSize; private final int bufferSize;
private boolean syncFileDescriptor; private boolean syncFileDescriptor;
private boolean respectCacheFragmentationFlag;
private DataSpec dataSpec; private DataSpec dataSpec;
private long dataSpecFragmentSize; private long dataSpecFragmentSize;
private File file; private File file;
...@@ -123,20 +122,6 @@ public final class CacheDataSink implements DataSink { ...@@ -123,20 +122,6 @@ public final class CacheDataSink implements DataSink {
this.syncFileDescriptor = syncFileDescriptor; this.syncFileDescriptor = syncFileDescriptor;
} }
/**
* Sets whether this instance respects the {@link DataSpec#FLAG_ALLOW_CACHE_FRAGMENTATION} flag.
* If set to {@code false} requests will always be fragmented. If set to {@code true} requests
* will be fragmented only if the flag is set.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param respectCacheFragmentationFlag Whether to respect the {@link
* DataSpec#FLAG_ALLOW_CACHE_FRAGMENTATION} flag.
*/
public void experimental_setRespectCacheFragmentationFlag(boolean respectCacheFragmentationFlag) {
this.respectCacheFragmentationFlag = respectCacheFragmentationFlag;
}
@Override @Override
public void open(DataSpec dataSpec) throws CacheDataSinkException { public void open(DataSpec dataSpec) throws CacheDataSinkException {
if (dataSpec.length == C.LENGTH_UNSET if (dataSpec.length == C.LENGTH_UNSET
...@@ -146,10 +131,7 @@ public final class CacheDataSink implements DataSink { ...@@ -146,10 +131,7 @@ public final class CacheDataSink implements DataSink {
} }
this.dataSpec = dataSpec; this.dataSpec = dataSpec;
this.dataSpecFragmentSize = this.dataSpecFragmentSize =
!respectCacheFragmentationFlag dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHE_FRAGMENTATION) ? fragmentSize : Long.MAX_VALUE;
|| dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHE_FRAGMENTATION)
? fragmentSize
: Long.MAX_VALUE;
dataSpecBytesWritten = 0; dataSpecBytesWritten = 0;
try { try {
openNextOutputStream(); openNextOutputStream();
......
...@@ -27,7 +27,6 @@ public final class CacheDataSinkFactory implements DataSink.Factory { ...@@ -27,7 +27,6 @@ public final class CacheDataSinkFactory implements DataSink.Factory {
private final int bufferSize; private final int bufferSize;
private boolean syncFileDescriptor; private boolean syncFileDescriptor;
private boolean respectCacheFragmentationFlag;
/** @see CacheDataSink#CacheDataSink(Cache, long) */ /** @see CacheDataSink#CacheDataSink(Cache, long) */
public CacheDataSinkFactory(Cache cache, long fragmentSize) { public CacheDataSinkFactory(Cache cache, long fragmentSize) {
...@@ -51,22 +50,10 @@ public final class CacheDataSinkFactory implements DataSink.Factory { ...@@ -51,22 +50,10 @@ public final class CacheDataSinkFactory implements DataSink.Factory {
return this; return this;
} }
/**
* See {@link CacheDataSink#experimental_setRespectCacheFragmentationFlag(boolean)}.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*/
public CacheDataSinkFactory experimental_setRespectCacheFragmentationFlag(
boolean respectCacheFragmentationFlag) {
this.respectCacheFragmentationFlag = respectCacheFragmentationFlag;
return this;
}
@Override @Override
public DataSink createDataSink() { public DataSink createDataSink() {
CacheDataSink dataSink = new CacheDataSink(cache, fragmentSize, bufferSize); CacheDataSink dataSink = new CacheDataSink(cache, fragmentSize, bufferSize);
dataSink.experimental_setSyncFileDescriptor(syncFileDescriptor); dataSink.experimental_setSyncFileDescriptor(syncFileDescriptor);
dataSink.experimental_setRespectCacheFragmentationFlag(respectCacheFragmentationFlag);
return dataSink; return dataSink;
} }
} }
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