voidDefaultMessagePump::Run(Delegate* delegate) { // Quit must have been called outside of Run! assert(should_quit_ == false);
for (;;) { // 任务态 bool did_work = delegate->DoWork(); if (should_quit_) break;
did_work |= delegate->DoDelayedWork(&delayed_work_time_); if (should_quit_) break;
if (did_work) continue;
// 空闲态 did_work = delegate->DoIdleWork(); if (should_quit_) break;
if (did_work) continue;
// 睡眠态 if (delayed_work_time_.is_null()) { Wait(); } else { TimeDelta delay = delayed_work_time_ - TimeTicks::Now(); if (delay > TimeDelta()) WaitTimeout(delay); else { // It looks like delayed_work_time_ indicates a time in the past, so we // need to call DoDelayedWork now. delayed_work_time_ = TimeTicks(); } } }