From c4935abc362e46d29ea72f7fc2643c496ffb9da2 Mon Sep 17 00:00:00 2001 From: "mitesh%netscape.com" Date: Wed, 26 Sep 2001 20:28:45 +0000 Subject: [PATCH] Additional Fix for bug 99515 - nsAutoConfig event loop hanging. r=danm and sr=alecf git-svn-id: svn://10.0.0.236/trunk@103859 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/libpref/src/nsAutoConfig.cpp | 70 ++++++++------------ 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/mozilla/modules/libpref/src/nsAutoConfig.cpp b/mozilla/modules/libpref/src/nsAutoConfig.cpp index a504a24450b..18390345e32 100644 --- a/mozilla/modules/libpref/src/nsAutoConfig.cpp +++ b/mozilla/modules/libpref/src/nsAutoConfig.cpp @@ -299,52 +299,48 @@ nsresult nsAutoConfig::downloadAutoConfig() } } - // Getting an event queue. If we start an AsyncOpen, the thread - // needs to wait before the reading of autoconfig is done - nsCOMPtr currentThreadQ; - nsCOMPtr service; - - // We are having the event queue processing only for the startup - // It is not needed with the repeating timer. - if (firstTime) { - service = do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return rv; - rv = service->PushThreadEventQueue(getter_AddRefs(currentThreadQ)); - if (NS_FAILED(rv)) - return rv; - } - // create a new url nsCOMPtr url; nsCOMPtr channel; rv = NS_NewURI(getter_AddRefs(url), mConfigURL, nsnull, nsnull); - if (NS_FAILED(rv)) { - service->PopThreadEventQueue(currentThreadQ); + if (NS_FAILED(rv)) return rv; - } - + // open a channel for the url rv = NS_OpenURI(getter_AddRefs(channel),url, nsnull, nsnull, nsnull, nsIRequest::INHIBIT_PERSISTENT_CACHING | nsIRequest::LOAD_BYPASS_CACHE); - if (NS_FAILED(rv)) { - service->PopThreadEventQueue(currentThreadQ); + if (NS_FAILED(rv)) return rv; - } + rv = channel->AsyncOpen(this, nsnull); if (NS_FAILED(rv)) { - service->PopThreadEventQueue(currentThreadQ); readOfflineFile(); return rv; } // Set a repeating timer if the pref is set. // This is to be done only once. + // Also We are having the event queue processing only for the startup + // It is not needed with the repeating timer. if (firstTime) { firstTime = PR_FALSE; + // Getting an event queue. If we start an AsyncOpen, the thread + // needs to wait before the reading of autoconfig is done + + nsCOMPtr service = + do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr currentThreadQ; + rv = service->GetThreadEventQueue(NS_CURRENT_THREAD, + getter_AddRefs(currentThreadQ)); + if (NS_FAILED(rv)) + return rv; + /* process events until we're finished. AutoConfig.jsc reading needs to be finished before the browser starts loading up We are waiting for the mLoaded which will be set through @@ -353,27 +349,19 @@ nsresult nsAutoConfig::downloadAutoConfig() that mLoaded will be set to true in any case (success/failure) */ - PLEvent *event; while (!mLoaded) { - rv = currentThreadQ->WaitForEvent(&event); - NS_ASSERTION(NS_SUCCEEDED(rv),"-->nsAutoConfig::downloadAutoConfig: currentThreadQ->WaitForEvent failed..."); - if (NS_FAILED(rv)) { - service->PopThreadEventQueue(currentThreadQ); - return rv; - } - rv = currentThreadQ->HandleEvent(event); - NS_ASSERTION(NS_SUCCEEDED(rv), "-->nsAutoConfig::downloadAutoConfig: currentThreadQ->HandleEvent failed..."); - if (NS_FAILED(rv)) { - service->PopThreadEventQueue(currentThreadQ); - return rv; + + PRBool isEventPending; + rv = currentThreadQ->PendingEvents(&isEventPending); + if (NS_FAILED(rv)) + return rv; + if (isEventPending) { + rv = currentThreadQ->ProcessPendingEvents(); + if (NS_FAILED(rv)) + return rv; } } - // Removing the eventQueue from the list - rv = service->PopThreadEventQueue(currentThreadQ); - if (NS_FAILED(rv)) - return rv; - PRInt32 minutes = 0; rv = mPrefBranch->GetIntPref("autoadmin.refresh_interval", &minutes);