diff options
-rw-r--r-- | remoting/jingle_glue/jingle_thread.cc | 18 | ||||
-rw-r--r-- | remoting/jingle_glue/jingle_thread_unittest.cc | 26 |
2 files changed, 37 insertions, 7 deletions
diff --git a/remoting/jingle_glue/jingle_thread.cc b/remoting/jingle_glue/jingle_thread.cc index 25f646a..b8bc428 100644 --- a/remoting/jingle_glue/jingle_thread.cc +++ b/remoting/jingle_glue/jingle_thread.cc @@ -42,12 +42,6 @@ class JingleThread::JingleMessagePump : public base::MessagePump, // TODO(sergeyu): Remove it when JingleThread moved on Chromium's // base::Thread. base::MessagePump::Delegate* delegate = thread_->message_loop(); - // Loop until we run out of work. - while (true) { - if (!delegate->DoWork()) - break; - } - // Process all pending tasks. while (true) { if (delegate->DoWork()) @@ -61,7 +55,6 @@ class JingleThread::JingleMessagePump : public base::MessagePump, } private: - void ScheduleNextDelayedTask() { DCHECK_EQ(thread_->message_loop(), MessageLoop::current()); @@ -86,6 +79,16 @@ class JingleThread::JingleMessageLoop : public MessageLoop { : MessageLoop(MessageLoop::TYPE_IO) { pump_ = new JingleMessagePump(thread); } + + void Initialize() { + jingle_message_loop_state_.reset(new AutoRunState(this)); + } + + private: + // AutoRunState sets |state_| for this message loop. It needs to be + // created here because we never call Run() or RunAllPending() for + // the thread. + scoped_ptr<AutoRunState> jingle_message_loop_state_; }; TaskPump::TaskPump() { @@ -119,6 +122,7 @@ void JingleThread::Start() { void JingleThread::Run() { JingleMessageLoop message_loop(this); + message_loop.Initialize(); message_loop_ = &message_loop; TaskPump task_pump; diff --git a/remoting/jingle_glue/jingle_thread_unittest.cc b/remoting/jingle_glue/jingle_thread_unittest.cc index bbaad79..e144727 100644 --- a/remoting/jingle_glue/jingle_thread_unittest.cc +++ b/remoting/jingle_glue/jingle_thread_unittest.cc @@ -33,6 +33,16 @@ TEST(JingleThreadTest, PostTask) { thread.Stop(); } +TEST(JingleThreadTest, PostNonNestableTask) { + JingleThread thread; + MockTask* task = new MockTask(); + EXPECT_CALL(*task, Run()); + + thread.Start(); + thread.message_loop()->PostNonNestableTask(FROM_HERE, task); + thread.Stop(); +} + ACTION_P(SignalEvent, event) { event->Signal(); } @@ -53,4 +63,20 @@ TEST(JingleThreadTest, PostDelayedTask) { EXPECT_GE((end - start).InMillisecondsRoundedUp(), kDelayMs); } +TEST(JingleThreadTest, PostNonNestableDelayedTask) { + JingleThread thread; + MockTask* task = new MockTask(); + base::WaitableEvent event(true, false); + EXPECT_CALL(*task, Run()).WillOnce(SignalEvent(&event)); + + thread.Start(); + base::Time start = base::Time::Now(); + thread.message_loop()->PostNonNestableDelayedTask(FROM_HERE, task, kDelayMs); + event.TimedWait(base::TimeDelta::FromMilliseconds(kDelayTimeoutMs)); + base::Time end = base::Time::Now(); + thread.Stop(); + + EXPECT_GE((end - start).InMillisecondsRoundedUp(), kDelayMs); +} + } // namespace remoting |