Make RunLoop remove handle when a timeout is notified

BUG=None
TEST=Added to existing tests
R=sky

Review URL: https://codereview.chromium.org/126883002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243467 0039d316-1c4b-4281-b951-d872f2087c98
parent 1d801997
...@@ -92,6 +92,10 @@ void RunLoop::RemoveHandler(const Handle& handle) { ...@@ -92,6 +92,10 @@ void RunLoop::RemoveHandler(const Handle& handle) {
handler_data_.erase(handle); handler_data_.erase(handle);
} }
bool RunLoop::HasHandler(const Handle& handle) const {
return handler_data_.find(handle) != handler_data_.end();
}
void RunLoop::Run() { void RunLoop::Run() {
assert(current() == this); assert(current() == this);
// We don't currently support nesting. // We don't currently support nesting.
...@@ -154,6 +158,7 @@ void RunLoop::NotifyDeadlineExceeded() { ...@@ -154,6 +158,7 @@ void RunLoop::NotifyDeadlineExceeded() {
i->second.deadline < now && i->second.deadline < now &&
handler_data_.find(i->first) != handler_data_.end() && handler_data_.find(i->first) != handler_data_.end() &&
handler_data_[i->first].id == i->second.id) { handler_data_[i->first].id == i->second.id) {
handler_data_.erase(i->first);
i->second.handler->OnHandleError(i->first, MOJO_RESULT_DEADLINE_EXCEEDED); i->second.handler->OnHandleError(i->first, MOJO_RESULT_DEADLINE_EXCEEDED);
} }
} }
......
...@@ -37,6 +37,7 @@ class RunLoop { ...@@ -37,6 +37,7 @@ class RunLoop {
MojoWaitFlags wait_flags, MojoWaitFlags wait_flags,
MojoDeadline deadline); MojoDeadline deadline);
void RemoveHandler(const Handle& handle); void RemoveHandler(const Handle& handle);
bool HasHandler(const Handle& handle) const;
// Runs the loop servicing handles as they are ready. This returns when Quit() // Runs the loop servicing handles as they are ready. This returns when Quit()
// is invoked, or there no more handles. // is invoked, or there no more handles.
......
...@@ -105,6 +105,7 @@ TEST_F(RunLoopTest, HandleReady) { ...@@ -105,6 +105,7 @@ TEST_F(RunLoopTest, HandleReady) {
run_loop.Run(); run_loop.Run();
EXPECT_EQ(1, handler.ready_count()); EXPECT_EQ(1, handler.ready_count());
EXPECT_EQ(0, handler.error_count()); EXPECT_EQ(0, handler.error_count());
EXPECT_FALSE(run_loop.HasHandler(test_pipe.handle0.get()));
} }
class QuitOnReadyRunLoopHandler : public TestRunLoopHandler { class QuitOnReadyRunLoopHandler : public TestRunLoopHandler {
...@@ -140,6 +141,7 @@ TEST_F(RunLoopTest, QuitFromReady) { ...@@ -140,6 +141,7 @@ TEST_F(RunLoopTest, QuitFromReady) {
run_loop.Run(); run_loop.Run();
EXPECT_EQ(1, handler.ready_count()); EXPECT_EQ(1, handler.ready_count());
EXPECT_EQ(0, handler.error_count()); EXPECT_EQ(0, handler.error_count());
EXPECT_TRUE(run_loop.HasHandler(test_pipe.handle0.get()));
} }
class QuitOnErrorRunLoopHandler : public TestRunLoopHandler { class QuitOnErrorRunLoopHandler : public TestRunLoopHandler {
...@@ -175,6 +177,7 @@ TEST_F(RunLoopTest, QuitWhenDeadlineExpired) { ...@@ -175,6 +177,7 @@ TEST_F(RunLoopTest, QuitWhenDeadlineExpired) {
EXPECT_EQ(0, handler.ready_count()); EXPECT_EQ(0, handler.ready_count());
EXPECT_EQ(1, handler.error_count()); EXPECT_EQ(1, handler.error_count());
EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, handler.last_error_result()); EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, handler.last_error_result());
EXPECT_FALSE(run_loop.HasHandler(test_pipe.handle0.get()));
} }
TEST_F(RunLoopTest, Current) { TEST_F(RunLoopTest, Current) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment