chromium之message_pump_win之二
接下来分析 MessagePumpForUI上一篇分析MessagePumpWin,可以参考chromium之message_pump_win之一
根据对MessagePumpWin的分析,MessagePumpForUI肯定要继承MessagePumpWin,且实现三个接口
// MessagePump methods:virtual void ScheduleWork();virtual void ScheduleDelayedWork(const Time& delayed_work_time);virtual void DoRunLoop();
先看看介绍,有点长
//----------------------------------------------------------------------------- // MessagePumpForUI extends MessagePumpWin with methods that are particular to a // MessageLoop instantiated with TYPE_UI. // // MessagePumpForUI implements a "traditional" Windows message pump. It contains // a nearly infinite loop that peeks out messages, and then dispatches them. // Intermixed with those peeks are callouts to DoWork for pending tasks, and // DoDelayedWork for pending timers. When there are no events to be serviced, // this pump goes into a wait state. In most cases, this message pump handles // all processing. // // However, when a task, or windows event, invokes on the stack a native dialog // box or such, that window typically provides a bare bones (native?) message // pump. That bare-bones message pump generally supports little more than a // peek of the Windows message queue, followed by a dispatch of the peeked // message. MessageLoop extends that bare-bones message pump to also service // Tasks, at the cost of some complexity. // // The basic structure of the extension (refered to as a sub-pump) is that a // special message, kMsgHaveWork, is repeatedly injected into the Windows // Message queue. Each time the kMsgHaveWork message is peeked, checks are // made for an extended set of events, including the availability of Tasks to // run. // // After running a task, the special message kMsgHaveWork is again posted to // the Windows Message queue, ensuring a future time slice for processing a // future event. To prevent flooding the Windows Message queue, care is taken // to be sure that at most one kMsgHaveWork message is EVER pending in the // Window's Message queue. // // There are a few additional complexities in this system where, when there are // no Tasks to run, this otherwise infinite stream of messages which drives the // sub-pump is halted. The pump is automatically re-started when Tasks are // queued. // // A second complexity is that the presence of this stream of posted tasks may // prevent a bare-bones message pump from ever peeking a WM_PAINT or WM_TIMER. // Such paint and timer events always give priority to a posted message, such as // kMsgHaveWork messages. As a result, care is taken to do some peeking in // between the posting of each kMsgHaveWork message (i.e., after kMsgHaveWork // is peeked, and before a replacement kMsgHaveWork is posted). // // NOTE: Although it may seem odd that messages are used to start and stop this // flow (as opposed to signaling objects, etc.), it should be understood that // the native message pump will *only* respond to messages. As a result, it is // an excellent choice. It is also helpful that the starter messages that are // placed in the queue when new task arrive also awakens DoRunLoop. //
看不下去了,看代码把,
总共两个步骤:
1) have_work_ = 1;
2) 发送一个kMsgHaveWork消息,通知MessagePump 工作
void MessagePumpForUI::ScheduleWork() {if (InterlockedExchange(&have_work_, 1))return; // Someone else continued the pumping.// Make sure the MessagePump does some work for us.PostMessage(message_hwnd_, kMsgHaveWork, reinterpret_cast<WPARAM>(this), 0); }
接下来是ScheduleDelayedWork
SetTimer, https://msdn.microsoft.com/en-us/library/windows/desktop/ms644906(v=vs.85).aspx
SetTimer的精度是10ms,通过SetTimer来设置延时任务,SetTimer的第四个参数是NULL,定时到的时候,
系统会发一个WM_TIMER消息到消息队列
void MessagePumpForUI::ScheduleDelayedWork(const Time& delayed_work_time) {//// We would *like* to provide high resolution timers. Windows timers using// SetTimer() have a 10ms granularity. We have to use WM_TIMER as a wakeup// mechanism because the application can enter modal windows loops where it// is not running our MessageLoop; the only way to have our timers fire in// these cases is to post messages there.//// To provide sub-10ms timers, we process timers directly from our run loop.// For the common case, timers will be processed there as the run loop does// its normal work. However, we *also* set the system timer so that WM_TIMER// events fire. This mops up the case of timers not being able to work in// modal message loops. It is possible for the SetTimer to pop and have no// pending timers, because they could have already been processed by the// run loop itself.//// We use a single SetTimer corresponding to the timer that will expire// soonest. As new timers are created and destroyed, we update SetTimer.// Getting a spurrious SetTimer event firing is benign, as we'll just be// processing an empty timer queue.// delayed_work_time_ = delayed_work_time;int delay_msec = GetCurrentDelay();DCHECK(delay_msec >= 0);if (delay_msec < USER_TIMER_MINIMUM)delay_msec = USER_TIMER_MINIMUM;// Create a WM_TIMER event that will wake us up to check for any pending// timers (in case we are running within a nested, external sub-pump).SetTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this), delay_msec, NULL); }
最后一个需要实现的函数DoMainLoop
void MessagePumpForUI::DoRunLoop() {// IF this was just a simple PeekMessage() loop (servicing all possible work// queues), then Windows would try to achieve the following order according// to MSDN documentation about PeekMessage with no filter):// * Sent messages// * Posted messages// * Sent messages (again)// * WM_PAINT messages// * WM_TIMER messages//// Summary: none of the above classes is starved, and sent messages has twice// the chance of being processed (i.e., reduced service time).for (;;) {// If we do any work, we may create more messages etc., and more work may// possibly be waiting in another task group. When we (for example)// ProcessNextWindowsMessage(), there is a good chance there are still more// messages waiting. On the other hand, when any of these methods return// having done no work, then it is pretty unlikely that calling them again// quickly will find any work to do. Finally, if they all say they had no// work, then it is a good time to consider sleeping (waiting) for more// work.bool more_work_is_plausible = ProcessNextWindowsMessage();if (state_->should_quit)break;more_work_is_plausible |= state_->delegate->DoWork();if (state_->should_quit)break;more_work_is_plausible |=state_->delegate->DoDelayedWork(&delayed_work_time_);// If we did not process any delayed work, then we can assume that our// existing WM_TIMER if any will fire when delayed work should run. We// don't want to disturb that timer if it is already in flight. However,// if we did do all remaining delayed work, then lets kill the WM_TIMER.if (more_work_is_plausible && delayed_work_time_.is_null())KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this));if (state_->should_quit)break;if (more_work_is_plausible)continue;more_work_is_plausible = state_->delegate->DoIdleWork();if (state_->should_quit)break;if (more_work_is_plausible)continue;WaitForWork(); // Wait (sleep) until we have work to do again. } }
转载于:https://www.cnblogs.com/ckelsel/p/9218412.html
chromium之message_pump_win之二相关推荐
- “完全自主”的木兰编程语言回应:承认基于Python二次开发,向中科院致歉
晓查 发自 凹非寺 量子位 报道 | 公众号 QbitAI 国产编程语言"木兰"面对换皮质疑,现在公开回应.并道歉了. 就在近期,一家国内公司中科智芯声称开发了首个跨平台.兼容多种 ...
- 使用代理同步Chromium代码的心得(V2.0)
先参看 http://www.chromium.org/developers/how-tos/build-instructions-windows 非常坑爹,谷歌获取chromium源码的方式又变了! ...
- UC:我们是怎么做出 Chromium M35 内核浏览器
对于这次内核升级,我们花了很大的精力,也有很多感触.下面简单分享一下,希望与同行一起探讨. 为什么要基于Chromium做二次开发? 肯定会有很多人好奇,为什么国内的双核浏览器都是无一例外地基于 Ch ...
- python中科院_“完全自主”的木兰编程语言回应:承认基于Python二次开发,向中科院致歉...
晓查 发自 凹非寺 量子位 报道 | 公众号 QbitAI 国产编程语言"木兰"面对换皮质疑,现在公开回应.并道歉了. 就在近期,一家国内公司中科智芯声称开发了首个跨平台.兼容多种 ...
- 木兰编程语言python_“完全自主”的木兰编程语言回应:承认基于Python二次开发...
晓查 发自 凹非寺量子位 报道 | 公众号 QbitAI 国产编程语言"木兰"面对换皮质疑,现在公开回应.并道歉了. 就在近期,一家国内公司中科智芯声称开发了首个跨平台.兼容多种硬 ...
- 促使整个团队改善的首要驱动力一定来自技术领域
对于中国的技术团队来说,我坚信促使整个团队改善的首要驱动力一定来自技术领域,只有采用以技术领域为切入点逐步渗透到管理领域的方式,才更有可能让团队发生质的变化. 入职半年后的2013年6月份左 ...
- Python selenium chrome 环境配置
Python selenium chrome 环境配置一.参考文章:1. 记录一下python easy_install和pip安装地址和方法http://heipark.iteye.com/blog ...
- 2020最新的web前端体系和路线图,想学web前端又不知道从哪开始的快来瞧一瞧呀
web前端其实是相对于服务器语言是简单的,并且对于初学者是非常友好的,因为在前期学习能够看到很好的效果.但是他的路线 也就是学习体系不成熟,所以导致很多初学者不知道怎么学?下面我就讲讲web前端的体系 ...
- 谷歌chrome安卓版_Chrome+Android能摩擦出怎样的火花?Fyde OS深入体验笔记
前言 在前段时间奇客君发布一篇关于Fyde OS的安装教程之后,发现不少小伙伴对这个系统(或者说是对Chrome OS)还是有着浓厚的兴趣,这也激励着奇客君尽快把这篇详细的体验文章发出来.(拖了这么久 ...
最新文章
- POJ 3458 Colour Sequence(简单题)
- 铁打的Python连续3年第一,PHP跌出前十:IEEE Spectrum 2019编程语言排行榜出炉
- 【C / C++】关于数组太大在编译器不能运行问题
- 中国第三代半导体行业应用动态与十四五发展格局展望报告2022版
- java程序_Java程序员必备----Java命令大全
- Android 性能优化——之图片的优化
- 循环所有数据库执行脚本
- 【操作系统】实验 设计一个按优先权调度算法实现处理器调度的程序
- 免费python全套教程-0基础学python 全套教程送你参考
- Json-getJSON
- 西南科技大学OJ题 顺序表上数据的划分问题的实现1102
- 非常值得收藏的15个 Google 高级搜索技巧
- ansys通过扫掠(sweep)方法划分网格的方法
- 7805和78l05可以代换吗_7805引脚图稳压
- Python断言与isinstance()判断数据类型
- 【日常踩坑】修复 chrome 打不开微信或者部分第三方应用内链接
- Fatal error: init(coder:) has not been implemented in Swfit
- Linux 搭建NodeBB社区,搭建CAS登录认证平台,实现Nodebb接入企业CAS认证(一)
- MFC DLL 不能正确调用的问题 + AFX_MANAGE_STATE(AfxGetStaticModuleState());
- 5G推动下,XR的需求“爆发”会来自B端还是C端?
热门文章
- java 防御编程_用Java编程。实现两个人对决。有血量有防御。有攻击力
- linux tcp文件分包_畅谈linux下TCP(下)
- 使用idea创建项目并通过git上传到码云
- R语言线性回归预测网页流量
- 此设备不允许更改其写入高速缓存设置_优化SiT15xx驱动器设置32 kHz晶体输入低功耗MCU程序设计细节(一)...
- datetime数据类型_当pandas遇上数据类型问题
- 计算机学硕考研复试编程能力,苏州大学计算机学硕专业考研复试真题
- C语言:某班有N名同学,每个学生的信息包括学号、姓名、三门课的成绩,从键盘输入名学生的信息,打印出N名学生三门课的平均成绩,以及最高分学生的信息(包括学号,姓名,三门课的成绩,平均分)
- java se 6 mac_Mac OS X “打开xx软件, 你需要一个Java SE 6运行环境”问题解决
- 计算机逻辑运算进位,二进位数进行逻辑运算1010AND1001的运算结果