Bug 850247 - Move nsRequestObserverProxy to nsMainThreadPtr{Holder,Handle}. r=mcmanus

This commit is contained in:
Bobby Holley 2013-03-19 09:04:57 -07:00
parent b9b61977e0
commit 3a47868d1d
2 changed files with 7 additions and 26 deletions

View File

@ -9,7 +9,6 @@
#include "nsRequestObserverProxy.h"
#include "nsIRequest.h"
#include "nsIServiceManager.h"
#include "nsProxyRelease.h"
#include "nsAutoPtr.h"
#include "nsString.h"
#include "prlog.h"
@ -93,7 +92,7 @@ public:
{
LOG(("nsOnStopRequestEvent::HandleEvent [req=%x]\n", mRequest.get()));
nsCOMPtr<nsIRequestObserver> observer = mProxy->mObserver;
nsMainThreadPtrHandle<nsIRequestObserver> observer = mProxy->mObserver;
if (!observer) {
NS_NOTREACHED("already handled onStopRequest event (observer is null)");
return NS_OK;
@ -112,23 +111,6 @@ public:
}
};
//-----------------------------------------------------------------------------
// nsRequestObserverProxy <public>
//-----------------------------------------------------------------------------
nsRequestObserverProxy::~nsRequestObserverProxy()
{
if (mObserver) {
// order is crucial here... we must be careful to clear mObserver
// before posting the proxy release event. otherwise, we'd risk
// releasing the object on this thread.
nsIRequestObserver *obs = nullptr;
mObserver.swap(obs);
nsCOMPtr<nsIEventTarget> mainThread(do_GetMainThread());
NS_ProxyRelease(mainThread, obs);
}
}
//-----------------------------------------------------------------------------
// nsRequestObserverProxy::nsISupports implementation...
//-----------------------------------------------------------------------------
@ -200,8 +182,8 @@ nsRequestObserverProxy::Init(nsIRequestObserver *observer, nsISupports *context)
gRequestObserverProxyLog = PR_NewLogModule("nsRequestObserverProxy");
#endif
mObserver = observer;
mContext = context;
mObserver = new nsMainThreadPtrHolder<nsIRequestObserver>(observer);
mContext = new nsMainThreadPtrHolder<nsISupports>(context);
return NS_OK;
}

View File

@ -11,10 +11,11 @@
#include "nsIRequest.h"
#include "nsThreadUtils.h"
#include "nsCOMPtr.h"
#include "nsProxyRelease.h"
class nsARequestObserverEvent;
class nsRequestObserverProxy : public nsIRequestObserverProxy
class nsRequestObserverProxy MOZ_FINAL : public nsIRequestObserverProxy
{
public:
NS_DECL_ISUPPORTS
@ -28,10 +29,8 @@ public:
nsresult FireEvent(nsARequestObserverEvent *);
protected:
virtual ~nsRequestObserverProxy();
nsCOMPtr<nsIRequestObserver> mObserver;
nsCOMPtr<nsISupports> mContext;
nsMainThreadPtrHandle<nsIRequestObserver> mObserver;
nsMainThreadPtrHandle<nsISupports> mContext;
friend class nsOnStartRequestEvent;
friend class nsOnStopRequestEvent;