Closed Bug 71879 Opened 25 years ago Closed 25 years ago

Preferences observer should get nsIPref as the subject parameter

Categories

(Core :: Preferences: Backend, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: beard, Assigned: dveditz)

Details

For performance reasons, when a preference observer gets its Observe() method called, it should receive a reference to the nsIPref as the subject parameter, to avoid having to use the service manager again to obtain it. Current the observer itself is passed, which is redundant, since that is also the "this" parameter in the call to Observe().
Here's a trivial patch to fix this problem: Index: mozilla/modules/libpref/src/nsPref.cpp =================================================================== RCS file: /cvsroot/mozilla/modules/libpref/src/nsPref.cpp,v retrieving revision 3.141 diff -b -u -2 -r3.141 nsPref.cpp --- nsPref.cpp 2001/03/11 22:11:34 3.141 +++ nsPref.cpp 2001/03/13 23:49:45 @@ -636,5 +636,6 @@ { nsCOMPtr<nsIObserver> observer = NS_STATIC_CAST(nsIObserver *, data); - observer->Observe(observer, NS_LITERAL_STRING("nsPref:changed").get(), + observer->Observe(NS_STATIC_CAST(nsIPref *, nsPref::GetInstance()), + NS_LITERAL_STRING("nsPref:changed").get(), NS_ConvertASCIItoUCS2(newpref).get()); return 0;
Seems reasonable to me, but could potentially break anyone currently Observing preferences.
There's a precedent for using observers like I'm suggesting. Take a look at: http://lxr.mozilla.org/seamonkey/source/embedding/tests/mfcembed/MfcEmbed.cpp#386 This usage passes an nsIProfileChangeStatus object to the observer, NOT the observer itself. Let's just fix this. r=gordon
Gordon and I used LXR to examine all implementations of the Observe() method, and only one of them is being used with nsIPref, all the rest either ignore the subject parameter, or QueryInterface it to an appropriate interface. NONE of them assume that aSubject == this.
> This usage passes an nsIProfileChangeStatus object to the observer, NOT the > observer itself. Let's just fix this. No way. This is observing profile changes *NOT* prefs changes. The documentation for profile changes - See nsIProfileChangeStatus - says that an nsIProfileChangeStatus object will be passed as the subject. This must remain so.
There are very few places in the Mozilla tree using addObserver() for prefs, and none of them would break given this change. Most places in the tree (C++ code) use the older non-scriptable RegisterCallback().
Conrad, I wasn't proposing changing the place I mentioned, I was using it as an example of the usage I am proposing. Not to worry!
So, can I have an sr?
r=dveditz
sr=alecf I'm going to add that it's really lame that we don't have access to the nsIPref that made this change and thus have to use nsPref::GetInstance(), but I'll fix that some other day, if/when bnesse or I ever get rid of nsPref::GetInstance()
This was checked in, marking fixed.
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
rubberstamp
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.