| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_EDK_SYSTEM_WATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_WATCHER_H_ |
| 6 #define MOJO_EDK_SYSTEM_WATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_WATCHER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // An event may occur at any time which should trigger a Watcher to run its | 22 // An event may occur at any time which should trigger a Watcher to run its |
| 23 // callback, but the callback needs to be deferred until all EDK locks are | 23 // callback, but the callback needs to be deferred until all EDK locks are |
| 24 // released. At the same time, a watch may be cancelled at any time by | 24 // released. At the same time, a watch may be cancelled at any time by |
| 25 // |MojoCancelWatch()| and it is not OK for the callback to be invoked after | 25 // |MojoCancelWatch()| and it is not OK for the callback to be invoked after |
| 26 // that happens. | 26 // that happens. |
| 27 // | 27 // |
| 28 // Therefore a Watcher needs to have some associated thread-safe state to track | 28 // Therefore a Watcher needs to have some associated thread-safe state to track |
| 29 // its cancellation, which is why it's ref-counted. | 29 // its cancellation, which is why it's ref-counted. |
| 30 class Watcher : public base::RefCountedThreadSafe<Watcher> { | 30 class Watcher : public base::RefCountedThreadSafe<Watcher> { |
| 31 public: | 31 public: |
| 32 using WatchCallback = | 32 using WatchCallback = base::Callback<void(MojoResult, |
| 33 base::Callback<void(MojoResult, const HandleSignalsState&)>; | 33 const HandleSignalsState&, |
| 34 MojoWatchNotificationFlags)>; |
| 34 | 35 |
| 35 // Constructs a new Watcher which watches for |signals| to be satisfied on a | 36 // Constructs a new Watcher which watches for |signals| to be satisfied on a |
| 36 // handle and which invokes |callback| either when one such signal is | 37 // handle and which invokes |callback| either when one such signal is |
| 37 // satisfied, or all such signals become unsatisfiable. | 38 // satisfied, or all such signals become unsatisfiable. |
| 38 Watcher(MojoHandleSignals signals, const WatchCallback& callback); | 39 Watcher(MojoHandleSignals signals, const WatchCallback& callback); |
| 39 | 40 |
| 40 // Runs the Watcher's callback with the given arguments if it hasn't been | 41 // Runs the Watcher's callback with the given arguments if it hasn't been |
| 41 // cancelled yet. | 42 // cancelled yet. |
| 42 void MaybeInvokeCallback(MojoResult result, const HandleSignalsState& state); | 43 void MaybeInvokeCallback(MojoResult result, |
| 44 const HandleSignalsState& state, |
| 45 MojoWatchNotificationFlags flags); |
| 43 | 46 |
| 44 // Notifies the Watcher of a state change. This may result in the Watcher | 47 // Notifies the Watcher of a state change. This may result in the Watcher |
| 45 // adding a finalizer to the current RequestContext to invoke its callback, | 48 // adding a finalizer to the current RequestContext to invoke its callback, |
| 46 // cancellation notwithstanding. | 49 // cancellation notwithstanding. |
| 47 void NotifyForStateChange(const HandleSignalsState& signals_state); | 50 void NotifyForStateChange(const HandleSignalsState& signals_state); |
| 48 | 51 |
| 49 // Notifies the Watcher of handle closure. This always results in the Watcher | 52 // Notifies the Watcher of handle closure. This always results in the Watcher |
| 50 // adding a finalizer to the current RequestContext to invoke its callback, | 53 // adding a finalizer to the current RequestContext to invoke its callback, |
| 51 // cancellation notwithstanding. | 54 // cancellation notwithstanding. |
| 52 void NotifyClosed(); | 55 void NotifyClosed(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 76 // hence this flag. | 79 // hence this flag. |
| 77 bool is_cancelled_ = false; | 80 bool is_cancelled_ = false; |
| 78 | 81 |
| 79 DISALLOW_COPY_AND_ASSIGN(Watcher); | 82 DISALLOW_COPY_AND_ASSIGN(Watcher); |
| 80 }; | 83 }; |
| 81 | 84 |
| 82 } // namespace edk | 85 } // namespace edk |
| 83 } // namespace mojo | 86 } // namespace mojo |
| 84 | 87 |
| 85 #endif // MOJO_EDK_SYSTEM_WATCHER_H_ | 88 #endif // MOJO_EDK_SYSTEM_WATCHER_H_ |
| OLD | NEW |