Closed Bug 65616 Opened 24 years ago Closed 24 years ago

pref observers do not support multiple observers per domain

Categories

(Core :: Preferences: Backend, defect, P2)

x86
All
defect

Tracking

()

VERIFIED FIXED
mozilla0.8

People

(Reporter: alecf, Assigned: alecf)

References

Details

(Keywords: crash, Whiteboard: fix in hand)

Attachments

(2 files)

The pref observer system gets really confused if you try to add multiple
observers on the same domain.
i.e. if from JS you say:

pref.addObserver("browser.toolbar.showbuttons", foo);
pref.addObserver("browser.toolbar.showbuttons", bar);

then the backend gets all confused because the mObservers hashtable throws out
it's reference to "foo" but keeps a pointer to it as a callback.

I have a fix, patch forthcoming. Looking for reviewers, super reviewers
Blocks: 46200
*** Bug 62935 has been marked as a duplicate of this bug. ***
Carrying over keywords from bug 62935 where there is a little more detail. I
closed that one in favor of this because you seem hot on the trail of a fix and
it was just middle-of-the-pile for me.
Keywords: crash, nsbeta1
so what I'm doing now is keeping two arrays, mObservers, and mObserverDomains,
which must be maintained in lock-step. mObservers keeps a refcount to each
observer, and mObserverDomains keeps the domain that they were registered with.
This is so that we can unregister all the domains in unregisterObservers()

I just realized that the patch is slightly dangerous if you have the same
observer observing two domains, and you remove one of them.

new patch forthcoming which walks the observer list, looking for an exact match
Status: NEW → ASSIGNED
OS: Windows 2000 → All
Priority: -- → P2
Target Milestone: --- → mozilla0.8
adding dveditz to CC for review, blizzard and bryner for possible super reviews
thanks, but i'm not a super-reviewer :)
 nsPref* nsPref::gInstance = NULL;
could we make this nsnull?

+nsresult
+nsPref::unregisterObservers()
+    PRUint32 i;
+    for (i=0; i< count; i++) {
is there any reason for i to survive the for loop?

i suppose parallelism to
+NS_IMETHODIMP nsPref::RemoveObserver(const char *aDomain,
+                                     nsIObserver *aObserver)
however, if that's the case then you have two styles for function definitions:
returntype\nfunctiondef and returntype\sfunctiondef

otherwise this code looks good.
the reason for the for() syntax as it is is because certain different compilers
scope for (PRInt32 i=0;...) differently

Whiteboard: fix in hand
got an sr from blizzard... thanks!
 fix is in.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
other than checking lxr to confirm alecf's changes to nsPref.cpp, am giving this
a rubberstamp...
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: