Commit c2ffdb50 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: No notification for scheduled download.

No notification should be shown for scheduled download for download
later feature.

OfflineItemSchedule for the old code path is moved from DownloadItem
to DownloadInfo so the old notification code path can get the struct.

Also fix an issue that offline item filter filtered out scheduled
download after loading download home.

Bug: 1103419,1078454
Change-Id: Iaf69f47273082f001f579b13babc2fce17b71b14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2288314Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786821}
parent 281c2641
......@@ -4,8 +4,6 @@
package org.chromium.chrome.browser.download;
import androidx.annotation.Nullable;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.components.download.DownloadState;
import org.chromium.components.download.ResumeMode;
......@@ -13,7 +11,6 @@ import org.chromium.components.offline_items_collection.ContentId;
import org.chromium.components.offline_items_collection.OfflineItem;
import org.chromium.components.offline_items_collection.OfflineItem.Progress;
import org.chromium.components.offline_items_collection.OfflineItemFilter;
import org.chromium.components.offline_items_collection.OfflineItemSchedule;
import org.chromium.components.offline_items_collection.OfflineItemState;
/**
......@@ -31,7 +28,6 @@ public class DownloadItem {
private long mStartTime;
private long mEndTime;
private boolean mHasBeenExternallyRemoved;
private OfflineItemSchedule mSchedule;
public DownloadItem(boolean useAndroidDownloadManager, DownloadInfo info) {
mUseAndroidDownloadManager = useAndroidDownloadManager;
......@@ -149,22 +145,6 @@ public class DownloadItem {
return mHasBeenExternallyRemoved;
}
/**
* Sets the {@link OfflineItemSchedule} to start the download on particular time or network.
* @param The {@link OfflineItemSchedule}.
*/
public void setOfflineItemSchedule(@Nullable OfflineItemSchedule schedule) {
mSchedule = schedule;
}
/**
* Gets the {@link OfflineItemSchedule} to start the download on particular time or network.
* @return The {@link OfflineItemSchedule}.
*/
public @Nullable OfflineItemSchedule getOfflineItemSchedule() {
return mSchedule;
}
/**
* Helper method to build an {@link OfflineItem} from a {@link DownloadItem}.
* @param item The {@link DownloadItem} to mimic.
......@@ -198,7 +178,7 @@ public class DownloadItem {
offlineItem.completionTimeMs = item.getEndTime();
offlineItem.externallyRemoved = item.hasBeenExternallyRemoved();
offlineItem.canRename = item.getDownloadInfo().state() == DownloadState.COMPLETE;
offlineItem.schedule = item.getOfflineItemSchedule();
offlineItem.schedule = downloadInfo.getOfflineItemSchedule();
switch (downloadInfo.state()) {
case DownloadState.IN_PROGRESS:
offlineItem.state = downloadInfo.isPaused() ? OfflineItemState.PAUSED
......@@ -264,12 +244,11 @@ public class DownloadItem {
@CalledByNative
private static DownloadItem createDownloadItem(DownloadInfo downloadInfo, long startTimestamp,
long endTimestamp, boolean hasBeenExternallyRemoved, OfflineItemSchedule schedule) {
long endTimestamp, boolean hasBeenExternallyRemoved) {
DownloadItem downloadItem = new DownloadItem(false, downloadInfo);
downloadItem.setStartTime(startTimestamp);
downloadItem.setEndTime(endTimestamp);
downloadItem.setHasBeenExternallyRemoved(hasBeenExternallyRemoved);
downloadItem.setOfflineItemSchedule(schedule);
return downloadItem;
}
......
......@@ -160,6 +160,8 @@ public class SystemDownloadNotifier implements DownloadNotifier {
@Override
public void notifyDownloadInterrupted(
DownloadInfo info, boolean isAutoResumable, @PendingState int pendingState) {
if (info.getOfflineItemSchedule() != null) return;
NotificationInfo notificationInfo =
new NotificationInfo(NotificationType.INTERRUPTED, info, NotificationPriority.HIGH);
notificationInfo.mIsAutoResumable = isAutoResumable;
......
......@@ -30,6 +30,8 @@ public class InvalidStateOfflineItemFilter extends OfflineItemFilter {
InvalidStateOfflineItemFilter.isInPrimaryStorageDownloadDirectory(item.filePath);
if ((item.externallyRemoved && inPrimaryDirectory) || item.isTransient) return true;
if (item.schedule != null) return false;
switch (item.state) {
case OfflineItemState.CANCELLED:
case OfflineItemState.FAILED:
......
......@@ -148,8 +148,9 @@ public class OfflineContentAggregatorNotificationBridgeUi
private void pushItemToUi(OfflineItem item, OfflineItemVisuals visuals) {
// TODO(http://crbug.com/855141): Find a cleaner way to hide unimportant UI updates.
// If it's a suggested page, do not add it to the notification UI.
if (item.isSuggested) return;
// If it's a suggested page, or the user choose to download later. Do not add it to the
// notification UI.
if (item.isSuggested || item.schedule != null) return;
DownloadInfo info = DownloadInfo.fromOfflineItem(item, visuals);
switch (item.state) {
......
......@@ -75,20 +75,10 @@ ScopedJavaLocalRef<jobject> JNI_DownloadManagerService_CreateJavaDownloadItem(
JNIEnv* env,
download::DownloadItem* item) {
DCHECK(!item->IsTransient());
base::Optional<OfflineItemSchedule> offline_item_schedule;
auto download_schedule = item->GetDownloadSchedule();
if (download_schedule.has_value()) {
offline_item_schedule = base::make_optional<OfflineItemSchedule>(
download_schedule->only_on_wifi(), download_schedule->start_time());
}
auto j_offline_item_schedule =
OfflineItemBridge::CreateOfflineItemSchedule(env, offline_item_schedule);
return Java_DownloadItem_createDownloadItem(
env, DownloadManagerService::CreateJavaDownloadInfo(env, item),
item->GetStartTime().ToJavaTime(), item->GetEndTime().ToJavaTime(),
item->GetFileExternallyRemoved(), j_offline_item_schedule);
item->GetFileExternallyRemoved());
}
void RenameItemCallback(
......@@ -155,6 +145,15 @@ ScopedJavaLocalRef<jobject> DownloadManagerService::CreateJavaDownloadInfo(
: item->GetOriginalUrl().spec();
content::BrowserContext* browser_context =
content::DownloadItemUtils::GetBrowserContext(item);
base::Optional<OfflineItemSchedule> offline_item_schedule;
auto download_schedule = item->GetDownloadSchedule();
if (download_schedule.has_value()) {
offline_item_schedule = base::make_optional<OfflineItemSchedule>(
download_schedule->only_on_wifi(), download_schedule->start_time());
}
auto j_offline_item_schedule =
OfflineItemBridge::CreateOfflineItemSchedule(env, offline_item_schedule);
return Java_DownloadInfo_createDownloadInfo(
env, ConvertUTF8ToJavaString(env, item->GetGuid()),
ConvertUTF8ToJavaString(env, item->GetFileNameToReportUser().value()),
......@@ -172,7 +171,8 @@ ScopedJavaLocalRef<jobject> DownloadManagerService::CreateJavaDownloadInfo(
item->GetLastAccessTime().ToJavaTime(), item->IsDangerous(),
static_cast<int>(
OfflineItemUtils::ConvertDownloadInterruptReasonToFailState(
item->GetLastReason())));
item->GetLastReason())),
j_offline_item_schedule);
}
static jlong JNI_DownloadManagerService_Init(JNIEnv* env,
......
......@@ -14,6 +14,7 @@ import org.chromium.components.offline_items_collection.LegacyHelpers;
import org.chromium.components.offline_items_collection.OfflineItem;
import org.chromium.components.offline_items_collection.OfflineItem.Progress;
import org.chromium.components.offline_items_collection.OfflineItemProgressUnit;
import org.chromium.components.offline_items_collection.OfflineItemSchedule;
import org.chromium.components.offline_items_collection.OfflineItemState;
import org.chromium.components.offline_items_collection.OfflineItemVisuals;
import org.chromium.components.offline_items_collection.PendingState;
......@@ -58,6 +59,7 @@ public final class DownloadInfo {
@FailState
private final int mFailState;
private final boolean mShouldPromoteOrigin;
private final OfflineItemSchedule mSchedule;
private DownloadInfo(Builder builder) {
mUrl = builder.mUrl;
......@@ -97,6 +99,7 @@ public final class DownloadInfo {
mPendingState = builder.mPendingState;
mFailState = builder.mFailState;
mShouldPromoteOrigin = builder.mShouldPromoteOrigin;
mSchedule = builder.mSchedule;
}
public String getUrl() {
......@@ -230,6 +233,10 @@ public final class DownloadInfo {
return mShouldPromoteOrigin;
}
public OfflineItemSchedule getOfflineItemSchedule() {
return mSchedule;
}
/**
* Helper method to build a {@link DownloadInfo} from an {@link OfflineItem}.
* @param item The {@link OfflineItem} to mimic.
......@@ -296,7 +303,8 @@ public final class DownloadInfo {
.setIcon(visuals == null ? null : visuals.icon)
.setPendingState(item.pendingState)
.setFailState(item.failState)
.setShouldPromoteOrigin(item.promoteOrigin);
.setShouldPromoteOrigin(item.promoteOrigin)
.setOfflineItemSchedule(item.schedule);
}
/**
......@@ -337,6 +345,7 @@ public final class DownloadInfo {
@FailState
private int mFailState;
private boolean mShouldPromoteOrigin;
private OfflineItemSchedule mSchedule;
public Builder setUrl(String url) {
mUrl = url;
......@@ -498,6 +507,11 @@ public final class DownloadInfo {
return this;
}
public Builder setOfflineItemSchedule(OfflineItemSchedule schedule) {
mSchedule = schedule;
return this;
}
public DownloadInfo build() {
return new DownloadInfo(this);
}
......@@ -538,7 +552,8 @@ public final class DownloadInfo {
.setIcon(downloadInfo.getIcon())
.setPendingState(downloadInfo.getPendingState())
.setFailState(downloadInfo.getFailState())
.setShouldPromoteOrigin(downloadInfo.getShouldPromoteOrigin());
.setShouldPromoteOrigin(downloadInfo.getShouldPromoteOrigin())
.setOfflineItemSchedule(downloadInfo.getOfflineItemSchedule());
return builder;
}
}
......@@ -549,7 +564,7 @@ public final class DownloadInfo {
boolean isIncognito, int state, int percentCompleted, boolean isPaused,
boolean hasUserGesture, boolean isResumable, boolean isParallelDownload,
String originalUrl, String referrerUrl, long timeRemainingInMs, long lastAccessTime,
boolean isDangerous, @FailState int failState) {
boolean isDangerous, @FailState int failState, OfflineItemSchedule schedule) {
String remappedMimeType = MimeUtils.remapGenericMimeType(mimeType, url, fileName);
Progress progress = new Progress(bytesReceived,
......@@ -577,6 +592,7 @@ public final class DownloadInfo {
.setIsDangerous(isDangerous)
.setUrl(url)
.setFailState(failState)
.setOfflineItemSchedule(schedule)
.build();
}
}
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