From 67dc096258ee0f551c4dd7b275ba3e08d4bb3710 Mon Sep 17 00:00:00 2001 From: "bienvenu%netscape.com" Date: Tue, 2 Nov 1999 23:22:29 +0000 Subject: [PATCH] remove the imap channel from the load group when finished running r=mscott --- mailnews/imap/public/nsIImapMockChannel.idl | 1 + mailnews/imap/public/nsIImapUrl.h | 1 + mailnews/imap/src/nsImapMailFolder.cpp | 2 +- mailnews/imap/src/nsImapProtocol.cpp | 44 +++++++++++++++------ mailnews/imap/src/nsImapProtocol.h | 1 + mailnews/imap/src/nsImapUrl.cpp | 15 +++++++ mailnews/imap/src/nsImapUrl.h | 1 + 7 files changed, 52 insertions(+), 13 deletions(-) diff --git a/mailnews/imap/public/nsIImapMockChannel.idl b/mailnews/imap/public/nsIImapMockChannel.idl index 1a60723286fe..aac3ec60588d 100644 --- a/mailnews/imap/public/nsIImapMockChannel.idl +++ b/mailnews/imap/public/nsIImapMockChannel.idl @@ -55,4 +55,5 @@ interface nsIImapMockChannel : nsIChannel void SetLoadGroup(in nsILoadGroup aLoadGroup); void SetURI(in nsIURI aUrl); void Close(); + attribute boolean cancelled; }; diff --git a/mailnews/imap/public/nsIImapUrl.h b/mailnews/imap/public/nsIImapUrl.h index 9ac596b7d103..acf85273093d 100644 --- a/mailnews/imap/public/nsIImapUrl.h +++ b/mailnews/imap/public/nsIImapUrl.h @@ -185,6 +185,7 @@ public: NS_IMETHOD SetMockChannel(nsIImapMockChannel * aChannel) = 0; NS_IMETHOD AddChannelToLoadGroup() = 0; + NS_IMETHOD RemoveChannel(nsresult status) = 0; }; #endif /* nsIImapUrl_h___ */ diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index 92bf138c654f..07640fc0a2d6 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -458,7 +458,7 @@ nsImapMailFolder::UpdateFolder(nsIMsgWindow *msgWindow) if (NS_SUCCEEDED(rv) && pEventQService) pEventQService->GetThreadEventQueue(PR_GetCurrentThread(), getter_AddRefs(eventQ)); - rv = imapService->SelectFolder(eventQ, this, this, nsnull, nsnull); + rv = imapService->SelectFolder(eventQ, this, this, msgWindow, nsnull); m_urlRunning = PR_TRUE; } return rv; diff --git a/mailnews/imap/src/nsImapProtocol.cpp b/mailnews/imap/src/nsImapProtocol.cpp index f95c81ef18ec..e7138a0ef2e3 100644 --- a/mailnews/imap/src/nsImapProtocol.cpp +++ b/mailnews/imap/src/nsImapProtocol.cpp @@ -1060,6 +1060,11 @@ PRBool nsImapProtocol::ProcessCurrentURL() WaitForFEEventCompletion(); } + // probably the wrong place to remove the channel - we need + // a place where we know we're finished with the url. + if (m_runningUrl) + m_runningUrl->RemoveChannel(NS_OK); + // release this by hand so that we can load the next queued url without thinking // this connection is busy running a url. m_runningUrl = null_nsCOMPtr(); @@ -3341,11 +3346,16 @@ PRMonitor *nsImapProtocol::GetDataMemberMonitor() // in 4.5 - we need to think about this some. Some of it may just go away in the new world order PRBool nsImapProtocol::DeathSignalReceived() { - PRBool returnValue; - PR_EnterMonitor(m_threadDeathMonitor); - returnValue = m_threadShouldDie; - PR_ExitMonitor(m_threadDeathMonitor); - + PRBool returnValue = PR_FALSE; + if (m_mockChannel) + m_mockChannel->GetCancelled(&returnValue); + + if (!returnValue) // check the other way of cancelling. + { + PR_EnterMonitor(m_threadDeathMonitor); + returnValue = m_threadShouldDie; + PR_ExitMonitor(m_threadDeathMonitor); + } return returnValue; } @@ -6149,6 +6159,7 @@ nsImapMockChannel::nsImapMockChannel() { NS_INIT_REFCNT(); m_channelContext = nsnull; + m_cancelled = PR_FALSE; } nsImapMockChannel::~nsImapMockChannel() @@ -6323,13 +6334,8 @@ NS_IMETHODIMP nsImapMockChannel::IsPending(PRBool *result) NS_IMETHODIMP nsImapMockChannel::Cancel() { - if (m_channelContext) - { - nsCOMPtr protocol = do_QueryInterface(m_channelContext); - if (protocol) - protocol->TellThreadToDie(PR_TRUE); - } - return NS_ERROR_NOT_IMPLEMENTED; + m_cancelled = PR_TRUE; + return NS_OK; } NS_IMETHODIMP nsImapMockChannel::Suspend() @@ -6341,3 +6347,17 @@ NS_IMETHODIMP nsImapMockChannel::Resume() { return NS_ERROR_NOT_IMPLEMENTED; } + +NS_IMETHODIMP nsImapMockChannel::GetCancelled(PRBool *aResult) +{ + if (!aResult) + return NS_ERROR_NULL_POINTER; + *aResult = m_cancelled; + return NS_OK; +} + +NS_IMETHODIMP nsImapMockChannel::SetCancelled(PRBool cancelled) +{ + m_cancelled = cancelled; + return NS_OK; +} diff --git a/mailnews/imap/src/nsImapProtocol.h b/mailnews/imap/src/nsImapProtocol.h index 84758b0fc04f..4cb0c203724d 100644 --- a/mailnews/imap/src/nsImapProtocol.h +++ b/mailnews/imap/src/nsImapProtocol.h @@ -559,6 +559,7 @@ protected: // non owning ref of the context in order to fix a circular ref count // because the context is already the uri... nsISupports * m_channelContext; + PRBool m_cancelled; }; #endif // nsImapProtocol_h___ diff --git a/mailnews/imap/src/nsImapUrl.cpp b/mailnews/imap/src/nsImapUrl.cpp index 87ebb3080bf7..e85f7eedc344 100644 --- a/mailnews/imap/src/nsImapUrl.cpp +++ b/mailnews/imap/src/nsImapUrl.cpp @@ -81,6 +81,7 @@ nsImapUrl::~nsImapUrl() PR_FREEIF(m_listOfMessageIds); PR_FREEIF(m_destinationCanonicalFolderPathSubString); PR_FREEIF(m_sourceCanonicalFolderPathSubString); + } NS_IMPL_ADDREF_INHERITED(nsImapUrl, nsMsgMailNewsUrl) @@ -946,6 +947,20 @@ NS_IMETHODIMP nsImapUrl::AddChannelToLoadGroup() return NS_OK; } +NS_IMETHODIMP nsImapUrl::RemoveChannel(nsresult status) +{ + nsCOMPtr aLoadGroup; + if (m_mockChannel) + { + GetLoadGroup(getter_AddRefs(aLoadGroup)); + if (aLoadGroup) + { + aLoadGroup->RemoveChannel(m_mockChannel, nsnull, status, nsnull); + } + } + return NS_OK; +} + NS_IMETHODIMP nsImapUrl::GetAllowContentChange(PRBool *result) { if (!result) diff --git a/mailnews/imap/src/nsImapUrl.h b/mailnews/imap/src/nsImapUrl.h index fb57d0940c1b..2b0462ff660b 100644 --- a/mailnews/imap/src/nsImapUrl.h +++ b/mailnews/imap/src/nsImapUrl.h @@ -95,6 +95,7 @@ public: NS_IMETHOD SetMockChannel(nsIImapMockChannel * aChannel); NS_IMETHOD AddChannelToLoadGroup(); + NS_IMETHOD RemoveChannel(nsresult status); // nsIMsgMessageUrl NS_DECL_NSIMSGMESSAGEURL