Commit 3449a001 authored by Side Yilmaz's avatar Side Yilmaz Committed by Chromium LUCI CQ

[DownloadProfile-1] Add OTRProfileID to DownloadInfo.

This CL adds OTRProfileId to DownloadInfo to be able to reach non
primary OTR profiles. Also, this CL passes OTRProfileId from native
download manager service to the DownloadInfo.

Bug: 1099577, 1145502
Change-Id: I68ff6768fc9ee6810bfbd1f5015b57f6a3df8be2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2541863Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarRamin Halavati <rhalavati@chromium.org>
Reviewed-by: default avatarSky Malice <skym@chromium.org>
Commit-Queue: Side YILMAZ <sideyilmaz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835708}
parent 9fa87b5b
......@@ -154,6 +154,12 @@ ScopedJavaLocalRef<jobject> DownloadManagerService::CreateJavaDownloadInfo(
content::BrowserContext* browser_context =
content::DownloadItemUtils::GetBrowserContext(item);
base::android::ScopedJavaLocalRef<jobject> otr_profile_id;
if (browser_context && browser_context->IsOffTheRecord()) {
Profile* profile = Profile::FromBrowserContext(browser_context);
otr_profile_id = profile->GetOTRProfileID().ConvertToJavaOTRProfileID(env);
}
base::Optional<OfflineItemSchedule> offline_item_schedule;
auto download_schedule = item->GetDownloadSchedule();
if (download_schedule.has_value()) {
......@@ -170,9 +176,10 @@ ScopedJavaLocalRef<jobject> DownloadManagerService::CreateJavaDownloadInfo(
ConvertUTF8ToJavaString(env, item->GetMimeType()),
item->GetReceivedBytes(), item->GetTotalBytes(),
browser_context ? browser_context->IsOffTheRecord() : false,
item->GetState(), item->PercentComplete(), item->IsPaused(),
DownloadUtils::IsDownloadUserInitiated(item), item->CanResume(),
item->IsParallelDownload(), ConvertUTF8ToJavaString(env, original_url),
otr_profile_id, item->GetState(), item->PercentComplete(),
item->IsPaused(), DownloadUtils::IsDownloadUserInitiated(item),
item->CanResume(), item->IsParallelDownload(),
ConvertUTF8ToJavaString(env, original_url),
ConvertUTF8ToJavaString(env, item->GetReferrerUrl().spec()),
time_remaining_known ? time_delta.InMilliseconds()
: kUnknownRemainingTime,
......
......@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.download;
import android.graphics.Bitmap;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.profiles.OTRProfileID;
import org.chromium.components.download.DownloadState;
import org.chromium.components.offline_items_collection.ContentId;
import org.chromium.components.offline_items_collection.FailState;
......@@ -43,6 +44,7 @@ public final class DownloadInfo {
private final boolean mIsResumable;
private final boolean mIsPaused;
private final boolean mIsOffTheRecord;
private final OTRProfileID mOTRProfileId;
private final boolean mIsOfflinePage;
private final int mState;
private final long mLastAccessTime;
......@@ -82,6 +84,7 @@ public final class DownloadInfo {
mIsResumable = builder.mIsResumable;
mIsPaused = builder.mIsPaused;
mIsOffTheRecord = builder.mIsOffTheRecord;
mOTRProfileId = builder.mOTRProfileId;
mIsOfflinePage = builder.mIsOfflinePage;
mState = builder.mState;
mLastAccessTime = builder.mLastAccessTime;
......@@ -185,6 +188,10 @@ public final class DownloadInfo {
return mIsOffTheRecord;
}
public OTRProfileID getOTRProfileId() {
return mOTRProfileId;
}
public boolean isOfflinePage() {
return mIsOfflinePage;
}
......@@ -331,6 +338,7 @@ public final class DownloadInfo {
private boolean mIsResumable = true;
private boolean mIsPaused;
private boolean mIsOffTheRecord;
private OTRProfileID mOTRProfileId;
private boolean mIsOfflinePage;
private int mState = DownloadState.IN_PROGRESS;
private long mLastAccessTime;
......@@ -447,6 +455,11 @@ public final class DownloadInfo {
return this;
}
public Builder setOTRProfileId(OTRProfileID otrProfileId) {
mOTRProfileId = otrProfileId;
return this;
}
public Builder setIsOfflinePage(boolean isOfflinePage) {
mIsOfflinePage = isOfflinePage;
return this;
......@@ -544,6 +557,7 @@ public final class DownloadInfo {
.setIsResumable(downloadInfo.isResumable())
.setIsPaused(downloadInfo.isPaused())
.setIsOffTheRecord(downloadInfo.isOffTheRecord())
.setOTRProfileId(downloadInfo.getOTRProfileId())
.setIsOfflinePage(downloadInfo.isOfflinePage())
.setState(downloadInfo.state())
.setLastAccessTime(downloadInfo.getLastAccessTime())
......@@ -561,15 +575,16 @@ public final class DownloadInfo {
@CalledByNative
private static DownloadInfo createDownloadInfo(String downloadGuid, String fileName,
String filePath, String url, String mimeType, long bytesReceived, long bytesTotalSize,
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, OfflineItemSchedule schedule) {
boolean isOffTheRecord, OTRProfileID otrProfileId, 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, OfflineItemSchedule schedule) {
String remappedMimeType = MimeUtils.remapGenericMimeType(mimeType, url, fileName);
Progress progress = new Progress(bytesReceived,
percentCompleted == -1 ? null : bytesTotalSize, OfflineItemProgressUnit.BYTES);
if (isOffTheRecord) assert otrProfileId != null;
return new DownloadInfo.Builder()
.setBytesReceived(bytesReceived)
.setBytesTotalSize(bytesTotalSize)
......@@ -578,7 +593,8 @@ public final class DownloadInfo {
.setFileName(fileName)
.setFilePath(filePath)
.setHasUserGesture(hasUserGesture)
.setIsOffTheRecord(isIncognito)
.setIsOffTheRecord(isOffTheRecord)
.setOTRProfileId(otrProfileId)
.setIsPaused(isPaused)
.setIsResumable(isResumable)
.setIsParallelDownload(isParallelDownload)
......
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