Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / libpref / public / nsIPrefBranch2.idl
blob5d7fef9a1116b40d39fbe5c8139e4465d73f5f60
1 /* -*- Mode: IDL; 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 Communicator client 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):
23 * Alec Flett <alecf@netscape.com>
24 * Brian Nesse <bnesse@netscape.com>
25 * Benjamin Smedberg <benjamin@smedbergs.us>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #include "nsIPrefBranch.idl"
43 interface nsIObserver;
45 /**
46 * nsIPrefBranch2 allows clients to observe changes to pref values.
48 * @status FROZEN
49 * @see nsIPrefBranch
51 [scriptable, uuid(74567534-eb94-4b1c-8f45-389643bfc555)]
52 interface nsIPrefBranch2 : nsIPrefBranch
54 /**
55 * Add a preference change observer. On preference changes, the following
56 * arguments will be passed to the nsIObserver.observe() method:
57 * aSubject - The nsIPrefBranch object (this)
58 * aTopic - The string defined by NS_PREFBRANCH_PREFCHANGE_TOPIC_ID
59 * aData - The name of the preference which has changed, relative to
60 * the |root| of the aSubject branch.
62 * aSubject.get*Pref(aData) will get the new value of the modified
63 * preference. For example, if your observer is registered with
64 * addObserver("bar.", ...) on a branch with root "foo.", modifying
65 * the preference "foo.bar.baz" will trigger the observer, and aData
66 * parameter will be "bar.baz".
68 * @param aDomain The preference on which to listen for changes. This can
69 * be the name of an entire branch to observe.
70 * e.g. Holding the "root" prefbranch and calling
71 * addObserver("foo.bar.", ...) will observe changes to
72 * foo.bar.baz and foo.bar.bzip
73 * @param aObserver The object to be notified if the preference changes.
74 * @param aHoldWeak true Hold a weak reference to |aObserver|. The object
75 * must implement the nsISupportsWeakReference
76 * interface or this will fail.
77 * false Hold a strong reference to |aObserver|.
79 * @note
80 * Registering as a preference observer can open an object to potential
81 * cyclical references which will cause memory leaks. These cycles generally
82 * occur because an object both registers itself as an observer (causing the
83 * branch to hold a reference to the observer) and holds a reference to the
84 * branch object for the purpose of getting/setting preference values. There
85 * are 3 approaches which have been implemented in an attempt to avoid these
86 * situations.
87 * 1) The nsPrefBranch object supports nsISupportsWeakReference. Any consumer
88 * may hold a weak reference to it instead of a strong one.
89 * 2) The nsPrefBranch object listens for xpcom-shutdown and frees all of the
90 * objects currently in its observer list. This ensures that long lived
91 * objects (services for example) will be freed correctly.
92 * 3) The observer can request to be held as a weak reference when it is
93 * registered. This insures that shorter lived objects (say one tied to an
94 * open window) will not fall into the cyclical reference trap.
96 * @note
97 * The list of registered observers may be changed during the dispatch of
98 * nsPref:changed notification. However, the observers are not guaranteed
99 * to be notified in any particular order, so you can't be sure whether the
100 * added/removed observer will be called during the notification when it
101 * is added/removed.
103 * @note
104 * It is possible to change preferences during the notification.
106 * @note
107 * It is not safe to change observers during this callback in Gecko
108 * releases before 1.9. If you want a safe way to remove a pref observer,
109 * please use an nsITimer.
111 * @see nsIObserver
112 * @see removeObserver
114 void addObserver(in string aDomain, in nsIObserver aObserver,
115 in boolean aHoldWeak);
118 * Remove a preference change observer.
120 * @param aDomain The preference which is being observed for changes.
121 * @param aObserver An observer previously registered with addObserver().
123 * @note
124 * Note that you must call removeObserver() on the same nsIPrefBranch2
125 * instance on which you called addObserver() in order to remove aObserver;
126 * otherwise, the observer will not be removed.
128 * @see nsIObserver
129 * @see addObserver
131 void removeObserver(in string aDomain, in nsIObserver aObserver);
134 %{C++
137 * Notification sent when a preference changes.
139 #define NS_PREFBRANCH_PREFCHANGE_TOPIC_ID "nsPref:changed"