Commit d808dc95 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Always show the infobar in latest tab.

When there are multiple scheduled downloads in different tabs, always
show the scheduled infobar in the latest tab instead of the first tab.

Also tweaked the delay, that 2 scheduled download must show inside a 12
seconds window to have the multiple scheduled string shown.

Bug: 1123924
Change-Id: I9b9de9d484871b94c2a3e2c4a60dad31950e29d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401404
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806402}
parent 481ef0bb
...@@ -70,6 +70,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -70,6 +70,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
private static final String SPEEDING_UP_MESSAGE_ENABLED = "speeding_up_message_enabled"; private static final String SPEEDING_UP_MESSAGE_ENABLED = "speeding_up_message_enabled";
private static final long DURATION_ACCELERATED_INFOBAR_IN_MS = 3000; private static final long DURATION_ACCELERATED_INFOBAR_IN_MS = 3000;
private static final long DURATION_SHOW_RESULT_IN_MS = 6000; private static final long DURATION_SHOW_RESULT_IN_MS = 6000;
private static final long DURATION_SHOW_RESULT_DOWNLOAD_SCHEDULED_IN_MS = 12000;
// Values for the histogram Android.Download.InfoBar.Shown. Keep this in sync with the // Values for the histogram Android.Download.InfoBar.Shown. Keep this in sync with the
// DownloadInfoBar.ShownState enum in enums.xml. // DownloadInfoBar.ShownState enum in enums.xml.
...@@ -210,6 +211,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -210,6 +211,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
forceReparent = other.forceReparent; forceReparent = other.forceReparent;
downloadCount = other.downloadCount; downloadCount = other.downloadCount;
resultState = other.resultState; resultState = other.resultState;
schedule = other.schedule;
} }
} }
...@@ -572,7 +574,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -572,7 +574,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
/** /**
* Determines the {@link OfflineItemState} for the message to be shown on the infobar. For * Determines the {@link OfflineItemState} for the message to be shown on the infobar. For
* DOWNLOADING state, it will return {@link OfflineItemState.IN_PROGRESS}. Otherwise it should * DOWNLOADING state, it will return {@link OfflineItemState#IN_PROGRESS}. Otherwise it should
* show the result state which can be complete, failed or pending. There is usually a delay of * show the result state which can be complete, failed or pending. There is usually a delay of
* DURATION_SHOW_RESULT_IN_MS between transition between these states, except for the complete * DURATION_SHOW_RESULT_IN_MS between transition between these states, except for the complete
* state which must be shown as soon as received. While the InfoBar is in one of these states, * state which must be shown as soon as received. While the InfoBar is in one of these states,
...@@ -717,8 +719,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -717,8 +719,7 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
clearEndTimerRunnable(); clearEndTimerRunnable();
if (startTimer) { if (startTimer) {
long delay = long delay = getDelayToNextStep(showAccelerating, resultState);
showAccelerating ? getDurationAcceleratedInfoBar() : getDurationShowResult();
mEndTimerRunnable = () -> { mEndTimerRunnable = () -> {
mEndTimerRunnable = null; mEndTimerRunnable = null;
if (mCurrentInfo != null) mCurrentInfo.resultState = ResultState.INVALID; if (mCurrentInfo != null) mCurrentInfo.resultState = ResultState.INVALID;
...@@ -740,6 +741,12 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -740,6 +741,12 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
info.downloadCount = getDownloadCount(); info.downloadCount = getDownloadCount();
info.forceReparent = !info.downloadCount.equals( info.forceReparent = !info.downloadCount.equals(
mCurrentInfo == null ? null : mCurrentInfo.downloadCount); mCurrentInfo == null ? null : mCurrentInfo.downloadCount);
// TODO(xingliu, shaktisahu): downloadCount may not be updated at the correct time, see
// https://crbug.com/1127522. For now, scheduled download will always show in new tabs.
if (info.downloadCount.scheduled > 0) {
info.forceReparent = true;
}
} }
private void setAccessibilityMessage( private void setAccessibilityMessage(
...@@ -790,13 +797,12 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe ...@@ -790,13 +797,12 @@ public class DownloadInfoBarController implements OfflineContentProvider.Observe
} }
@VisibleForTesting @VisibleForTesting
protected long getDurationAcceleratedInfoBar() { protected long getDelayToNextStep(boolean showAccelerating, @ResultState int resultState) {
return DURATION_ACCELERATED_INFOBAR_IN_MS; if (showAccelerating) return DURATION_ACCELERATED_INFOBAR_IN_MS;
}
@VisibleForTesting // Scheduled download uses a longer delay to reset tracking downloads states.
protected long getDurationShowResult() { return resultState == ResultState.SCHEDULED ? DURATION_SHOW_RESULT_DOWNLOAD_SCHEDULED_IN_MS
return DURATION_SHOW_RESULT_IN_MS; : DURATION_SHOW_RESULT_IN_MS;
} }
@VisibleForTesting @VisibleForTesting
......
...@@ -51,8 +51,7 @@ public class DownloadInfoBarControllerTest { ...@@ -51,8 +51,7 @@ public class DownloadInfoBarControllerTest {
private static final String TEST_FILE_NAME = "TestFile"; private static final String TEST_FILE_NAME = "TestFile";
private static final String MESSAGE_SINGLE_DOWNLOAD_COMPLETE = "TestFile."; private static final String MESSAGE_SINGLE_DOWNLOAD_COMPLETE = "TestFile.";
private static final long TEST_DURATION_ACCELERATED_INFOBAR = 100; private static final long TEST_TO_NEXT_STEP_DELAY = 100;
private static final long TEST_DURATION_SHOW_RESULT = 200;
private TestDownloadInfoBarController mTestController; private TestDownloadInfoBarController mTestController;
...@@ -83,13 +82,8 @@ public class DownloadInfoBarControllerTest { ...@@ -83,13 +82,8 @@ public class DownloadInfoBarControllerTest {
} }
@Override @Override
protected long getDurationAcceleratedInfoBar() { protected long getDelayToNextStep(boolean showAccelerating, int resultState) {
return TEST_DURATION_ACCELERATED_INFOBAR; return TEST_TO_NEXT_STEP_DELAY;
}
@Override
protected long getDurationShowResult() {
return TEST_DURATION_SHOW_RESULT;
} }
@Override @Override
......
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