Skip to content

Commit

Permalink
Fix bug for resuming offline downloads.
Browse files Browse the repository at this point in the history
There was a bug where resuming an offline page download while offline
was making it impossible to pause the download again. This CL fixes it.

Bug: 773759
Change-Id: I66f6f1bda50a2afa3bacf7329421780da7cd7128
Reviewed-on: https://chromium-review.googlesource.com/717142
Reviewed-by: David Trainor <dtrainor@chromium.org>
Commit-Queue: Joy Ming <jming@chromium.org>
Cr-Commit-Position: refs/heads/master@{#508494}
  • Loading branch information
Joy Ming authored and Commit Bot committed Oct 12, 2017
1 parent c0600a2 commit 4afbd51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ void updateNotification(Intent intent) {
break;

case ACTION_DOWNLOAD_RESUME:
// If user manually resumes a download, update the network type if it
// is not metered previously.
boolean canDownloadWhileMetered = entry.canDownloadWhileMetered
|| DownloadManagerService.isActiveNetworkMetered(mApplicationContext);
// Update the SharedPreference entry.
mDownloadSharedPreferenceHelper.addOrReplaceSharedPreferenceEntry(
new DownloadSharedPreferenceEntry(entry.id, entry.notificationId,
entry.isOffTheRecord, canDownloadWhileMetered, entry.fileName, true,
entry.isTransient));

mDownloadNotificationService.notifyDownloadPending(entry.id, entry.fileName,
entry.isOffTheRecord, entry.canDownloadWhileMetered, entry.isTransient,
null, true);
Expand Down Expand Up @@ -207,6 +217,7 @@ void propagateInteraction(Intent intent) {

Preconditions.checkNotNull(downloadServiceDelegate);
Preconditions.checkNotNull(id);
Preconditions.checkNotNull(entry);

// Handle all remaining actions.
switch (action) {
Expand All @@ -219,13 +230,8 @@ void propagateInteraction(Intent intent) {
break;

case ACTION_DOWNLOAD_RESUME:
DownloadInfo info = new DownloadInfo.Builder()
.setDownloadGuid(id.id)
.setIsOffTheRecord(isOffTheRecord)
.build();

downloadServiceDelegate.resumeDownload(
id, new DownloadItem(false, info), true /* hasUserGesture */);
id, entry.buildDownloadItem(), true /* hasUserGesture */);
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private void updateActiveDownloadNotification(ContentId id, String fileName, Pro
updateNotification(notificationId, notification, id,
new DownloadSharedPreferenceEntry(id, notificationId, isOffTheRecord,
canDownloadWhileMetered, fileName, true, isTransient));
// TODO(jming): do we want to handle the pending option in a different manner?

mDownloadForegroundServiceManager.updateDownloadStatus(context,
DownloadForegroundServiceManager.DownloadStatus.IN_PROGRESS, notificationId,
notification);
Expand Down

0 comments on commit 4afbd51

Please sign in to comment.