Commit 0c12dcec authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Plumb DownloadSchedule through LegacyDownloadProvider.

This is the plumbing for the old download offline content provider
code path.

Bug: 1078454
Change-Id: I20ceca491477b5c12738c647e158d21681a50fbd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2253201Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781621}
parent 7dc6ff02
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.download; package org.chromium.chrome.browser.download;
import androidx.annotation.Nullable;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.components.download.DownloadState; import org.chromium.components.download.DownloadState;
import org.chromium.components.download.ResumeMode; import org.chromium.components.download.ResumeMode;
...@@ -11,6 +13,7 @@ import org.chromium.components.offline_items_collection.ContentId; ...@@ -11,6 +13,7 @@ import org.chromium.components.offline_items_collection.ContentId;
import org.chromium.components.offline_items_collection.OfflineItem; import org.chromium.components.offline_items_collection.OfflineItem;
import org.chromium.components.offline_items_collection.OfflineItem.Progress; import org.chromium.components.offline_items_collection.OfflineItem.Progress;
import org.chromium.components.offline_items_collection.OfflineItemFilter; import org.chromium.components.offline_items_collection.OfflineItemFilter;
import org.chromium.components.offline_items_collection.OfflineItemSchedule;
import org.chromium.components.offline_items_collection.OfflineItemState; import org.chromium.components.offline_items_collection.OfflineItemState;
/** /**
...@@ -28,6 +31,7 @@ public class DownloadItem { ...@@ -28,6 +31,7 @@ public class DownloadItem {
private long mStartTime; private long mStartTime;
private long mEndTime; private long mEndTime;
private boolean mHasBeenExternallyRemoved; private boolean mHasBeenExternallyRemoved;
private OfflineItemSchedule mSchedule;
public DownloadItem(boolean useAndroidDownloadManager, DownloadInfo info) { public DownloadItem(boolean useAndroidDownloadManager, DownloadInfo info) {
mUseAndroidDownloadManager = useAndroidDownloadManager; mUseAndroidDownloadManager = useAndroidDownloadManager;
...@@ -145,6 +149,22 @@ public class DownloadItem { ...@@ -145,6 +149,22 @@ public class DownloadItem {
return mHasBeenExternallyRemoved; 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}. * Helper method to build an {@link OfflineItem} from a {@link DownloadItem}.
* @param item The {@link DownloadItem} to mimic. * @param item The {@link DownloadItem} to mimic.
...@@ -178,6 +198,7 @@ public class DownloadItem { ...@@ -178,6 +198,7 @@ public class DownloadItem {
offlineItem.completionTimeMs = item.getEndTime(); offlineItem.completionTimeMs = item.getEndTime();
offlineItem.externallyRemoved = item.hasBeenExternallyRemoved(); offlineItem.externallyRemoved = item.hasBeenExternallyRemoved();
offlineItem.canRename = item.getDownloadInfo().state() == DownloadState.COMPLETE; offlineItem.canRename = item.getDownloadInfo().state() == DownloadState.COMPLETE;
offlineItem.schedule = item.getOfflineItemSchedule();
switch (downloadInfo.state()) { switch (downloadInfo.state()) {
case DownloadState.IN_PROGRESS: case DownloadState.IN_PROGRESS:
offlineItem.state = downloadInfo.isPaused() ? OfflineItemState.PAUSED offlineItem.state = downloadInfo.isPaused() ? OfflineItemState.PAUSED
...@@ -243,11 +264,12 @@ public class DownloadItem { ...@@ -243,11 +264,12 @@ public class DownloadItem {
@CalledByNative @CalledByNative
private static DownloadItem createDownloadItem(DownloadInfo downloadInfo, long startTimestamp, private static DownloadItem createDownloadItem(DownloadInfo downloadInfo, long startTimestamp,
long endTimestamp, boolean hasBeenExternallyRemoved) { long endTimestamp, boolean hasBeenExternallyRemoved, OfflineItemSchedule schedule) {
DownloadItem downloadItem = new DownloadItem(false, downloadInfo); DownloadItem downloadItem = new DownloadItem(false, downloadInfo);
downloadItem.setStartTime(startTimestamp); downloadItem.setStartTime(startTimestamp);
downloadItem.setEndTime(endTimestamp); downloadItem.setEndTime(endTimestamp);
downloadItem.setHasBeenExternallyRemoved(hasBeenExternallyRemoved); downloadItem.setHasBeenExternallyRemoved(hasBeenExternallyRemoved);
downloadItem.setOfflineItemSchedule(schedule);
return downloadItem; return downloadItem;
} }
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "components/download/public/common/simple_download_manager_coordinator.h" #include "components/download/public/common/simple_download_manager_coordinator.h"
#include "components/download/public/common/url_download_handler_factory.h" #include "components/download/public/common/url_download_handler_factory.h"
#include "components/download/public/task/task_manager_impl.h" #include "components/download/public/task/task_manager_impl.h"
#include "components/offline_items_collection/core/android/offline_item_bridge.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/download_item_utils.h" #include "content/public/browser/download_item_utils.h"
#include "content/public/browser/download_request_utils.h" #include "content/public/browser/download_request_utils.h"
...@@ -51,6 +52,10 @@ using base::android::ConvertUTF16ToJavaString; ...@@ -51,6 +52,10 @@ using base::android::ConvertUTF16ToJavaString;
using base::android::ConvertUTF8ToJavaString; using base::android::ConvertUTF8ToJavaString;
using base::android::JavaParamRef; using base::android::JavaParamRef;
using base::android::ScopedJavaLocalRef; using base::android::ScopedJavaLocalRef;
using offline_items_collection::android::OfflineItemBridge;
using DownloadSchedule = download::DownloadSchedule;
using OfflineItemSchedule = offline_items_collection::OfflineItemSchedule;
namespace { namespace {
// The remaining time for a download item if it cannot be calculated. // The remaining time for a download item if it cannot be calculated.
...@@ -68,10 +73,20 @@ ScopedJavaLocalRef<jobject> JNI_DownloadManagerService_CreateJavaDownloadItem( ...@@ -68,10 +73,20 @@ ScopedJavaLocalRef<jobject> JNI_DownloadManagerService_CreateJavaDownloadItem(
JNIEnv* env, JNIEnv* env,
download::DownloadItem* item) { download::DownloadItem* item) {
DCHECK(!item->IsTransient()); 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( return Java_DownloadItem_createDownloadItem(
env, DownloadManagerService::CreateJavaDownloadInfo(env, item), env, DownloadManagerService::CreateJavaDownloadInfo(env, item),
item->GetStartTime().ToJavaTime(), item->GetEndTime().ToJavaTime(), item->GetStartTime().ToJavaTime(), item->GetEndTime().ToJavaTime(),
item->GetFileExternallyRemoved()); item->GetFileExternallyRemoved(), j_offline_item_schedule);
} }
void RenameItemCallback( void RenameItemCallback(
......
...@@ -15,19 +15,6 @@ namespace android { ...@@ -15,19 +15,6 @@ namespace android {
namespace { namespace {
// Creates a Java OfflineItemSchedule from a native OfflineItemSchedule.
ScopedJavaLocalRef<jobject> CreateOfflineItemSchedule(
JNIEnv* env,
const base::Optional<OfflineItemSchedule>& schedule) {
if (!schedule.has_value())
return ScopedJavaLocalRef<jobject>();
int64_t start_time_ms =
schedule->start_time.has_value() ? schedule->start_time->ToJavaTime() : 0;
return Java_OfflineItemBridge_createOfflineItemSchedule(
env, schedule->only_on_wifi, start_time_ms);
}
// Helper method to unify the OfflineItem conversion argument list to a single // Helper method to unify the OfflineItem conversion argument list to a single
// place. This is meant to reduce code churn from OfflineItem member // place. This is meant to reduce code churn from OfflineItem member
// modification. The behavior is as follows: // modification. The behavior is as follows:
...@@ -60,7 +47,7 @@ JNI_OfflineItemBridge_createOfflineItemAndMaybeAddToList( ...@@ -60,7 +47,7 @@ JNI_OfflineItemBridge_createOfflineItemAndMaybeAddToList(
static_cast<jint>(item.progress.unit), item.time_remaining_ms, static_cast<jint>(item.progress.unit), item.time_remaining_ms,
item.is_dangerous, item.can_rename, item.ignore_visuals, item.is_dangerous, item.can_rename, item.ignore_visuals,
item.content_quality_score, item.content_quality_score,
CreateOfflineItemSchedule(env, item.schedule)); OfflineItemBridge::CreateOfflineItemSchedule(env, item.schedule));
} }
} // namespace } // namespace
...@@ -96,6 +83,19 @@ ScopedJavaLocalRef<jobject> OfflineItemBridge::CreateUpdateDelta( ...@@ -96,6 +83,19 @@ ScopedJavaLocalRef<jobject> OfflineItemBridge::CreateUpdateDelta(
update_delta.value().visuals_changed); update_delta.value().visuals_changed);
} }
// static
ScopedJavaLocalRef<jobject> OfflineItemBridge::CreateOfflineItemSchedule(
JNIEnv* env,
const base::Optional<OfflineItemSchedule>& schedule) {
if (!schedule.has_value())
return ScopedJavaLocalRef<jobject>();
int64_t start_time_ms =
schedule->start_time.has_value() ? schedule->start_time->ToJavaTime() : 0;
return Java_OfflineItemBridge_createOfflineItemSchedule(
env, schedule->only_on_wifi, start_time_ms);
}
OfflineItemBridge::OfflineItemBridge() = default; OfflineItemBridge::OfflineItemBridge() = default;
} // namespace android } // namespace android
......
...@@ -34,6 +34,11 @@ class OfflineItemBridge { ...@@ -34,6 +34,11 @@ class OfflineItemBridge {
JNIEnv* env, JNIEnv* env,
const base::Optional<UpdateDelta>& update_delta); const base::Optional<UpdateDelta>& update_delta);
// Creates a Java OfflineItemSchedule.
static base::android::ScopedJavaLocalRef<jobject> CreateOfflineItemSchedule(
JNIEnv* env,
const base::Optional<OfflineItemSchedule>& schedule);
private: private:
OfflineItemBridge(); OfflineItemBridge();
}; };
......
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