[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 ...
随机推荐
- 仿百度排列图片预览插件-Simple Lightbox
很久以前遇到过这样的一个面试题,要求手写代码,实现百度图片的排列预览,并且可以左右点击查看下一张照片,当时没有做出来,这个问题也就一直放在了脑后,工作之后,遇到这样的需求之后,第一反应想到的是在源码网 ...
- OpenResty.spec
Name: openresty Version: 1.13.6.1 Release: 2%{?dist} Summary: OpenResty, scalable web platform by ex ...
- OpenStack 与 大数据的融合
此处是hadoop 2.7.2以前 Hadoop 预留的一个 HDFS 文件系统的接口. 可以通过修改这里 将数据源的读取改为 Swift. 也可以通过修改 MR 源码 将数据抽取部分变换成 ...
- Effective C++ 11-17
11.为须要动态分配内存的类声明一个拷贝构造函数和一个赋值操作符. 显然,由于动态内存分配,绝对会有深浅拷贝的问题,要重写拷贝构造函数.使其为深拷贝,才干实现真正意义上的拷贝.这是我理解的关于要声明拷 ...
- Java IO(二) 之 InputStream
源代码均以JDK1.8作为參考 前言: InputStream实现了两个接口Closeable和AutoCloseable: Closeable:JDK1.5中引入,Closeable接口中仅仅有一个 ...
- HDOJ 5296 Annoying problem LCA+数据结构
dfs一遍得到每一个节点的dfs序,对于要插入的节点x分两种情况考虑: 1,假设x能够在集合中的某些点之间,找到左边和右边距离x近期的两个点,即DFS序小于x的DFS序最大点,和大于x的DFS序最小的 ...
- django admin显示多对多字段
参考文档https://jingyan.baidu.com/article/4e5b3e190f55c591901e24b3.html admin.py from .models import *cl ...
- QuerySet和对象的例子 个人记录
import osif __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE&quo ...
- python 同步IO
IO在计算机中指Input/Output 由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘.网络等,就需要IO接口.IO编程中,Stream(流)是一个很重要的概念,可以把流想象成一 ...
- CUDA笔记(十)
下午仔细研究了两个程序,然后搜了一下解决方法 http://blog.sina.com.cn/s/blog_6de28fbd01011cru.html http://blog.csdn.net/che ...