386376 get services lazily in order to avoid recursive getService calls

r=bsmedberg
This commit is contained in:
cbiesinger@gmx.at 2007-07-24 16:47:33 -07:00
Родитель 4c4b9931ca
Коммит 1a21866674
2 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -102,7 +102,7 @@ public:
PRUint32 flags);
// Gets the array of registered content sniffers
const nsCOMArray<nsIContentSniffer>& GetContentSniffers() const {
const nsCOMArray<nsIContentSniffer>& GetContentSniffers() {
return mContentSniffers.GetEntries();
}

Просмотреть файл

@ -91,7 +91,13 @@ class nsCategoryCache : protected nsCategoryListener {
explicit nsCategoryCache(const char* aCategory);
~nsCategoryCache() { if (mObserver) mObserver->ListenerDied(); }
const nsCOMArray<T>& GetEntries() const { return mEntries; }
const nsCOMArray<T>& GetEntries() {
// Lazy initialization, so that services in this category can't
// cause reentrant getService (bug 386376)
if (!mObserver)
mObserver = new nsCategoryObserver(mCategoryName.get(), this);
return mEntries;
}
protected:
virtual void EntryAdded(const nsCString& aValue);
virtual void EntryRemoved(const nsCString& aValue);
@ -102,6 +108,7 @@ class nsCategoryCache : protected nsCategoryListener {
// Not to be implemented
nsCategoryCache(const nsCategoryCache<T>&);
nsCString mCategoryName;
nsCOMArray<T> mEntries;
nsRefPtr<nsCategoryObserver> mObserver;
};
@ -111,8 +118,8 @@ class nsCategoryCache : protected nsCategoryListener {
template<class T>
nsCategoryCache<T>::nsCategoryCache(const char* aCategory)
: mCategoryName(aCategory)
{
mObserver = new nsCategoryObserver(aCategory, this);
}
template<class T>