Trying to establish a basic Mojo connection in Chromium

38 views
Skip to first unread message

Simon Que

unread,
Jan 6, 2016, 5:04:05 PM1/6/16
to Chromium-dev
I'm trying to connect the browser and renderer processes using Mojo. I want the renderer process to call the function on the browser process. I imitated some of the existing Chromium code that uses Mojo but it's not working. The Mojo interface function is not being called when the caller in the remote process is attempting to call it.

Explanation of files:
- leak_detector_monitor.mojom: The LeakDetectorMonitor interface that exposes a single function, StoreLeakReport().
- leak_detector_monitor_impl.(cc|h): Implements the LeakDetectorMonitor interface. StoreLeakReport() doesn't actually do anything. It just logs a message. Exposes a Create() function.
- leak_detector_monitor_client.(cc|h): Singleton class that connects to LeakDetectorMonitorImpl using the ServiceRegistry and calls StoreLeakReport().
- chrome/browser/chrome_content_browser_client.cc: Add LeakDetectorMonitorImpl::Create() to the service registry.
- chrome/renderer/chrome_render_process_observer.cc: Initialize LeakDetectorMonitorClient.

The log is shown below (Chrome on Chrome OS). The new interface is registered with the service registry in chrome_content_browser_client.cc and leak_detector_monitor_client.cc connects to it successfully. However, there is no logging from either the Create() function or the StoreLeakReport() function in leak_detector_monitor_impl.cc.

What am I doing wrong?

Simon

========================================================================
[3662:3662:0105/180101:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service
[3662:3662:0105/180101:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service
[3920:3920:0105/180101:ERROR:leak_detector_monitor_client.cc(44)] Connecting to remote service
[3920:3920:0105/180101:ERROR:leak_detector_monitor_client.cc(46)]   result: 1
[3920:3920:0105/180101:ERROR:leak_detector_monitor_client.cc(56)] LeakDetectorMonitorClient::OnLeakFound
[3920:3920:0105/180101:ERROR:leak_detector_monitor_client.cc(58)] Done
[3662:3662:0105/180101:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service
[4110:4110:0105/180101:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service
[4110:4110:0105/180101:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service
[4345:4345:0105/180101:ERROR:leak_detector_monitor_client.cc(44)] Connecting to remote service
[4345:4345:0105/180101:ERROR:leak_detector_monitor_client.cc(46)]   result: 1
[4345:4345:0105/180101:ERROR:leak_detector_monitor_client.cc(56)] LeakDetectorMonitorClient::OnLeakFound
[4345:4345:0105/180101:ERROR:leak_detector_monitor_client.cc(58)] Done
[4110:4110:0105/180101:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service
[4548:4548:0105/180101:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service
[4548:4548:0105/180101:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service
[4810:4810:0105/180101:ERROR:leak_detector_monitor_client.cc(44)] Connecting to remote service
[4810:4810:0105/180101:ERROR:leak_detector_monitor_client.cc(46)]   result: 1
[4810:4810:0105/180101:ERROR:leak_detector_monitor_client.cc(56)] LeakDetectorMonitorClient::OnLeakFound
[4548:4548:0105/180102:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service
[5034:5034:0105/180102:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service
[5034:5034:0105/180102:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service
[5292:5292:0105/180102:ERROR:leak_detector_monitor_client.cc(44)] Connecting to remote service
[5292:5292:0105/180102:ERROR:leak_detector_monitor_client.cc(46)]   result: 1
[5292:5292:0105/180102:ERROR:leak_detector_monitor_client.cc(56)] LeakDetectorMonitorClient::OnLeakFound
[5292:5292:0105/180102:ERROR:leak_detector_monitor_client.cc(58)] Done
[5034:5034:0105/180102:ERROR:chrome_content_browser_client.cc(2648)] Adding LeakDetectorMonitorImpl service

Ken Rockot

unread,
Jan 6, 2016, 5:15:50 PM1/6/16
to sq...@chromium.org, Chromium-dev
There is a ServiceRegistry per frame as well as a ServiceRegistry per render process (the one on RenderThread). These are not the same registry.

You're registering your service per-frame but requesting it from the per-process registry. If you want a per-process instance (which seems to make sense in this case) you should register your service in ContentBrowserClient::RegisterRenderProcessMojoServices.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Jeremy Roman

unread,
Jan 6, 2016, 5:19:41 PM1/6/16
to Simon Que, Chromium-dev, chromium-mojo
[+chromium-mojo]

Anand K. Mistry

unread,
Jan 6, 2016, 5:24:11 PM1/6/16
to Jeremy Roman, Simon Que, Chromium-dev, chromium-mojo
It looks like you're exposing the service in the browser process on the RenderFrame's service registry. but using the RenderProcess's service registry to connect in the renderer. Try attaching your service to the RenderProcessHost's service registry in the browser.

--
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 post to this group, send email to chromi...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-mojo/CACuR13cCx94T9FiOQZMMvwJtNWvcWsXmayGzVaRU-yvyKp2RFQ%40mail.gmail.com.

Simon Que

unread,
Jan 6, 2016, 6:12:10 PM1/6/16
to Anand K. Mistry, Jeremy Roman, Chromium-dev, chromium-mojo, roc...@chromium.org
I've moved the registration to ChromeContentBrowserClient::RegisterRenderProcessMojoServices in chrome_content_browser_client.ccThe CL has been updated with these changes.

Now I'm running into a different problem. The registration happens before the client attempts to connect, but the Create() function doesn't get called, and Chrome crashes after a few attempts by the renderer process to call the remote function. See below:
========================= begin log ===========================
[chrome_content_browser_client.cc(2631)] Adding LeakDetectorMonitorImpl service
[leak_detector_monitor_client.cc(44)] Connecting to remote service
[leak_detector_monitor_client.cc(46)]   result: 1
[leak_detector_monitor_client.cc(56)] LeakDetectorMonitorClient::OnLeakFound
[leak_detector_monitor_client.cc(58)] Done
========================= end log ===========================

If I comment out the attempt to call the remote function StoreLeakReport(), I see the Create() function getting called..
========================= begin log ===========================
[chrome_content_browser_client.cc(2631)] Adding LeakDetectorMonitorImpl service
[leak_detector_monitor_client.cc(44)] Connecting to remote service
[leak_detector_monitor_client.cc(46)]   result: 1
[chrome_content_browser_client.cc(2631)] Adding LeakDetectorMonitorImpl service
[leak_detector_monitor_impl.cc(14)] LeakDetectorMonitorImpl::Create
[leak_detector_monitor_impl.cc(16)] LeakDetectorMonitorImpl::Create
[leak_detector_monitor_client.cc(44)] Connecting to remote service
[leak_detector_monitor_client.cc(46)]   result: 1
[leak_detector_monitor_impl.cc(14)] LeakDetectorMonitorImpl::Create
[leak_detector_monitor_impl.cc(16)] LeakDetectorMonitorImpl::Create
========================= end log ===========================

Perhaps the problem is that the renderer process is attempting to call the remote function immediately after connecting, without letting the remote process call Create() first. If that's the case, then how can we guarantee that a call to the remote function occurs after Create()?

Ken Rockot

unread,
Jan 6, 2016, 6:25:14 PM1/6/16
to Simon Que, Anand K. Mistry, Jeremy Roman, Chromium-dev, chromium-mojo
Perhaps the problem is that the renderer process is attempting to call the remote function immediately after connecting, without letting the remote process call Create() first. If that's the case, then how can we guarantee that a call to the remote function occurs after Create()?

That's not a problem. This is specifically allowed by Mojo bindings. It's safe to call methods on an interface proxy before the other end is bound. Messages will be queued and dispatched ASAP. I'll take another look at the CL.
 

Anand K. Mistry

unread,
Jan 6, 2016, 6:28:30 PM1/6/16
to Ken Rockot, Simon Que, Jeremy Roman, Chromium-dev, chromium-mojo
I'm going to take a wild guess and say that maybe you're calling metrics::LeakDetectorMonitorClient::Initialize() too early (before stuff has finished initializing) and something is getting dropped. Try moving it to ChromeRenderProcessObserver::WebKitInitialized(). If this is the problem, I think we should fix Mojo's usage in Chrome, since what you're doing should be ok.

Ken Rockot

unread,
Jan 6, 2016, 7:04:39 PM1/6/16
to Anand K. Mistry, Simon Que, Jeremy Roman, Chromium-dev, chromium-mojo, John Abd-El-Malek
This looks like a bug in the current Mojo system implementation. As Anand suggests, you're probably trying to send a message too early in process startup, however this should be fine to do and we should fix the crash. For now, hopefully you can initialize your client a bit later.

I've filed a bug here.

Ken Rockot

unread,
Jan 6, 2016, 7:24:31 PM1/6/16
to Anand K. Mistry, Simon Que, Jeremy Roman, Chromium-dev, chromium-mojo, John Abd-El-Malek
Note that you can also continue testing your CL in its current state by running chrome with --use-old-edk to avoid crashing here until the bug is fixed, if you so desire.

Simon Que

unread,
Jan 6, 2016, 7:32:04 PM1/6/16
to Ken Rockot, Anand K. Mistry, Jeremy Roman, Chromium-dev, chromium-mojo, John Abd-El-Malek
Moving the LeakDetectorMonitorClient::Initialize() call to WebKitInitialized() did not fix it.

But the "--use-old-edk" flag did. Thanks.
Reply all
Reply to author
Forward
0 new messages