| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_MESSAGE_PUMP_HANDLE_WATCHER_H_ | |
| 6 #define MOJO_MESSAGE_PUMP_HANDLE_WATCHER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/callback_forward.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/run_loop.h" | |
| 12 #include "third_party/mojo/src/mojo/public/cpp/system/core.h" | |
| 13 | |
| 14 namespace base { | |
| 15 class Thread; | |
| 16 } | |
| 17 | |
| 18 namespace mojo { | |
| 19 namespace common { | |
| 20 namespace test { | |
| 21 class HandleWatcherTest; | |
| 22 } | |
| 23 | |
| 24 // HandleWatcher is used to asynchronously wait on a handle and notify a Closure | |
| 25 // when the handle is ready, or the deadline has expired. | |
| 26 class HandleWatcher { | |
| 27 public: | |
| 28 HandleWatcher(); | |
| 29 | |
| 30 // The destructor implicitly stops listening. See Stop() for details. | |
| 31 ~HandleWatcher(); | |
| 32 | |
| 33 // Starts listening for |handle|. This implicitly invokes Stop(). In other | |
| 34 // words, Start() performs one asynchronous watch at a time. It is ok to call | |
| 35 // Start() multiple times, but it cancels any existing watches. |callback| is | |
| 36 // notified when the handle is ready, invalid or deadline has passed and is | |
| 37 // notified on the thread Start() was invoked on. If the current thread exits | |
| 38 // before the handle is ready, then |callback| is invoked with a result of | |
| 39 // MOJO_RESULT_ABORTED. | |
| 40 void Start(const Handle& handle, | |
| 41 MojoHandleSignals handle_signals, | |
| 42 MojoDeadline deadline, | |
| 43 const base::Callback<void(MojoResult)>& callback); | |
| 44 | |
| 45 // Stops listening. Does nothing if not in the process of listening. Blocks | |
| 46 // until no longer listening on the handle. | |
| 47 void Stop(); | |
| 48 | |
| 49 private: | |
| 50 class StateBase; | |
| 51 class SameThreadWatchingState; | |
| 52 class SecondaryThreadWatchingState; | |
| 53 | |
| 54 // If non-NULL Start() has been invoked. | |
| 55 scoped_ptr<StateBase> state_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(HandleWatcher); | |
| 58 }; | |
| 59 | |
| 60 } // namespace common | |
| 61 } // namespace mojo | |
| 62 | |
| 63 #endif // MOJO_MESSAGE_PUMP_HANDLE_WATCHER_H_ | |
| OLD | NEW |