ML service: Implement D-Bus->Mojo bootstrap & add a thin client library

This CL adds logic for Chromium to bootstrap a Mojo connection to the
Chrome OS ML service daemon via D-Bus, and a very simple client library
for client code in Chromium to use to access the ML service.

1. Bootstrap
To connect to the daemon, Chromium prepares a Unix socket pair and sends
a Mojo invitation, including a primordial pipe handle, through the
socket. The file descriptor for the other end of the socket pair is
passed to the daemon as the argument of its BootstrapMojoConnection
D-Bus method. The daemon is expected to bind the primordial pipe to an
implementation of the MachineLearningService top-level Mojo interface.

The ML service daemon side of the above interaction is added in

2. Thin client library
This CL adds chromeos::machine_learning::ServiceConnection which client
code in Chromium can use to access the ML service. This singleton class
automatically performs D-Bus->Mojo bootstrap as necessary, and exposes
a method clients can use to bind a ModelProviderPtr mojo interface and
thereby access the ML service.

This CL also brings the .mojom files specifying the ML service Mojo
interface under public/mojom. Previously we intended to access these via
third_party/cros_system_api, but Chromium will instead maintain its own
copy of these mojoms, which will be manually eventually-consistent with
the Chrome OS copies (under src/platform2/ml). We are switching to this
recommended approach for the reasons discussed in the following doc:
A separate CL will remove the .mojoms under platform/system_api/mojo.


How to automatically test that Chromium + the daemon successfully
perform the D-Bus -> Mojo bootstrap is not clear and is under discussion
(comments welcome). It may have to wait until there is a client in
Chromium calling the daemon, which could then have an end-to-end

I manually tested this against a Chrome OS ML service built with by adding some test calls to BootstrapMojoConnection
initiated from chrome_browser_main_chromeos.

Bug: 836091, 836092, 836107
Change-Id: I3dbcaeb7a0af0bc09a56a98e68d9420cc1626d91
Reviewed-by: Ben Chan <>
Reviewed-by: Ken Rockot <>
Reviewed-by: Dan Erat <>
Commit-Queue: Andrew Moylan <>
Cr-Commit-Position: refs/heads/master@{#575193}
21 files changed