mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 850251 - Remove Off-Main-Thread XPCWrappedJS refcounting from HTTP Activity Distributor. r=mcmanus
This commit is contained in:
parent
96d535920c
commit
0c2044d543
@ -10,6 +10,9 @@
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
typedef nsMainThreadPtrHolder<nsIHttpActivityObserver> ObserverHolder;
|
||||
typedef nsMainThreadPtrHandle<nsIHttpActivityObserver> ObserverHandle;
|
||||
typedef nsTArray<ObserverHandle> ObserverArray;
|
||||
|
||||
class nsHttpActivityEvent : public nsRunnable
|
||||
{
|
||||
@ -20,7 +23,7 @@ public:
|
||||
PRTime aTimestamp,
|
||||
uint64_t aExtraSizeData,
|
||||
const nsACString & aExtraStringData,
|
||||
nsCOMArray<nsIHttpActivityObserver> *aObservers)
|
||||
ObserverArray *aObservers)
|
||||
: mHttpChannel(aHttpChannel)
|
||||
, mActivityType(aActivityType)
|
||||
, mActivitySubtype(aActivitySubtype)
|
||||
@ -33,7 +36,7 @@ public:
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
for (int32_t i = 0 ; i < mObservers.Count() ; i++)
|
||||
for (size_t i = 0 ; i < mObservers.Length() ; i++)
|
||||
mObservers[i]->ObserveActivity(mHttpChannel, mActivityType,
|
||||
mActivitySubtype, mTimestamp,
|
||||
mExtraSizeData, mExtraStringData);
|
||||
@ -52,7 +55,7 @@ private:
|
||||
uint64_t mExtraSizeData;
|
||||
nsCString mExtraStringData;
|
||||
|
||||
nsCOMArray<nsIHttpActivityObserver> mObservers;
|
||||
ObserverArray mObservers;
|
||||
};
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS2(nsHttpActivityDistributor,
|
||||
@ -80,7 +83,7 @@ nsHttpActivityDistributor::ObserveActivity(nsISupports *aHttpChannel,
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
if (!mObservers.Count())
|
||||
if (!mObservers.Length())
|
||||
return NS_OK;
|
||||
|
||||
event = new nsHttpActivityEvent(aHttpChannel, aActivityType,
|
||||
@ -97,7 +100,7 @@ nsHttpActivityDistributor::GetIsActive(bool *isActive)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(isActive);
|
||||
MutexAutoLock lock(mLock);
|
||||
*isActive = !!mObservers.Count();
|
||||
*isActive = !!mObservers.Length();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -106,7 +109,8 @@ nsHttpActivityDistributor::AddObserver(nsIHttpActivityObserver *aObserver)
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
if (!mObservers.AppendObject(aObserver))
|
||||
ObserverHandle observer(new ObserverHolder(aObserver));
|
||||
if (!mObservers.AppendElement(observer))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
@ -117,7 +121,8 @@ nsHttpActivityDistributor::RemoveObserver(nsIHttpActivityObserver *aObserver)
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
if (!mObservers.RemoveObject(aObserver))
|
||||
ObserverHandle observer(new ObserverHolder(aObserver));
|
||||
if (!mObservers.RemoveElement(observer))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
|
@ -6,12 +6,15 @@
|
||||
#define nsHttpActivityDistributor_h__
|
||||
|
||||
#include "nsIHttpActivityObserver.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsProxyRelease.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
|
||||
|
||||
class nsHttpActivityDistributor : public nsIHttpActivityDistributor
|
||||
{
|
||||
public:
|
||||
typedef nsTArray<nsMainThreadPtrHandle<nsIHttpActivityObserver> > ObserverArray;
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIHTTPACTIVITYOBSERVER
|
||||
NS_DECL_NSIHTTPACTIVITYDISTRIBUTOR
|
||||
@ -20,7 +23,7 @@ public:
|
||||
virtual ~nsHttpActivityDistributor();
|
||||
|
||||
protected:
|
||||
nsCOMArray<nsIHttpActivityObserver> mObservers;
|
||||
ObserverArray mObservers;
|
||||
mozilla::Mutex mLock;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user