summaryrefslogtreecommitdiffstats
path: root/mojo/public/utility
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-08 02:11:45 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-08 02:11:45 +0000
commit3d4fa3ff3a39b354027d23396be6150f3558c177 (patch)
treeb3cfd9a3e712f2b1af2d457cd89bd1bcc94dc599 /mojo/public/utility
parent1d801997a2e91f8c36bdaf31f9d2a006c8f3580c (diff)
downloadchromium_src-3d4fa3ff3a39b354027d23396be6150f3558c177.zip
chromium_src-3d4fa3ff3a39b354027d23396be6150f3558c177.tar.gz
chromium_src-3d4fa3ff3a39b354027d23396be6150f3558c177.tar.bz2
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
Diffstat (limited to 'mojo/public/utility')
-rw-r--r--mojo/public/utility/run_loop.cc5
-rw-r--r--mojo/public/utility/run_loop.h1
-rw-r--r--mojo/public/utility/run_loop_unittest.cc3
3 files changed, 9 insertions, 0 deletions
diff --git a/mojo/public/utility/run_loop.cc b/mojo/public/utility/run_loop.cc
index 5842188..bef601c 100644
--- a/mojo/public/utility/run_loop.cc
+++ b/mojo/public/utility/run_loop.cc
@@ -92,6 +92,10 @@ void RunLoop::RemoveHandler(const Handle& handle) {
handler_data_.erase(handle);
}
+bool RunLoop::HasHandler(const Handle& handle) const {
+ return handler_data_.find(handle) != handler_data_.end();
+}
+
void RunLoop::Run() {
assert(current() == this);
// We don't currently support nesting.
@@ -154,6 +158,7 @@ void RunLoop::NotifyDeadlineExceeded() {
i->second.deadline < now &&
handler_data_.find(i->first) != handler_data_.end() &&
handler_data_[i->first].id == i->second.id) {
+ handler_data_.erase(i->first);
i->second.handler->OnHandleError(i->first, MOJO_RESULT_DEADLINE_EXCEEDED);
}
}
diff --git a/mojo/public/utility/run_loop.h b/mojo/public/utility/run_loop.h
index 839d6de..a0c4d70 100644
--- a/mojo/public/utility/run_loop.h
+++ b/mojo/public/utility/run_loop.h
@@ -37,6 +37,7 @@ class RunLoop {
MojoWaitFlags wait_flags,
MojoDeadline deadline);
void RemoveHandler(const Handle& handle);
+ bool HasHandler(const Handle& handle) const;
// Runs the loop servicing handles as they are ready. This returns when Quit()
// is invoked, or there no more handles.
diff --git a/mojo/public/utility/run_loop_unittest.cc b/mojo/public/utility/run_loop_unittest.cc
index 0c0762d..2ca8c3e 100644
--- a/mojo/public/utility/run_loop_unittest.cc
+++ b/mojo/public/utility/run_loop_unittest.cc
@@ -105,6 +105,7 @@ TEST_F(RunLoopTest, HandleReady) {
run_loop.Run();
EXPECT_EQ(1, handler.ready_count());
EXPECT_EQ(0, handler.error_count());
+ EXPECT_FALSE(run_loop.HasHandler(test_pipe.handle0.get()));
}
class QuitOnReadyRunLoopHandler : public TestRunLoopHandler {
@@ -140,6 +141,7 @@ TEST_F(RunLoopTest, QuitFromReady) {
run_loop.Run();
EXPECT_EQ(1, handler.ready_count());
EXPECT_EQ(0, handler.error_count());
+ EXPECT_TRUE(run_loop.HasHandler(test_pipe.handle0.get()));
}
class QuitOnErrorRunLoopHandler : public TestRunLoopHandler {
@@ -175,6 +177,7 @@ TEST_F(RunLoopTest, QuitWhenDeadlineExpired) {
EXPECT_EQ(0, handler.ready_count());
EXPECT_EQ(1, handler.error_count());
EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, handler.last_error_result());
+ EXPECT_FALSE(run_loop.HasHandler(test_pipe.handle0.get()));
}
TEST_F(RunLoopTest, Current) {