[Chromium文档转载,第005章]Calling Mojo from Blink
Calling Mojo from Blink
VariantsLet's assume we have a mojom file such as this:
module example.mojom; interface Foo { SendData(string param1, array<int32> param2); }; Given the following GN mojom definition the compiler will generate two targets: example and example_blink
mojom("example") { sources = [ "example.mojom" ] } The target "example" will generate Chromium-style C++ bindings using STL types:
// example.mojom.h
class Example { The target "example_blink" will generate Blink-style C++ bindings using WTF types:
// example.mojom-blink.h
class Example { Thanks to these separate sets of bindings no work is necessary to convert types between Blink-style code and Chromium-style code. It is handled automatically during message serialization and deserialization.
Converting WTF::Function to base::Callback
Mojo methods that return a value take an instance of base::Callback. To solve this problem use WTF::convertToBaseCallback to turn a WTF::Function into a base::Callback that accepts the same arguments. Do not try to use base::Bind directly as it doesn't understand Oilpan. For example,
#include "wtf/Functional.h"
Mojo is not traced by Oilpan so one must be careful. If an interface pointer is owned by an managed object the message pipe will be closed during lazy sweeping. This means that messages may be received after the object has become unreachable and pointers to other managed objects are possibly invalid. To avoid this all managed objects bound with WTF::bind must be either Persistent or WeakPersistent references. This is done by wrapping pointers passed to WTF::bind with either wrapPersistent() or wrapWeakPersistent(this).
WeakPersistent references should be used to avoid cycles whenever a callback is expected to have the same lifetime as the object. The most common example of this is the this pointer bound to the callback passed to InterfacePtr::set_connection_error_callback.
Persistent references should be used at any other time when the interface pointer is owned by the bound object. This is because if no other reference to the object exists it will be garbage collected before the response is received, canceling the request. Only if this behavior is desired should a WeakPersistent be used instead.
If response callbacks are bound with wrapPersistent() then a connection error handler that closes the message pipe should be attached to the interface pointer. Otherwise callbacks will not be destroyed when the pipe is closed and the object will leak.
// m_service is a member of MyObject. This code should be run as soon as m_foo is bound to a message pipe. Implementing Mojo interfaces in Blink
Only a mojo::Binding or mojo::BindingSet should be used when implementing a Mojo interface in an Oilpan managed object. The object must then have a pre-finalizer to close any open pipes when the object is about to be swept as lazy sweeping means that it may be invalid long before the destructor is called. This requires setup in both the object header and implementation.
// MyObject.h
|
[Chromium文档转载,第005章]Calling Mojo from Blink的更多相关文章
- [Chromium文档转载,第002章]Mojo C++ Bindings API
Mojo C++ Bindings API This document is a subset of the Mojo documentation. Contents Overview Getting ...
- [Chromium文档转载,第001章] Mojo Migration Guide
For Developers > Design Documents > Mojo > Mojo Migration Guide 目录 1 Summary 2 H ...
- [Chromium文档转载,第003章]Proposal: Mojo Synchronous Methods
Proposal: Mojo Synchronous Methods yzshen@chromium.org 02/02/2016 Overview Currently there are quite ...
- [Chromium文档转载,第007章]JNI on Chromium for Android
Overview JNI (Java Native Interface) is the mechanism that enables Java code to call native function ...
- [Chromium文档转载,第006章]Chrome IPC To Mojo IPC Cheat Sheet
For Developers > Design Documents > Mojo > Chrome IPC To Mojo IPC Cheat Sheet 目录 1 O ...
- [Chromium文档转载,第004章]Mojo Synchronous Calls
For Developers > Design Documents > Mojo > Synchronous Calls Think carefully before ...
- 用R创建Word和PowerPoint文档--转载
https://www.jianshu.com/p/7df62865c3ed Rapp --简书 Microsoft的Office软件在办公软件领域占有绝对的主导地位,几乎每个职场人士都必须掌握Wor ...
- java实现支付宝接口--文档..转载
//实现java支付宝很简单,只要从支付宝官方下载 http://help.alipay.com/support/index_sh.htm下载程序,配置一下参数就OK了: 1.先到http:/ ...
- iOS开发主要参考文档(转载)
Objective-C,语言的系统详细资料.这是做iOS开发的前题与基础.https://developer.apple.com/library/ios/#documentation/Cocoa/Co ...
随机推荐
- 纯CSS实现小圆点和三角形图案
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 更改linux文件的拥有者及用户组(chown和chgrp)
.使用chown命令更改文件拥有者 在 shell 中,能够使用chown命令来改变文件全部者.chown命令是change owner(改变拥有者)的缩写.须要要注意的是,用户必须是已经存在系统中的 ...
- JAVA学习第四十五课 — 其它对象API(一)System、Runtime、Math类
一.System类 1. static long currentTimeMillis() 返回以毫秒为单位的当前时间. 实际上:当前时间与协调世界时 1970 年 1 月 1 日午夜之间的时间差(以毫 ...
- Minikube之Win10单机部署Kubernetes(k8s)自动化容器操作的开源平台
Minikube之Win10单机部署 Kubernetes(k8s)是自动化容器操作的开源平台,基于这个平台,你可以进行容器部署,资源调度和集群扩容等操作.如果你曾经用过Docker部署容器,那么可以 ...
- [学习笔记]HTTP协议
转自:www.cnblogs.com/li0803/archive/2008/11/03/1324746.html Author :Jeffrey 引言 HTTP是一个属于应用层的面向对象的协议,由于 ...
- Bayes++ Library入门学习之熟悉UKF相关类
UKF-SLAM是一种比较流行SLAM方案.相比EKF-SLAM,UKF利用unscented transform代替了EKF的线性化趋近,因而具有更高的精度.Bayes++库中的unsFlt.hpp ...
- BAPC 2014 Preliminary(第一场)
D:Lift Problems On the ground floor (floor zero) of a large university building a number of students ...
- Java调用Python遇到的一系列问题与解决方案
首先,百度了几个方法 1.用jython里的一个jar包,jython.jar,里面封装了一个专门调用Python的类, 但是不知道为什么我用Java一调用就报错,因此放弃. 2.用runtime ...
- php基础:implode()函数 和exlplode函数
1implode() 函数返回一个由数组元素组合成的字符串. 注释:implode() 函数接受两种参数顺序.但是由于历史原因,explode() 是不行的,您必须保证 separator 参数在 s ...
- 链表python
无序链表.有序链表 有序列表排序通常是升序或降序,并且我们假设列表项具有已经定义的有意义的比较运算. 许多有序列表操作与无序列表的操作相同. 必须明确链表的第一项位置,一旦知道第一项. 链表实现的基本 ...