Commit 996b0a41 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Fix a bug that scheduled download can't be deleted.

This CL fixed an issue that scheduled download can't be deleted.

Bug: 1106368
Change-Id: If5c83452917dc6a77cffe5cae79f0422a4f4f892
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303853
Commit-Queue: Min Qin <qinmin@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789505}
parent f94de081
...@@ -48,7 +48,6 @@ import org.chromium.components.browser_ui.widget.selectable_list.SelectionDelega ...@@ -48,7 +48,6 @@ import org.chromium.components.browser_ui.widget.selectable_list.SelectionDelega
import org.chromium.components.offline_items_collection.OfflineContentProvider; import org.chromium.components.offline_items_collection.OfflineContentProvider;
import org.chromium.components.offline_items_collection.OfflineItem; import org.chromium.components.offline_items_collection.OfflineItem;
import org.chromium.components.offline_items_collection.OfflineItemShareInfo; import org.chromium.components.offline_items_collection.OfflineItemShareInfo;
import org.chromium.components.offline_items_collection.OfflineItemState;
import org.chromium.components.offline_items_collection.VisualsCallback; import org.chromium.components.offline_items_collection.VisualsCallback;
import java.io.Closeable; import java.io.Closeable;
...@@ -373,11 +372,7 @@ class DateOrderedListMediator { ...@@ -373,11 +372,7 @@ class DateOrderedListMediator {
mDeleteController.canDelete(items, delete -> { mDeleteController.canDelete(items, delete -> {
if (delete) { if (delete) {
for (OfflineItem item : itemsToDelete) { for (OfflineItem item : itemsToDelete) {
if (item.state != OfflineItemState.COMPLETE) { mProvider.removeItem(item);
mProvider.cancelDownload(item);
} else {
mProvider.removeItem(item);
}
// Remove and have a single decision path for cleaning up thumbnails when the // Remove and have a single decision path for cleaning up thumbnails when the
// glue layer is no longer needed. // glue layer is no longer needed.
......
...@@ -651,6 +651,7 @@ void DownloadItemImpl::UpdateResumptionInfo(bool user_resume) { ...@@ -651,6 +651,7 @@ void DownloadItemImpl::UpdateResumptionInfo(bool user_resume) {
void DownloadItemImpl::Cancel(bool user_cancel) { void DownloadItemImpl::Cancel(bool user_cancel) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DVLOG(20) << __func__ << "() download = " << DebugString(true); DVLOG(20) << __func__ << "() download = " << DebugString(true);
download_schedule_ = base::nullopt;
InterruptAndDiscardPartialState( InterruptAndDiscardPartialState(
user_cancel ? DOWNLOAD_INTERRUPT_REASON_USER_CANCELED user_cancel ? DOWNLOAD_INTERRUPT_REASON_USER_CANCELED
: DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN); : DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN);
......
...@@ -2736,5 +2736,21 @@ TEST_P(DownloadLaterTest, TestOnDownloadScheduleChanged) { ...@@ -2736,5 +2736,21 @@ TEST_P(DownloadLaterTest, TestOnDownloadScheduleChanged) {
} }
} }
TEST_F(DownloadItemTest, CancelWithDownloadSchedule) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kDownloadLater);
auto item = CreateDownloadItem(DownloadItem::DownloadState::INTERRUPTED,
DOWNLOAD_INTERRUPT_REASON_CRASH);
auto download_schedule = base::make_optional<DownloadSchedule>(
false, base::Time::Now() + base::TimeDelta::FromDays(10));
item->OnDownloadScheduleChanged(std::move(download_schedule));
EXPECT_EQ(item->GetState(), DownloadItem::DownloadState::INTERRUPTED);
EXPECT_TRUE(item->GetDownloadSchedule().has_value());
item->Cancel(true);
EXPECT_FALSE(item->GetDownloadSchedule().has_value());
}
} // namespace } // namespace
} // namespace download } // namespace download
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