Open Bug 1228115 Opened 9 years ago Updated 2 years ago

Make nsIURI creation and usage threadsafe


(Core :: Networking, defect, P3)





(Reporter: sicking, Unassigned)


(Depends on 3 open bugs)


(Whiteboard: [necko-backlog])

It's currently a pain in the a** that nsIURIs can't be created or used off the main thread. It forces a bunch of worker related stuff to use strings rather than nsIURIs.

This is also keeping us from using nsIPrincipals off the main thread. Which, again, is making worker code much more painful.
Awesome! Thanks for tackling this jonas.
Note that I'm not planning on doing this on any particular schedule. This definitely will be my side project when I need a break from other things. So I'd definitely appreciate any help I can get with the various blocking bugs. I'll make sure to assign any bug that I'm actually working on to myself.
Whiteboard: [necko-backlog]
Honza, I was thinking of giving this a shot. I recently bumped against bug 1280584, and this would have been helpful.
I recall you had a plan for this, but I don't know if it's written down here, so I'll summarize what I remember:

The plan was that we'd have a Mutate() method on nsIURI which returns an nsIURIMutator.
nsIURIMutator would have all of the regular SetHost,SetPath,SetRef,etc methods, that would also return an nsIURIMutator; so you could call
> newURI = uri->Mutate()->SetHost("hostname")->SetRef("#hello")->Finalize(&rv);
Here, Finalize(&rv) would return an nsIURI or nullptr, and rv would be set to an error if any of the setters failed.

Honza, is this correct, and does this look sound like a good pattern? Thanks!
Flags: needinfo?(honzab.moz)
Yes!  Something like that.  The idea of having a mutator is to not pass nsIURI around with methods to modify it that may or may not fail.  That would be a hard to implement and hard to use API IMO.  

What you suggests sounds good if we want to go the de-xpcom way.  You understand this could only be used in C++ but not in JS (not sure what the long term plans for mutation of URLs in JS are, but I think our chrome code may use it ; hence, you may need a common IDL for this, too.)
Flags: needinfo?(honzab.moz)
I think Jonas had ideas on how to fix this as well.
Flags: needinfo?(jonas)
I think Jonas wrote down his plans for handling this in bug 922464. There is a certain amount of overlap.
See Also: → OMT-nsIURI
Yeah, see bug 922464 comment 0 as well as the bugs that this bug depends on. Sadly the mutators are only a small part of the problem.
Flags: needinfo?(jonas)
Bulk change to priority:
Priority: -- → P1
Bulk change to priority:
Priority: P1 → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.