[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 ...
随机推荐
- Fragmen直接来回切换deno
思路: 第一步.建立一个activity.用来管理fragment. 第二步'获取fragmentManger 和fragmentTraction. private FragmentManager f ...
- swift学习笔记(五)构造过程
构造过程是为了使用某个类.结构体或枚举类型的实例而进行的准备过程.在构造过程中,对每一个属性进行了初始值预设和其它必要的准备和初始化工作. 与OC相比,swift的构造函数.不须要返回值.同一时候,在 ...
- light oj 1094 Farthest Nodes in a Tree(树的直径模板)
1094 - Farthest Nodes in a Tree problem=1094" style="color:rgb(79,107,114)"> probl ...
- Html学习(三) 分类学习
代码: <h1>这是一级分类吗</h1> <h2>这是二级分类吗</h2> <h3>这是三级分类吗 </h3> 效果: 介绍: ...
- angularjs 指令2
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- String slices
String slices A segment of a string is called a slice. Selecting a slice is similar selecting a char ...
- 泪奔,配好了bioconductor环境
最近因为极度忙,没有写总结.今天补一下总结. 今天完成关静最后给的大project这个作业来说,结合自己的研究方向是个让我纠结一周多的事.好在找到了对应的研究内容. R的书目前还是很多的.R我一开始觉 ...
- Android开发日志统一管理
在开发中,我们通常要对日志的输出做统一管理,下面就为大家推荐一个日志输出类,在开发阶段只需将DEBUG常量设为true,生产环境将DEBUG设为false即可控制日志的输出.啥都不说了,需要的朋友直接 ...
- mysql语句判断一天操作记录的个数
话说有一文章表article,存储文章的添加文章的时间是add_time字段,该字段为int(5)类型的,现需要查询今天添加的文章总数并且按照时间从大到小排序,则查询语句如下: 1 select ...
- [JSOI2007]文本生成器(AC自动机+DP)
题意 给你n个串.问有多少长度为m的串使得这n个串至少在其中出现过一次.输出答案膜10007意义下的结果. (n<=100,每个串的长度<=100) 题解 在AC自动机上跑DP. 用到一个 ...