Bug 850245 - Remove Off-Main-Thread XPCWrappedJS refcounting from DNSListenerProxy. r=mcmanus

This commit is contained in:
Bobby Holley 2013-03-18 20:39:53 -07:00
parent 67dff5d95a
commit 6b99053512

View File

@ -27,6 +27,7 @@
#include "nsIOService.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsNetAddr.h"
#include "nsProxyRelease.h"
#include "mozilla/Attributes.h"
@ -516,23 +517,21 @@ class DNSListenerProxy MOZ_FINAL : public nsIDNSListener
{
public:
DNSListenerProxy(nsIDNSListener* aListener, nsIEventTarget* aTargetThread)
: mListener(aListener)
// Sometimes aListener is a main-thread only object like XPCWrappedJS, and
// sometimes it's a threadsafe object like nsSOCKSSocketInfo. Use a main-
// thread pointer holder, but disable strict enforcement of thread invariants.
// The AddRef implementation of XPCWrappedJS will assert if we go wrong here.
: mListener(new nsMainThreadPtrHolder<nsIDNSListener>(aListener, false))
, mTargetThread(aTargetThread)
{ }
~DNSListenerProxy()
{
nsCOMPtr<nsIThread> mainThread(do_GetMainThread());
NS_ProxyRelease(mainThread, mListener);
}
NS_DECL_ISUPPORTS
NS_DECL_NSIDNSLISTENER
class OnLookupCompleteRunnable : public nsRunnable
{
public:
OnLookupCompleteRunnable(nsIDNSListener* aListener,
OnLookupCompleteRunnable(nsMainThreadPtrHolder<nsIDNSListener>* aListener,
nsICancelable* aRequest,
nsIDNSRecord* aRecord,
nsresult aStatus)
@ -542,23 +541,17 @@ public:
, mStatus(aStatus)
{ }
~OnLookupCompleteRunnable()
{
nsCOMPtr<nsIThread> mainThread(do_GetMainThread());
NS_ProxyRelease(mainThread, mListener);
}
NS_DECL_NSIRUNNABLE
private:
nsCOMPtr<nsIDNSListener> mListener;
nsMainThreadPtrHandle<nsIDNSListener> mListener;
nsCOMPtr<nsICancelable> mRequest;
nsCOMPtr<nsIDNSRecord> mRecord;
nsresult mStatus;
};
private:
nsCOMPtr<nsIDNSListener> mListener;
nsMainThreadPtrHandle<nsIDNSListener> mListener;
nsCOMPtr<nsIEventTarget> mTargetThread;
};