Remove Loadable.isLoadCanceled

This simplifies Loadable implementations, and also removes the
possibility of an incorrect Loadable implementation causing the
wrong Loader.Callback method being called (perviously, for the
correct method to be called, we relied on isLoadCanceled being
implemented correctly).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=198871133
This commit is contained in:
olly 2018-06-01 07:46:29 -07:00 committed by Oliver Woodman
parent 47c1404865
commit 6cfc7b7ebb
10 changed files with 7 additions and 59 deletions

View file

@ -832,11 +832,6 @@ import java.util.Arrays;
loadCanceled = true;
}
@Override
public boolean isLoadCanceled() {
return loadCanceled;
}
@Override
public void load() throws IOException, InterruptedException {
int result = Extractor.RESULT_CONTINUE;

View file

@ -348,11 +348,6 @@ import java.util.Arrays;
// Never happens.
}
@Override
public boolean isLoadCanceled() {
return false;
}
@Override
public void load() throws IOException, InterruptedException {
// We always load from the beginning, so reset the sampleSize to 0.

View file

@ -106,11 +106,6 @@ public class ContainerMediaChunk extends BaseMediaChunk {
loadCanceled = true;
}
@Override
public final boolean isLoadCanceled() {
return loadCanceled;
}
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public final void load() throws IOException, InterruptedException {

View file

@ -75,11 +75,6 @@ public abstract class DataChunk extends Chunk {
loadCanceled = true;
}
@Override
public final boolean isLoadCanceled() {
return loadCanceled;
}
@Override
public final void load() throws IOException, InterruptedException {
try {

View file

@ -69,11 +69,6 @@ public final class InitializationChunk extends Chunk {
loadCanceled = true;
}
@Override
public boolean isLoadCanceled() {
return loadCanceled;
}
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException, InterruptedException {

View file

@ -34,7 +34,6 @@ public final class SingleSampleMediaChunk extends BaseMediaChunk {
private final Format sampleFormat;
private volatile int bytesLoaded;
private volatile boolean loadCanceled;
private volatile boolean loadCompleted;
/**
@ -90,12 +89,7 @@ public final class SingleSampleMediaChunk extends BaseMediaChunk {
@Override
public void cancelLoad() {
loadCanceled = true;
}
@Override
public boolean isLoadCanceled() {
return loadCanceled;
// Do nothing.
}
@SuppressWarnings("NonAtomicVolatileUpdate")

View file

@ -57,11 +57,6 @@ public final class Loader implements LoaderErrorThrower {
*/
void cancelLoad();
/**
* Returns whether the load has been canceled.
*/
boolean isLoadCanceled();
/**
* Performs the load, returning on completion or cancellation.
*
@ -260,6 +255,7 @@ public final class Loader implements LoaderErrorThrower {
private int errorCount;
private volatile Thread executorThread;
private volatile boolean canceled;
private volatile boolean released;
public LoadTask(Looper looper, T loadable, Loader.Callback<T> callback,
@ -296,6 +292,7 @@ public final class Loader implements LoaderErrorThrower {
sendEmptyMessage(MSG_CANCEL);
}
} else {
canceled = true;
loadable.cancelLoad();
if (executorThread != null) {
executorThread.interrupt();
@ -317,7 +314,7 @@ public final class Loader implements LoaderErrorThrower {
public void run() {
try {
executorThread = Thread.currentThread();
if (!loadable.isLoadCanceled()) {
if (!canceled) {
TraceUtil.beginSection("load:" + loadable.getClass().getSimpleName());
try {
loadable.load();
@ -334,7 +331,7 @@ public final class Loader implements LoaderErrorThrower {
}
} catch (InterruptedException e) {
// The load was canceled.
Assertions.checkState(loadable.isLoadCanceled());
Assertions.checkState(canceled);
if (!released) {
sendEmptyMessage(MSG_END_OF_SOURCE);
}
@ -379,7 +376,7 @@ public final class Loader implements LoaderErrorThrower {
finish();
long nowMs = SystemClock.elapsedRealtime();
long durationMs = nowMs - startTimeMs;
if (loadable.isLoadCanceled()) {
if (canceled) {
callback.onLoadCanceled(loadable, nowMs, durationMs, false);
return;
}

View file

@ -78,7 +78,6 @@ public final class ParsingLoadable<T> implements Loadable {
private final Parser<? extends T> parser;
private volatile T result;
private volatile boolean isCanceled;
private volatile long bytesLoaded;
/**
@ -128,14 +127,7 @@ public final class ParsingLoadable<T> implements Loadable {
@Override
public final void cancelLoad() {
// We don't actually cancel anything, but we need to record the cancellation so that
// isLoadCanceled can return the correct value.
isCanceled = true;
}
@Override
public final boolean isLoadCanceled() {
return isCanceled;
// Do nothing.
}
@Override

View file

@ -391,11 +391,6 @@ public final class AdaptiveTrackSelectionTest {
// Do nothing.
}
@Override
public boolean isLoadCanceled() {
return false;
}
@Override
public void load() throws IOException, InterruptedException {
// Do nothing.

View file

@ -206,11 +206,6 @@ import java.util.concurrent.atomic.AtomicInteger;
loadCanceled = true;
}
@Override
public boolean isLoadCanceled() {
return loadCanceled;
}
@Override
public void load() throws IOException, InterruptedException {
maybeLoadInitData();