| 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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/test/simple_test_tick_clock.h" | 10 #include "base/test/simple_test_tick_clock.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 // Runs the current MessageLoop until the callback returned from GetCallback() | 53 // Runs the current MessageLoop until the callback returned from GetCallback() |
| 54 // is notified. | 54 // is notified. |
| 55 void RunUntilGotCallback() { | 55 void RunUntilGotCallback() { |
| 56 ASSERT_TRUE(run_loop_ == NULL); | 56 ASSERT_TRUE(run_loop_ == NULL); |
| 57 base::RunLoop run_loop; | 57 base::RunLoop run_loop; |
| 58 base::AutoReset<base::RunLoop*> reseter(&run_loop_, &run_loop); | 58 base::AutoReset<base::RunLoop*> reseter(&run_loop_, &run_loop); |
| 59 run_loop.Run(); | 59 run_loop.Run(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 base::Closure GetCallback() { | 62 base::Callback<void(MojoResult)> GetCallback() { |
| 63 return base::Bind(&CallbackHelper::OnCallback, weak_factory_.GetWeakPtr()); | 63 return base::Bind(&CallbackHelper::OnCallback, weak_factory_.GetWeakPtr()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void Start(HandleWatcher* watcher, MojoHandle handle) { | 66 void Start(HandleWatcher* watcher, MojoHandle handle) { |
| 67 watcher->Start(handle, MOJO_WAIT_FLAG_READABLE, MOJO_DEADLINE_INDEFINITE, | 67 watcher->Start(handle, MOJO_WAIT_FLAG_READABLE, MOJO_DEADLINE_INDEFINITE, |
| 68 GetCallback()); | 68 GetCallback()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 void OnCallback() { | 72 void OnCallback(MojoResult result) { |
| 73 got_callback_ = true; | 73 got_callback_ = true; |
| 74 if (run_loop_) | 74 if (run_loop_) |
| 75 run_loop_->Quit(); | 75 run_loop_->Quit(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Set to true when the callback is called. | 78 // Set to true when the callback is called. |
| 79 bool got_callback_; | 79 bool got_callback_; |
| 80 | 80 |
| 81 // If non-NULL we're in RunUntilGotCallback(). | 81 // If non-NULL we're in RunUntilGotCallback(). |
| 82 base::RunLoop* run_loop_; | 82 base::RunLoop* run_loop_; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 callback_helper2.RunUntilGotCallback(); | 272 callback_helper2.RunUntilGotCallback(); |
| 273 EXPECT_FALSE(callback_helper1.got_callback()); | 273 EXPECT_FALSE(callback_helper1.got_callback()); |
| 274 EXPECT_TRUE(callback_helper2.got_callback()); | 274 EXPECT_TRUE(callback_helper2.got_callback()); |
| 275 EXPECT_FALSE(callback_helper3.got_callback()); | 275 EXPECT_FALSE(callback_helper3.got_callback()); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace test | 278 } // namespace test |
| 279 } // namespace common | 279 } // namespace common |
| 280 } // namespace mojo | 280 } // namespace mojo |
| OLD | NEW |