add offline msg display r=sspitzer, sr=,mscott 41751, finish support for memory cache

This commit is contained in:
bienvenu%netscape.com 2001-01-13 15:29:51 +00:00
Родитель de30bd017a
Коммит d4501f4b46
2 изменённых файлов: 64 добавлений и 21 удалений

Просмотреть файл

@ -694,10 +694,11 @@ public:
nsNntpCacheStreamListener (); nsNntpCacheStreamListener ();
virtual ~nsNntpCacheStreamListener(); virtual ~nsNntpCacheStreamListener();
nsresult Init(nsIStreamListener * aStreamListener, nsIChannel * aChannelToUse); nsresult Init(nsIStreamListener * aStreamListener, nsIChannel * aChannelToUse, nsIMsgMailNewsUrl *aRunningUrl);
protected: protected:
nsCOMPtr<nsIChannel> mChannelToUse; nsCOMPtr<nsIChannel> mChannelToUse;
nsCOMPtr<nsIStreamListener> mListener; nsCOMPtr<nsIStreamListener> mListener;
nsCOMPtr<nsIMsgMailNewsUrl> mRunningUrl;
}; };
NS_IMPL_ADDREF(nsNntpCacheStreamListener); NS_IMPL_ADDREF(nsNntpCacheStreamListener);
@ -717,14 +718,15 @@ nsNntpCacheStreamListener::nsNntpCacheStreamListener()
nsNntpCacheStreamListener::~nsNntpCacheStreamListener() nsNntpCacheStreamListener::~nsNntpCacheStreamListener()
{} {}
nsresult nsNntpCacheStreamListener::Init(nsIStreamListener * aStreamListener, nsIChannel * aChannelToUse) nsresult nsNntpCacheStreamListener::Init(nsIStreamListener * aStreamListener, nsIChannel * aChannelToUse,
nsIMsgMailNewsUrl *aRunningUrl)
{ {
NS_ENSURE_ARG(aStreamListener); NS_ENSURE_ARG(aStreamListener);
NS_ENSURE_ARG(aChannelToUse); NS_ENSURE_ARG(aChannelToUse);
mChannelToUse = aChannelToUse; mChannelToUse = aChannelToUse;
mListener = aStreamListener; mListener = aStreamListener;
mRunningUrl = aRunningUrl;
return NS_OK; return NS_OK;
} }
@ -747,6 +749,10 @@ nsNntpCacheStreamListener::OnStopRequest(nsIChannel * aChannel, nsISupports * aC
if (loadGroup) if (loadGroup)
loadGroup->RemoveChannel(mChannelToUse, nsnull, aStatus, nsnull); loadGroup->RemoveChannel(mChannelToUse, nsnull, aStatus, nsnull);
// clear out mem cache entry so we're not holding onto it.
if (mRunningUrl)
mRunningUrl->SetMemCacheEntry(nsnull);
mListener = nsnull; mListener = nsnull;
mChannelToUse = nsnull; mChannelToUse = nsnull;
return rv; return rv;
@ -797,9 +803,10 @@ NS_IMETHODIMP nsNNTPProtocol::AsyncRead(nsIStreamListener *listener, nsISupports
m_typeWanted = ARTICLE_WANTED; m_typeWanted = ARTICLE_WANTED;
nsNntpCacheStreamListener * cacheListener = new nsNntpCacheStreamListener(); nsNntpCacheStreamListener * cacheListener = new nsNntpCacheStreamListener();
NS_ADDREF(cacheListener); NS_ADDREF(cacheListener);
cacheListener->Init(m_channelListener, NS_STATIC_CAST(nsIChannel *, this)); cacheListener->Init(m_channelListener, NS_STATIC_CAST(nsIChannel *, this), mailnewsUrl);
rv = fileChannel->AsyncRead(cacheListener, m_channelContext); rv = fileChannel->AsyncRead(cacheListener, m_channelContext);
NS_RELEASE(cacheListener); NS_RELEASE(cacheListener);
MarkCurrentMsgRead();
if (NS_SUCCEEDED(rv)) // ONLY if we succeeded in actually starting the read should we return if (NS_SUCCEEDED(rv)) // ONLY if we succeeded in actually starting the read should we return
return NS_OK; return NS_OK;
@ -814,6 +821,7 @@ NS_IMETHODIMP nsNNTPProtocol::AsyncRead(nsIStreamListener *listener, nsISupports
if (NS_SUCCEEDED(rv) && cacheEntry) if (NS_SUCCEEDED(rv) && cacheEntry)
{ {
PRBool updateInProgress; PRBool updateInProgress;
m_typeWanted = ARTICLE_WANTED;
cacheEntry->GetPartialFlag(&partialFlag); cacheEntry->GetPartialFlag(&partialFlag);
cacheEntry->GetUpdateInProgress(&updateInProgress); cacheEntry->GetUpdateInProgress(&updateInProgress);
cacheEntry->GetStoredContentLength(&contentLength); cacheEntry->GetStoredContentLength(&contentLength);
@ -830,9 +838,35 @@ NS_IMETHODIMP nsNNTPProtocol::AsyncRead(nsIStreamListener *listener, nsISupports
// do we have a listener here? // do we have a listener here?
nsIStreamListener *listener = m_channelListener; nsIStreamListener *listener = m_channelListener;
rv = cacheEntry->InterceptAsyncRead(listener, 0, getter_AddRefs(m_channelListener)); rv = cacheEntry->InterceptAsyncRead(listener, 0, getter_AddRefs(m_channelListener));
if (NS_SUCCEEDED(rv))
return nsMsgProtocol::AsyncRead(m_channelListener, ctxt);
} }
} }
} }
// now, determine if we should be loading from the cache or if we have
// to really load the msg with a protocol connection...
if (cacheEntry && contentLength > 0 && !partialFlag)
{
nsCOMPtr<nsIChannel> cacheChannel;
rv = cacheEntry->NewChannel(m_loadGroup, getter_AddRefs(cacheChannel));
if (NS_SUCCEEDED(rv))
{
nsNntpCacheStreamListener * cacheListener = new nsNntpCacheStreamListener();
NS_ADDREF(cacheListener);
SetLoadGroup(m_loadGroup);
m_typeWanted = ARTICLE_WANTED;
cacheListener->Init(m_channelListener, NS_STATIC_CAST(nsIChannel *, this), mailnewsUrl);
rv = cacheChannel->AsyncRead(cacheListener, m_channelContext);
NS_RELEASE(cacheListener);
MarkCurrentMsgRead();
if (NS_SUCCEEDED(rv)) // ONLY if we succeeded in actually starting the read should we return
{
return rv;
}
}
}
} }
return nsMsgProtocol::AsyncRead(listener, ctxt); return nsMsgProtocol::AsyncRead(listener, ctxt);
} }
@ -2402,14 +2436,7 @@ PRInt32 nsNNTPProtocol::DisplayArticle(nsIInputStream * inputStream, PRUint32 le
if (line[0] == '.' && line[1] == 0) if (line[0] == '.' && line[1] == 0)
{ {
m_nextState = NEWS_DONE; m_nextState = NEWS_DONE;
nsCOMPtr<nsIMsgDBHdr> msgHdr; MarkCurrentMsgRead();
nsresult rv = NS_OK;
rv = m_runningURL->GetMessageHeader(getter_AddRefs(msgHdr));
if (NS_SUCCEEDED(rv) && msgHdr) {
msgHdr->MarkRead(PR_TRUE);
}
ClearFlag(NNTP_PAUSE_FOR_READ); ClearFlag(NNTP_PAUSE_FOR_READ);
@ -2433,6 +2460,20 @@ PRInt32 nsNNTPProtocol::DisplayArticle(nsIInputStream * inputStream, PRUint32 le
return 0; return 0;
} }
nsresult nsNNTPProtocol::MarkCurrentMsgRead()
{
nsCOMPtr<nsIMsgDBHdr> msgHdr;
nsresult rv = NS_OK;
if (m_runningURL)
{
rv = m_runningURL->GetMessageHeader(getter_AddRefs(msgHdr));
if (NS_SUCCEEDED(rv) && msgHdr)
msgHdr->MarkRead(PR_TRUE);
}
return rv;
}
PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 length) PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 length)
{ {
@ -2495,15 +2536,7 @@ PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 lengt
#ifdef DEBUG_sspitzer #ifdef DEBUG_sspitzer
printf("should we be marking later, after the message has finished loading?\n"); printf("should we be marking later, after the message has finished loading?\n");
#endif #endif
nsCOMPtr<nsIMsgDBHdr> msgHdr; MarkCurrentMsgRead();
nsresult rv = NS_OK;
rv = m_runningURL->GetMessageHeader(getter_AddRefs(msgHdr));
if (NS_SUCCEEDED(rv) && msgHdr) {
msgHdr->MarkRead(PR_TRUE);
}
ClearFlag(NNTP_PAUSE_FOR_READ); ClearFlag(NNTP_PAUSE_FOR_READ);
} }
else else
@ -5377,6 +5410,15 @@ nsresult nsNNTPProtocol::CleanupAfterRunningUrl()
/* NS_RELEASE(m_newsgroup->GetNewsgroupList()); */ /* NS_RELEASE(m_newsgroup->GetNewsgroupList()); */
} }
// clear out mem cache entry so we're not holding onto it.
if (m_runningURL)
{
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningURL);
if (mailnewsurl)
mailnewsurl->SetMemCacheEntry(nsnull);
}
PR_FREEIF(m_path); PR_FREEIF(m_path);
PR_FREEIF(m_responseText); PR_FREEIF(m_responseText);
PR_FREEIF(m_dataBuf); PR_FREEIF(m_dataBuf);

Просмотреть файл

@ -396,6 +396,7 @@ private:
void SetProgressBarPercent(PRUint32 aProgress, PRUint32 aProgressMax); void SetProgressBarPercent(PRUint32 aProgress, PRUint32 aProgressMax);
nsresult SetProgressStatus(const PRUnichar *aMessage); nsresult SetProgressStatus(const PRUnichar *aMessage);
nsresult SetCheckingForNewNewsStatus(PRInt32 current, PRInt32 total); nsresult SetCheckingForNewNewsStatus(PRInt32 current, PRInt32 total);
nsresult MarkCurrentMsgRead(); // marks the message corresponding to the currently running url read.
nsresult SetNewsFolder(); /* sets m_newsFolder, if not already set */ nsresult SetNewsFolder(); /* sets m_newsFolder, if not already set */
nsresult CreateNewsFolderURI (const char *username, const char *hostname, const char *newsgroupname, char **uri); nsresult CreateNewsFolderURI (const char *username, const char *hostname, const char *newsgroupname, char **uri);
nsresult InitializeNewsFolderFromUri(const char *uri); nsresult InitializeNewsFolderFromUri(const char *uri);