summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadThread.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-01-12 15:58:51 -0800
committerJeff Sharkey <jsharkey@android.com>2013-01-28 16:00:54 -0800
commit38648831a92295e9a11831e19e5a9dab4cbd939e (patch)
treefeed2c5d167c42d3a548a6e029372b278e2660e1 /src/com/android/providers/downloads/DownloadThread.java
parente4b1f0ae43f169886d8d651a418e7f309e3e6f2f (diff)
downloadandroid_packages_providers_DownloadProvider-38648831a92295e9a11831e19e5a9dab4cbd939e.tar.gz
android_packages_providers_DownloadProvider-38648831a92295e9a11831e19e5a9dab4cbd939e.tar.bz2
android_packages_providers_DownloadProvider-38648831a92295e9a11831e19e5a9dab4cbd939e.zip
Cleaner thread management, less global state.
Switch to using a ThreadPoolExecutor for handling downloads, which gives us parallelism logic that is easier to reason about. Also open the door to eventually waiting until the executor is drained to stopSelf(). Removes DownloadHandler singleton, and gives explicit path for publishing active download speeds to notifications. Change-Id: I1836e7742bb8a84861d1ca6bd1e59b2040bd12f8
Diffstat (limited to 'src/com/android/providers/downloads/DownloadThread.java')
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 5bb1e9bd..bd347e42 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -68,10 +68,10 @@ import libcore.io.IoUtils;
import libcore.net.http.HttpEngine;
/**
- * Thread which executes a given {@link DownloadInfo}: making network requests,
+ * Task which executes a given {@link DownloadInfo}: making network requests,
* persisting data to disk, and updating {@link DownloadProvider}.
*/
-public class DownloadThread extends Thread {
+public class DownloadThread implements Runnable {
private static final int HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
private static final int HTTP_TEMP_REDIRECT = 307;
@@ -82,15 +82,17 @@ public class DownloadThread extends Thread {
private final DownloadInfo mInfo;
private final SystemFacade mSystemFacade;
private final StorageManager mStorageManager;
+ private final DownloadNotifier mNotifier;
private volatile boolean mPolicyDirty;
public DownloadThread(Context context, SystemFacade systemFacade, DownloadInfo info,
- StorageManager storageManager) {
+ StorageManager storageManager, DownloadNotifier notifier) {
mContext = context;
mSystemFacade = systemFacade;
mInfo = info;
mStorageManager = storageManager;
+ mNotifier = notifier;
}
/**
@@ -151,16 +153,13 @@ public class DownloadThread extends Thread {
}
}
- /**
- * Executes the download in a separate thread
- */
@Override
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
try {
runInternal();
} finally {
- DownloadHandler.getInstance().dequeueDownload(mInfo.mId);
+ mNotifier.notifyDownloadSpeed(mInfo.mId, 0);
}
}
@@ -526,7 +525,7 @@ public class DownloadThread extends Thread {
state.mSpeedSampleStart = now;
state.mSpeedSampleBytes = state.mCurrentBytes;
- DownloadHandler.getInstance().setCurrentSpeed(mInfo.mId, state.mSpeed);
+ mNotifier.notifyDownloadSpeed(mInfo.mId, state.mSpeed);
}
if (state.mCurrentBytes - state.mBytesNotified > Constants.MIN_PROGRESS_STEP &&