Bug 1185515 - Don't hold the observer service alive from nsDNSService; r=mcmanus

This commit is contained in:
Ehsan Akhgari 2015-07-20 09:47:15 -04:00
parent 486abe85e1
commit 3171e4a984
2 changed files with 10 additions and 22 deletions

View File

@ -454,25 +454,24 @@ nsDNSSyncRequest::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) const
class NotifyDNSResolution: public nsRunnable
{
public:
NotifyDNSResolution(nsMainThreadPtrHandle<nsIObserverService> &aObs,
const nsACString &aHostname)
: mObs(aObs)
, mHostname(aHostname)
explicit NotifyDNSResolution(const nsACString &aHostname)
: mHostname(aHostname)
{
MOZ_ASSERT(mObs);
}
NS_IMETHOD Run()
{
MOZ_ASSERT(NS_IsMainThread());
mObs->NotifyObservers(nullptr,
"dns-resolution-request",
NS_ConvertUTF8toUTF16(mHostname).get());
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (obs) {
obs->NotifyObservers(nullptr,
"dns-resolution-request",
NS_ConvertUTF8toUTF16(mHostname).get());
}
return NS_OK;
}
private:
nsMainThreadPtrHandle<nsIObserverService> mObs;
nsCString mHostname;
};
@ -606,8 +605,6 @@ nsDNSService::Init()
nsCOMPtr<nsIIDNService> idn = do_GetService(NS_IDNSERVICE_CONTRACTID);
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
nsRefPtr<nsHostResolver> res;
nsresult rv = nsHostResolver::Create(maxCacheEntries,
defaultCacheLifetime,
@ -635,10 +632,6 @@ nsDNSService::Init()
}
}
mNotifyResolution = notifyResolution;
if (mNotifyResolution) {
mObserverService =
new nsMainThreadPtrHolder<nsIObserverService>(obs);
}
}
#if !defined(MOZILLA_XPCOMRT_API)
@ -760,8 +753,7 @@ nsDNSService::AsyncResolveExtended(const nsACString &aHostname,
}
if (mNotifyResolution) {
NS_DispatchToMainThread(new NotifyDNSResolution(mObserverService,
aHostname));
NS_DispatchToMainThread(new NotifyDNSResolution(aHostname));
}
if (!res)
@ -874,8 +866,7 @@ nsDNSService::Resolve(const nsACString &aHostname,
}
if (mNotifyResolution) {
NS_DispatchToMainThread(new NotifyDNSResolution(mObserverService,
aHostname));
NS_DispatchToMainThread(new NotifyDNSResolution(aHostname));
}
NS_ENSURE_TRUE(res, NS_ERROR_OFFLINE);

View File

@ -16,8 +16,6 @@
#include "nsString.h"
#include "nsTHashtable.h"
#include "nsHashKeys.h"
#include "nsIObserverService.h"
#include "nsProxyRelease.h"
#include "mozilla/Mutex.h"
#include "mozilla/Attributes.h"
@ -61,7 +59,6 @@ private:
bool mOffline;
bool mNotifyResolution;
bool mOfflineLocalhost;
nsMainThreadPtrHandle<nsIObserverService> mObserverService;
nsTHashtable<nsCStringHashKey> mLocalDomains;
};