steps
1.onDownloadStartNoStream
2.3 in BrowserActivity.onDownloadStartNoStream, 3.2 in Controller to DownloadHandler.onDownloadStartNoStream.
2.in onDownloadStartNoStream
check sdcard
generate DownloadManager.Request
set download path and filename.
3.DownloadManager.enque(Request)
in enque of DownloadManager, it will insert the download item to database.
4. since DownloadService regist a ContentObserver on DownloadProvider's uri.
so the DownloadProvider's 'onChange' will be called when the database has changed.
5. in the onChange ot the ContentObserver, call 'DownloadService.updateFromProvider'
and then start a new thread.
mUpdateThread = new UpdateThread();
mSystemFacade.startThread(mUpdateThread);
6. in the thread's 'run' function
traverse the database , get the data into a DownloadInfo class.
and call DownloadInfo.startIfReady() to start a thread to download
DownloadThread downloader = new DownloadThread(mContext, mSystemFacade, this,
storageManager);
mHasActiveThread = true;
mSystemFacade.startThread(downloader);
//mSystemFacade was assigned in
public void onCreate() {
super.onCreate();
if (Constants.LOGVV) {
Log.v(Constants.TAG, "Service onCreate");
}
if (mSystemFacade == null) {
mSystemFacade = new RealSystemFacade(this);
}
call DownloadThread's run()
start download.
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
State state = new State(mInfo);
AndroidHttpClient client = null;
PowerManager.WakeLock wakeLock = null;
int finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR;
try {
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG);
wakeLock.acquire();
if (Constants.LOGV) {
Log.v(Constants.TAG, "initiating download for " + mInfo.mUri);
}
client = AndroidHttpClient.newInstance(userAgent(), mContext);
boolean finished = false;
while(!finished) {
Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId);
HttpGet request = new HttpGet(state.mRequestUri);
try {
executeDownload(state, client, request);
finished = true;
} catch (RetryDownload exc) {
// fall through
} finally {
request.abort();
request = null;
}
}
if (Constants.LOGV) {
Log.v(Constants.TAG, "download completed for " + mInfo.mUri);
}
finalizeDestinationFile(state);
finalStatus = Downloads.Impl.STATUS_SUCCESS;
} catch (StopRequest error) {
// remove the cause before printing, in case it contains PII
Log.w(Constants.TAG,
"Aborting request for download " + mInfo.mId + ": " + error.getMessage());
finalStatus = error.mFinalStatus;
// fall through to finally block
} catch (Throwable ex) { //sometimes the socket code throws unchecked exceptions
Log.w(Constants.TAG, "Exception for id " + mInfo.mId + ": " + ex);
finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR;
// falls through to the code that reports an error
} finally {
if (wakeLock != null) {
wakeLock.release();
wakeLock = null;
}
if (client != null) {
client.close();
client = null;
}
cleanupDestination(state, finalStatus);
notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter,
state.mGotData, state.mFilename,
state.mNewUri, state.mMimeType);
mInfo.mHasActiveThread = false;
}
webkit download notes
1, ResourceHandle
a class for managing Resource downloading, it's has functions "connection","loadResourceSynchronously" and so forth.
2.ResourceHandleClient
ResourceHandle's client who may really need the data, and using ResourceHandle to download it.
3.ResourceHandleInternal
media class between ReourceHandle and ResourehandleClient.
ResourceHandle use it to find it's client. (so that we can change it's ResourceHandle's real client).
4,ResourceLoader
son of ResourceHandleClient, it will use ResourceHandle to download data, client of ResourceHandle.
5.MainResourceLoader
son of ResourceLoader, same function as it's parent, it will load Main resource, client of ResourceHandle.
6. FrameLoader
member of ResourceLoader, also memeber of MainResourceLoader.
7.FrameLoaderClient
FrameLoader's client. ResourceLoader's member's client. ResoruceHandle'client's memeber's client.
8.FrameLoaderClientAndroid
son of FrameLoaderClient. ResoruceHandle'client's memeber's client.
9.ResourceLoaderAndroid
member of ResourceHandleInternal. only in android. has nothing to do with ResourceLoader.
may be real download work in android. ?? it's should be android's ResourceHandle.
10. WebUrlLoader
son of ResourceLoaderAndroid, do real work.
11.WebUrlLoaderClient (I think may be we should call WebUrlLoaderWorker better)
client of WebUrlLoader, do work for WebUrlLoader.
(may be different from the client relation ship we talked between "ResourceHandle" and "ResourceHandleClient")