mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Some cleanup to nsProxyObject: implement refcounting without nsISupports inheritance, inline getters, and fix a few warnings. Bug 232022, r=dougt, sr=dbaron.
This commit is contained in:
parent
f6258a1404
commit
0518680d42
@ -39,6 +39,7 @@
|
||||
#define __nsProxyEvent_h_
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
@ -86,21 +87,16 @@ class nsProxyObjectCallInfo;
|
||||
|
||||
|
||||
|
||||
// Using the ISupports interface just for addrefing.
|
||||
|
||||
class nsProxyObject : public nsISupports
|
||||
class nsProxyObject
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISUPPORTS_IID)
|
||||
// wierd, but it shouldn't break. Need to discuss this with dougt
|
||||
|
||||
nsProxyObject();
|
||||
nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject);
|
||||
nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID);
|
||||
|
||||
virtual ~nsProxyObject();
|
||||
void AddRef();
|
||||
void Release();
|
||||
|
||||
~nsProxyObject();
|
||||
|
||||
nsresult Post( PRUint32 methodIndex,
|
||||
nsXPTMethodInfo * info,
|
||||
@ -108,13 +104,15 @@ public:
|
||||
nsIInterfaceInfo * interfaceInfo);
|
||||
|
||||
nsresult PostAndWait(nsProxyObjectCallInfo *proxyInfo);
|
||||
nsISupports* GetRealObject() const;
|
||||
nsIEventQueue* GetQueue() const;
|
||||
nsISupports* GetRealObject() const { return mRealObject; }
|
||||
nsIEventQueue* GetQueue() const { return mDestQueue; }
|
||||
PRInt32 GetProxyType() const { return mProxyType; }
|
||||
|
||||
friend class nsProxyEventObject;
|
||||
private:
|
||||
|
||||
nsAutoRefCnt mRefCnt;
|
||||
|
||||
PRInt32 mProxyType;
|
||||
|
||||
nsCOMPtr<nsIEventQueue> mDestQueue; /* destination queue */
|
||||
@ -142,8 +140,8 @@ public:
|
||||
PRUint32 parameterCount,
|
||||
PLEvent *event);
|
||||
|
||||
virtual ~nsProxyObjectCallInfo();
|
||||
|
||||
~nsProxyObjectCallInfo();
|
||||
|
||||
PRUint32 GetMethodIndex() const { return mMethodIndex; }
|
||||
nsXPTCVariant* GetParameterList() const { return mParameterList; }
|
||||
PRUint32 GetParameterCount() const { return mParameterCount; }
|
||||
@ -174,7 +172,7 @@ private:
|
||||
when we are done invoking the method (only PROXY_SYNC).
|
||||
*/
|
||||
|
||||
nsCOMPtr<nsProxyObject> mOwner; /* this is the strong referenced nsProxyObject */
|
||||
nsRefPtr<nsProxyObject> mOwner; /* this is the strong referenced nsProxyObject */
|
||||
|
||||
void RefCountInInterfacePointers(PRBool addRef);
|
||||
void CopyStrings(PRBool copy);
|
||||
|
@ -255,13 +255,6 @@ nsProxyObjectCallInfo::SetCallersQueue(nsIEventQueue* queue)
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsProxyObject)
|
||||
NS_IMPL_THREADSAFE_QUERY_INTERFACE0(nsProxyObject)
|
||||
|
||||
nsProxyObject::nsProxyObject()
|
||||
{
|
||||
// the mac compiler demands that I have this useless constructor.
|
||||
}
|
||||
nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject)
|
||||
{
|
||||
mEventQService = do_GetService(kEventQueueServiceCID);
|
||||
@ -295,8 +288,14 @@ nsProxyObject::~nsProxyObject()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsProxyObject::AddRef()
|
||||
{
|
||||
PR_AtomicIncrement((PRInt32 *)&mRefCnt);
|
||||
NS_LOG_ADDREF(this, mRefCnt, "nsProxyObject", sizeof(*this));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
void
|
||||
nsProxyObject::Release(void)
|
||||
{
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
||||
@ -308,53 +307,36 @@ nsProxyObject::Release(void)
|
||||
{
|
||||
mRefCnt = 1; /* stabilize */
|
||||
|
||||
PRBool callDirectly;
|
||||
mDestQueue->IsOnCurrentThread(&callDirectly);
|
||||
PRBool callDirectly;
|
||||
mDestQueue->IsOnCurrentThread(&callDirectly);
|
||||
|
||||
if (callDirectly)
|
||||
{
|
||||
NS_DELETEXPCOM(this);
|
||||
return 0;
|
||||
}
|
||||
if (callDirectly)
|
||||
{
|
||||
delete this;
|
||||
return;
|
||||
}
|
||||
|
||||
// need to do something special here so that
|
||||
// the real object will always be deleted on
|
||||
// the correct thread..
|
||||
|
||||
PLEvent *event = PR_NEW(PLEvent);
|
||||
if (event == nsnull)
|
||||
{
|
||||
NS_ASSERTION(0, "Could not create a plevent. Leaking nsProxyObject!");
|
||||
return 0; // if this happens we are going to leak.
|
||||
}
|
||||
PLEvent *event = PR_NEW(PLEvent);
|
||||
if (event == nsnull)
|
||||
{
|
||||
NS_ASSERTION(0, "Could not create a plevent. Leaking nsProxyObject!");
|
||||
return; // if this happens we are going to leak.
|
||||
}
|
||||
|
||||
PL_InitEvent(event,
|
||||
this,
|
||||
ProxyDestructorEventHandler,
|
||||
ProxyDestructorDestroyHandler);
|
||||
PL_InitEvent(event,
|
||||
this,
|
||||
ProxyDestructorEventHandler,
|
||||
ProxyDestructorDestroyHandler);
|
||||
|
||||
mDestQueue->PostEvent(event);
|
||||
return 0;
|
||||
mDestQueue->PostEvent(event);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
// GetRealObject
|
||||
// This function must return the real pointer to the object to be proxied.
|
||||
// It must not be a comptr or be addreffed.
|
||||
nsISupports*
|
||||
nsProxyObject::GetRealObject() const
|
||||
{
|
||||
return mRealObject.get();
|
||||
}
|
||||
|
||||
nsIEventQueue*
|
||||
nsProxyObject::GetQueue() const
|
||||
{
|
||||
return mDestQueue;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsProxyObject::PostAndWait(nsProxyObjectCallInfo *proxyInfo)
|
||||
{
|
||||
@ -583,8 +565,8 @@ static void* CompletedEventHandler(PLEvent *self)
|
||||
|
||||
static void* ProxyDestructorEventHandler(PLEvent *self)
|
||||
{
|
||||
nsProxyObject* owner = (nsProxyObject*) PL_GetEventOwner(self);
|
||||
NS_DELETEXPCOM(owner);
|
||||
nsProxyObject* owner = (nsProxyObject*) PL_GetEventOwner(self);
|
||||
NS_DELETEXPCOM(owner);
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
@ -448,7 +448,10 @@ nsProxyEventObject::~nsProxyEventObject()
|
||||
nsCOMPtr<nsISupports> rootObject = do_QueryInterface(mProxyObject->mRealObject);
|
||||
nsCOMPtr<nsISupports> rootQueue = do_QueryInterface(mProxyObject->mDestQueue);
|
||||
nsProxyEventKey key(rootObject, rootQueue, mProxyObject->mProxyType);
|
||||
void* value = realToProxyMap->Remove(&key);
|
||||
#ifdef DEBUG_dougt
|
||||
void* value =
|
||||
#endif
|
||||
realToProxyMap->Remove(&key);
|
||||
#ifdef DEBUG_dougt
|
||||
NS_ASSERTION(value, "failed to remove from realToProxyMap");
|
||||
#endif
|
||||
|
@ -150,7 +150,7 @@ protected:
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsProxyEventClass> mClass;
|
||||
nsCOMPtr<nsProxyObject> mProxyObject;
|
||||
nsRefPtr<nsProxyObject> mProxyObject;
|
||||
|
||||
// Owning reference...
|
||||
nsProxyEventObject *mRoot;
|
||||
|
@ -108,8 +108,8 @@ nsProxyObjectManager* nsProxyObjectManager::mInstance = nsnull;
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsProxyObjectManager, nsIProxyObjectManager)
|
||||
|
||||
nsProxyObjectManager::nsProxyObjectManager()
|
||||
: mProxyClassMap(256, PR_TRUE),
|
||||
mProxyObjectMap(256, PR_TRUE)
|
||||
: mProxyObjectMap(256, PR_TRUE),
|
||||
mProxyClassMap(256, PR_TRUE)
|
||||
{
|
||||
mProxyCreationMonitor = PR_NewMonitor();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user