Skip to content

Commit

Permalink
Don't cancel download when dismissing the notification
Browse files Browse the repository at this point in the history
BUG=698321

Review-Url: https://codereview.chromium.org/2729623007
Cr-Commit-Position: refs/heads/master@{#454946}
  • Loading branch information
qinmin authored and Commit bot committed Mar 6, 2017
1 parent 2fe2e35 commit 18aa717
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1192,9 +1192,8 @@ public void resumeDownload(DownloadItem item, boolean hasUserGesture) {
*/
@Override
public void cancelDownload(
String downloadGuid, boolean isOffTheRecord, boolean isNotificationDismissed) {
nativeCancelDownload(getNativeDownloadManagerService(), downloadGuid, isOffTheRecord,
isNotificationDismissed);
String downloadGuid, boolean isOffTheRecord) {
nativeCancelDownload(getNativeDownloadManagerService(), downloadGuid, isOffTheRecord);
removeDownloadProgress(downloadGuid);
recordDownloadFinishedUMA(DOWNLOAD_STATUS_CANCELLED, downloadGuid, 0);
}
Expand Down Expand Up @@ -1812,8 +1811,7 @@ public void purgeActiveNetworkList(long[] activeNetIds) {}
private native void nativeResumeDownload(
long nativeDownloadManagerService, String downloadGuid, boolean isOffTheRecord);
private native void nativeCancelDownload(
long nativeDownloadManagerService, String downloadGuid, boolean isOffTheRecord,
boolean isNotificationDismissed);
long nativeDownloadManagerService, String downloadGuid, boolean isOffTheRecord);
private native void nativePauseDownload(long nativeDownloadManagerService, String downloadGuid,
boolean isOffTheRecord);
private native void nativeRemoveDownload(long nativeDownloadManagerService, String downloadGuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void cancelOffTheRecordDownloads() {
notifyDownloadCanceled(entry.downloadGuid);
if (cancelActualDownload) {
DownloadServiceDelegate delegate = getServiceDelegate(entry.itemType);
delegate.cancelDownload(entry.downloadGuid, entry.isOffTheRecord, false);
delegate.cancelDownload(entry.downloadGuid, entry.isOffTheRecord);
delegate.destroyServiceDelegate();
}
for (Observer observer : mObservers) observer.onDownloadCanceled(entry.downloadGuid);
Expand Down Expand Up @@ -718,10 +718,6 @@ public void notifyDownloadPaused(String downloadGuid, boolean isResumable,
mContext.getResources().getString(R.string.download_notification_cancel_button),
buildPendingIntent(cancelIntent, entry.notificationId));

Intent dismissIntent = new Intent(cancelIntent);
dismissIntent.putExtra(EXTRA_NOTIFICATION_DISMISSED, true);
builder.setDeleteIntent(buildPendingIntent(dismissIntent, entry.notificationId));

updateNotification(entry.notificationId, builder.build(), downloadGuid,
entry.isOfflinePage(),
new DownloadSharedPreferenceEntry(entry.notificationId, entry.isOffTheRecord,
Expand Down Expand Up @@ -933,6 +929,11 @@ private void handleDownloadOperation(final Intent intent) {
return;
} else if (ACTION_DOWNLOAD_OPEN.equals(intent.getAction())) {
// TODO(fgorski): Do we even need to do anything special here, before we launch Chrome?
} else if (ACTION_DOWNLOAD_CANCEL.equals(intent.getAction())
&& IntentUtils.safeGetBooleanExtra(intent, EXTRA_NOTIFICATION_DISMISSED, false)) {
// User canceled a download by dismissing its notification from earlier versions, ignore
// it. TODO(qinmin): remove this else-if block after M60.
return;
}

BrowserParts parts = new EmptyBrowserParts() {
Expand All @@ -956,8 +957,7 @@ public void finishNativeInitialization() {
// don't need to restart the browser process. http://crbug.com/579643.
cancelNotification(entry.notificationId, entry.downloadGuid);
downloadServiceDelegate.cancelDownload(entry.downloadGuid,
entry.isOffTheRecord, IntentUtils.safeGetBooleanExtra(
intent, EXTRA_NOTIFICATION_DISMISSED, false));
entry.isOffTheRecord);
for (Observer observer : mObservers) {
observer.onDownloadCanceled(entry.downloadGuid);
}
Expand Down Expand Up @@ -1019,7 +1019,7 @@ private void handleDownloadOperationForMissingNotification(Intent intent) {

// Pass information directly to the DownloadManagerService.
if (TextUtils.equals(action, ACTION_DOWNLOAD_CANCEL)) {
getServiceDelegate(itemType).cancelDownload(downloadGuid, isOffTheRecord, false);
getServiceDelegate(itemType).cancelDownload(downloadGuid, isOffTheRecord);
} else if (TextUtils.equals(action, ACTION_DOWNLOAD_PAUSE)) {
getServiceDelegate(itemType).pauseDownload(downloadGuid, isOffTheRecord);
} else if (TextUtils.equals(action, ACTION_DOWNLOAD_RESUME)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ public interface DownloadServiceDelegate {
* Called to cancel a download.
* @param downloadGuid GUID of the download.
* @param isOffTheRecord Whether the download is off the record.
* @param isNotificationDismissed Whether cancel is caused by dismissing the notification.
*/
void cancelDownload(String downloadGuid, boolean isOffTheRecord,
boolean isNotificationDismissed);
void cancelDownload(String downloadGuid, boolean isOffTheRecord);

/**
* Called to pause a download.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public OfflinePageDownloadItem getItem(String guid) {
}

@Override
public void cancelDownload(String downloadGuid, boolean isOffTheRecord,
boolean isNotificationDismissed) {
public void cancelDownload(String downloadGuid, boolean isOffTheRecord) {
cancelDownload(downloadGuid);
}

Expand Down
7 changes: 2 additions & 5 deletions chrome/browser/android/download/download_manager_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,10 @@ void DownloadManagerService::CancelDownload(
JNIEnv* env,
jobject obj,
const JavaParamRef<jstring>& jdownload_guid,
bool is_off_the_record,
bool is_notification_dismissed) {
bool is_off_the_record) {
std::string download_guid = ConvertJavaStringToUTF8(env, jdownload_guid);
DownloadController::RecordDownloadCancelReason(
is_notification_dismissed ?
DownloadController::CANCEL_REASON_NOTIFICATION_DISMISSED :
DownloadController::CANCEL_REASON_ACTION_BUTTON);
DownloadController::CANCEL_REASON_ACTION_BUTTON);
if (is_history_query_complete_ || is_off_the_record)
CancelDownloadInternal(download_guid, is_off_the_record);
else
Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/android/download/download_manager_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class DownloadManagerService : public AllDownloadItemNotifier::Observer,
void CancelDownload(JNIEnv* env,
jobject obj,
const JavaParamRef<jstring>& jdownload_guid,
bool is_off_the_record,
bool is_notification_dismissed);
bool is_off_the_record);

// Called to pause a download item that has GUID equal to |jdownload_guid|.
// If the DownloadItem is not yet created, do nothing as it is already paused.
Expand Down

0 comments on commit 18aa717

Please sign in to comment.