Skip to content

Commit

Permalink
Revert pushing download thread interruption into the Downloader imple…
Browse files Browse the repository at this point in the history
…mentations

Issue: #5978
PiperOrigin-RevId: 314175257
  • Loading branch information
ojw28 committed Jun 2, 2020
1 parent 8b89a5e commit 2f3c7cb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ public void cancel(boolean released) {
if (!isCanceled) {
isCanceled = true;
downloader.cancel();
interrupt();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ interface ProgressListener {
*/
void download(@Nullable ProgressListener progressListener) throws IOException;

/** Cancels the download operation and prevents future download operations from running. */
/**
* Cancels the download operation and prevents future download operations from running. The caller
* should also interrupt the downloading thread immediately after calling this method.
*/
void cancel();

/** Removes the content. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.upstream.cache.CacheWriter;
import com.google.android.exoplayer2.upstream.cache.CacheWriter.ProgressListener;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.PriorityTaskManager;
import com.google.android.exoplayer2.util.PriorityTaskManager.PriorityTooLowException;
Expand All @@ -37,8 +36,6 @@ public final class ProgressiveDownloader implements Downloader {
private final CacheDataSource dataSource;
private final AtomicBoolean isCanceled;

@Nullable private volatile Thread downloadThread;

/** @deprecated Use {@link #ProgressiveDownloader(MediaItem, CacheDataSource.Factory)} instead. */
@SuppressWarnings("deprecation")
@Deprecated
Expand Down Expand Up @@ -100,11 +97,6 @@ public ProgressiveDownloader(

@Override
public void download(@Nullable ProgressListener progressListener) throws IOException {
downloadThread = Thread.currentThread();
if (isCanceled.get()) {
return;
}

CacheWriter cacheWriter =
new CacheWriter(
dataSource,
Expand Down Expand Up @@ -143,10 +135,6 @@ public void download(@Nullable ProgressListener progressListener) throws IOExcep
@Override
public void cancel() {
isCanceled.set(true);
@Nullable Thread downloadThread = this.downloadThread;
if (downloadThread != null) {
downloadThread.interrupt();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public int compareTo(Segment other) {
private final Executor executor;
private final AtomicBoolean isCanceled;

@Nullable private volatile Thread downloadThread;

/**
* @param mediaItem The {@link MediaItem} to be downloaded.
* @param manifestParser A parser for the manifest.
Expand All @@ -107,10 +105,6 @@ public SegmentDownloader(

@Override
public final void download(@Nullable ProgressListener progressListener) throws IOException {
downloadThread = Thread.currentThread();
if (isCanceled.get()) {
return;
}
@Nullable
PriorityTaskManager priorityTaskManager =
cacheDataSourceFactory.getUpstreamPriorityTaskManager();
Expand Down Expand Up @@ -212,10 +206,6 @@ public final void download(@Nullable ProgressListener progressListener) throws I
@Override
public void cancel() {
isCanceled.set(true);
@Nullable Thread downloadThread = this.downloadThread;
if (downloadThread != null) {
downloadThread.interrupt();
}
}

@Override
Expand Down

0 comments on commit 2f3c7cb

Please sign in to comment.