Commit 7621a71b by olly Committed by Oliver Woodman

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
parent 36701113
...@@ -833,11 +833,6 @@ import java.util.Arrays; ...@@ -833,11 +833,6 @@ import java.util.Arrays;
} }
@Override @Override
public boolean isLoadCanceled() {
return loadCanceled;
}
@Override
public void load() throws IOException, InterruptedException { public void load() throws IOException, InterruptedException {
int result = Extractor.RESULT_CONTINUE; int result = Extractor.RESULT_CONTINUE;
while (result == Extractor.RESULT_CONTINUE && !loadCanceled) { while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
......
...@@ -349,11 +349,6 @@ import java.util.Arrays; ...@@ -349,11 +349,6 @@ import java.util.Arrays;
} }
@Override @Override
public boolean isLoadCanceled() {
return false;
}
@Override
public void load() throws IOException, InterruptedException { public void load() throws IOException, InterruptedException {
// We always load from the beginning, so reset the sampleSize to 0. // We always load from the beginning, so reset the sampleSize to 0.
sampleSize = 0; sampleSize = 0;
......
...@@ -106,11 +106,6 @@ public class ContainerMediaChunk extends BaseMediaChunk { ...@@ -106,11 +106,6 @@ public class ContainerMediaChunk extends BaseMediaChunk {
loadCanceled = true; loadCanceled = true;
} }
@Override
public final boolean isLoadCanceled() {
return loadCanceled;
}
@SuppressWarnings("NonAtomicVolatileUpdate") @SuppressWarnings("NonAtomicVolatileUpdate")
@Override @Override
public final void load() throws IOException, InterruptedException { public final void load() throws IOException, InterruptedException {
......
...@@ -76,11 +76,6 @@ public abstract class DataChunk extends Chunk { ...@@ -76,11 +76,6 @@ public abstract class DataChunk extends Chunk {
} }
@Override @Override
public final boolean isLoadCanceled() {
return loadCanceled;
}
@Override
public final void load() throws IOException, InterruptedException { public final void load() throws IOException, InterruptedException {
try { try {
dataSource.open(dataSpec); dataSource.open(dataSpec);
......
...@@ -69,11 +69,6 @@ public final class InitializationChunk extends Chunk { ...@@ -69,11 +69,6 @@ public final class InitializationChunk extends Chunk {
loadCanceled = true; loadCanceled = true;
} }
@Override
public boolean isLoadCanceled() {
return loadCanceled;
}
@SuppressWarnings("NonAtomicVolatileUpdate") @SuppressWarnings("NonAtomicVolatileUpdate")
@Override @Override
public void load() throws IOException, InterruptedException { public void load() throws IOException, InterruptedException {
......
...@@ -34,7 +34,6 @@ public final class SingleSampleMediaChunk extends BaseMediaChunk { ...@@ -34,7 +34,6 @@ public final class SingleSampleMediaChunk extends BaseMediaChunk {
private final Format sampleFormat; private final Format sampleFormat;
private volatile int bytesLoaded; private volatile int bytesLoaded;
private volatile boolean loadCanceled;
private volatile boolean loadCompleted; private volatile boolean loadCompleted;
/** /**
...@@ -90,12 +89,7 @@ public final class SingleSampleMediaChunk extends BaseMediaChunk { ...@@ -90,12 +89,7 @@ public final class SingleSampleMediaChunk extends BaseMediaChunk {
@Override @Override
public void cancelLoad() { public void cancelLoad() {
loadCanceled = true; // Do nothing.
}
@Override
public boolean isLoadCanceled() {
return loadCanceled;
} }
@SuppressWarnings("NonAtomicVolatileUpdate") @SuppressWarnings("NonAtomicVolatileUpdate")
......
...@@ -58,11 +58,6 @@ public final class Loader implements LoaderErrorThrower { ...@@ -58,11 +58,6 @@ public final class Loader implements LoaderErrorThrower {
void cancelLoad(); void cancelLoad();
/** /**
* Returns whether the load has been canceled.
*/
boolean isLoadCanceled();
/**
* Performs the load, returning on completion or cancellation. * Performs the load, returning on completion or cancellation.
* *
* @throws IOException If the input could not be loaded. * @throws IOException If the input could not be loaded.
...@@ -260,6 +255,7 @@ public final class Loader implements LoaderErrorThrower { ...@@ -260,6 +255,7 @@ public final class Loader implements LoaderErrorThrower {
private int errorCount; private int errorCount;
private volatile Thread executorThread; private volatile Thread executorThread;
private volatile boolean canceled;
private volatile boolean released; private volatile boolean released;
public LoadTask(Looper looper, T loadable, Loader.Callback<T> callback, public LoadTask(Looper looper, T loadable, Loader.Callback<T> callback,
...@@ -296,6 +292,7 @@ public final class Loader implements LoaderErrorThrower { ...@@ -296,6 +292,7 @@ public final class Loader implements LoaderErrorThrower {
sendEmptyMessage(MSG_CANCEL); sendEmptyMessage(MSG_CANCEL);
} }
} else { } else {
canceled = true;
loadable.cancelLoad(); loadable.cancelLoad();
if (executorThread != null) { if (executorThread != null) {
executorThread.interrupt(); executorThread.interrupt();
...@@ -317,7 +314,7 @@ public final class Loader implements LoaderErrorThrower { ...@@ -317,7 +314,7 @@ public final class Loader implements LoaderErrorThrower {
public void run() { public void run() {
try { try {
executorThread = Thread.currentThread(); executorThread = Thread.currentThread();
if (!loadable.isLoadCanceled()) { if (!canceled) {
TraceUtil.beginSection("load:" + loadable.getClass().getSimpleName()); TraceUtil.beginSection("load:" + loadable.getClass().getSimpleName());
try { try {
loadable.load(); loadable.load();
...@@ -334,7 +331,7 @@ public final class Loader implements LoaderErrorThrower { ...@@ -334,7 +331,7 @@ public final class Loader implements LoaderErrorThrower {
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
// The load was canceled. // The load was canceled.
Assertions.checkState(loadable.isLoadCanceled()); Assertions.checkState(canceled);
if (!released) { if (!released) {
sendEmptyMessage(MSG_END_OF_SOURCE); sendEmptyMessage(MSG_END_OF_SOURCE);
} }
...@@ -379,7 +376,7 @@ public final class Loader implements LoaderErrorThrower { ...@@ -379,7 +376,7 @@ public final class Loader implements LoaderErrorThrower {
finish(); finish();
long nowMs = SystemClock.elapsedRealtime(); long nowMs = SystemClock.elapsedRealtime();
long durationMs = nowMs - startTimeMs; long durationMs = nowMs - startTimeMs;
if (loadable.isLoadCanceled()) { if (canceled) {
callback.onLoadCanceled(loadable, nowMs, durationMs, false); callback.onLoadCanceled(loadable, nowMs, durationMs, false);
return; return;
} }
......
...@@ -78,7 +78,6 @@ public final class ParsingLoadable<T> implements Loadable { ...@@ -78,7 +78,6 @@ public final class ParsingLoadable<T> implements Loadable {
private final Parser<? extends T> parser; private final Parser<? extends T> parser;
private volatile T result; private volatile T result;
private volatile boolean isCanceled;
private volatile long bytesLoaded; private volatile long bytesLoaded;
/** /**
...@@ -128,14 +127,7 @@ public final class ParsingLoadable<T> implements Loadable { ...@@ -128,14 +127,7 @@ public final class ParsingLoadable<T> implements Loadable {
@Override @Override
public final void cancelLoad() { public final void cancelLoad() {
// We don't actually cancel anything, but we need to record the cancellation so that // Do nothing.
// isLoadCanceled can return the correct value.
isCanceled = true;
}
@Override
public final boolean isLoadCanceled() {
return isCanceled;
} }
@Override @Override
......
...@@ -392,11 +392,6 @@ public final class AdaptiveTrackSelectionTest { ...@@ -392,11 +392,6 @@ public final class AdaptiveTrackSelectionTest {
} }
@Override @Override
public boolean isLoadCanceled() {
return false;
}
@Override
public void load() throws IOException, InterruptedException { public void load() throws IOException, InterruptedException {
// Do nothing. // Do nothing.
} }
......
...@@ -207,11 +207,6 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -207,11 +207,6 @@ import java.util.concurrent.atomic.AtomicInteger;
} }
@Override @Override
public boolean isLoadCanceled() {
return loadCanceled;
}
@Override
public void load() throws IOException, InterruptedException { public void load() throws IOException, InterruptedException {
maybeLoadInitData(); maybeLoadInitData();
if (!loadCanceled) { if (!loadCanceled) {
......
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