diff options
author | Steve Howard <showard@google.com> | 2010-07-16 14:28:35 -0700 |
---|---|---|
committer | Steve Howard <showard@google.com> | 2010-07-20 15:47:43 -0700 |
commit | b5629da794cb3c1ca1970d206343743b165b9644 (patch) | |
tree | 53703ac7a0ef36f9c3eaa2fc44bb6a43754a3b7f /src/com/android/providers/downloads/Helpers.java | |
parent | 5180de23e77139dd6971dfd48269242e3e3562d9 (diff) | |
download | android_packages_providers_DownloadProvider-b5629da794cb3c1ca1970d206343743b165b9644.tar.gz android_packages_providers_DownloadProvider-b5629da794cb3c1ca1970d206343743b165b9644.tar.bz2 android_packages_providers_DownloadProvider-b5629da794cb3c1ca1970d206343743b165b9644.zip |
Major refactoring of DownloadThread.run().
Motivation: I need to fix the handling of 302s, so that after a
disconnect, subsequent retries will use the original URI, not the
redirected one. Rather than store extra information in the DB, I'd
like to just keep the redirected URI in memory and make the redirected
request within the same DownloadThread. This involves working with
the large-scale structure of DownloadThread.run(). Since run() was a
~700 line method, I didn't feel comfortable making such changes.
So this change refactors run() into a ~80 line method which calls into
a collection of ~20 other short methods. The state previously kept in
local variables has been pulled into a couple of state-only inner
classes. The error-handling control flow, formerly handled by "break
http_request_loop" statements, is now handled by throwing a
"StopRequest" exception. The remaining structure of run() has been
simplified -- the outermost for loop, for example, could never
actually repeat and has been removed for now. Some other bits of code
have been cleaned up a bit, but the functionality has not been
modified.
There are many good next steps to this refactoring. Besides various
other cleanup bits, a major improvement would be to consolidate the
State/InnerState classes, move some functionality to this new class
(there are many functions of the form "void foo(State)" which would be
good candidates), and promote it to a top-level class. But I want to
take things one step at a time, and I think what I've got here is a
major improvement and should be enough to allow me to safely implement
the changes to redirection handling.
In the process of doing this refactoring I added many test cases to
PublicApiFunctionalTest to exercise some of the pieces of code I was
moving around. I also moved some test cases from
DownloadManagerFunctionalTest. Over time I'd like to move everything
over to use the PublicApiFunctionalTest approach, and then I may break
that into some smaller suites.
Other minor changes:
* use longs instead of ints to track file sizes, as these may be
getting quite large in the future
* provide a default DB value of -1 for COLUMN_TOTAL_BYTES, as this
simplifies some logic in DownloadThread
* small extensions to MockResponse to faciliate new test cases
Change-Id: If7862349296ad79ff6cdc97e554ad14c01ce1f49
Diffstat (limited to 'src/com/android/providers/downloads/Helpers.java')
-rw-r--r-- | src/com/android/providers/downloads/Helpers.java | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java index 0ad4edc0..dac4b55e 100644 --- a/src/com/android/providers/downloads/Helpers.java +++ b/src/com/android/providers/downloads/Helpers.java @@ -94,7 +94,7 @@ public class Helpers { String contentLocation, String mimeType, int destination, - int contentLength) throws FileNotFoundException { + long contentLength) throws FileNotFoundException { if (!canHandleDownload(context, mimeType, destination)) { return new DownloadFileInfo(null, null, Downloads.Impl.STATUS_NOT_ACCEPTABLE); @@ -134,7 +134,7 @@ public class Helpers { private static String chooseFullPath(Context context, String url, String hint, String contentDisposition, String contentLocation, - String mimeType, int destination, int contentLength) + String mimeType, int destination, long contentLength) throws GenerateSaveFileError { File base = locateDestinationDirectory(context, mimeType, destination, contentLength); String filename = chooseFilename(url, hint, contentDisposition, contentLocation, @@ -201,7 +201,7 @@ public class Helpers { } private static File locateDestinationDirectory(Context context, String mimeType, - int destination, int contentLength) + int destination, long contentLength) throws GenerateSaveFileError { File base = null; StatFs stat = null; |