aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs/sdklib
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2012-05-08 19:13:01 -0700
committerRaphael Moll <ralf@android.com>2012-05-09 20:40:51 -0700
commit73262b1c01e3a902c171a5de2825f8ab0f2b44fb (patch)
tree16b45728572a54ffb66f976ea15b6672a80227d9 /sdkmanager/libs/sdklib
parent21a74431ed9e69c1f6cfe6b5c88cbecaaff76b7c (diff)
downloadsdk-73262b1c01e3a902c171a5de2825f8ab0f2b44fb.zip
sdk-73262b1c01e3a902c171a5de2825f8ab0f2b44fb.tar.gz
sdk-73262b1c01e3a902c171a5de2825f8ab0f2b44fb.tar.bz2
SDK Manager: rework package loader.
When the SDK Manager window opens, the process is changed to: - first a package loader is created that only checks the local cache xml files. It populates the package list based on what the client last got, essentially. - next a regular package loader is created that will respect the expiration and refresh parameters of the download cache. This means for users, in the majority of cases when remote servers do not change, the package list will be populated as fast as possible and then an asynchronous refresh happens. Change-Id: Ifd1f58412dcc643eaae37257a9bc0a01fc222c90
Diffstat (limited to 'sdkmanager/libs/sdklib')
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/DownloadCache.java15
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskFactory.java14
2 files changed, 29 insertions, 0 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/DownloadCache.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/DownloadCache.java
index c29e988..591e447 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/DownloadCache.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/DownloadCache.java
@@ -134,6 +134,12 @@ public class DownloadCache {
public enum Strategy {
/**
+ * Exclusively serves data from the cache. If files are available in the
+ * cache, serve them as is (without trying to refresh them). If files are
+ * not available, they are <em>not</em> fetched at all.
+ */
+ ONLY_CACHE,
+ /**
* If the files are available in the cache, serve them as-is, otherwise
* download them and return the cached version. No expiration or refresh
* is attempted if a file is in the cache.
@@ -237,6 +243,7 @@ public class DownloadCache {
* @param monitor {@link ITaskMonitor} which is related to this URL
* fetching.
* @return Returns an {@link InputStream} holding the URL content.
+ * Returns null if the document is not cached and strategy is {@link Strategy#ONLY_CACHE}.
* @throws IOException Exception thrown when there are problems retrieving
* the URL or its content.
* @throws CanceledByUserException Exception thrown if the user cancels the
@@ -414,6 +421,14 @@ public class DownloadCache {
} catch (IOException ignore) {}
}
+ if (!useCached && mStrategy == Strategy.ONLY_CACHE) {
+ // We don't have a document to serve from the cache.
+ if (DEBUG) {
+ System.out.println(String.format("%s : file not in cache", urlString)); //$NON-NLS-1$
+ }
+ return null;
+ }
+
// If we're not using the cache, try to remove the cache and download again.
try {
cached.delete();
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskFactory.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskFactory.java
index fb59b42..dfd197d 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskFactory.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ITaskFactory.java
@@ -16,6 +16,7 @@
package com.android.sdklib.internal.repository;
+
/**
* A factory that can start and run new {@link ITask}s.
*/
@@ -23,6 +24,12 @@ public interface ITaskFactory {
/**
* Starts a new task with a new {@link ITaskMonitor}.
+ * <p/>
+ * The task will execute in a thread and runs it own UI loop.
+ * This means the task can perform UI operations using
+ * {@code Display#asyncExec(Runnable)}.
+ * <p/>
+ * In either case, the method only returns when the task has finished.
*
* @param title The title of the task, displayed in the monitor if any.
* @param task The task to run.
@@ -36,6 +43,13 @@ public interface ITaskFactory {
* and give the sub-monitor to the new task with the number of work units you want
* it to fill. The {@link #start} method will make sure to <em>fill</em> the progress
* when the task is completed, in case the actual task did not.
+ * <p/>
+ * When a task is started from within a monitor, it reuses the thread
+ * from the parent. Otherwise it starts a new thread and runs it own
+ * UI loop. This means the task can perform UI operations using
+ * {@code Display#asyncExec(Runnable)}.
+ * <p/>
+ * In either case, the method only returns when the task has finished.
*
* @param title The title of the task, displayed in the monitor if any.
* @param parentMonitor The parent monitor. Can be null.