From 0c2044d54344af07ae3e4ddb237f3b367443e78d Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 15 Mar 2013 16:02:02 -0700 Subject: [PATCH] Bug 850251 - Remove Off-Main-Thread XPCWrappedJS refcounting from HTTP Activity Distributor. r=mcmanus --- .../http/nsHttpActivityDistributor.cpp | 19 ++++++++++++------- .../protocol/http/nsHttpActivityDistributor.h | 7 +++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/netwerk/protocol/http/nsHttpActivityDistributor.cpp b/netwerk/protocol/http/nsHttpActivityDistributor.cpp index 9fb8f3ec2b85..bf64b56419bd 100644 --- a/netwerk/protocol/http/nsHttpActivityDistributor.cpp +++ b/netwerk/protocol/http/nsHttpActivityDistributor.cpp @@ -10,6 +10,9 @@ #include "nsThreadUtils.h" using namespace mozilla; +typedef nsMainThreadPtrHolder ObserverHolder; +typedef nsMainThreadPtrHandle ObserverHandle; +typedef nsTArray ObserverArray; class nsHttpActivityEvent : public nsRunnable { @@ -20,7 +23,7 @@ public: PRTime aTimestamp, uint64_t aExtraSizeData, const nsACString & aExtraStringData, - nsCOMArray *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 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; diff --git a/netwerk/protocol/http/nsHttpActivityDistributor.h b/netwerk/protocol/http/nsHttpActivityDistributor.h index bb1ecae7abff..460da0c7c839 100644 --- a/netwerk/protocol/http/nsHttpActivityDistributor.h +++ b/netwerk/protocol/http/nsHttpActivityDistributor.h @@ -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 > ObserverArray; NS_DECL_ISUPPORTS NS_DECL_NSIHTTPACTIVITYOBSERVER NS_DECL_NSIHTTPACTIVITYDISTRIBUTOR @@ -20,7 +23,7 @@ public: virtual ~nsHttpActivityDistributor(); protected: - nsCOMArray mObservers; + ObserverArray mObservers; mozilla::Mutex mLock; };