Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsDownloader Class Reference

#include <nsDownloader.h>

Inheritance diagram for nsDownloader:
Inheritance graph
[legend]
Collaboration diagram for nsDownloader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIDOWNLOADER
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER 
nsDownloader ()
void init (in nsIDownloadObserver observer, in nsIFile downloadLocation)
 Initialize this downloader.
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.

Protected Member Functions

virtual ~nsDownloader ()

Static Protected Member Functions

static NS_METHOD ConsumeData (nsIInputStream *in, void *closure, const char *fromRawSegment, PRUint32 toOffset, PRUint32 count, PRUint32 *writeCount)

Protected Attributes

nsCOMPtr< nsIDownloadObservermObserver
nsCOMPtr< nsIFilemLocation
nsCOMPtr< nsIOutputStreammSink
nsCOMPtr< nsISupports > mCacheToken
PRBool mLocationIsTemp

Detailed Description

Definition at line 46 of file nsDownloader.h.


Constructor & Destructor Documentation

NS_DECL_ISUPPORTS NS_DECL_NSIDOWNLOADER NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSISTREAMLISTENER nsDownloader::nsDownloader ( ) [inline]

Definition at line 54 of file nsDownloader.h.

nsDownloader::~nsDownloader ( ) [protected, virtual]

Definition at line 78 of file nsDownloader.cpp.

{
    if (mLocation && mLocationIsTemp) {
        // release the sink first since it may still hold an open file
        // descriptor to mLocation.  this needs to happen before the
        // file can be removed otherwise the Remove call will fail.
        mSink = 0;

        nsresult rv = mLocation->Remove(PR_FALSE);
        if (NS_FAILED(rv))
            NS_ERROR("unable to remove temp file");
    }
}

Member Function Documentation

NS_METHOD nsDownloader::ConsumeData ( nsIInputStream in,
void closure,
const char *  fromRawSegment,
PRUint32  toOffset,
PRUint32  count,
PRUint32 writeCount 
) [static, protected]

Definition at line 169 of file nsDownloader.cpp.

{
    nsDownloader *self = (nsDownloader *) closure;
    if (self->mSink)
        return self->mSink->Write(fromRawSegment, count, writeCount);

    *writeCount = count;
    return NS_OK;
}
void nsIDownloader::init ( in nsIDownloadObserver  observer,
in nsIFile  downloadLocation 
) [inherited]

Initialize this downloader.

Parameters:
observerthe observer to be notified when the download completes.
downloadLocationthe location where the stream contents should be written. if null, the downloader will select a location and the resulting file will be deleted (or otherwise made invalid) when the downloader object is destroyed. if an explicit download location is specified then the resulting file will not be deleted, and it will be the callers responsibility to keep track of the file, etc.
void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:


Member Data Documentation

nsCOMPtr<nsISupports> nsDownloader::mCacheToken [protected]

Definition at line 69 of file nsDownloader.h.

Definition at line 67 of file nsDownloader.h.

Definition at line 70 of file nsDownloader.h.

Definition at line 66 of file nsDownloader.h.

Definition at line 68 of file nsDownloader.h.


The documentation for this class was generated from the following files: