User:Brahmana/Download Control Flow
Here I will try to write the actual control in case of downloads, as in which component (in Biesi's Diagram) is an instance of which class, which function calls what other function and what arguments are passed and what they mean. It will take a lot of time before it is complete and completely correct. I will have to do this as I cannot rely on my memory. I will putting in data as and when I understand some code and get some info from IRC.
Control somehow comes to nsExternalHelperAppService(nsEHAS defined in nsEHAS.cpp), probably from nsHelperAppService. From nsEHAS it goes to the nsITransfer (nsEHAS.cpp#2217). From there finally it comes to nsDownloadProxy(nsDP.h).
From somewhere the control comes to the URILoader. As in some component, which wants a URI to be loaded via some channel calls the openChannel() function of the URILoader. This funciton takes the channel from which the data is to be loaded as an arguments and returns a StreamListener which can later be used by the caller to access the loaded data. Note that here the caller has to open the channel that is passed to this function. It is also the responsibility of the caller itself to pump the data into the StreamListener that is returned.
<!-- Breaking this further -->
This openChannel() function calls the doContent() method of the ExternalHelperAppService. This function takes a nsIRequest object as parameter. This can be the channel argument that was received by the caller of this function, the openChannel() function. This function, doContent(), binds an external application with a StreamListener, and this StreamListener is returned to openChannel(), which in-turn returns the StreamListener to its caller. Now here also the condition is that the caller has to pump the data into the StreamListener, which when traced back happens to be the caller of the openChannel() function which was returned the StreamListener. It is the same caller which had also opened the channel. So it takes the data from the channel that it opened and puts it into the StreamListener. It calls the onStartRequest()to (probably) signal the start of data pumping. As per the diagram a lot of things happen at this function call which is will broken further later. After this data is pumped into the listener at appropriate times(which is something that I have to find out).
<!-- NOTE -->
In Biesi's diagram, the component named <<nsExternalAppHandler>> is nothing but a StreamListener. Because that is what the doContent() creates and returns. It is the StreamListener that has the onDataAvailable() function which is called as and when data is pumped into this listener by the ultimate caller(the caller who opened the channel and called openChannel() and also reads the data from it).
<!-- END NOTE -->
Now after the data pumping is over the onStopRequest() is called on the listener. Here all the shutdown operations happen. Apart from this the data that has been accumulated has to be given some final destiny. Either it is to be launched with the appropriate external application or saved to some file or the temporary file is to be moved or any such damn action. To do this ExecuteDesiredAction() is called. That does the job.
And the story continues.....
nsDP has a private member mInner, which actually is a nsCOMPtr<nsIDownload>.