| 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 #ifndef MOJO_COMMON_HANDLE_WATCHER_H_ | 5 #ifndef MOJO_COMMON_HANDLE_WATCHER_H_ |
| 6 #define MOJO_COMMON_HANDLE_WATCHER_H_ | 6 #define MOJO_COMMON_HANDLE_WATCHER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // when the handle is ready, or the deadline has expired. | 26 // when the handle is ready, or the deadline has expired. |
| 27 class MOJO_COMMON_EXPORT HandleWatcher { | 27 class MOJO_COMMON_EXPORT HandleWatcher { |
| 28 public: | 28 public: |
| 29 HandleWatcher(); | 29 HandleWatcher(); |
| 30 ~HandleWatcher(); | 30 ~HandleWatcher(); |
| 31 | 31 |
| 32 // Starts listening for |handle|. This implicitly invokes Stop(). In other | 32 // Starts listening for |handle|. This implicitly invokes Stop(). In other |
| 33 // words, Start() performs one asynchronous watch at a time. It is ok to call | 33 // words, Start() performs one asynchronous watch at a time. It is ok to call |
| 34 // Start() multiple times, but it cancels any existing watches. |callback| is | 34 // Start() multiple times, but it cancels any existing watches. |callback| is |
| 35 // notified when the handle is ready, invalid or deadline has passed and is | 35 // notified when the handle is ready, invalid or deadline has passed and is |
| 36 // notified on the thread Start() was invoked on. | 36 // notified on the thread Start() was invoked on. If the current thread exits |
| 37 // before the handle is ready, then |callback| is invoked with a result of |
| 38 // MOJO_RESULT_ABORTED. |
| 37 void Start(const Handle& handle, | 39 void Start(const Handle& handle, |
| 38 MojoWaitFlags wait_flags, | 40 MojoWaitFlags wait_flags, |
| 39 MojoDeadline deadline, | 41 MojoDeadline deadline, |
| 40 const base::Callback<void(MojoResult)>& callback); | 42 const base::Callback<void(MojoResult)>& callback); |
| 41 | 43 |
| 42 // Stops listening. Does nothing if not in the process of listening. | 44 // Stops listening. Does nothing if not in the process of listening. |
| 43 void Stop(); | 45 void Stop(); |
| 44 | 46 |
| 45 private: | 47 private: |
| 46 struct StartState; | 48 struct State; |
| 47 | |
| 48 // See description of |StartState::weak_factory| for details. | |
| 49 void OnHandleReady(MojoResult result); | |
| 50 | 49 |
| 51 // If non-NULL Start() has been invoked. | 50 // If non-NULL Start() has been invoked. |
| 52 scoped_ptr<StartState> start_state_; | 51 scoped_ptr<State> state_; |
| 53 | 52 |
| 54 DISALLOW_COPY_AND_ASSIGN(HandleWatcher); | 53 DISALLOW_COPY_AND_ASSIGN(HandleWatcher); |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 } // namespace common | 56 } // namespace common |
| 58 } // namespace mojo | 57 } // namespace mojo |
| 59 | 58 |
| 60 #endif // MOJO_COMMON_HANDLE_WATCHER_H_ | 59 #endif // MOJO_COMMON_HANDLE_WATCHER_H_ |
| OLD | NEW |