Commit 484d6ab4 authored by twellington's avatar twellington Committed by Commit bot

[Downloads UI] Add null checks to prevent crash when selecting deleted items

If you move quickly enough, it's possible to select an item that was just
deleted then choose to delete it again. Add some null checks to prevent
a crash.

BUG=652176

Review-Url: https://codereview.chromium.org/2387003003
Cr-Commit-Position: refs/heads/master@{#422662}
parent 14731754
......@@ -429,6 +429,10 @@ public class DownloadManagerUi implements OnMenuItemClickListener {
mBackendProvider.getSelectionDelegate().getSelectedItems();
final List<DownloadHistoryItemWrapper> itemsToDelete = getItemsForDeletion();
mBackendProvider.getSelectionDelegate().clearSelection();
if (itemsToDelete.isEmpty()) return;
mHistoryAdapter.removeItemsFromAdapter(itemsToDelete);
dismissUndoDeletionSnackbars();
......@@ -445,8 +449,6 @@ public class DownloadManagerUi implements OnMenuItemClickListener {
snackbar.setTemplateText(mActivity.getString(snackbarTemplateId));
((SnackbarManageable) mActivity).getSnackbarManager().showSnackbar(snackbar);
mBackendProvider.getSelectionDelegate().clearSelection();
}
private List<DownloadHistoryItemWrapper> getItemsForDeletion() {
......@@ -457,7 +459,11 @@ public class DownloadManagerUi implements OnMenuItemClickListener {
for (DownloadHistoryItemWrapper item : selectedItems) {
if (!filePathsToRemove.contains(item.getFilePath())) {
itemsToRemove.addAll(mHistoryAdapter.getItemsForFilePath(item.getFilePath()));
List<DownloadHistoryItemWrapper> itemsForFilePath =
mHistoryAdapter.getItemsForFilePath(item.getFilePath());
if (itemsForFilePath != null) {
itemsToRemove.addAll(itemsForFilePath);
}
filePathsToRemove.add(item.getFilePath());
}
}
......
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