Closed Bug 560095 Opened 15 years ago Closed 15 years ago

Make use of mozilla::services

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9.3a5

People

(Reporter: Mitch, Assigned: Mitch)

References

Details

Attachments

(17 files, 11 obsolete files)

11.59 KB, patch
roc
: review+
Details | Diff | Splinter Review
5.45 KB, patch
surkov
: review+
Details | Diff | Splinter Review
1.82 KB, patch
roc
: review+
Details | Diff | Splinter Review
2.91 KB, patch
smontagu
: review+
Details | Diff | Splinter Review
8.38 KB, patch
jaas
: review+
Details | Diff | Splinter Review
1.40 KB, patch
mrbkap
: review+
Details | Diff | Splinter Review
1.30 KB, patch
sdwilsh
: review+
Details | Diff | Splinter Review
10.97 KB, patch
shaver
: review+
Details | Diff | Splinter Review
6.57 KB, patch
Details | Diff | Splinter Review
26.56 KB, patch
Gavin
: review+
Details | Diff | Splinter Review
13.04 KB, patch
jst
: review+
Details | Diff | Splinter Review
8.82 KB, patch
Biesinger
: review+
Details | Diff | Splinter Review
12.80 KB, patch
jst
: review+
Details | Diff | Splinter Review
19.42 KB, patch
Mitch
: review+
Details | Diff | Splinter Review
15.08 KB, patch
Mitch
: review+
Details | Diff | Splinter Review
7.39 KB, patch
Mitch
: review+
Details | Diff | Splinter Review
152.87 KB, patch
Details | Diff | Splinter Review
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.
Attached patch /toolkit (observer service, v1) (obsolete) — Splinter Review
Assignee: nobody → mitchell.field
Status: NEW → ASSIGNED
Attachment #439760 - Flags: review?(benjamin)
Attached patch layout (observer service, v1) (obsolete) — Splinter Review
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.
Attached patch netwerk (observer service, v1) (obsolete) — Splinter Review
Attachment #439763 - Flags: review?(cbiesinger)
What a horrible style rule.
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+
> 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.
Attached patch netwerk (observer service, v2) (obsolete) — Splinter Review
Review comments addressed.
Attachment #439763 - Attachment is obsolete: true
Attachment #439779 - Flags: review?(cbiesinger)
Attachment #439779 - Flags: review?(cbiesinger) → review+
Attachment #439761 - Attachment is obsolete: true
Attachment #439788 - Flags: review?(roc)
Attachment #439761 - Flags: review?(roc)
Attached patch toolkit (observer service, v2) (obsolete) — Splinter Review
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)
Attached patch toolkit (observer service, v3) (obsolete) — Splinter Review
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)
Attachment #439797 - Flags: review?(surkov.alexander)
Attached patch content (observer service, v1) (obsolete) — Splinter Review
Attachment #439798 - Flags: review?(bzbarsky)
Attached patch docshell (observer service, v1) (obsolete) — Splinter Review
Attachment #439799 - Flags: review?(bzbarsky)
Attached patch dom (observer service, v1) (obsolete) — Splinter Review
Attachment #439800 - Flags: review?(jonas)
Attached patch embedding (observer service, v1) (obsolete) — Splinter Review
Attachment #439801 - Flags: review?(jst)
Attachment #439802 - Flags: review?(roc)
Attachment #439803 - Flags: review?(smontagu)
Attachment #439804 - Flags: review?(joshmoz)
Attachment #439805 - Flags: review?(mrbkap)
Attachment #439806 - Flags: review?
Attachment #439806 - Flags: review? → review?(sdwilsh)
Attached patch widget (observer service, v1) (obsolete) — Splinter Review
Attachment #439807 - Flags: review?(roc)
Attachment #439809 - Flags: review?(shaver)
Attachment #439810 - Flags: review?(dveditz)
Sorry for all the bug spam. There has to be a better way to do this.
Attachment #439804 - Flags: review?(joshmoz) → review+
Attachment #439809 - Flags: review?(shaver) → review+
Attachment #439805 - Flags: review?(mrbkap) → review+
Do we actually need to use nsCOMPtr to hold the service? I don't think we do.
(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?
(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.
(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.
Attachment #439797 - Flags: review?(surkov.alexander) → review+
(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 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+
Attachment #439796 - Attachment is obsolete: true
Attachment #439845 - Flags: review?(gavin.sharp)
Restored some braces.
Attachment #439798 - Attachment is obsolete: true
Attachment #439924 - Flags: review?(bzbarsky)
Attachment #439798 - Flags: review?(bzbarsky)
Restored some more braces.
Attachment #439799 - Attachment is obsolete: true
Attachment #439926 - Flags: review?(bzbarsky)
Attachment #439799 - Flags: review?(bzbarsky)
Attachment #439926 - Flags: review?(bzbarsky) → review?(cbiesinger)
Attachment #439926 - Flags: review?(cbiesinger) → review+
Attachment #439845 - Flags: review?(gavin.sharp) → review+
Comment on attachment 439806 [details] [diff] [review] storage (observer service, v1) r=sdwilsh
Attachment #439806 - Flags: review?(sdwilsh) → review+
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 #439803 - Flags: review?(smontagu) → review+
mozilla::services returns already_AddRefed objects, so you do need a comptr.
(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.
(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.
Attachment #439801 - Flags: review?(jst) → 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.
Attachment #439800 - Attachment is obsolete: true
Attachment #440438 - Flags: review?(jonas)
Attachment #439924 - Flags: review?(bzbarsky) → review?(jst)
Attachment #439924 - Flags: review?(jst) → review+
Comment on attachment 440438 [details] [diff] [review] dom (observer service, v2) Stealing review from sicking...
Attachment #440438 - Flags: review?(jonas) → review+
Attachment #439810 - Flags: review?(dveditz)
Comment on attachment 439810 [details] [diff] [review] xpinstall (observer service, v1) r=dvedit
TryServer picked up a missing include. Carrying over r+.
Attachment #439779 - Attachment is obsolete: true
Attachment #440831 - Flags: review+
Ditto.
Attachment #439807 - Attachment is obsolete: true
Attachment #440834 - Flags: review+
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 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.
Fixed. Thanks, Justin.
Attachment #439801 - Attachment is obsolete: true
Attachment #442359 - Flags: review+
Attachment #442359 - Attachment description: patch (observer service, v2) → embedding (observer service, v2)
This amalgamation of all above patches passes TryServer, and should be ready for check-in. Patch includes Hg changeset summary.
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.3a5
Blocks: 564950
Blocks: 560772
No longer blocks: 562709
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: