From 512218087a4e13876e153d9622fb072781dd9cb8 Mon Sep 17 00:00:00 2001 From: Krishna Date: Sun, 4 Dec 2016 23:06:35 +0800 Subject: [PATCH] Bug 1276588 - Handling Hyphenation-Dictionaries in DownloadAction. r=sebastian MozReview-Commit-ID: GTuR0IarjGe --HG-- extra : rebase_source : 3718d249a0413d278b8a5e7d77a77086caafbd9e --- .../org/mozilla/gecko/dlc/BaseAction.java | 22 ++++++++++--------- .../org/mozilla/gecko/dlc/DownloadAction.java | 6 ----- .../org/mozilla/gecko/dlc/StudyAction.java | 2 +- .../org/mozilla/gecko/dlc/SyncAction.java | 2 +- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/dlc/BaseAction.java b/mobile/android/base/java/org/mozilla/gecko/dlc/BaseAction.java index 28d6b238df6e..8c76ab35afff 100644 --- a/mobile/android/base/java/org/mozilla/gecko/dlc/BaseAction.java +++ b/mobile/android/base/java/org/mozilla/gecko/dlc/BaseAction.java @@ -94,19 +94,21 @@ public abstract class BaseAction { protected File getDestinationFile(Context context, DownloadContent content) throws UnrecoverableDownloadContentException, RecoverableDownloadContentException { + File destinationDirectory; if (content.isFont()) { - File destinationDirectory = new File(context.getApplicationInfo().dataDir, "fonts"); - - if (!destinationDirectory.exists() && !destinationDirectory.mkdirs()) { - throw new RecoverableDownloadContentException(RecoverableDownloadContentException.DISK_IO, - "Destination directory does not exist and cannot be created"); - } - - return new File(destinationDirectory, content.getFilename()); + destinationDirectory = new File(context.getApplicationInfo().dataDir, "fonts"); + } else if (content.isHyphenationDictionary()) { + destinationDirectory = new File(context.getApplicationInfo().dataDir, "hyphenation"); + } else { + throw new UnrecoverableDownloadContentException("Can't determine destination for kind: " + content.getKind()); } - // Unrecoverable: We downloaded a file and we don't know what to do with it (Should not happen) - throw new UnrecoverableDownloadContentException("Can't determine destination for kind: " + content.getKind()); + if (!destinationDirectory.exists() && !destinationDirectory.mkdirs()) { + throw new RecoverableDownloadContentException(RecoverableDownloadContentException.DISK_IO, + "Destination directory does not exist and cannot be created"); + } + + return new File(destinationDirectory, content.getFilename()); } protected boolean verify(File file, String expectedChecksum) diff --git a/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java b/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java index 8618d4699cef..098343cf7cca 100644 --- a/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java +++ b/mobile/android/base/java/org/mozilla/gecko/dlc/DownloadAction.java @@ -11,10 +11,8 @@ import android.net.NetworkInfo; import android.support.v4.net.ConnectivityManagerCompat; import android.util.Log; -import org.mozilla.gecko.AppConstants; import org.mozilla.gecko.dlc.catalog.DownloadContent; import org.mozilla.gecko.dlc.catalog.DownloadContentCatalog; -import org.mozilla.gecko.util.HardwareUtils; import org.mozilla.gecko.util.IOUtils; import java.io.BufferedInputStream; @@ -27,8 +25,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; import java.util.zip.GZIPInputStream; /** @@ -253,8 +249,6 @@ public class DownloadAction extends BaseAction { } protected String createDownloadURL(DownloadContent content) { - final String location = content.getLocation(); - return CDN_BASE_URL + content.getLocation(); } diff --git a/mobile/android/base/java/org/mozilla/gecko/dlc/StudyAction.java b/mobile/android/base/java/org/mozilla/gecko/dlc/StudyAction.java index e15a17bbeee4..378e7c8387cf 100644 --- a/mobile/android/base/java/org/mozilla/gecko/dlc/StudyAction.java +++ b/mobile/android/base/java/org/mozilla/gecko/dlc/StudyAction.java @@ -29,7 +29,7 @@ public class StudyAction extends BaseAction { continue; } - if (content.isAssetArchive() && content.isFont()) { + if (content.isKnownContent()) { catalog.scheduleDownload(content); Log.d(LOGTAG, "Scheduled download: " + content); diff --git a/mobile/android/base/java/org/mozilla/gecko/dlc/SyncAction.java b/mobile/android/base/java/org/mozilla/gecko/dlc/SyncAction.java index e8ca0d9bcbe8..450c240b2513 100644 --- a/mobile/android/base/java/org/mozilla/gecko/dlc/SyncAction.java +++ b/mobile/android/base/java/org/mozilla/gecko/dlc/SyncAction.java @@ -130,7 +130,7 @@ public class SyncAction extends BaseAction { } // Only select the fields we are actually going to read. builder.appendQueryParameter(KINTO_PARAMETER_FIELDS, - "attachment.location,attachment.original.filename,attachment.original.hash,attachment.hash,type,kind,attachment.original.size,match"); + "type,kind,attachment.location,attachment.hash,attachment.original.size,attachment.original.filename,attachment.original.hash,match"); // We want to process items in the order they have been modified. This is to ensure that // our last_modified values are correct if we processing is interrupted and not all items