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)
Core
Preferences: Backend
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().
| Reporter | ||
Comment 1•25 years ago
|
||
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;
Comment 2•25 years ago
|
||
Seems reasonable to me, but could potentially break anyone currently Observing
preferences.
| Reporter | ||
Comment 3•25 years ago
|
||
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
| Reporter | ||
Comment 4•25 years ago
|
||
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.
Comment 5•25 years ago
|
||
> 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.
| Assignee | ||
Comment 6•25 years ago
|
||
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().
| Reporter | ||
Comment 7•25 years ago
|
||
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!
| Reporter | ||
Comment 8•25 years ago
|
||
So, can I have an sr?
| Assignee | ||
Comment 9•25 years ago
|
||
r=dveditz
Comment 10•25 years ago
|
||
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()
| Reporter | ||
Comment 11•25 years ago
|
||
This was checked in, marking fixed.
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•