Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / xpcom / components / nsCategoryManager.h
blobf327e35a0a41c567b2b85fd541a165137b373de2
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 #ifndef NSCATEGORYMANAGER_H
40 #define NSCATEGORYMANAGER_H
42 #include "prio.h"
43 #include "prlock.h"
44 #include "plarena.h"
45 #include "nsClassHashtable.h"
46 #include "nsICategoryManager.h"
48 #define NS_CATEGORYMANAGER_CLASSNAME "Category Manager"
50 /* 16d222a6-1dd2-11b2-b693-f38b02c021b2 */
51 #define NS_CATEGORYMANAGER_CID \
52 { 0x16d222a6, 0x1dd2, 0x11b2, \
53 {0xb6, 0x93, 0xf3, 0x8b, 0x02, 0xc0, 0x21, 0xb2} }
55 /**
56 * a "leaf-node", managed by the nsCategoryNode hashtable.
58 * we need to keep a "persistent value" (which will be written to the registry)
59 * and a non-persistent value (for the current runtime): these are usually
60 * the same, except when aPersist==PR_FALSE. The strings are permanently arena-
61 * allocated, and will never go away.
63 class CategoryLeaf : public nsDepCharHashKey
65 public:
66 CategoryLeaf(const char* aKey)
67 : nsDepCharHashKey(aKey),
68 pValue(nsnull),
69 nonpValue(nsnull) { }
70 const char* pValue;
71 const char* nonpValue;
75 /**
76 * CategoryNode keeps a hashtable of its entries.
77 * the CategoryNode itself is permanently allocated in
78 * the arena.
80 class CategoryNode
82 public:
83 NS_METHOD GetLeaf(const char* aEntryName,
84 char** _retval);
86 NS_METHOD AddLeaf(const char* aEntryName,
87 const char* aValue,
88 PRBool aPersist,
89 PRBool aReplace,
90 char** _retval,
91 PLArenaPool* aArena);
93 NS_METHOD DeleteLeaf(const char* aEntryName,
94 PRBool aDontPersist);
96 void Clear() {
97 PR_Lock(mLock);
98 mTable.Clear();
99 PR_Unlock(mLock);
102 PRUint32 Count() {
103 PR_Lock(mLock);
104 PRUint32 tCount = mTable.Count();
105 PR_Unlock(mLock);
106 return tCount;
109 NS_METHOD Enumerate(nsISimpleEnumerator** _retval);
111 PRBool WritePersistentEntries(PRFileDesc* fd, const char* aCategoryName);
113 // CategoryNode is arena-allocated, with the strings
114 static CategoryNode* Create(PLArenaPool* aArena);
115 ~CategoryNode();
116 void operator delete(void*) { }
118 private:
119 CategoryNode() { }
120 void* operator new(size_t aSize, PLArenaPool* aArena);
122 nsTHashtable<CategoryLeaf> mTable;
123 PRLock* mLock;
128 * The main implementation of nsICategoryManager.
130 * This implementation is thread-safe.
132 class nsCategoryManager
133 : public nsICategoryManager
135 public:
136 NS_DECL_ISUPPORTS
137 NS_DECL_NSICATEGORYMANAGER
140 * Write the categories to the XPCOM persistent registry.
141 * This is to be used by nsComponentManagerImpl (and NO ONE ELSE).
143 NS_METHOD WriteCategoryManagerToRegistry(PRFileDesc* fd);
146 * Suppress or unsuppress notifications of category changes to the
147 * observer service. This is to be used by nsComponentManagerImpl
148 * on startup while reading the stored category list.
150 NS_METHOD SuppressNotifications(PRBool aSuppress);
152 nsCategoryManager()
153 : mSuppressNotifications(PR_FALSE) { }
154 private:
155 friend class nsCategoryManagerFactory;
156 static nsCategoryManager* Create();
158 ~nsCategoryManager();
160 CategoryNode* get_category(const char* aName);
161 void NotifyObservers(const char* aTopic,
162 const char* aCategoryName,
163 const char* aEntryName);
165 PLArenaPool mArena;
166 nsClassHashtable<nsDepCharHashKey, CategoryNode> mTable;
167 PRLock* mLock;
168 PRBool mSuppressNotifications;
171 #endif