From ac75f56600691d318d40301204baaf840c9586f2 Mon Sep 17 00:00:00 2001 From: Grace Kloba Date: Wed, 3 Feb 2010 10:24:06 -0800 Subject: Enable StreamLoader to be loaded in a separate thread. Move ContentLoader and FileLoader to this new way as they involves IO. Will work on CacheLoader later. Change StreamLoader to contain a Handler instead of derive from a Handler so that the Handler can be created in the thread where load() is called. Rename StreamLoader's old "LoadListener mHandler" to mLoadListener. Remove unused import and unreachable exception. Fix http://b/issue?id=2158613 This improved page_cycler performance in moz/intl by 10-30% as we are not blocked by IO any more. --- core/java/android/webkit/FileLoader.java | 34 +++++++------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) (limited to 'core/java/android/webkit/FileLoader.java') diff --git a/core/java/android/webkit/FileLoader.java b/core/java/android/webkit/FileLoader.java index e856cde..e21e9ef 100644 --- a/core/java/android/webkit/FileLoader.java +++ b/core/java/android/webkit/FileLoader.java @@ -18,11 +18,9 @@ package android.webkit; import com.android.internal.R; -import android.content.Context; import android.content.res.AssetManager; import android.net.http.EventHandler; import android.net.http.Headers; -import android.os.Environment; import android.util.Log; import android.util.TypedValue; @@ -111,7 +109,7 @@ class FileLoader extends StreamLoader { // ".R$drawable" if (mPath == null || mPath.length() == 0) { Log.e(LOGTAG, "Need a path to resolve the res file"); - mHandler.error(EventHandler.FILE_ERROR, mContext + mLoadListener.error(EventHandler.FILE_ERROR, mContext .getString(R.string.httpErrorFileNotFound)); return false; @@ -120,7 +118,7 @@ class FileLoader extends StreamLoader { int dot = mPath.indexOf('.', slash); if (slash == -1 || dot == -1) { Log.e(LOGTAG, "Incorrect res path: " + mPath); - mHandler.error(EventHandler.FILE_ERROR, mContext + mLoadListener.error(EventHandler.FILE_ERROR, mContext .getString(R.string.httpErrorFileNotFound)); return false; } @@ -157,13 +155,13 @@ class FileLoader extends StreamLoader { errorMsg = "Caught IllegalAccessException: " + e; } if (errorMsg != null) { - mHandler.error(EventHandler.FILE_ERROR, mContext + mLoadListener.error(EventHandler.FILE_ERROR, mContext .getString(R.string.httpErrorFileNotFound)); return false; } } else { if (!mAllowFileAccess) { - mHandler.error(EventHandler.FILE_ERROR, + mLoadListener.error(EventHandler.FILE_ERROR, mContext.getString(R.string.httpErrorFileNotFound)); return false; } @@ -171,14 +169,14 @@ class FileLoader extends StreamLoader { mDataStream = new FileInputStream(mPath); mContentLength = (new File(mPath)).length(); } - mHandler.status(1, 1, 200, "OK"); + mLoadListener.status(1, 1, 200, "OK"); } catch (java.io.FileNotFoundException ex) { - mHandler.error(EventHandler.FILE_NOT_FOUND_ERROR, errString(ex)); + mLoadListener.error(EventHandler.FILE_NOT_FOUND_ERROR, errString(ex)); return false; } catch (java.io.IOException ex) { - mHandler.error(EventHandler.FILE_ERROR, errString(ex)); + mLoadListener.error(EventHandler.FILE_ERROR, errString(ex)); return false; } return true; @@ -188,22 +186,4 @@ class FileLoader extends StreamLoader { protected void buildHeaders(Headers headers) { // do nothing. } - - - /** - * Construct a FileLoader and instruct it to start loading. - * - * @param url Full file url pointing to content to be loaded - * @param loadListener LoadListener to pass the content to - * @param asset true if url points to an asset. - * @param allowFileAccess true if this FileLoader can load files from the - * file system. - */ - public static void requestUrl(String url, LoadListener loadListener, - int type, boolean allowFileAccess) { - FileLoader loader = new FileLoader(url, loadListener, type, - allowFileAccess); - loader.load(); - } - } -- cgit v1.1