Commit 23fd3d89 authored by twellington's avatar twellington Committed by Commit bot

[Downloads UI] Return early in DownloadItemWrapper#delete()

If the download item has been externally deleted from the file system,
return after removing it from the download backend but before
kicking off an AsyncTask to delete the file.

BUG=643753

Review-Url: https://codereview.chromium.org/2307123002
Cr-Commit-Position: refs/heads/master@{#416342}
parent 5bbd4485
...@@ -25,6 +25,8 @@ import org.chromium.ui.widget.Toast; ...@@ -25,6 +25,8 @@ import org.chromium.ui.widget.Toast;
import java.io.File; import java.io.File;
import java.util.Locale; import java.util.Locale;
import javax.annotation.Nullable;
/** Wraps different classes that contain information about downloads. */ /** Wraps different classes that contain information about downloads. */
public abstract class DownloadHistoryItemWrapper implements TimedItem { public abstract class DownloadHistoryItemWrapper implements TimedItem {
private static final String TAG = "download_ui"; private static final String TAG = "download_ui";
...@@ -80,7 +82,7 @@ public abstract class DownloadHistoryItemWrapper implements TimedItem { ...@@ -80,7 +82,7 @@ public abstract class DownloadHistoryItemWrapper implements TimedItem {
* Called when the user wants to delete the file. * Called when the user wants to delete the file.
* @param callback The Callback to be notified when the item is finished being deleted. * @param callback The Callback to be notified when the item is finished being deleted.
*/ */
abstract void delete(Callback<Void> callback); abstract void delete(@Nullable Callback<Void> callback);
/** /**
* @return Whether the file associated with this item has been removed through an external * @return Whether the file associated with this item has been removed through an external
...@@ -201,10 +203,19 @@ public abstract class DownloadHistoryItemWrapper implements TimedItem { ...@@ -201,10 +203,19 @@ public abstract class DownloadHistoryItemWrapper implements TimedItem {
} }
@Override @Override
public void delete(final Callback<Void> callback) { public void delete(@Nullable final Callback<Void> callback) {
// Tell the DownloadManager to remove the file from history. // Tell the DownloadManager to remove the file from history.
mBackendProvider.getDownloadDelegate().removeDownload(getId(), mIsOffTheRecord); mBackendProvider.getDownloadDelegate().removeDownload(getId(), mIsOffTheRecord);
// Return early if the file has already been deleted from storage.
if (hasBeenExternallyRemoved()) {
if (callback != null) callback.onResult(null);
return;
}
// TODO(twellington): implement batch deletion of files. If too many items are selected
// for deletion at once, we will exceed the ThreadPool's maximum
// queue capacity, causing a crash.
// Delete the file from storage. // Delete the file from storage.
new AsyncTask<Void, Void, Void>() { new AsyncTask<Void, Void, Void>() {
@Override @Override
...@@ -326,9 +337,9 @@ public abstract class DownloadHistoryItemWrapper implements TimedItem { ...@@ -326,9 +337,9 @@ public abstract class DownloadHistoryItemWrapper implements TimedItem {
} }
@Override @Override
public void delete(Callback<Void> callback) { public void delete(@Nullable Callback<Void> callback) {
mBackendProvider.getOfflinePageBridge().deleteItem(getId()); mBackendProvider.getOfflinePageBridge().deleteItem(getId());
callback.onResult(null); if (callback != null) callback.onResult(null);
} }
@Override @Override
......
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 to comment