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_PUBLIC_CPP_SYSTEM_WATCHER_H_ | 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_WATCHER_H_ |
6 #define MOJO_PUBLIC_CPP_SYSTEM_WATCHER_H_ | 6 #define MOJO_PUBLIC_CPP_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 30 matching lines...) Expand all Loading... |
41 using ReadyCallback = base::Callback<void(MojoResult result)>; | 41 using ReadyCallback = base::Callback<void(MojoResult result)>; |
42 | 42 |
43 // TODO(rockot/yzshen): Support giving Watcher an explicit TaskRunner for | 43 // TODO(rockot/yzshen): Support giving Watcher an explicit TaskRunner for |
44 // more fine-grained control over dispatch behavior. | 44 // more fine-grained control over dispatch behavior. |
45 Watcher(); | 45 Watcher(); |
46 | 46 |
47 // NOTE: This destructor automatically calls |Cancel()| if the Watcher is | 47 // NOTE: This destructor automatically calls |Cancel()| if the Watcher is |
48 // still active. | 48 // still active. |
49 ~Watcher(); | 49 ~Watcher(); |
50 | 50 |
| 51 // Allows the watcher to dispatch notifications synchronously if notified on |
| 52 // its own thread. This should be used with caution since it means watched |
| 53 // endpoints may reenter each other. |
| 54 void SetAllowSyncDispatch(bool allowed); |
| 55 |
51 // Indicates if the Watcher is currently watching a handle. | 56 // Indicates if the Watcher is currently watching a handle. |
52 bool IsWatching() const; | 57 bool IsWatching() const; |
53 | 58 |
54 // Starts watching |handle|. A Watcher may only watch one handle at a time, | 59 // Starts watching |handle|. A Watcher may only watch one handle at a time, |
55 // but it is safe to call this more than once as long as the previous watch | 60 // but it is safe to call this more than once as long as the previous watch |
56 // has been cancelled (i.e. |is_watching()| returns |false|.) | 61 // has been cancelled (i.e. |is_watching()| returns |false|.) |
57 // | 62 // |
58 // If no signals in |signals| can ever be satisfied for |handle|, this returns | 63 // If no signals in |signals| can ever be satisfied for |handle|, this returns |
59 // |MOJO_RESULT_FAILED_PRECONDITION|. | 64 // |MOJO_RESULT_FAILED_PRECONDITION|. |
60 // | 65 // |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 base::WeakPtr<Watcher> weak_self_; | 105 base::WeakPtr<Watcher> weak_self_; |
101 | 106 |
102 // Fields below must only be accessed on the Watcher's owning thread. | 107 // Fields below must only be accessed on the Watcher's owning thread. |
103 | 108 |
104 // The handle currently under watch. Not owned. | 109 // The handle currently under watch. Not owned. |
105 Handle handle_; | 110 Handle handle_; |
106 | 111 |
107 // The callback to call when the handle is signaled. | 112 // The callback to call when the handle is signaled. |
108 ReadyCallback callback_; | 113 ReadyCallback callback_; |
109 | 114 |
| 115 bool allow_sync_dispatch_ = false; |
| 116 |
110 base::WeakPtrFactory<Watcher> weak_factory_; | 117 base::WeakPtrFactory<Watcher> weak_factory_; |
111 | 118 |
112 DISALLOW_COPY_AND_ASSIGN(Watcher); | 119 DISALLOW_COPY_AND_ASSIGN(Watcher); |
113 }; | 120 }; |
114 | 121 |
115 } // namespace mojo | 122 } // namespace mojo |
116 | 123 |
117 #endif // MOJO_PUBLIC_CPP_SYSTEM_WATCHER_H_ | 124 #endif // MOJO_PUBLIC_CPP_SYSTEM_WATCHER_H_ |
OLD | NEW |