summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorppi <ppi@chromium.org>2015-01-27 04:25:00 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-27 12:26:16 +0000
commit5e9a3adac10fdf8d172de5aa0d7ec9a7bbb1e441 (patch)
tree07cedfbc36262211ab7e700905488508032aaeec
parent6359f67e1de919cf1fbc40f2e87881ab151e5766 (diff)
downloadchromium_src-5e9a3adac10fdf8d172de5aa0d7ec9a7bbb1e441.zip
chromium_src-5e9a3adac10fdf8d172de5aa0d7ec9a7bbb1e441.tar.gz
chromium_src-5e9a3adac10fdf8d172de5aa0d7ec9a7bbb1e441.tar.bz2
Fix handle_watcher when start is called twice on the same handle.
This carries over a fix by qsr@ for the mojo helper handle_watcher landed in the mojo repo in https://codereview.chromium.org/781753004. The fix allows the network service apptests not to crash when built against the Chromium copy of mojo/common. BUG=450356 Review URL: https://codereview.chromium.org/878513003 Cr-Commit-Position: refs/heads/master@{#313261}
-rw-r--r--mojo/common/handle_watcher.cc2
-rw-r--r--mojo/common/handle_watcher_unittest.cc16
2 files changed, 18 insertions, 0 deletions
diff --git a/mojo/common/handle_watcher.cc b/mojo/common/handle_watcher.cc
index 7819779..79cdcdb 100644
--- a/mojo/common/handle_watcher.cc
+++ b/mojo/common/handle_watcher.cc
@@ -459,6 +459,8 @@ void HandleWatcher::Start(const Handle& handle,
DCHECK(handle.is_valid());
DCHECK_NE(MOJO_HANDLE_SIGNAL_NONE, handle_signals);
+ // Need to clear the state before creating a new one.
+ state_.reset();
if (MessagePumpMojo::IsCurrent()) {
state_.reset(new SameThreadWatchingState(
this, handle, handle_signals, deadline, callback));
diff --git a/mojo/common/handle_watcher_unittest.cc b/mojo/common/handle_watcher_unittest.cc
index 3323421..41d5ffb 100644
--- a/mojo/common/handle_watcher_unittest.cc
+++ b/mojo/common/handle_watcher_unittest.cc
@@ -280,6 +280,22 @@ TEST_P(HandleWatcherTest, Restart) {
EXPECT_FALSE(callback_helper2.got_callback());
}
+// Verifies Start() invoked a second time on the same handle works.
+TEST_P(HandleWatcherTest, RestartOnSameHandle) {
+ MessagePipe test_pipe;
+ CallbackHelper callback_helper;
+ ASSERT_TRUE(test_pipe.handle0.is_valid());
+
+ HandleWatcher watcher;
+ callback_helper.Start(&watcher, test_pipe.handle0.get());
+ RunUntilIdle();
+ EXPECT_FALSE(callback_helper.got_callback());
+
+ callback_helper.Start(&watcher, test_pipe.handle0.get());
+ RunUntilIdle();
+ EXPECT_FALSE(callback_helper.got_callback());
+}
+
// Verifies deadline is honored.
TEST_P(HandleWatcherTest, Deadline) {
InstallTickClock();