Chromium Code Reviews| 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 takes a pipe endpoint and does something with it. It's expected that you'll | 258 takes a pipe endpoint and does something with it. It's expected that you'll |
| 259 either bind it to a service implementation of some kind or you will close it, ef fectively rejecting the connection request. | 259 either bind it to a service implementation of some kind or you will close it, ef fectively rejecting the connection request. |
| 260 | 260 |
| 261 We can build a simple browser-side `FrobinatorImpl` service that has access to a | 261 We can build a simple browser-side `FrobinatorImpl` service that has access to a |
| 262 `BrowserContext` for any frame which connects to it: | 262 `BrowserContext` for any frame which connects to it: |
| 263 | 263 |
| 264 ``` | 264 ``` |
| 265 #include "base/macros.h" | 265 #include "base/macros.h" |
| 266 #include "components/frob/public/interfaces/frobinator.mojom.h" | 266 #include "components/frob/public/interfaces/frobinator.mojom.h" |
| 267 #include "content/public/browser/browser_context.h" | 267 #include "content/public/browser/browser_context.h" |
| 268 #inlcude "mojo/public/cpp/system/interface_request.h" | 268 #include "mojo/public/cpp/system/interface_request.h" |
| 269 #inlcude "mojo/public/cpp/system/message_pipe.h" | 269 #include "mojo/public/cpp/system/strong_binding.h" |
| 270 #inlcude "mojo/public/cpp/system/strong_binding.h" | |
| 271 | 270 |
| 272 namespace frob { | 271 namespace frob { |
| 273 | 272 |
| 274 class FrobinatorImpl : public mojom::Frobinator { | 273 class FrobinatorImpl : public mojom::Frobinator { |
| 275 public: | 274 public: |
| 276 FrobinatorImpl(content::BrowserContext* context, | 275 FrobinatorImpl(content::BrowserContext* context, |
| 277 mojo::InterfaceRequest<mojom::Frobinator> request) | 276 mojo::InterfaceRequest<mojom::Frobinator> request) |
| 278 : context_(context), binding_(this, std::move(request)) {} | 277 : context_(context), binding_(this, std::move(request)) {} |
| 279 ~FrobinatorImpl() override {} | 278 ~FrobinatorImpl() override {} |
| 280 | 279 |
| 281 // A factory function to use in conjunction with ServiceRegistry. | 280 // A factory function to use in conjunction with ServiceRegistry. |
| 282 static void Create(content::BrowserContext* context, | 281 static void Create(content::BrowserContext* context, |
| 283 mojo::InterfaceRequest<mojom::Frobinator> request) { | 282 mojo::InterfaceRequest<mojom::Frobinator> request) { |
|
Ken Rockot(use gerrit already)
2016/03/21 17:13:43
optional nit: We actually have an alias for reques
| |
| 284 // See comment below for why this doesn't leak. | 283 // See comment below for why this doesn't leak. |
| 285 new FrobinatorImpl(context, | 284 new FrobinatorImpl(context, std::move(request)); |
| 286 mojo::MakeRequest<mojom::Frobinator>(std::move(pipe))); | |
| 287 } | 285 } |
| 288 | 286 |
| 289 private: | 287 private: |
| 290 // mojom::Frobinator: | 288 // mojom::Frobinator: |
| 291 void Frobinate() override { /* ... */ } | 289 void Frobinate() override { /* ... */ } |
| 292 | 290 |
| 293 content::BrowserContext* context_; | 291 content::BrowserContext* context_; |
| 294 | 292 |
| 295 // A StrongBinding is just like a Binding, except that it takes ownership of | 293 // A StrongBinding is just like a Binding, except that it takes ownership of |
| 296 // its bound implementation and deletes itself (and the impl) if and when the | 294 // its bound implementation and deletes itself (and the impl) if and when the |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 | 332 |
| 335 This is a work in progress. TL;DR: We'll also soon begin using Mojo services | 333 This is a work in progress. TL;DR: We'll also soon begin using Mojo services |
| 336 from Blink so that the platform layer can consume browser services | 334 from Blink so that the platform layer can consume browser services |
| 337 directly via Mojo. The long-term goal there is to eliminate `content/renderer`. | 335 directly via Mojo. The long-term goal there is to eliminate `content/renderer`. |
| 338 | 336 |
| 339 ## Questions, Discussion, etc. | 337 ## Questions, Discussion, etc. |
| 340 | 338 |
| 341 A good place to find highly concentrated doses of people who know and care | 339 A good place to find highly concentrated doses of people who know and care |
| 342 about Mojo in Chromium would be the [chromium-mojo](https://goo.gl/A4ebWB) | 340 about Mojo in Chromium would be the [chromium-mojo](https://goo.gl/A4ebWB) |
| 343 mailing list[.](https://goo.gl/L70ihQ) | 341 mailing list[.](https://goo.gl/L70ihQ) |
| OLD | NEW |