Bug 1272354 - (DLC) DownloadAction: Move network checks inside download loop. r?grisha
This has two advantages:
* If the network changes while we are downloading content then we do not continue on an metered network.
* When adding telemetry in one of the next patches then we can report which kind of content we did not
download.
MozReview-Commit-ID: 80QzSRyCArr
--- a/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java
+++ b/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java
@@ -50,34 +50,34 @@ public class DownloadAction extends Base
public void perform(Context context, DownloadContentCatalog catalog) {
Log.d(LOGTAG, "Downloading content..");
if (!catalog.hasScheduledDownloads()) {
Log.d(LOGTAG, "No scheduled downloads. Nothing to do.");
return;
}
- if (!isConnectedToNetwork(context)) {
- Log.d(LOGTAG, "No connected network available. Postponing download.");
- // TODO: Reschedule download (bug 1209498)
- return;
- }
-
- if (isActiveNetworkMetered(context)) {
- Log.d(LOGTAG, "Network is metered. Postponing download.");
- // TODO: Reschedule download (bug 1209498)
- return;
- }
-
for (DownloadContent content : catalog.getScheduledDownloads()) {
Log.d(LOGTAG, "Downloading: " + content);
File temporaryFile = null;
try {
+ if (!isConnectedToNetwork(context)) {
+ Log.d(LOGTAG, "No connected network available. Postponing download.");
+ // TODO: Reschedule download (bug 1209498)
+ return;
+ }
+
+ if (isActiveNetworkMetered(context)) {
+ Log.d(LOGTAG, "Network is metered. Postponing download.");
+ // TODO: Reschedule download (bug 1209498)
+ return;
+ }
+
File destinationFile = getDestinationFile(context, content);
if (destinationFile.exists() && verify(destinationFile, content.getChecksum())) {
Log.d(LOGTAG, "Content already exists and is up-to-date.");
catalog.markAsDownloaded(content);
continue;
}
temporaryFile = createTemporaryFile(context, content);