Commit 0e869531 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Make infobar attached to the current tab.

Currently if the user doesn't dismiss the infobar for scheduled
download, and scheduled another download in another tab, the new
infobar will show in the previous tab.

Also, if the user switches to another tab and come back the tab that
has shown the infobar, clicking on the "Change" button will show an
error page.

This CL fixed these 2 issues. If there is more than one scheduled
downloads across multiple tabs during the lifetime of the infobar,
"X downloads scheduled" should be shown as the infobar text.

Bug: 1123924
Change-Id: Ib952c84ba5d6ad358c2d0b3d55238dc85e9ea313
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391585Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804443}
parent a488a475
......@@ -174,6 +174,9 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
@ResultState
public int resultState;
// Contains the information to change the download schedule for download later feature.
public OfflineItemSchedule schedule;
@Override
public int hashCode() {
int result = (id == null ? 0 : id.hashCode());
......@@ -247,6 +250,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
result = 31 * result + pending;
result = 31 * result + failed;
result = 31 * result + completed;
result = 31 * result + scheduled;
return result;
}
......@@ -257,7 +261,8 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
DownloadCount other = (DownloadCount) obj;
return inProgress == other.inProgress && pending == other.pending
&& failed == other.failed && completed == other.completed;
&& failed == other.failed && completed == other.completed
&& scheduled == other.scheduled;
}
}
......@@ -693,6 +698,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
info.message = getMessageForDownloadScheduled(itemToShow);
info.link = getContext().getString(R.string.change_link);
info.id = itemToShow.id;
info.schedule = itemToShow.schedule.clone();
} else {
// TODO(shaktisahu): Incorporate various types of failure messages.
// TODO(shaktisahu, xingliu): Consult UX to handle multiple schedule variations.
......@@ -1028,13 +1034,12 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
private class DownloadProgressInfoBarClient implements DownloadProgressInfoBar.Client {
@Override
public void onLinkClicked(ContentId itemId) {
final OfflineItem item = mTrackedItems.get(itemId);
public void onLinkClicked(ContentId itemId, final OfflineItemSchedule schedule) {
mTrackedItems.remove(itemId);
removeNotification(itemId);
if (item != null && item.schedule != null) {
onChangeScheduleClicked(itemId, item.schedule);
if (itemId != null && schedule != null) {
onChangeScheduleClicked(itemId, schedule);
} else if (itemId != null) {
DownloadUtils.openItem(
itemId, mIsIncognito, DownloadOpenSource.DOWNLOAD_PROGRESS_INFO_BAR);
......
......@@ -23,6 +23,7 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.components.infobars.InfoBar;
import org.chromium.components.infobars.InfoBarLayout;
import org.chromium.components.offline_items_collection.ContentId;
import org.chromium.components.offline_items_collection.OfflineItemSchedule;
import org.chromium.content_public.browser.UiThreadTaskTraits;
/**
......@@ -38,7 +39,8 @@ public class DownloadProgressInfoBar extends InfoBar {
* Called when a link is clicked by the user.
* @param itemId The ContentId of the item currently being shown in the InfoBar.
*/
void onLinkClicked(@Nullable ContentId itemId);
void onLinkClicked(
@Nullable ContentId itemId, @Nullable final OfflineItemSchedule schedule);
/**
* Called when the InfoBar is closed either implicitly or explicitly by the user.
......@@ -86,7 +88,7 @@ public class DownloadProgressInfoBar extends InfoBar {
@Override
public void onLinkClicked() {
mClient.onLinkClicked(mInfo.id);
mClient.onLinkClicked(mInfo.id, mInfo.schedule);
}
/**
......
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