OLD | NEW |
1 # Mojo in Chromium | 1 # Mojo in Chromium |
2 | 2 |
3 This document is intended to serve as a Mojo primer for Chromium developers. No | 3 This document is intended to serve as a Mojo primer for Chromium developers. No |
4 prior knowledge of Mojo is assumed. | 4 prior knowledge of Mojo is assumed. |
5 | 5 |
6 [TOC] | 6 [TOC] |
7 | 7 |
8 ## Should I Bother Reading This? | 8 ## Should I Bother Reading This? |
9 | 9 |
10 If you're planning to build a Chromium feature that needs IPC and you aren't | 10 If you're planning to build a Chromium feature that needs IPC and you aren't |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 is likely to be the most common usage encountered by Chromium developers. | 42 is likely to be the most common usage encountered by Chromium developers. |
43 | 43 |
44 ### Message Pipes | 44 ### Message Pipes |
45 | 45 |
46 A message pipe is a lightweight primitive for reliable bidirectional transfer of | 46 A message pipe is a lightweight primitive for reliable bidirectional transfer of |
47 relatively small packets of data. Unsurprisingly a pipe has two endpoints, and | 47 relatively small packets of data. Unsurprisingly a pipe has two endpoints, and |
48 either endpoint may be transferred over another message pipe. | 48 either endpoint may be transferred over another message pipe. |
49 | 49 |
50 Because we bootstrap a primordial message pipe between the browser process and | 50 Because we bootstrap a primordial message pipe between the browser process and |
51 each child process, this in turn means that you can create a new pipe and | 51 each child process, this in turn means that you can create a new pipe and |
52 ultimately send either end to any any process, and the two ends will still be | 52 ultimately send either end to any process, and the two ends will still be |
53 able to talk to each other seamlessly and exclusively. Goodbye, routing IDs! | 53 able to talk to each other seamlessly and exclusively. Goodbye, routing IDs! |
54 | 54 |
55 While message pipes can carry arbitrary packets of unstructured data, we | 55 While message pipes can carry arbitrary packets of unstructured data we |
56 generally use them in conjunction with generated bindings to ensure a | 56 generally use them in conjunction with generated bindings to ensure a |
57 consistent, well-defined, versioned message structure on all endpoints. | 57 consistent, well-defined, versioned message structure on all endpoints. |
58 | 58 |
59 ### Mojom | 59 ### Mojom |
60 | 60 |
61 Mojom is the IDL for Mojo interfaces. Given a `.mojom` file, the bindings | 61 Mojom is the IDL for Mojo interfaces. Given a `.mojom` file, the bindings |
62 generator outputs bindings for all three of the currently supported languages. | 62 generator outputs bindings for all three of the currently supported languages. |
63 | 63 |
64 For example: | 64 For example: |
65 | 65 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 ``` | 171 ``` |
172 frob:mojom::FrobinatorPtr frobinator; | 172 frob:mojom::FrobinatorPtr frobinator; |
173 frob::FrobinatorImpl impl(GetProxy(&frobinator)); | 173 frob::FrobinatorImpl impl(GetProxy(&frobinator)); |
174 | 174 |
175 // Tada! | 175 // Tada! |
176 frobinator->Frobinate(); | 176 frobinator->Frobinate(); |
177 ``` | 177 ``` |
178 | 178 |
179 Behind the scenes this serializes a message corresponding to the `Frobinate` | 179 Behind the scenes this serializes a message corresponding to the `Frobinate` |
180 request and writes it to one end of the pipe. Eventually (and, incidentally, | 180 request and writes it to one end of the pipe. Eventually (and incidentally, |
181 very soon after), `impl`'s internal `mojo::Binding` will decode this message and | 181 very soon after), `impl`'s internal `mojo::Binding` will decode this message and |
182 dispatch a call to `impl.Frobinate()`. | 182 dispatch a call to `impl.Frobinate()`. |
183 | 183 |
184 ### Responding to Requests | 184 ### Responding to Requests |
185 | 185 |
186 A common idiom in Chromium IPC is to keep track of IPC requests with some kind | 186 A common idiom in Chromium IPC is to keep track of IPC requests with some kind |
187 of opaque identifier (i.e. an integer *request ID*) so that you can later | 187 of opaque identifier (i.e. an integer *request ID*) so that you can later |
188 respond to a specific request using some nominally related message in the other | 188 respond to a specific request using some nominally related message in the other |
189 direction. | 189 direction. |
190 | 190 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 329 |
330 This is a work in progress. TL;DR: We'll also soon begin using Mojo services | 330 This is a work in progress. TL;DR: We'll also soon begin using Mojo services |
331 from Blink so that the platform layer can consume browser services | 331 from Blink so that the platform layer can consume browser services |
332 directly via Mojo. The long-term goal there is to eliminate `content/renderer`. | 332 directly via Mojo. The long-term goal there is to eliminate `content/renderer`. |
333 | 333 |
334 ## Questions, Discussion, etc. | 334 ## Questions, Discussion, etc. |
335 | 335 |
336 A good place to find highly concentrated doses of people who know and care | 336 A good place to find highly concentrated doses of people who know and care |
337 about Mojo in Chromium would be the [chromium-mojo](https://goo.gl/A4ebWB) | 337 about Mojo in Chromium would be the [chromium-mojo](https://goo.gl/A4ebWB) |
338 mailing list[.](https://goo.gl/L70ihQ) | 338 mailing list[.](https://goo.gl/L70ihQ) |
OLD | NEW |