2015-04-09 20:25:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
1999-09-29 06:35:42 +04:00
|
|
|
|
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
#ifndef NSCATEGORYMANAGER_H
|
|
|
|
#define NSCATEGORYMANAGER_H
|
|
|
|
|
|
|
|
#include "prio.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsICategoryManager.h"
|
2013-11-07 09:35:30 +04:00
|
|
|
#include "nsIMemoryReporter.h"
|
2017-03-31 02:46:58 +03:00
|
|
|
#include "mozilla/ArenaAllocator.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2009-07-23 18:29:00 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2012-06-13 07:08:53 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2012-10-19 16:07:36 +04:00
|
|
|
class nsIMemoryReporter;
|
2002-07-18 09:09:10 +04:00
|
|
|
|
2017-03-31 02:46:58 +03:00
|
|
|
typedef mozilla::ArenaAllocator<1024*8, 8> CategoryAllocator;
|
|
|
|
|
2002-07-18 09:09:10 +04:00
|
|
|
/* 16d222a6-1dd2-11b2-b693-f38b02c021b2 */
|
|
|
|
#define NS_CATEGORYMANAGER_CID \
|
|
|
|
{ 0x16d222a6, 0x1dd2, 0x11b2, \
|
|
|
|
{0xb6, 0x93, 0xf3, 0x8b, 0x02, 0xc0, 0x21, 0xb2} }
|
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
/**
|
|
|
|
* a "leaf-node", managed by the nsCategoryNode hashtable.
|
|
|
|
*
|
|
|
|
* we need to keep a "persistent value" (which will be written to the registry)
|
|
|
|
* and a non-persistent value (for the current runtime): these are usually
|
2011-10-17 18:59:28 +04:00
|
|
|
* the same, except when aPersist==false. The strings are permanently arena-
|
2003-06-18 15:26:27 +04:00
|
|
|
* allocated, and will never go away.
|
|
|
|
*/
|
|
|
|
class CategoryLeaf : public nsDepCharHashKey
|
|
|
|
{
|
|
|
|
public:
|
2014-08-05 17:21:27 +04:00
|
|
|
explicit CategoryLeaf(const char* aKey) : nsDepCharHashKey(aKey), value(nullptr) {}
|
2010-06-10 22:11:11 +04:00
|
|
|
const char* value;
|
2003-06-18 15:26:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-10-02 10:49:45 +04:00
|
|
|
* CategoryNode keeps a hashtable of its entries.
|
2003-06-18 15:26:27 +04:00
|
|
|
* the CategoryNode itself is permanently allocated in
|
|
|
|
* the arena.
|
|
|
|
*/
|
|
|
|
class CategoryNode
|
|
|
|
{
|
|
|
|
public:
|
2018-07-24 04:55:03 +03:00
|
|
|
nsresult GetLeaf(const char* aEntryName,
|
|
|
|
char** aResult);
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2018-07-24 04:55:03 +03:00
|
|
|
nsresult AddLeaf(const char* aEntryName,
|
|
|
|
const char* aValue,
|
2016-08-15 07:30:14 +03:00
|
|
|
bool aReplace,
|
2018-07-24 04:55:03 +03:00
|
|
|
char** aResult,
|
2017-03-31 02:46:58 +03:00
|
|
|
CategoryAllocator* aArena);
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2018-07-24 04:55:03 +03:00
|
|
|
void DeleteLeaf(const char* aEntryName);
|
2010-06-24 22:31:18 +04:00
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
void Clear()
|
|
|
|
{
|
2010-06-24 22:31:18 +04:00
|
|
|
mozilla::MutexAutoLock lock(mLock);
|
|
|
|
mTable.Clear();
|
|
|
|
}
|
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
uint32_t Count()
|
|
|
|
{
|
2009-07-23 18:29:00 +04:00
|
|
|
mozilla::MutexAutoLock lock(mLock);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t tCount = mTable.Count();
|
2003-06-18 15:26:27 +04:00
|
|
|
return tCount;
|
|
|
|
}
|
|
|
|
|
2016-08-15 07:30:14 +03:00
|
|
|
nsresult Enumerate(nsISimpleEnumerator** aResult);
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
// CategoryNode is arena-allocated, with the strings
|
2017-03-31 02:46:58 +03:00
|
|
|
static CategoryNode* Create(CategoryAllocator* aArena);
|
2003-06-18 15:26:27 +04:00
|
|
|
~CategoryNode();
|
2014-08-03 00:44:06 +04:00
|
|
|
void operator delete(void*) {}
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
|
2012-10-19 16:07:36 +04:00
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
private:
|
2014-08-03 00:44:06 +04:00
|
|
|
CategoryNode() : mLock("CategoryLeaf") {}
|
2009-07-23 18:29:00 +04:00
|
|
|
|
2017-03-31 02:46:58 +03:00
|
|
|
void* operator new(size_t aSize, CategoryAllocator* aArena);
|
2003-06-18 15:26:27 +04:00
|
|
|
|
|
|
|
nsTHashtable<CategoryLeaf> mTable;
|
2009-07-23 18:29:00 +04:00
|
|
|
mozilla::Mutex mLock;
|
2003-06-18 15:26:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The main implementation of nsICategoryManager.
|
|
|
|
*
|
|
|
|
* This implementation is thread-safe.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsCategoryManager final
|
2013-12-08 10:09:10 +04:00
|
|
|
: public nsICategoryManager
|
|
|
|
, public nsIMemoryReporter
|
2003-06-18 15:26:27 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICATEGORYMANAGER
|
2013-12-08 10:09:10 +04:00
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2005-06-18 01:07:47 +04:00
|
|
|
/**
|
|
|
|
* Suppress or unsuppress notifications of category changes to the
|
|
|
|
* observer service. This is to be used by nsComponentManagerImpl
|
|
|
|
* on startup while reading the stored category list.
|
|
|
|
*/
|
2016-08-15 07:30:14 +03:00
|
|
|
nsresult SuppressNotifications(bool aSuppress);
|
2005-06-18 01:07:47 +04:00
|
|
|
|
2018-07-24 04:55:03 +03:00
|
|
|
void AddCategoryEntry(const char* aCategory,
|
|
|
|
const char* aKey,
|
|
|
|
const char* aValue,
|
|
|
|
bool aReplace = true,
|
|
|
|
char** aOldValue = nullptr);
|
2010-06-10 22:11:11 +04:00
|
|
|
|
|
|
|
static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
2012-10-19 16:07:36 +04:00
|
|
|
void InitMemoryReporter();
|
2010-06-10 22:11:11 +04:00
|
|
|
|
|
|
|
static nsCategoryManager* GetSingleton();
|
|
|
|
static void Destroy();
|
2009-07-23 18:29:00 +04:00
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
private:
|
2010-06-10 22:11:11 +04:00
|
|
|
static nsCategoryManager* gCategoryManager;
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
nsCategoryManager();
|
2003-06-18 15:26:27 +04:00
|
|
|
~nsCategoryManager();
|
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
|
2013-01-18 09:43:21 +04:00
|
|
|
|
2018-07-24 04:55:03 +03:00
|
|
|
CategoryNode* get_category(const char* aName);
|
2005-06-18 01:07:47 +04:00
|
|
|
void NotifyObservers(const char* aTopic,
|
2018-07-24 04:55:03 +03:00
|
|
|
const char* aCategoryName, // must be a static string
|
|
|
|
const char* aEntryName);
|
2003-06-18 15:26:27 +04:00
|
|
|
|
2017-03-31 02:46:58 +03:00
|
|
|
CategoryAllocator mArena;
|
2003-06-18 15:26:27 +04:00
|
|
|
nsClassHashtable<nsDepCharHashKey, CategoryNode> mTable;
|
2009-07-23 18:29:00 +04:00
|
|
|
mozilla::Mutex mLock;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mSuppressNotifications;
|
2003-06-18 15:26:27 +04:00
|
|
|
};
|
2002-07-18 09:09:10 +04:00
|
|
|
|
2003-06-18 15:26:27 +04:00
|
|
|
#endif
|