Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadBroadcastReceiver.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadBroadcastReceiver.java b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadBroadcastReceiver.java |
| index 04beb7d484e1ee21db7b7271b53a7f8a5e0f1505..9e3e016e51fba0f6f3c4e6c41a0ea58084534b9d 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadBroadcastReceiver.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadBroadcastReceiver.java |
| @@ -9,10 +9,13 @@ import android.content.BroadcastReceiver; |
| import android.content.Context; |
| import android.content.Intent; |
| import android.net.Uri; |
| +import android.os.AsyncTask; |
| import org.chromium.chrome.browser.util.IntentUtils; |
| import org.chromium.components.offline_items_collection.ContentId; |
| +import java.util.concurrent.RejectedExecutionException; |
| + |
| /** |
| * This {@link BroadcastReceiver} handles clicks to download notifications and their action buttons. |
| * Clicking on an in-progress or failed download will open the download manager. Clicking on |
| @@ -55,22 +58,40 @@ public class DownloadBroadcastReceiver extends BroadcastReceiver { |
| return; |
| } |
| - long id = ids[0]; |
| - Uri uri = DownloadManagerDelegate.getContentUriFromDownloadManager(context, id); |
| - if (uri == null) { |
| - DownloadManagerService.openDownloadsPage(context); |
| - return; |
| - } |
| - |
| - String downloadFilename = IntentUtils.safeGetStringExtra( |
| + final long id = ids[0]; |
|
nyquist
2017/04/18 22:44:20
Any reason why we're not doing this conditionally
|
| + final String downloadFilename = IntentUtils.safeGetStringExtra( |
| intent, DownloadNotificationService.EXTRA_DOWNLOAD_FILE_PATH); |
| - boolean isSupportedMimeType = IntentUtils.safeGetBooleanExtra( |
| + final boolean isSupportedMimeType = IntentUtils.safeGetBooleanExtra( |
| intent, DownloadNotificationService.EXTRA_IS_SUPPORTED_MIME_TYPE, false); |
| - boolean isOffTheRecord = IntentUtils.safeGetBooleanExtra( |
| + final boolean isOffTheRecord = IntentUtils.safeGetBooleanExtra( |
| intent, DownloadNotificationService.EXTRA_IS_OFF_THE_RECORD, false); |
| - ContentId contentId = DownloadNotificationService.getContentIdFromIntent(intent); |
| - DownloadManagerService.openDownloadedContent( |
| - context, downloadFilename, isSupportedMimeType, isOffTheRecord, contentId.id, id); |
| + final ContentId contentId = DownloadNotificationService.getContentIdFromIntent(intent); |
| + |
| + final PendingResult receiverResult = goAsync(); |
| + AsyncTask<Void, Void, Uri> task = new AsyncTask<Void, Void, Uri>() { |
| + @Override |
| + protected Uri doInBackground(Void... params) { |
| + return DownloadManagerDelegate.getContentUriFromDownloadManager(context, id); |
| + } |
| + |
| + @Override |
| + protected void onPostExecute(Uri result) { |
| + if (result == null) { |
| + DownloadManagerService.openDownloadsPage(context); |
| + } else { |
| + DownloadManagerService.openDownloadedContent(context, downloadFilename, |
| + isSupportedMimeType, isOffTheRecord, contentId.id, id); |
| + } |
| + |
| + receiverResult.finish(); |
| + } |
| + }; |
| + |
| + try { |
| + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| + } catch (RejectedExecutionException ex) { |
| + receiverResult.finish(); |
| + } |
| } |
| /** |