Closed
Bug 560095
Opened 15 years ago
Closed 15 years ago
Make use of mozilla::services
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
mozilla1.9.3a5
People
(Reporter: Mitch, Assigned: Mitch)
References
Details
Attachments
(17 files, 11 obsolete files)
Following the great work done in bug 516085 to provide easy access for common global services, we can now start replacing do_GetService() calls with mozilla::services::Get*Service().
In forthcoming patches I'm doing so with GetObserverService(), but I got a bit carried away and nuked hundreds of unnecessary {} brackets in the process.
Assignee | ||
Comment 1•15 years ago
|
||
Assignee: nobody → mitchell.field
Status: NEW → ASSIGNED
Attachment #439760 -
Flags: review?(benjamin)
Assignee | ||
Comment 2•15 years ago
|
||
Attachment #439761 -
Flags: review?(roc)
Our style guide says
> Always brace controlled statements, even a single-line consequent of an if else
> else. This is redundant typically, but it avoids dangling else bugs, so it's
> safer at scale than fine-tuning.
So removing those {}s is not right.
Assignee | ||
Comment 4•15 years ago
|
||
Attachment #439763 -
Flags: review?(cbiesinger)
Assignee | ||
Comment 5•15 years ago
|
||
What a horrible style rule.
Comment 6•15 years ago
|
||
Comment on attachment 439763 [details] [diff] [review]
netwerk (observer service, v1)
+++ b/netwerk/cache/src/nsCacheService.cpp
+ if (!observerService)
+ return NS_ERROR_FAILURE;
NS_ENSURE_ARG(observerService);
you don't need both of those checks
+ if (obs)
+ for (unsigned int i=0; i<NS_ARRAY_LENGTH(observerList); i++)
+ obs->RemoveObserver(this, observerList[i]);
please keep the {}, I find multi-line bodies easier to read if they're bracketed even when they're a single statement.
Attachment #439763 -
Flags: review?(cbiesinger) → review+
Comment 7•15 years ago
|
||
> What a horrible style rule.
It's there because not having it led to serious bugs, including security bugs, in the past. Put the curlies back, please.
Assignee | ||
Comment 8•15 years ago
|
||
Review comments addressed.
Attachment #439763 -
Attachment is obsolete: true
Attachment #439779 -
Flags: review?(cbiesinger)
Updated•15 years ago
|
Attachment #439779 -
Flags: review?(cbiesinger) → review+
Assignee | ||
Comment 9•15 years ago
|
||
Attachment #439761 -
Attachment is obsolete: true
Attachment #439788 -
Flags: review?(roc)
Attachment #439761 -
Flags: review?(roc)
Assignee | ||
Comment 10•15 years ago
|
||
Note: I changed "obssvc" to "obsSvc" for a bit of consistency within one file.
Attachment #439760 -
Attachment is obsolete: true
Attachment #439790 -
Flags: review?(gavin.sharp)
Attachment #439760 -
Flags: review?(benjamin)
Assignee | ||
Comment 11•15 years ago
|
||
I didn't realise the toolkit component encompassed "chrome" and "profile" directories.
Attachment #439790 -
Attachment is obsolete: true
Attachment #439796 -
Flags: review?(gavin.sharp)
Attachment #439790 -
Flags: review?(gavin.sharp)
Assignee | ||
Comment 12•15 years ago
|
||
Attachment #439797 -
Flags: review?(surkov.alexander)
Assignee | ||
Comment 13•15 years ago
|
||
Attachment #439798 -
Flags: review?(bzbarsky)
Assignee | ||
Comment 14•15 years ago
|
||
Attachment #439799 -
Flags: review?(bzbarsky)
Assignee | ||
Comment 15•15 years ago
|
||
Attachment #439800 -
Flags: review?(jonas)
Assignee | ||
Comment 16•15 years ago
|
||
Attachment #439801 -
Flags: review?(jst)
Assignee | ||
Comment 17•15 years ago
|
||
Attachment #439802 -
Flags: review?(roc)
Assignee | ||
Comment 18•15 years ago
|
||
Attachment #439803 -
Flags: review?(smontagu)
Assignee | ||
Comment 19•15 years ago
|
||
Attachment #439804 -
Flags: review?(joshmoz)
Assignee | ||
Comment 20•15 years ago
|
||
Attachment #439805 -
Flags: review?(mrbkap)
Assignee | ||
Comment 21•15 years ago
|
||
Attachment #439806 -
Flags: review?
Assignee | ||
Updated•15 years ago
|
Attachment #439806 -
Flags: review? → review?(sdwilsh)
Assignee | ||
Comment 22•15 years ago
|
||
Attachment #439807 -
Flags: review?(roc)
Assignee | ||
Comment 23•15 years ago
|
||
Attachment #439809 -
Flags: review?(shaver)
Assignee | ||
Comment 24•15 years ago
|
||
Attachment #439810 -
Flags: review?(dveditz)
Assignee | ||
Comment 25•15 years ago
|
||
Sorry for all the bug spam. There has to be a better way to do this.
Attachment #439804 -
Flags: review?(joshmoz) → review+
Updated•15 years ago
|
Attachment #439809 -
Flags: review?(shaver) → review+
Updated•15 years ago
|
Attachment #439805 -
Flags: review?(mrbkap) → review+
Do we actually need to use nsCOMPtr to hold the service? I don't think we do.
Comment 27•15 years ago
|
||
(In reply to comment #26)
> Do we actually need to use nsCOMPtr to hold the service? I don't think we do.
The services still need to be reference-counted as they are also accessed via JS. I'd rather not have someone accidentally hold on to a service until after it is shutdown.
(In reply to comment #27)
> (In reply to comment #26)
> > Do we actually need to use nsCOMPtr to hold the service? I don't think we do.
>
> The services still need to be reference-counted as they are also accessed via
> JS.
But isn't the mozilla::service layer holding a reference to the service? Why does layout etc need to add a reference?
Comment 29•15 years ago
|
||
(In reply to comment #28)
> (In reply to comment #27)
> > (In reply to comment #26)
> > > Do we actually need to use nsCOMPtr to hold the service? I don't think we do.
> >
> > The services still need to be reference-counted as they are also accessed via
> > JS.
>
> But isn't the mozilla::service layer holding a reference to the service? Why
> does layout etc need to add a reference?
It holds one reference, until xpcom shutdown when it goes away. At which point any references via raw pointers will be bad.
OK but most of the uses here are storing the service reference in an nsCOMPtr local variable. Those surely aren't needed.
Comment 31•15 years ago
|
||
(In reply to comment #30)
> OK but most of the uses here are storing the service reference in an nsCOMPtr
> local variable. Those surely aren't needed.
Indeed, but I'd rather not risk having that leak(or have xpcom shutdown midmethod). As far as saving cpu time it's pointless, getservice-type things just don't get called enough for reference counting to make any measurable difference.
XPCOM can shut down mid-method? I seriously hope not!
If the caller doesn't add a reference, it can't leak.
Updated•15 years ago
|
Attachment #439797 -
Flags: review?(surkov.alexander) → review+
Comment 33•15 years ago
|
||
(In reply to comment #32)
> XPCOM can shut down mid-method? I seriously hope not!
yes if the method initiates a shutdown.
>
> If the caller doesn't add a reference, it can't leak.
Worried about dereferencing free()ed memory, not leaks. My original idea was to not ref count, but ref counting turned out to be safer.
OK, but XPCOM can't shut down without spinning a nested event loop, right?
Lots of code holds raw pointers across function calls because we assume/know that the callee can't spin a nested event loop. The same should be true here.
Comment 35•15 years ago
|
||
Comment on attachment 439796 [details] [diff] [review]
toolkit (observer service, v3)
>diff --git a/toolkit/xre/nsNativeAppSupportUnix.cpp b/toolkit/xre/nsNativeAppSupportUnix.cpp
>@@ -323,24 +323,24 @@ static void OssoHardwareCallback(osso_hw
> if (state->memory_low_ind) {
> if (! ourState->memory_low_ind) {
>- nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
>+ nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
> if (os)
> os->NotifyObservers(nsnull, "memory-pressure", NS_LITERAL_STRING("low-memory").get());
> }
> }
Yeesh, what's going on here? Hate to scope creep, but this is so ugly I can't help it - can you make this a single conditional rather than nested if()s, and fix the indent?
Please undo all of the brace removals.
r=me with that.
Attachment #439796 -
Flags: review?(gavin.sharp) → review+
Assignee | ||
Comment 36•15 years ago
|
||
Attachment #439796 -
Attachment is obsolete: true
Attachment #439845 -
Flags: review?(gavin.sharp)
Assignee | ||
Comment 37•15 years ago
|
||
Restored some braces.
Attachment #439798 -
Attachment is obsolete: true
Attachment #439924 -
Flags: review?(bzbarsky)
Attachment #439798 -
Flags: review?(bzbarsky)
Assignee | ||
Comment 38•15 years ago
|
||
Restored some more braces.
Attachment #439799 -
Attachment is obsolete: true
Attachment #439926 -
Flags: review?(bzbarsky)
Attachment #439799 -
Flags: review?(bzbarsky)
Assignee | ||
Updated•15 years ago
|
Attachment #439926 -
Flags: review?(bzbarsky) → review?(cbiesinger)
Updated•15 years ago
|
Attachment #439926 -
Flags: review?(cbiesinger) → review+
Updated•15 years ago
|
Attachment #439845 -
Flags: review?(gavin.sharp) → review+
Comment 39•15 years ago
|
||
Comment on attachment 439806 [details] [diff] [review]
storage (observer service, v1)
r=sdwilsh
Attachment #439806 -
Flags: review?(sdwilsh) → review+
Assignee | ||
Updated•15 years ago
|
Keywords: checkin-needed
+ nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
This doesn't need to be an nsCOMPtr.
+ nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
Neither does this. etc...
I guess we can take these patches for now, but at some point --- perhaps when we have infrastructure for annotating/analyzing which methods can spin the event loop --- I would like to remove the nsCOMPtrs.
Attachment #439788 -
Flags: review?(roc) → review+
Attachment #439802 -
Flags: review?(roc) → review+
Attachment #439807 -
Flags: review?(roc) → review+
Updated•15 years ago
|
Attachment #439803 -
Flags: review?(smontagu) → review+
Comment 41•15 years ago
|
||
mozilla::services returns already_AddRefed objects, so you do need a comptr.
It shouldn't.
Comment 43•15 years ago
|
||
(In reply to comment #41)
> mozilla::services returns already_AddRefed objects, so you do need a comptr.
You can do mozilla::services::GetIOService().get(), so technically you don't.
I think making nsCOMPtr<>s optional is an interesting project, that should be investigated as part of another bug. It would be easier to make that change after giving services explicit getters like this bug is doing.
Ridding services of nsCOMPtrs is not a low-hanging performance fruit, so didn't consider it as important as providing a way to bypass the massive GetService() slowness.
One was to accomplish a comptr-less operation would be to define a wrapper class that lets one dereference services, but not store them.
Ie allow mozilla::services::IOService->...., but not nsIIOService *io = mozilla::services::IOService.
Comment 44•15 years ago
|
||
(In reply to comment #43)
> You can do mozilla::services::GetIOService().get(), so technically you don't.
Well sure, but then you need to call release manually, so you might as well use a comptr.
Updated•15 years ago
|
Attachment #439801 -
Flags: review?(jst) → review+
Attachment #439800 -
Flags: review?(jonas) → review+
Comment on attachment 439800 [details] [diff] [review]
dom (observer service, v1)
Please put back the braces to keep with the bracing stile of these files. (It also makes future patches easier to read)
Looks good otherwise.
Assignee | ||
Comment 46•15 years ago
|
||
Attachment #439800 -
Attachment is obsolete: true
Attachment #440438 -
Flags: review?(jonas)
Assignee | ||
Updated•15 years ago
|
Attachment #439924 -
Flags: review?(bzbarsky) → review?(jst)
Updated•15 years ago
|
Attachment #439924 -
Flags: review?(jst) → review+
Comment 47•15 years ago
|
||
Comment on attachment 440438 [details] [diff] [review]
dom (observer service, v2)
Stealing review from sicking...
Attachment #440438 -
Flags: review?(jonas) → review+
Updated•15 years ago
|
Attachment #439810 -
Flags: review?(dveditz)
Comment 48•15 years ago
|
||
Comment on attachment 439810 [details] [diff] [review]
xpinstall (observer service, v1)
r=dvedit
Assignee | ||
Comment 49•15 years ago
|
||
TryServer picked up a missing include. Carrying over r+.
Attachment #439779 -
Attachment is obsolete: true
Attachment #440831 -
Flags: review+
Assignee | ||
Comment 50•15 years ago
|
||
Ditto.
Attachment #439807 -
Attachment is obsolete: true
Attachment #440834 -
Flags: review+
Comment 51•15 years ago
|
||
Comment on attachment 439845 [details] [diff] [review]
toolkit (observer service, v4)
this patch failed a try-build, nsNativeAppSupportUnix.cpp doesn't have "mozilla/services.h" in scope. The other files in this patch that don't directly include it get it for free from NetUtils.h. I'm not sure if toolkit would want explicit #includes in any file that uses mozilla::services though; so re-pushed the patchset to try without this...
Comment 52•15 years ago
|
||
Comment on attachment 439801 [details] [diff] [review]
embedding (observer service, v1)
mozilla::services is not externally linkable, therefore this fails to compile [and link] TestGtkEmbed.cpp please revert in this file.
Assignee | ||
Comment 53•15 years ago
|
||
Fixed. Thanks, Justin.
Attachment #439801 -
Attachment is obsolete: true
Attachment #442359 -
Flags: review+
Assignee | ||
Updated•15 years ago
|
Attachment #442359 -
Attachment description: patch (observer service, v2) → embedding (observer service, v2)
Assignee | ||
Comment 54•15 years ago
|
||
This amalgamation of all above patches passes TryServer, and should be ready for check-in. Patch includes Hg changeset summary.
Comment 55•15 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.3a5
Updated•14 years ago
|
You need to log in
before you can comment on or make changes to this bug.
Description
•