| Index: chrome/android/java/src/org/chromium/chrome/browser/download/SystemDownloadNotifier.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/SystemDownloadNotifier.java b/chrome/android/java/src/org/chromium/chrome/browser/download/SystemDownloadNotifier.java
|
| index 43f1dfa0c8717b52f43eeed6d35c671866c64eac..9705370f775edfd30a2374adbae54a7d74ee249a 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/download/SystemDownloadNotifier.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/download/SystemDownloadNotifier.java
|
| @@ -11,6 +11,7 @@ import android.content.ServiceConnection;
|
| import android.os.IBinder;
|
|
|
| import org.chromium.base.Log;
|
| +import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.VisibleForTesting;
|
| import org.chromium.content.browser.DownloadInfo;
|
|
|
| @@ -38,7 +39,7 @@ public class SystemDownloadNotifier implements DownloadNotifier {
|
| private final Object mLock = new Object();
|
| @Nullable private DownloadNotificationService mBoundService;
|
| private boolean mServiceStarted;
|
| - private Set<Integer> mActiveNotificationIds = new HashSet<Integer>();
|
| + private Set<String> mActiveDownloads = new HashSet<String>();
|
| private List<PendingNotificationInfo> mPendingNotifications =
|
| new ArrayList<PendingNotificationInfo>();
|
|
|
| @@ -53,6 +54,9 @@ public class SystemDownloadNotifier implements DownloadNotifier {
|
| public long startTime;
|
| public boolean isAutoResumable;
|
| public boolean canDownloadWhileMetered;
|
| + public boolean canResolve;
|
| + public long systemDownloadId;
|
| + public int notificationId;
|
|
|
| public PendingNotificationInfo(int type, DownloadInfo downloadInfo) {
|
| this.type = type;
|
| @@ -137,7 +141,7 @@ public class SystemDownloadNotifier implements DownloadNotifier {
|
| */
|
| private void stopServiceIfNeeded() {
|
| assert Thread.holdsLock(mLock);
|
| - if (mActiveNotificationIds.isEmpty() && mServiceStarted) {
|
| + if (mActiveDownloads.isEmpty() && mServiceStarted) {
|
| stopService();
|
| mServiceStarted = false;
|
| }
|
| @@ -166,20 +170,22 @@ public class SystemDownloadNotifier implements DownloadNotifier {
|
| }
|
|
|
| @Override
|
| - public void cancelNotification(int notificationId, String downloadGuid) {
|
| - DownloadInfo info = new DownloadInfo.Builder()
|
| - .setNotificationId(notificationId)
|
| + public void notifyDownloadCanceled(String downloadGuid) {
|
| + DownloadInfo downloadInfo = new DownloadInfo.Builder()
|
| .setDownloadGuid(downloadGuid)
|
| .build();
|
| updateDownloadNotification(
|
| - new PendingNotificationInfo(DOWNLOAD_NOTIFICATION_TYPE_CANCEL, info));
|
| + new PendingNotificationInfo(DOWNLOAD_NOTIFICATION_TYPE_CANCEL, downloadInfo));
|
| }
|
|
|
| @Override
|
| - public void notifyDownloadSuccessful(DownloadInfo downloadInfo, Intent intent) {
|
| + public void notifyDownloadSuccessful(DownloadInfo downloadInfo, long systemDownloadId,
|
| + boolean canResolve, Intent intent) {
|
| PendingNotificationInfo info =
|
| new PendingNotificationInfo(DOWNLOAD_NOTIFICATION_TYPE_SUCCESS, downloadInfo);
|
| info.intent = intent;
|
| + info.canResolve = canResolve;
|
| + info.systemDownloadId = systemDownloadId;
|
| updateDownloadNotification(info);
|
| }
|
|
|
| @@ -218,14 +224,14 @@ public class SystemDownloadNotifier implements DownloadNotifier {
|
| * wait for the notification service to become ready.
|
| * @param info Pending notification information to be handled.
|
| */
|
| - private void updateDownloadNotification(PendingNotificationInfo notificationInfo) {
|
| + private void updateDownloadNotification(final PendingNotificationInfo notificationInfo) {
|
| synchronized (mLock) {
|
| startAndBindToServiceIfNeeded();
|
| - DownloadInfo info = notificationInfo.downloadInfo;
|
| + final DownloadInfo info = notificationInfo.downloadInfo;
|
| if (notificationInfo.type == DOWNLOAD_NOTIFICATION_TYPE_PROGRESS) {
|
| - mActiveNotificationIds.add(info.getNotificationId());
|
| + mActiveDownloads.add(info.getDownloadGuid());
|
| } else if (notificationInfo.type != DOWNLOAD_NOTIFICATION_TYPE_RESUME_ALL) {
|
| - mActiveNotificationIds.remove(info.getNotificationId());
|
| + mActiveDownloads.remove(info.getDownloadGuid());
|
| }
|
| if (mBoundService == null) {
|
| // We need to wait for the service to connect before we can handle
|
| @@ -235,7 +241,7 @@ public class SystemDownloadNotifier implements DownloadNotifier {
|
| } else {
|
| switch (notificationInfo.type) {
|
| case DOWNLOAD_NOTIFICATION_TYPE_PROGRESS:
|
| - mBoundService.notifyDownloadProgress(info.getNotificationId(),
|
| + mBoundService.notifyDownloadProgress(
|
| info.getDownloadGuid(), info.getFileName(),
|
| info.getPercentCompleted(), info.getTimeRemainingInMillis(),
|
| notificationInfo.startTime, info.isResumable(),
|
| @@ -247,20 +253,27 @@ public class SystemDownloadNotifier implements DownloadNotifier {
|
| info.getDownloadGuid(), notificationInfo.isAutoResumable);
|
| break;
|
| case DOWNLOAD_NOTIFICATION_TYPE_SUCCESS:
|
| - mBoundService.notifyDownloadSuccessful(
|
| - info.getNotificationId(), info.getDownloadGuid(),
|
| - info.getFileName(), notificationInfo.intent);
|
| + final int notificationId = mBoundService.notifyDownloadSuccessful(
|
| + info.getDownloadGuid(), info.getFileName(),
|
| + notificationInfo.intent);
|
| + ThreadUtils.postOnUiThread(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + DownloadManagerService.getDownloadManagerService(
|
| + mApplicationContext).onSuccessNotificationShown(
|
| + info, notificationInfo.canResolve, notificationId,
|
| + notificationInfo.systemDownloadId);
|
| + }
|
| + });
|
| stopServiceIfNeeded();
|
| break;
|
| case DOWNLOAD_NOTIFICATION_TYPE_FAILURE:
|
| mBoundService.notifyDownloadFailed(
|
| - info.getNotificationId(), info.getDownloadGuid(),
|
| - info.getFileName());
|
| + info.getDownloadGuid(), info.getFileName());
|
| stopServiceIfNeeded();
|
| break;
|
| case DOWNLOAD_NOTIFICATION_TYPE_CANCEL:
|
| - mBoundService.cancelNotification(
|
| - info.getNotificationId(), info.getDownloadGuid());
|
| + mBoundService.notifyDownloadCanceled(info.getDownloadGuid());
|
| stopServiceIfNeeded();
|
| break;
|
| case DOWNLOAD_NOTIFICATION_TYPE_RESUME_ALL:
|
|
|