Questions for using mojo as thread-safe interfaces within the blink renderer process

407 views
Skip to first unread message

Jiacheng Guo

unread,
Dec 7, 2024, 4:38:15 AM12/7/24
to chromi...@chromium.org
Hi team

We are working on exporting the language detection feature to the service workers. Currently the language detection code runs on the main thread of the renderer and depends heavily on static objects so it is not thread-safe.

I wonder if it is possible to set up a mojo service within the renderer to resolve the issue. Is such an approach recommended? If it is, what is the equivalent of the `GetBrowserInterfaceBroker` to register and acquire mojo interfaces within the renderer?

Your help is much appreciated.

Jiacheng Guo

Joe Mason

unread,
Dec 8, 2024, 12:42:22 PM12/8/24
to Jiacheng Guo, chromi...@chromium.org
What's the current interface to language detection?

My first thought is that mojo sounds like overkill for this, but to give better advice I'd like to know more about how this code is called.

--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-moj...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chromium-mojo/CAJQw1NxK63yAZ1xPyzYBarYf5pkycA%2B3G2rbgq6%3DDkXRw4qCuQ%40mail.gmail.com.

Jiacheng Guo

unread,
Dec 9, 2024, 9:56:37 AM12/9/24
to Joe Mason, chromi...@chromium.org
The current interface is language_detection_model.h. One of the usages is detect.cc. The main issue is the language_detection::GetLanguageDetectionModel() static function and the load callback. They are currently all triggered in the renderer main thread.

Dave Tapuska

unread,
Dec 9, 2024, 10:29:05 AM12/9/24
to Jiacheng Guo, Joe Mason, chromi...@chromium.org
Is the main single API you use DeterminePageLanguage if so you could just PostTaskAndReply the request to the main thread.

dave.

Joe Mason

unread,
Dec 9, 2024, 3:56:46 PM12/9/24
to Jiacheng Guo, chromi...@chromium.org
If you want to be able to call GetLanguageDetectionModel() on any thread, but the returned LanguageDetectionModel object must be accessed from the main thread, you could modify it to return a base::SequenceBound<LanguageDetectionModel>&.

Making LanguageDetectionModel a mojo interface would only be useful if you expect to move language detection out-of-process at some point.

Jiacheng Guo

unread,
Dec 10, 2024, 10:03:16 AM12/10/24
to Joe Mason, chromi...@chromium.org
Thanks for the tip!

Jiacheng Guo

unread,
Dec 10, 2024, 10:03:20 AM12/10/24
to chrome-builtin-ai, Fergal Daly, chromi...@chromium.org, Joe Mason

Fergal Daly

unread,
Dec 10, 2024, 10:03:24 AM12/10/24
to Jiacheng Guo, chrome-builtin-ai, chromi...@chromium.org, Joe Mason
I don't think mojo is the right tool here. All we need is to ensure that the model is used consistently from the correct thread. I think that should just be a matter of posting tasks on the correct sequence. I added some ideas on this to https://crbug.com/362707418 earlier today,

F
Reply all
Reply to author
Forward
0 new messages