2000-02-05 06:19:49 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-03-14 05:07:24 +00:00
|
|
|
#define PL_ARENA_CONST_ALIGN_MASK 7
|
|
|
|
|
2000-02-05 06:19:49 +00:00
|
|
|
#include "nsICategoryManager.h"
|
2002-07-18 05:09:10 +00:00
|
|
|
#include "nsCategoryManager.h"
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
#include "plarena.h"
|
|
|
|
#include "prio.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "prlock.h"
|
2000-02-05 06:19:49 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2003-06-18 11:26:27 +00:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsClassHashtable.h"
|
2000-02-06 02:01:39 +00:00
|
|
|
#include "nsIFactory.h"
|
2003-06-18 11:26:27 +00:00
|
|
|
#include "nsIStringEnumerator.h"
|
2012-10-19 12:07:36 +00:00
|
|
|
#include "nsIMemoryReporter.h"
|
2002-06-14 21:33:05 +00:00
|
|
|
#include "nsSupportsPrimitives.h"
|
2010-06-10 18:11:11 +00:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2004-11-24 22:48:45 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2001-10-16 03:35:52 +00:00
|
|
|
#include "nsIObserver.h"
|
2005-06-17 21:07:47 +00:00
|
|
|
#include "nsIObserverService.h"
|
2001-10-24 09:06:49 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2003-03-14 05:07:24 +00:00
|
|
|
#include "nsCRT.h"
|
2005-06-13 18:39:19 +00:00
|
|
|
#include "nsQuickSort.h"
|
2000-02-05 06:19:49 +00:00
|
|
|
#include "nsEnumeratorUtils.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 16:59:13 +00:00
|
|
|
#include "mozilla/Services.h"
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2010-07-20 13:28:45 +00:00
|
|
|
#include "ManifestParser.h"
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2009-07-23 14:29:00 +00:00
|
|
|
using namespace mozilla;
|
2003-06-18 11:26:27 +00:00
|
|
|
class nsIComponentLoaderManager;
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
/*
|
|
|
|
CategoryDatabase
|
|
|
|
contains 0 or more 1-1 mappings of string to Category
|
|
|
|
each Category contains 0 or more 1-1 mappings of string keys to string values
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
In other words, the CategoryDatabase is a tree, whose root is a hashtable.
|
|
|
|
Internal nodes (or Categories) are hashtables. Leaf nodes are strings.
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
The leaf strings are allocated in an arena, because we assume they're not
|
|
|
|
going to change much ;)
|
|
|
|
*/
|
2002-10-30 00:57:40 +00:00
|
|
|
|
2003-03-14 05:07:24 +00:00
|
|
|
#define NS_CATEGORYMANAGER_ARENA_SIZE (1024 * 8)
|
|
|
|
|
|
|
|
// pulled in from nsComponentManager.cpp
|
|
|
|
char* ArenaStrdup(const char* s, PLArenaPool* aArena);
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
//
|
|
|
|
// BaseStringEnumerator is subclassed by EntryEnumerator and
|
|
|
|
// CategoryEnumerator
|
|
|
|
//
|
|
|
|
class BaseStringEnumerator
|
|
|
|
: public nsISimpleEnumerator,
|
2008-08-18 18:39:19 +00:00
|
|
|
private nsIUTF8StringEnumerator
|
2003-06-18 11:26:27 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISIMPLEENUMERATOR
|
|
|
|
NS_DECL_NSIUTF8STRINGENUMERATOR
|
|
|
|
|
|
|
|
protected:
|
2005-06-13 18:39:19 +00:00
|
|
|
// Callback function for NS_QuickSort to sort mArray
|
|
|
|
static int SortCallback(const void *, const void *, void *);
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
BaseStringEnumerator()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mArray(nullptr),
|
2003-06-18 11:26:27 +00:00
|
|
|
mCount(0),
|
|
|
|
mSimpleCurItem(0),
|
|
|
|
mStringCurItem(0) { }
|
2004-01-22 01:01:19 +00:00
|
|
|
|
|
|
|
// A virtual destructor is needed here because subclasses of
|
|
|
|
// BaseStringEnumerator do not implement their own Release() method.
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
virtual ~BaseStringEnumerator()
|
|
|
|
{
|
|
|
|
if (mArray)
|
2003-06-18 18:55:35 +00:00
|
|
|
delete[] mArray;
|
2003-06-18 11:26:27 +00:00
|
|
|
}
|
|
|
|
|
2005-06-13 18:39:19 +00:00
|
|
|
void Sort();
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
const char** mArray;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mCount;
|
|
|
|
uint32_t mSimpleCurItem;
|
|
|
|
uint32_t mStringCurItem;
|
2003-06-18 11:26:27 +00:00
|
|
|
};
|
|
|
|
|
2003-09-08 00:31:50 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(BaseStringEnumerator, nsISimpleEnumerator, nsIUTF8StringEnumerator)
|
2003-06-18 11:26:27 +00:00
|
|
|
|
2000-02-05 06:19:49 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
BaseStringEnumerator::HasMoreElements(bool *_retval)
|
2003-06-18 11:26:27 +00:00
|
|
|
{
|
|
|
|
*_retval = (mSimpleCurItem < mCount);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BaseStringEnumerator::GetNext(nsISupports **_retval)
|
|
|
|
{
|
|
|
|
if (mSimpleCurItem >= mCount)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsSupportsDependentCString* str =
|
|
|
|
new nsSupportsDependentCString(mArray[mSimpleCurItem++]);
|
|
|
|
if (!str)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*_retval = str;
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
BaseStringEnumerator::HasMore(bool *_retval)
|
2003-06-18 11:26:27 +00:00
|
|
|
{
|
|
|
|
*_retval = (mStringCurItem < mCount);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BaseStringEnumerator::GetNext(nsACString& _retval)
|
|
|
|
{
|
|
|
|
if (mStringCurItem >= mCount)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
_retval = nsDependentCString(mArray[mStringCurItem++]);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-13 18:39:19 +00:00
|
|
|
int
|
|
|
|
BaseStringEnumerator::SortCallback(const void *e1, const void *e2,
|
|
|
|
void * /*unused*/)
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
char const *const *s1 = reinterpret_cast<char const *const *>(e1);
|
|
|
|
char const *const *s2 = reinterpret_cast<char const *const *>(e2);
|
2005-06-13 18:39:19 +00:00
|
|
|
|
|
|
|
return strcmp(*s1, *s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BaseStringEnumerator::Sort()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_QuickSort(mArray, mCount, sizeof(mArray[0]), SortCallback, nullptr);
|
2005-06-13 18:39:19 +00:00
|
|
|
}
|
2003-06-18 11:26:27 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// EntryEnumerator is the wrapper that allows nsICategoryManager::EnumerateCategory
|
|
|
|
//
|
|
|
|
class EntryEnumerator
|
|
|
|
: public BaseStringEnumerator
|
2000-08-10 06:19:37 +00:00
|
|
|
{
|
2003-06-18 11:26:27 +00:00
|
|
|
public:
|
|
|
|
static EntryEnumerator* Create(nsTHashtable<CategoryLeaf>& aTable);
|
|
|
|
|
|
|
|
private:
|
2008-10-10 15:04:34 +00:00
|
|
|
static PLDHashOperator
|
2003-06-18 11:26:27 +00:00
|
|
|
enumfunc_createenumerator(CategoryLeaf* aLeaf, void* userArg);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
PLDHashOperator
|
2003-06-18 11:26:27 +00:00
|
|
|
EntryEnumerator::enumfunc_createenumerator(CategoryLeaf* aLeaf, void* userArg)
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
EntryEnumerator* mythis = static_cast<EntryEnumerator*>(userArg);
|
2010-06-10 18:11:11 +00:00
|
|
|
if (aLeaf->value)
|
2006-03-07 20:48:44 +00:00
|
|
|
mythis->mArray[mythis->mCount++] = aLeaf->GetKey();
|
2003-06-18 11:26:27 +00:00
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2002-06-14 21:33:05 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
EntryEnumerator*
|
|
|
|
EntryEnumerator::Create(nsTHashtable<CategoryLeaf>& aTable)
|
|
|
|
{
|
|
|
|
EntryEnumerator* enumObj = new EntryEnumerator();
|
|
|
|
if (!enumObj)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2003-06-18 11:26:27 +00:00
|
|
|
|
|
|
|
enumObj->mArray = new char const* [aTable.Count()];
|
|
|
|
if (!enumObj->mArray) {
|
|
|
|
delete enumObj;
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2000-02-05 06:19:49 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
aTable.EnumerateEntries(enumfunc_createenumerator, enumObj);
|
|
|
|
|
2005-06-13 18:39:19 +00:00
|
|
|
enumObj->Sort();
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
return enumObj;
|
2000-08-10 06:19:37 +00:00
|
|
|
}
|
|
|
|
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
//
|
|
|
|
// CategoryNode implementations
|
|
|
|
//
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
CategoryNode*
|
|
|
|
CategoryNode::Create(PLArenaPool* aArena)
|
|
|
|
{
|
|
|
|
CategoryNode* node = new(aArena) CategoryNode();
|
|
|
|
if (!node)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
CategoryNode::~CategoryNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
CategoryNode::operator new(size_t aSize, PLArenaPool* aArena)
|
|
|
|
{
|
|
|
|
void* p;
|
|
|
|
PL_ARENA_ALLOCATE(p, aArena, aSize);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CategoryNode::GetLeaf(const char* aEntryName,
|
|
|
|
char** _retval)
|
|
|
|
{
|
2009-07-23 14:29:00 +00:00
|
|
|
MutexAutoLock lock(mLock);
|
2003-06-18 11:26:27 +00:00
|
|
|
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
CategoryLeaf* ent =
|
|
|
|
mTable.GetEntry(aEntryName);
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (ent && ent->value) {
|
|
|
|
*_retval = NS_strdup(ent->value);
|
2003-06-18 11:26:27 +00:00
|
|
|
if (*_retval)
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CategoryNode::AddLeaf(const char* aEntryName,
|
|
|
|
const char* aValue,
|
2010-06-28 01:14:54 +00:00
|
|
|
bool aReplace,
|
2003-06-18 11:26:27 +00:00
|
|
|
char** _retval,
|
|
|
|
PLArenaPool* aArena)
|
|
|
|
{
|
2010-06-28 01:14:54 +00:00
|
|
|
if (_retval)
|
|
|
|
*_retval = NULL;
|
|
|
|
|
2009-07-23 14:29:00 +00:00
|
|
|
MutexAutoLock lock(mLock);
|
2003-06-18 11:26:27 +00:00
|
|
|
CategoryLeaf* leaf =
|
|
|
|
mTable.GetEntry(aEntryName);
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!leaf) {
|
2003-06-18 11:26:27 +00:00
|
|
|
const char* arenaEntryName = ArenaStrdup(aEntryName, aArena);
|
2010-06-28 01:14:54 +00:00
|
|
|
if (!arenaEntryName)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
leaf = mTable.PutEntry(arenaEntryName);
|
|
|
|
if (!leaf)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-02-05 06:19:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-28 01:14:54 +00:00
|
|
|
if (leaf->value && !aReplace)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
const char* arenaValue = ArenaStrdup(aValue, aArena);
|
|
|
|
if (!arenaValue)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (_retval && leaf->value) {
|
|
|
|
*_retval = ToNewCString(nsDependentCString(leaf->value));
|
|
|
|
if (!*_retval)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-06-18 11:26:27 +00:00
|
|
|
}
|
2010-06-28 01:14:54 +00:00
|
|
|
|
|
|
|
leaf->value = arenaValue;
|
|
|
|
return NS_OK;
|
2003-06-18 11:26:27 +00:00
|
|
|
}
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2010-06-24 18:31:18 +00:00
|
|
|
void
|
|
|
|
CategoryNode::DeleteLeaf(const char* aEntryName)
|
|
|
|
{
|
|
|
|
// we don't throw any errors, because it normally doesn't matter
|
|
|
|
// and it makes JS a lot cleaner
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
|
|
|
|
// we can just remove the entire hash entry without introspection
|
|
|
|
mTable.RemoveEntry(aEntryName);
|
|
|
|
}
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
NS_METHOD
|
|
|
|
CategoryNode::Enumerate(nsISimpleEnumerator **_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2009-07-23 14:29:00 +00:00
|
|
|
MutexAutoLock lock(mLock);
|
2003-06-18 11:26:27 +00:00
|
|
|
EntryEnumerator* enumObj = EntryEnumerator::Create(mTable);
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
if (!enumObj)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
*_retval = enumObj;
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-06 08:26:13 +00:00
|
|
|
|
2012-10-19 12:07:36 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
CategoryNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf)
|
2012-10-19 12:07:36 +00:00
|
|
|
{
|
|
|
|
// We don't measure the strings pointed to by the entries because the
|
|
|
|
// pointers are non-owning.
|
|
|
|
return mTable.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
struct persistent_userstruct {
|
|
|
|
PRFileDesc* fd;
|
|
|
|
const char* categoryName;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool success;
|
2003-06-18 11:26:27 +00:00
|
|
|
};
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
PLDHashOperator
|
2003-06-18 11:26:27 +00:00
|
|
|
enumfunc_pentries(CategoryLeaf* aLeaf, void* userArg)
|
|
|
|
{
|
|
|
|
persistent_userstruct* args =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<persistent_userstruct*>(userArg);
|
2003-06-18 11:26:27 +00:00
|
|
|
|
|
|
|
PLDHashOperator status = PL_DHASH_NEXT;
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (aLeaf->value) {
|
2003-06-18 11:26:27 +00:00
|
|
|
if (PR_fprintf(args->fd,
|
|
|
|
"%s,%s,%s\n",
|
|
|
|
args->categoryName,
|
|
|
|
aLeaf->GetKey(),
|
2012-08-22 15:56:38 +00:00
|
|
|
aLeaf->value) == (uint32_t) -1) {
|
2011-10-17 14:59:28 +00:00
|
|
|
args->success = false;
|
2003-06-18 11:26:27 +00:00
|
|
|
status = PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
}
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
return status;
|
|
|
|
}
|
2003-03-14 05:07:24 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
//
|
|
|
|
// CategoryEnumerator class
|
|
|
|
//
|
|
|
|
|
|
|
|
class CategoryEnumerator
|
|
|
|
: public BaseStringEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static CategoryEnumerator* Create(nsClassHashtable<nsDepCharHashKey, CategoryNode>& aTable);
|
|
|
|
|
|
|
|
private:
|
2008-10-10 15:04:34 +00:00
|
|
|
static PLDHashOperator
|
2003-06-18 11:26:27 +00:00
|
|
|
enumfunc_createenumerator(const char* aStr,
|
|
|
|
CategoryNode* aNode,
|
|
|
|
void* userArg);
|
|
|
|
};
|
|
|
|
|
|
|
|
CategoryEnumerator*
|
|
|
|
CategoryEnumerator::Create(nsClassHashtable<nsDepCharHashKey, CategoryNode>& aTable)
|
|
|
|
{
|
|
|
|
CategoryEnumerator* enumObj = new CategoryEnumerator();
|
|
|
|
if (!enumObj)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2003-06-18 11:26:27 +00:00
|
|
|
|
|
|
|
enumObj->mArray = new const char* [aTable.Count()];
|
|
|
|
if (!enumObj->mArray) {
|
|
|
|
delete enumObj;
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2000-02-05 06:19:49 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
aTable.EnumerateRead(enumfunc_createenumerator, enumObj);
|
|
|
|
|
|
|
|
return enumObj;
|
|
|
|
}
|
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
PLDHashOperator
|
2003-06-18 11:26:27 +00:00
|
|
|
CategoryEnumerator::enumfunc_createenumerator(const char* aStr, CategoryNode* aNode, void* userArg)
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
CategoryEnumerator* mythis = static_cast<CategoryEnumerator*>(userArg);
|
2003-06-18 11:26:27 +00:00
|
|
|
|
|
|
|
// if a category has no entries, we pretend it doesn't exist
|
|
|
|
if (aNode->Count())
|
|
|
|
mythis->mArray[mythis->mCount++] = aStr;
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsCategoryManager implementations
|
|
|
|
//
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_IMPL_QUERY_INTERFACE1(nsCategoryManager, nsICategoryManager)
|
2003-06-18 11:26:27 +00:00
|
|
|
|
2013-09-05 05:42:06 +00:00
|
|
|
class XPCOMCategoryManagerReporter MOZ_FINAL : public MemoryReporterBase
|
2013-01-18 05:43:21 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
XPCOMCategoryManagerReporter()
|
2013-09-05 05:42:06 +00:00
|
|
|
: MemoryReporterBase("explicit/xpcom/category-manager",
|
2013-01-18 05:43:21 +00:00
|
|
|
KIND_HEAP, UNITS_BYTES,
|
|
|
|
"Memory used for the XPCOM category manager.")
|
|
|
|
{}
|
|
|
|
private:
|
|
|
|
int64_t Amount() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return nsCategoryManager::SizeOfIncludingThis(MallocSizeOf);
|
|
|
|
}
|
|
|
|
};
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsCategoryManager::AddRef()
|
2003-06-18 11:26:27 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsCategoryManager::Release()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2003-06-18 11:26:27 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCategoryManager* nsCategoryManager::gCategoryManager;
|
2003-06-18 11:26:27 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
/* static */ nsCategoryManager*
|
|
|
|
nsCategoryManager::GetSingleton()
|
|
|
|
{
|
|
|
|
if (!gCategoryManager)
|
|
|
|
gCategoryManager = new nsCategoryManager();
|
|
|
|
return gCategoryManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsCategoryManager::Destroy()
|
|
|
|
{
|
|
|
|
delete gCategoryManager;
|
2012-10-19 12:07:36 +00:00
|
|
|
gCategoryManager = nullptr;
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult
|
|
|
|
nsCategoryManager::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
|
|
|
{
|
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
return GetSingleton()->QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCategoryManager::nsCategoryManager()
|
|
|
|
: mLock("nsCategoryManager")
|
2011-10-17 14:59:28 +00:00
|
|
|
, mSuppressNotifications(false)
|
2012-10-19 12:07:36 +00:00
|
|
|
, mReporter(nullptr)
|
2010-06-10 18:11:11 +00:00
|
|
|
{
|
|
|
|
PL_INIT_ARENA_POOL(&mArena, "CategoryManagerArena",
|
|
|
|
NS_CATEGORYMANAGER_ARENA_SIZE);
|
2003-06-18 11:26:27 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 12:07:36 +00:00
|
|
|
void
|
|
|
|
nsCategoryManager::InitMemoryReporter()
|
|
|
|
{
|
2013-01-18 05:43:21 +00:00
|
|
|
mReporter = new XPCOMCategoryManagerReporter();
|
2012-10-19 12:07:36 +00:00
|
|
|
NS_RegisterMemoryReporter(mReporter);
|
|
|
|
}
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
nsCategoryManager::~nsCategoryManager()
|
|
|
|
{
|
2013-01-18 05:43:21 +00:00
|
|
|
NS_UnregisterMemoryReporter(mReporter);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
// the hashtable contains entries that must be deleted before the arena is
|
|
|
|
// destroyed, or else you will have PRLocks undestroyed and other Really
|
|
|
|
// Bad Stuff (TM)
|
|
|
|
mTable.Clear();
|
|
|
|
|
|
|
|
PL_FinishArenaPool(&mArena);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline CategoryNode*
|
|
|
|
nsCategoryManager::get_category(const char* aName) {
|
|
|
|
CategoryNode* node;
|
|
|
|
if (!mTable.Get(aName, &node)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2000-02-05 06:19:49 +00:00
|
|
|
}
|
2003-06-18 11:26:27 +00:00
|
|
|
return node;
|
|
|
|
}
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2012-10-19 12:07:36 +00:00
|
|
|
/* static */ int64_t
|
2013-01-18 05:43:21 +00:00
|
|
|
nsCategoryManager::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
|
2012-10-19 12:07:36 +00:00
|
|
|
{
|
2013-01-18 05:43:21 +00:00
|
|
|
return nsCategoryManager::gCategoryManager
|
|
|
|
? nsCategoryManager::gCategoryManager->SizeOfIncludingThisHelper(
|
|
|
|
aMallocSizeOf)
|
|
|
|
: 0;
|
2012-10-19 12:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
SizeOfCategoryManagerTableEntryExcludingThis(nsDepCharHashKey::KeyType aKey,
|
|
|
|
const nsAutoPtr<CategoryNode> &aData,
|
2013-06-23 12:03:39 +00:00
|
|
|
MallocSizeOf aMallocSizeOf,
|
2012-10-19 12:07:36 +00:00
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
// We don't measure the string pointed to by aKey because it's a non-owning
|
|
|
|
// pointer.
|
|
|
|
return aData.get()->SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2013-01-18 05:43:21 +00:00
|
|
|
nsCategoryManager::SizeOfIncludingThisHelper(MallocSizeOf aMallocSizeOf)
|
2012-10-19 12:07:36 +00:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
|
2013-02-12 16:54:38 +00:00
|
|
|
n += PL_SizeOfArenaPoolExcludingPool(&mArena, aMallocSizeOf);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
|
|
|
n += mTable.SizeOfExcludingThis(SizeOfCategoryManagerTableEntryExcludingThis,
|
|
|
|
aMallocSizeOf);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2012-01-11 16:28:21 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class CategoryNotificationRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CategoryNotificationRunnable(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const char* aData)
|
|
|
|
: mSubject(aSubject)
|
|
|
|
, mTopic(aTopic)
|
|
|
|
, mData(aData)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISupports> mSubject;
|
|
|
|
const char* mTopic;
|
|
|
|
NS_ConvertUTF8toUTF16 mData;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CategoryNotificationRunnable::Run()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (observerService)
|
|
|
|
observerService->NotifyObservers(mSubject, mTopic, mData.get());
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
2005-06-17 21:07:47 +00:00
|
|
|
void
|
|
|
|
nsCategoryManager::NotifyObservers( const char *aTopic,
|
|
|
|
const char *aCategoryName,
|
|
|
|
const char *aEntryName )
|
|
|
|
{
|
|
|
|
if (mSuppressNotifications)
|
|
|
|
return;
|
|
|
|
|
2012-01-11 16:28:21 +00:00
|
|
|
nsRefPtr<CategoryNotificationRunnable> r;
|
2005-09-19 17:13:32 +00:00
|
|
|
|
2005-06-17 21:07:47 +00:00
|
|
|
if (aEntryName) {
|
|
|
|
nsCOMPtr<nsISupportsCString> entry
|
|
|
|
(do_CreateInstance (NS_SUPPORTS_CSTRING_CONTRACTID));
|
|
|
|
if (!entry)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsresult rv = entry->SetData(nsDependentCString(aEntryName));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
2012-01-11 16:28:21 +00:00
|
|
|
r = new CategoryNotificationRunnable(entry, aTopic, aCategoryName);
|
2005-06-17 21:07:47 +00:00
|
|
|
} else {
|
2012-01-11 16:28:21 +00:00
|
|
|
r = new CategoryNotificationRunnable(this, aTopic, aCategoryName);
|
|
|
|
}
|
|
|
|
|
2012-02-09 15:41:16 +00:00
|
|
|
NS_DispatchToMainThread(r);
|
2005-06-17 21:07:47 +00:00
|
|
|
}
|
|
|
|
|
2000-02-05 06:19:49 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCategoryManager::GetCategoryEntry( const char *aCategoryName,
|
|
|
|
const char *aEntryName,
|
|
|
|
char **_retval )
|
2003-06-18 11:26:27 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCategoryName);
|
|
|
|
NS_ENSURE_ARG_POINTER(aEntryName);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
nsresult status = NS_ERROR_NOT_AVAILABLE;
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2009-07-23 14:29:00 +00:00
|
|
|
CategoryNode* category;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
category = get_category(aCategoryName);
|
|
|
|
}
|
2003-06-18 11:26:27 +00:00
|
|
|
|
|
|
|
if (category) {
|
|
|
|
status = category->GetLeaf(aEntryName, _retval);
|
2000-02-05 06:19:49 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2010-06-24 18:31:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCategoryManager::AddCategoryEntry( const char *aCategoryName,
|
|
|
|
const char *aEntryName,
|
|
|
|
const char *aValue,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aPersist,
|
|
|
|
bool aReplace,
|
2010-06-24 18:31:18 +00:00
|
|
|
char **_retval )
|
|
|
|
{
|
|
|
|
if (aPersist) {
|
|
|
|
NS_ERROR("Category manager doesn't support persistence.");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddCategoryEntry(aCategoryName, aEntryName, aValue, aReplace, _retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
void
|
|
|
|
nsCategoryManager::AddCategoryEntry(const char *aCategoryName,
|
|
|
|
const char *aEntryName,
|
2010-06-24 18:31:18 +00:00
|
|
|
const char *aValue,
|
|
|
|
bool aReplace,
|
|
|
|
char** aOldValue)
|
2003-06-18 11:26:27 +00:00
|
|
|
{
|
2010-06-24 18:31:18 +00:00
|
|
|
if (aOldValue)
|
|
|
|
*aOldValue = NULL;
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
// Before we can insert a new entry, we'll need to
|
|
|
|
// find the |CategoryNode| to put it in...
|
2009-07-23 14:29:00 +00:00
|
|
|
CategoryNode* category;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
category = get_category(aCategoryName);
|
2003-06-18 11:26:27 +00:00
|
|
|
|
2009-07-23 14:29:00 +00:00
|
|
|
if (!category) {
|
|
|
|
// That category doesn't exist yet; let's make it.
|
|
|
|
category = CategoryNode::Create(&mArena);
|
2003-03-14 05:07:24 +00:00
|
|
|
|
2009-07-23 14:29:00 +00:00
|
|
|
char* categoryName = ArenaStrdup(aCategoryName, &mArena);
|
|
|
|
mTable.Put(categoryName, category);
|
|
|
|
}
|
2000-02-05 06:19:49 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
if (!category)
|
2010-06-10 18:11:11 +00:00
|
|
|
return;
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2007-06-11 06:10:27 +00:00
|
|
|
// We will need the return value of AddLeaf even if the called doesn't want it
|
2012-07-30 14:20:58 +00:00
|
|
|
char *oldEntry = nullptr;
|
2007-06-11 06:10:27 +00:00
|
|
|
|
2005-06-17 21:07:47 +00:00
|
|
|
nsresult rv = category->AddLeaf(aEntryName,
|
|
|
|
aValue,
|
2010-06-28 01:14:54 +00:00
|
|
|
aReplace,
|
2007-06-11 06:10:27 +00:00
|
|
|
&oldEntry,
|
2005-06-17 21:07:47 +00:00
|
|
|
&mArena);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-06-11 06:10:27 +00:00
|
|
|
if (oldEntry) {
|
|
|
|
NotifyObservers(NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID,
|
|
|
|
aCategoryName, oldEntry);
|
|
|
|
}
|
2005-06-17 21:07:47 +00:00
|
|
|
NotifyObservers(NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID,
|
|
|
|
aCategoryName, aEntryName);
|
2007-06-11 06:10:27 +00:00
|
|
|
|
2010-06-24 18:31:18 +00:00
|
|
|
if (aOldValue)
|
|
|
|
*aOldValue = oldEntry;
|
|
|
|
else
|
|
|
|
NS_Free(oldEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCategoryManager::DeleteCategoryEntry( const char *aCategoryName,
|
|
|
|
const char *aEntryName,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aDontPersist)
|
2010-06-24 18:31:18 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCategoryName);
|
|
|
|
NS_ENSURE_ARG_POINTER(aEntryName);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Note: no errors are reported since failure to delete
|
|
|
|
probably won't hurt you, and returning errors seriously
|
|
|
|
inconveniences JS clients
|
|
|
|
*/
|
|
|
|
|
|
|
|
CategoryNode* category;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
category = get_category(aCategoryName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (category) {
|
|
|
|
category->DeleteLeaf(aEntryName);
|
|
|
|
|
|
|
|
NotifyObservers(NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID,
|
|
|
|
aCategoryName, aEntryName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCategoryManager::DeleteCategory( const char *aCategoryName )
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCategoryName);
|
|
|
|
|
|
|
|
// the categories are arena-allocated, so we don't
|
|
|
|
// actually delete them. We just remove all of the
|
|
|
|
// leaf nodes.
|
|
|
|
|
|
|
|
CategoryNode* category;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
category = get_category(aCategoryName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (category) {
|
|
|
|
category->Clear();
|
|
|
|
NotifyObservers(NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID,
|
2012-07-30 14:20:58 +00:00
|
|
|
aCategoryName, nullptr);
|
2010-06-24 18:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2003-06-18 11:26:27 +00:00
|
|
|
}
|
2000-02-05 06:19:49 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCategoryManager::EnumerateCategory( const char *aCategoryName,
|
|
|
|
nsISimpleEnumerator **_retval )
|
2003-06-18 11:26:27 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCategoryName);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
|
2009-07-23 14:29:00 +00:00
|
|
|
CategoryNode* category;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
category = get_category(aCategoryName);
|
|
|
|
}
|
2003-06-18 11:26:27 +00:00
|
|
|
|
|
|
|
if (!category) {
|
|
|
|
return NS_NewEmptyEnumerator(_retval);
|
|
|
|
}
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
return category->Enumerate(_retval);
|
|
|
|
}
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCategoryManager::EnumerateCategories(nsISimpleEnumerator **_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2000-02-05 06:19:49 +00:00
|
|
|
|
2009-07-23 14:29:00 +00:00
|
|
|
MutexAutoLock lock(mLock);
|
2003-06-18 11:26:27 +00:00
|
|
|
CategoryEnumerator* enumObj = CategoryEnumerator::Create(mTable);
|
2000-02-05 07:42:30 +00:00
|
|
|
|
2003-06-18 11:26:27 +00:00
|
|
|
if (!enumObj)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*_retval = enumObj;
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct writecat_struct {
|
|
|
|
PRFileDesc* fd;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool success;
|
2003-06-18 11:26:27 +00:00
|
|
|
};
|
|
|
|
|
2005-06-17 21:07:47 +00:00
|
|
|
NS_METHOD
|
2011-09-29 06:19:26 +00:00
|
|
|
nsCategoryManager::SuppressNotifications(bool aSuppress)
|
2005-06-17 21:07:47 +00:00
|
|
|
{
|
|
|
|
mSuppressNotifications = aSuppress;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-16 03:35:52 +00:00
|
|
|
/*
|
|
|
|
* CreateServicesFromCategory()
|
|
|
|
*
|
|
|
|
* Given a category, this convenience functions enumerates the category and
|
|
|
|
* creates a service of every CID or ContractID registered under the category.
|
|
|
|
* If observerTopic is non null and the service implements nsIObserver,
|
|
|
|
* this will attempt to notify the observer with the origin, observerTopic string
|
|
|
|
* as parameter.
|
|
|
|
*/
|
2011-08-18 13:46:39 +00:00
|
|
|
void
|
2001-10-16 03:35:52 +00:00
|
|
|
NS_CreateServicesFromCategory(const char *category,
|
|
|
|
nsISupports *origin,
|
2001-10-19 20:52:59 +00:00
|
|
|
const char *observerTopic)
|
2001-10-16 03:35:52 +00:00
|
|
|
{
|
2010-07-20 13:28:45 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICategoryManager> categoryManager =
|
|
|
|
do_GetService("@mozilla.org/categorymanager;1");
|
|
|
|
if (!categoryManager)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> enumerator;
|
|
|
|
rv = categoryManager->EnumerateCategory(category,
|
|
|
|
getter_AddRefs(enumerator));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUTF8StringEnumerator> senumerator =
|
|
|
|
do_QueryInterface(enumerator);
|
|
|
|
if (!senumerator) {
|
|
|
|
NS_WARNING("Category enumerator doesn't support nsIUTF8StringEnumerator.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasMore;
|
2010-07-20 13:28:45 +00:00
|
|
|
while (NS_SUCCEEDED(senumerator->HasMore(&hasMore)) && hasMore) {
|
|
|
|
// From here on just skip any error we get.
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString entryString;
|
2010-07-20 13:28:45 +00:00
|
|
|
if (NS_FAILED(senumerator->GetNext(entryString)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsXPIDLCString contractID;
|
|
|
|
rv = categoryManager->GetCategoryEntry(category,entryString.get(),
|
|
|
|
getter_Copies(contractID));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> instance = do_GetService(contractID);
|
|
|
|
if (!instance) {
|
|
|
|
LogMessage("While creating services from category '%s', could not create service for entry '%s', contract ID '%s'",
|
|
|
|
category, entryString.get(), contractID.get());
|
|
|
|
continue;
|
2001-10-16 03:35:52 +00:00
|
|
|
}
|
2010-07-20 13:28:45 +00:00
|
|
|
|
|
|
|
if (observerTopic) {
|
|
|
|
// try an observer, if it implements it.
|
|
|
|
nsCOMPtr<nsIObserver> observer = do_QueryInterface(instance);
|
|
|
|
if (observer)
|
|
|
|
observer->Observe(origin, observerTopic, EmptyString().get());
|
|
|
|
else
|
|
|
|
LogMessage("While creating services from category '%s', service for entry '%s', contract ID '%s' does not implement nsIObserver.",
|
|
|
|
category, entryString.get(), contractID.get());
|
|
|
|
}
|
|
|
|
}
|
2001-10-16 03:35:52 +00:00
|
|
|
}
|