Commit 88276e18 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Android Download: Fix an issue that Chrome removes external renamed file.

When user downloads a file in Chrome and remove the file in other
application, we check if the file is externally removed and call
Android API DownloadManager.remove(id) to avoid a crash on Android.

However, if the user rename the file, currently Chrome still deletes it
via the id provided by Android DownloadManager.

In this CL, we only let Android remove the file if it's deleted in
Chrome.


Bug: 774870
Change-Id: I5448a155c1e05e44ec3a812e93d3035d7061ecf7
Reviewed-on: https://chromium-review.googlesource.com/899770Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534738}
parent 02938fe2
......@@ -132,10 +132,14 @@ public class DownloadManagerDelegate {
/**
* Removes a download from Android DownloadManager.
* @param downloadGuid The GUID of the download.
* @param externallyRemoved If download is externally removed in other application.
*/
void removeCompletedDownload(String downloadGuid) {
void removeCompletedDownload(String downloadGuid, boolean externallyRemoved) {
long downloadId = removeDownloadIdMapping(downloadGuid);
if (downloadId != INVALID_SYSTEM_DOWNLOAD_ID) {
// Let Android DownloadManager to remove download only if the user removed the file in
// Chrome. If the user renamed or moved the file, Chrome should keep it intact.
if (downloadId != INVALID_SYSTEM_DOWNLOAD_ID && !externallyRemoved) {
DownloadManager manager =
(DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
manager.remove(downloadId);
......
......@@ -990,9 +990,11 @@ public class DownloadManagerService
* Removes a download from the list.
* @param downloadGuid GUID of the download.
* @param isOffTheRecord Whether the download is off the record.
* @param externallyRemoved If the file is externally removed by other applications.
*/
@Override
public void removeDownload(final String downloadGuid, boolean isOffTheRecord) {
public void removeDownload(
final String downloadGuid, boolean isOffTheRecord, boolean externallyRemoved) {
mHandler.post(() -> {
nativeRemoveDownload(getNativeDownloadManagerService(), downloadGuid, isOffTheRecord);
removeDownloadProgress(downloadGuid);
......@@ -1001,7 +1003,7 @@ public class DownloadManagerService
new AsyncTask<Void, Void, Void>() {
@Override
public Void doInBackground(Void... params) {
mDownloadManagerDelegate.removeCompletedDownload(downloadGuid);
mDownloadManagerDelegate.removeCompletedDownload(downloadGuid, externallyRemoved);
return null;
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
......
......@@ -33,7 +33,7 @@ public interface BackendProvider {
void checkForExternallyRemovedDownloads(boolean isOffTheRecord);
/** See {@link DownloadManagerService#removeDownload}. */
void removeDownload(String guid, boolean isOffTheRecord);
void removeDownload(String guid, boolean isOffTheRecord, boolean externallyRemoved);
/** See {@link DownloadManagerService#isDownloadOpenableInBrowser}. */
boolean isDownloadOpenableInBrowser(boolean isOffTheRecord, String mimeType);
......
......@@ -384,7 +384,8 @@ public abstract class DownloadHistoryItemWrapper extends TimedItem {
@Override
public boolean removePermanently() {
// Tell the DownloadManager to remove the file from history.
mBackendProvider.getDownloadDelegate().removeDownload(getId(), isOffTheRecord());
mBackendProvider.getDownloadDelegate().removeDownload(
getId(), isOffTheRecord(), hasBeenExternallyRemoved());
mBackendProvider.getThumbnailProvider().removeThumbnailsFromDisk(getId());
return true;
}
......
......@@ -80,7 +80,8 @@ public class StubbedProvider implements BackendProvider {
}
@Override
public void removeDownload(final String guid, final boolean isOffTheRecord) {
public void removeDownload(
final String guid, final boolean isOffTheRecord, boolean externallyRemoved) {
mHandler.post(new Runnable() {
@Override
public void run() {
......
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