OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/common/handle_watcher.h" | 5 #include "mojo/common/handle_watcher.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 return base::Bind(&CallbackHelper::OnCallback, weak_factory_.GetWeakPtr()); | 71 return base::Bind(&CallbackHelper::OnCallback, weak_factory_.GetWeakPtr()); |
72 } | 72 } |
73 | 73 |
74 void Start(HandleWatcher* watcher, const MessagePipeHandle& handle) { | 74 void Start(HandleWatcher* watcher, const MessagePipeHandle& handle) { |
75 StartWithCallback(watcher, handle, GetCallback()); | 75 StartWithCallback(watcher, handle, GetCallback()); |
76 } | 76 } |
77 | 77 |
78 void StartWithCallback(HandleWatcher* watcher, | 78 void StartWithCallback(HandleWatcher* watcher, |
79 const MessagePipeHandle& handle, | 79 const MessagePipeHandle& handle, |
80 const base::Callback<void(MojoResult)>& callback) { | 80 const base::Callback<void(MojoResult)>& callback) { |
81 watcher->Start(handle, MOJO_WAIT_FLAG_READABLE, MOJO_DEADLINE_INDEFINITE, | 81 watcher->Start(handle, MOJO_HANDLE_SIGNAL_READABLE, |
82 callback); | 82 MOJO_DEADLINE_INDEFINITE, callback); |
83 } | 83 } |
84 | 84 |
85 private: | 85 private: |
86 void OnCallback(MojoResult result) { | 86 void OnCallback(MojoResult result) { |
87 got_callback_ = true; | 87 got_callback_ = true; |
88 if (run_loop_) | 88 if (run_loop_) |
89 run_loop_->Quit(); | 89 run_loop_->Quit(); |
90 } | 90 } |
91 | 91 |
92 // Set to true when the callback is called. | 92 // Set to true when the callback is called. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // Add a watcher with an infinite timeout. | 272 // Add a watcher with an infinite timeout. |
273 HandleWatcher watcher1; | 273 HandleWatcher watcher1; |
274 callback_helper1.Start(&watcher1, test_pipe1.handle0.get()); | 274 callback_helper1.Start(&watcher1, test_pipe1.handle0.get()); |
275 RunUntilIdle(); | 275 RunUntilIdle(); |
276 EXPECT_FALSE(callback_helper1.got_callback()); | 276 EXPECT_FALSE(callback_helper1.got_callback()); |
277 EXPECT_FALSE(callback_helper2.got_callback()); | 277 EXPECT_FALSE(callback_helper2.got_callback()); |
278 EXPECT_FALSE(callback_helper3.got_callback()); | 278 EXPECT_FALSE(callback_helper3.got_callback()); |
279 | 279 |
280 // Add another watcher wth a timeout of 500 microseconds. | 280 // Add another watcher wth a timeout of 500 microseconds. |
281 HandleWatcher watcher2; | 281 HandleWatcher watcher2; |
282 watcher2.Start(test_pipe2.handle0.get(), MOJO_WAIT_FLAG_READABLE, 500, | 282 watcher2.Start(test_pipe2.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, 500, |
283 callback_helper2.GetCallback()); | 283 callback_helper2.GetCallback()); |
284 RunUntilIdle(); | 284 RunUntilIdle(); |
285 EXPECT_FALSE(callback_helper1.got_callback()); | 285 EXPECT_FALSE(callback_helper1.got_callback()); |
286 EXPECT_FALSE(callback_helper2.got_callback()); | 286 EXPECT_FALSE(callback_helper2.got_callback()); |
287 EXPECT_FALSE(callback_helper3.got_callback()); | 287 EXPECT_FALSE(callback_helper3.got_callback()); |
288 | 288 |
289 // Advance the clock passed the deadline. We also have to start another | 289 // Advance the clock passed the deadline. We also have to start another |
290 // watcher to wake up the background thread. | 290 // watcher to wake up the background thread. |
291 tick_clock_.Advance(base::TimeDelta::FromMicroseconds(501)); | 291 tick_clock_.Advance(base::TimeDelta::FromMicroseconds(501)); |
292 | 292 |
(...skipping 25 matching lines...) Expand all Loading... |
318 bool was_signaled = false; | 318 bool was_signaled = false; |
319 MojoResult result = MOJO_RESULT_OK; | 319 MojoResult result = MOJO_RESULT_OK; |
320 | 320 |
321 base::ShadowingAtExitManager at_exit; | 321 base::ShadowingAtExitManager at_exit; |
322 MessagePipe pipe; | 322 MessagePipe pipe; |
323 HandleWatcher watcher; | 323 HandleWatcher watcher; |
324 { | 324 { |
325 base::MessageLoop loop; | 325 base::MessageLoop loop; |
326 | 326 |
327 watcher.Start(pipe.handle0.get(), | 327 watcher.Start(pipe.handle0.get(), |
328 MOJO_WAIT_FLAG_READABLE, | 328 MOJO_HANDLE_SIGNAL_READABLE, |
329 MOJO_DEADLINE_INDEFINITE, | 329 MOJO_DEADLINE_INDEFINITE, |
330 base::Bind(&ObserveCallback, &was_signaled, &result)); | 330 base::Bind(&ObserveCallback, &was_signaled, &result)); |
331 | 331 |
332 // Now, let the MessageLoop get torn down. We expect our callback to run. | 332 // Now, let the MessageLoop get torn down. We expect our callback to run. |
333 } | 333 } |
334 | 334 |
335 EXPECT_TRUE(was_signaled); | 335 EXPECT_TRUE(was_signaled); |
336 EXPECT_EQ(MOJO_RESULT_ABORTED, result); | 336 EXPECT_EQ(MOJO_RESULT_ABORTED, result); |
337 } | 337 } |
338 | 338 |
339 } // namespace test | 339 } // namespace test |
340 } // namespace common | 340 } // namespace common |
341 } // namespace mojo | 341 } // namespace mojo |
OLD | NEW |