first time use of mojo

13 views
Skip to first unread message

Laura Lucas Alday (xWF)

unread,
Sep 15, 2025, 1:23:44 PM (11 days ago) Sep 15
to chromium-mojo
Hello, I'm trying to follow the documentation here https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/mojo_and_services.md

After pasting 

 mojo::Remote<math::mojom::MathService> math_service =
   content::ServiceProcessHost::Launch<math::mojom::MathService>(
     content::ServiceProcessHost::Options().WithDisplayName("Math!").Pass());

in my code and trying to build, I get:

Error:  fatal error: 'chrome/services/math/public/mojom/math_service.mojom.h' file not found

How do I generate this file? thanks

Alex Gough

unread,
Sep 15, 2025, 1:27:12 PM (11 days ago) Sep 15
to chromium-mojo, Laura Lucas Alday (xWF)
Hello,

You'll need to ensure the .mojom file is in a build.gn mojom("")[0] or mojom_component() target that is a dep of the target that contains your .cc files.

Laura Lucas Alday (xWF)

unread,
Sep 17, 2025, 1:02:43 PM (9 days ago) Sep 17
to chromium-mojo, Alex Gough, Laura Lucas Alday (xWF)
I'm working on credential_provider, I don't quite understand what I need to do, where do I need to add it? and what do I need to add? in this case for the math example to work. I'm getting fatal error: 'chrome/services/math/public/mojom/math_service.mojom.h' file not found. Could you point at a BUILD file in credential_provider that is the right one? 

Alex Gough

unread,
Sep 17, 2025, 1:14:29 PM (9 days ago) Sep 17
to Laura Lucas Alday (xWF), chromium-mojo
This is probably easier to figure out if you can upload a CL with what you're trying already - or you can chat on the chromium slack's #mojo channel.

Joe Mason

unread,
Sep 19, 2025, 4:05:49 PM (7 days ago) Sep 19
to Laura Lucas Alday (xWF), chromium-mojo, Alex Gough
If you're following the example exactly , you created a math_service.mojom file in the .../chrome/services/math/public/mojom directory, not in .../chrome/credential_provider. If you actually put the file somewhere in the .../chrome/credential_provider, you need to change all the paths in the example to where you actually put math_services.mojom.

Assuming you put the example code in chrome/services/math, and you want to USE the services in .../chrome/credential_provider (using that code you pasted), there are two BUILD.gn files involved:


# src/chrome/services/math/public/mojom/BUILD.gn
import("//mojo/public/tools/bindings/mojom.gni")

mojom("mojom") {
  sources = [
    "math_service.mojom",
  ]
}

That defines a target called "//chrome/services/math/public/mojom:mojom" that generates math_service.mojom.h and some other files from math_service.mojom. (It can also just be "//chrome/services/math/public/mojom" for short, since the target name ":mojom" matches the directory name.)

And whatever .cc file you're putting that "math_service = ..." line in should be in a BUILD.gn file in credential_provider. For instance if you're adding it to chrome/credential_provider/test/gcp_setup_unittest.cc, I see that file in the "gcp_unittests" target of chrome/credential_provider/test/BUILD.gn. So you need to tell the build system that target now depends on "//chrome/services/math/public/mojom:mojom" to make sure it builds it first, by adding it to the "deps" list:

  deps = [
    "../extension:app_inventory",
    "../extension:common",
    ...
    "//chrome/common:version_header",
    "//chrome/services/math/public/mojom:mojom", <-- Add this.
    "//content/public/browser",

I see there's an existing gaia_credential_provider_win_hid.mojom in credential_provider which might be a better example. You can see the "mojom" target for it is defined in the BUILD.gn file in the same directory, and it's used in credential_provider_broker_win.h. The "gaiacp_lib" target in chrome/credential_provider/gaiacp/BUILD.gn contains credential_provider_broker_win.h and has //chrome/credential_provider/gaiacp/mojom as a depedendency.

--
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/dcf432ba-c525-43b8-8494-c793cda531a4n%40chromium.org.

Laura Lucas Alday (xWF)

unread,
Sep 19, 2025, 4:05:52 PM (7 days ago) Sep 19
to Joe Mason, chromium-mojo, Alex Gough
Very helpful, thanks! So If I want to use these methods declared in credential_provider from chrome, how should I do it? For example, I want to call OpenDevice implemented in credential_provider from a chrome process, do I need to add or change anything from chrome side?

Joe Mason

unread,
Sep 23, 2025, 11:02:11 AM (3 days ago) Sep 23
to lal...@xwf.google.com, chromium-mojo, Alex Gough
For anyone else who wants a more complete intro to Mojo than the docs, there's this Chrome University presentation:  https://youtu.be/ZdB5P88-w8s?si=iAqW0wEnSSwsCGJo

And this What's Up With Mojo? video is a deeper dive: https://www.youtube.com/watch?v=at_35qCGJPQ
Reply all
Reply to author
Forward
0 new messages