Closed Bug 1628016 Opened 6 years ago Closed 11 months ago

Rethink provider concurrency in the Urlbar

Categories

(Firefox :: Address Bar, enhancement, P3)

enhancement
Points:
5

Tracking

()

RESOLVED FIXED
144 Branch
Tracking Status
firefox144 --- fixed

People

(Reporter: bugzilla, Assigned: mbeier)

References

(Blocks 1 open bug)

Details

(Whiteboard: [sng])

Attachments

(3 files, 1 obsolete file)

Suggested by Marco here.

we should rethink the whole concurrency handling so that we have a different provider instance for each input, or use the input name as key in this.queries, rather than the queryContext.

This would make it safer to keep member variables across queries, such as UrlbarProviderSearchSuggestions._lastLowResultsSearchSuggestion.

Pretty much we don't have a very good way of keeping query state for a specific input now.

Priority: -- → P3
See Also: → 1632035
Assignee: nobody → mak
Status: NEW → ASSIGNED
Iteration: --- → 80.1 - June 29 - July 12

I started on this and then the patch began to grow, so I must split changes into parts, a few cleanups can land sooner.

There's a few things to consider. The simplest approach has 1 manager per input, and one provider instance per manager. So pretty much everything becomes per-window, things that should be global can be stored in each module's global scope and accessed through static methods on the class.
Though, when a provider is registered with a manager, it should be registered for all the same-id inputs, not just for that window. That likely means I'll have to keep registered providers per input id in the manager's module scope.

An alternative would be to have everything per input id, but then we need Maps to keep and retrieve those objects, I suspect it would become even more complex. Or there may be a manager per input id, but then we'd need a manager of managers, it sounds like a complication again.

For now I'm sticking to the per-window + global scopes approach. It seems to work, but I didn't go through all consumers yet. XPCShell tests will have to create their own manager, since there's no real input field.

Points: --- → 5

Small update: I'm discussing this with Drew, we're debating the approach, whether to go for a per-input, per-input-per-window or per-query approach and how to handle runtime added (extension) providers in those cases.
In the meanwhile, I'm landing some cleanups for providers boilerplate to potentially simplify the above concurrency change.

we'll go for instance-per-input-type. This is pretty much the de-facto situation today, because we have only one consumer. The upside of this approach thus is simplicity. The downside is there's no sandboxing of state across windows.

The alternative approach instance-per-input would be a natural evolution of this, providing also cross-window sandboxing of state, but it's more complex requiring the manager to be per window, and a lot more compex handling of the WebExtensions side, indeed the WebExtension scope is global and we should still track per-window state in it.
Currently we don't have use-cases for the more complex approach, thus it's not worth the cost.

Iteration: 80.1 - June 29 - July 12 → 81.1 - July 27 - Aug 09
Severity: normal → S3

I'm not actively working on this, but posted my very old and likely bitrotted patch as inspiration for future work. It could probably be broken down further.
The idea is having one provider manager per input field id, so all the "urlbar" fields will share the same manager. The manager will own provider instances and track static data that those instances want to persist. No provider should use their "global" to store static data unless it's valid for the whole process (and thus all the input fields can use that data, regardless what they are).

Assignee: mak → nobody
Status: ASSIGNED → NEW
Iteration: 81.1 - July 27 - Aug 09 → ---

Reposting my comment to Marc for future reference:

The overall scope, long term, is to have the urlbar components/modules usable in more than one field. Currently a lot of the code is a singleton and it only works with the single urlbar field.
I started some time ago to do some of the work in bug 1628016 (ad you can see from some of the fixed dependencies) that consisted mostly in making providers instantiatable, unifying some of the code, making some methods static...
Then I started looking into the one-instance-per-input-field problem, with the WIP patch here that I didn't finish.
The idea was to have the providersManager own the providers instances, so each providersManager has its own providers instances. Then I wanted each input field have its own providersManager...
But there was a problem there, the urlbars in different windows often want to share some states.
So I ended up thinking to have one providerManager per input type, where by input type I mean "urlbar", "searchbar", "virtual-reality bar" and so on... so the urlbar in different windows share the same providers manager, the legacy search bars in different windows share their own manager.
My WIP here was an initial attempt but it's likely unclean, and there may be a better way to do that.
What you want is probably a providersManager getter in UrlbarInput that gets the right instance depending on the input DOM node id. Since js modules are unique per process, you could have a providersManagers' Manager (sorry for the ugly name) that has an id -> providersManager instance Map.
Then it's pretty much matter of ensuring each provider doesn't store state in its global scope but rather keeps it in their instance.

Assignee: nobody → mseibert

The bug assignee is inactive on Bugzilla, so the assignee is being reset.

Assignee: mseibert → nobody
Blocks: 1974218
Assignee: nobody → mbeier
Status: NEW → ASSIGNED

This bulk of this commit is about making those members of urlbar providers static that should be shared among instances.

Part 2 changed UrlbarProviderQuickSuggest to check whether the SearchSuggestions provider is really active in the current query. If it's not active, the suggested index of all quick suggestions will be -1. In tests, it's almost never active, so this patch fixes those tests.

Attachment #9351828 - Attachment is obsolete: true
Status: ASSIGNED → RESOLVED
Closed: 11 months ago
Resolution: --- → FIXED
Target Milestone: --- → 144 Branch
Blocks: 1985281
Blocks: 1985833
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: