nsITimer* timer; rv = NS_NewTimer(&timer); if (NS_SUCCEEDED(rv)) { mContext  = ctxt; mListener = listener; rv = timer->Init(this, 0 ); if (NS_SUCCEEDED(rv)) { return NS_OK;
nsCOMPtr<nsIEventQueueService> svc = do_GetService(kEventQueueServiceCID, &rv); if (svc) { nsCOMPtr<nsIEventQueue> queue; rv = svc->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(queue)); if (NS_SUCCEEDED(rv) && queue) { rv = NS_ERROR_OUT_OF_MEMORY; StopLoadEvent* event = new StopLoadEvent; if (event) { PL_InitEvent(NS_REINTERPRET_CAST(PLEvent*, event), nsnull, HandleStopLoadEvent, DestroyStopLoadEvent);  event->mChannel = this; NS_ADDREF(event->mChannel);  rv = queue->EnterMonitor(); if (NS_SUCCEEDED(rv)) { mContext  = ctxt; mListener = listener;  (void) queue->PostEvent(NS_REINTERPRET_CAST(PLEvent*, event)); (void) queue->ExitMonitor(); return NS_OK; }   NS_RELEASE(event->mChannel); delete event; }
nsCachedChromeChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount, nsISupports *ctxt, nsIStreamListener *listener){    if (listener) {        nsresult rv;        if (mLoadGroup) {            rv = mLoadGroup->AddChannel(this, nsnull);            if (NS_FAILED(rv)) return rv;        }        // Fire the OnStartRequest(), which will cause the XUL        // document to get embedded.        rv = listener->OnStartRequest(this, ctxt);        // If that works, then set a timer to fire the        // OnStopRequest(). We want to do this on a callback to avoid        // unexpected re-entrancy problems.        if (NS_SUCCEEDED(rv)) {            nsITimer* timer;            rv = NS_NewTimer(&timer);            if (NS_SUCCEEDED(rv)) {                mContext  = ctxt;                mListener = listener;                rv = timer->Init(this, 0 /*ms*/);                if (NS_SUCCEEDED(rv)) {                    return NS_OK;                }                // Uh oh, something went wrong. Kill the timer.                NS_RELEASE(timer);            }        }        // Uh oh, something went wrong. Fire a balancing        // OnStopRequest() and indicate an error occurred.        (void) mListener->OnStopRequest(this, mContext, rv, nsnull);        if (mLoadGroup) {            (void) mLoadGroup->RemoveChannel(this, nsnull, nsnull, nsnull);        }    }    return NS_OK;}