rv = NS_ERROR_UNEXPECTED;
mInner->Unassert(mEngine, kNC_loading, trueLiteral);  if (mConnections) { PRUint32	count=0; mConnections->Count(&count); if (count < 1) { if (mParent) { mInner->Unassert(mParent, kNC_loading, trueLiteral); } } }
InternetSearchDataSource::OnStopRequest(nsIRequest *request, nsISupports *ctxt,                                        nsresult status){	if (!mInner)	return(NS_OK);  nsCOMPtr<nsIChannel> channel (do_QueryInterface(request));	nsCOMPtr<nsIInternetSearchContext> context (do_QueryInterface(ctxt));	if (!ctxt)	return(NS_ERROR_NO_INTERFACE);	nsresult	rv;	PRUint32	contextType = 0;	if (NS_FAILED(rv = context->GetContextType(&contextType)))		return(rv);	if (contextType == nsIInternetSearchContext::WEB_SEARCH_CONTEXT)	{		// continue to process nsIInternetSearchContext::WEB_SEARCH_CONTEXT		rv = webSearchFinalize(channel, context);	}	else if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_CONTEXT ||		 contextType == nsIInternetSearchContext::ICON_DOWNLOAD_CONTEXT)	{		nsCOMPtr<nsIHttpChannel> httpChannel (do_QueryInterface(channel));		if (!httpChannel)	return(NS_ERROR_UNEXPECTED);		// check HTTP status to ensure success		PRUint32	httpStatus = 0;		if (NS_SUCCEEDED(rv = httpChannel->GetResponseStatus(&httpStatus)) &&			(httpStatus == 200))		{			rv = saveContents(channel, context, contextType);		}	}	else if (contextType == nsIInternetSearchContext::ENGINE_UPDATE_CONTEXT)	{		nsCOMPtr<nsIRDFResource>	theEngine;		if (NS_FAILED(rv = context->GetEngine(getter_AddRefs(theEngine))))	return(rv);		if (!theEngine)	return(NS_ERROR_NO_INTERFACE);#ifdef	DEBUG_SEARCH_UPDATES		const char	*engineURI = nsnull;		theEngine->GetValueConst(&engineURI);#endif		// free up "busy" info now & mark as non-busy		busySchedule = PR_FALSE;		busyResource = nsnull;		// we only have HTTP "HEAD" information when doing updates		nsCOMPtr<nsIHttpChannel> httpChannel (do_QueryInterface(channel));		if (!httpChannel)	return(NS_ERROR_UNEXPECTED);		// check HTTP status to ensure success		PRUint32	httpStatus = 0;		if (NS_FAILED(rv = httpChannel->GetResponseStatus(&httpStatus)))			return(rv);		if (httpStatus != 200)	return(NS_ERROR_UNEXPECTED);		// get last-modified & content-length info		nsCAutoString			lastModValue, contentLengthValue;        if (NS_FAILED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Last-Modified"), lastModValue)))            lastModValue.Truncate();        if (NS_FAILED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Length"), contentLengthValue)))            contentLengthValue.Truncate();		// should we fetch the entire file?		PRBool		updateSearchEngineFile = PR_FALSE;		// save out new search engine state data into localstore		PRBool			tempDirty = PR_FALSE;		nsCOMPtr<nsIRDFLiteral>	newValue;		if (!lastModValue.IsEmpty())		{			gRDFService->GetLiteral(NS_ConvertASCIItoUCS2(lastModValue).get(),				getter_AddRefs(newValue));			if (newValue)			{				updateAtom(mLocalstore, theEngine, kWEB_LastPingModDate, newValue,					&tempDirty);        if (tempDirty)          updateSearchEngineFile = PR_TRUE;			}		}		if (!contentLengthValue.IsEmpty())		{			gRDFService->GetLiteral(NS_ConvertASCIItoUCS2(contentLengthValue).get(),				getter_AddRefs(newValue));			if (newValue)			{				updateAtom(mLocalstore, theEngine, kWEB_LastPingContentLen, newValue,					&tempDirty);        if (tempDirty)				{					updateSearchEngineFile = PR_TRUE;				}				else				{					// worst case: compare local data size vs. remote content size					nsCOMPtr<nsIRDFLiteral>	dataLit;					if (NS_SUCCEEDED(rv = FindData(theEngine, getter_AddRefs(dataLit))) &&						(rv != NS_RDF_NO_VALUE))					{						const PRUnichar	*dataUni = nsnull;						dataLit->GetValueConst(&dataUni);						nsAutoString	dataStr(dataUni);						PRInt32		dataLen=dataStr.Length();#ifdef	DEBUG_SEARCH_UPDATES						printf("    Search engine='%s' data length='%d'\n", engineURI, dataLen);#endif						PRInt32	contentLen=0, err=0;						contentLen = contentLengthValue.ToInteger(&err);						if ((!err) && (dataLen != contentLen))						{#ifdef	DEBUG_SEARCH_UPDATES							printf("    Search engine '%s' data length != remote content length, so update\n",								engineURI, dataLen);#endif							updateSearchEngineFile = PR_TRUE;						}					}				}			}		}		// mark now as the last time we stat'ted the search engine		validateEngineNow(theEngine);    if (updateSearchEngineFile)		{#ifdef	DEBUG_SEARCH_UPDATES			printf("    Search engine='%s' needs updating, so fetching it\n", engineURI);#endif			// get update URL			nsCString		updateURL;			nsCOMPtr<nsIRDFNode>	aNode;			if (NS_SUCCEEDED(rv = mInner->GetTarget(theEngine, kNC_Update, PR_TRUE, getter_AddRefs(aNode)))				&& (rv != NS_RDF_NO_VALUE))			{				nsCOMPtr<nsIRDFLiteral>	aLiteral (do_QueryInterface(aNode));				if (aLiteral)				{					const PRUnichar	*updateUni = nsnull;					aLiteral->GetValueConst(&updateUni);					if (updateUni)					{						updateURL.AssignWithConversion(updateUni);					}				}			}			// get update icon			nsCString		updateIconURL;			if (NS_SUCCEEDED(rv = mInner->GetTarget(theEngine, kNC_UpdateIcon, PR_TRUE, getter_AddRefs(aNode)))				&& (rv != NS_RDF_NO_VALUE))			{				nsCOMPtr<nsIRDFLiteral>	aIconLiteral (do_QueryInterface(aNode));				if (aIconLiteral)				{					const PRUnichar	*updateIconUni = nsnull;					aIconLiteral->GetValueConst(&updateIconUni);					if (updateIconUni)					{						updateIconURL.AssignWithConversion(updateIconUni);					}				}			}			// download it!			AddSearchEngine(updateURL.get(), updateIconURL.get(), nsnull, nsnull);		}		else		{#ifdef	DEBUG_SEARCH_UPDATES			printf("    Search engine='%s' is current and requires no updating\n", engineURI);#endif		}	}	else	{		rv = NS_ERROR_UNEXPECTED;	}	return(rv);}