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 #include "mojo/edk/system/watcher.h" | 5 #include "mojo/edk/system/watcher.h" |
6 | 6 |
7 #include "mojo/edk/system/handle_signals_state.h" | 7 #include "mojo/edk/system/handle_signals_state.h" |
8 #include "mojo/edk/system/request_context.h" | 8 #include "mojo/edk/system/request_context.h" |
9 | 9 |
10 namespace mojo { | 10 namespace mojo { |
11 namespace edk { | 11 namespace edk { |
12 | 12 |
13 Watcher::Watcher(MojoHandleSignals signals, const WatchCallback& callback) | 13 Watcher::Watcher(MojoHandleSignals signals, const WatchCallback& callback) |
14 : signals_(signals), callback_(callback) { | 14 : signals_(signals), callback_(callback) { |
15 } | 15 } |
16 | 16 |
17 void Watcher::MaybeInvokeCallback(MojoResult result, | 17 void Watcher::MaybeInvokeCallback(MojoResult result, |
18 const HandleSignalsState& state) { | 18 const HandleSignalsState& state, |
| 19 MojoWatchNotificationFlags flags) { |
19 base::AutoLock lock(lock_); | 20 base::AutoLock lock(lock_); |
20 if (is_cancelled_) | 21 if (is_cancelled_) |
21 return; | 22 return; |
22 | 23 |
23 callback_.Run(result, state); | 24 callback_.Run(result, state, flags); |
24 } | 25 } |
25 | 26 |
26 void Watcher::NotifyForStateChange(const HandleSignalsState& signals_state) { | 27 void Watcher::NotifyForStateChange(const HandleSignalsState& signals_state) { |
27 RequestContext* request_context = RequestContext::current(); | 28 RequestContext* request_context = RequestContext::current(); |
28 if (signals_state.satisfies(signals_)) { | 29 if (signals_state.satisfies(signals_)) { |
29 request_context->AddWatchNotifyFinalizer( | 30 request_context->AddWatchNotifyFinalizer( |
30 make_scoped_refptr(this), MOJO_RESULT_OK, signals_state); | 31 make_scoped_refptr(this), MOJO_RESULT_OK, signals_state); |
31 } else if (!signals_state.can_satisfy(signals_)) { | 32 } else if (!signals_state.can_satisfy(signals_)) { |
32 request_context->AddWatchNotifyFinalizer(make_scoped_refptr(this), | 33 request_context->AddWatchNotifyFinalizer( |
33 MOJO_RESULT_FAILED_PRECONDITION, | 34 make_scoped_refptr(this), MOJO_RESULT_FAILED_PRECONDITION, |
34 signals_state); | 35 signals_state); |
35 } | 36 } |
36 } | 37 } |
37 | 38 |
38 void Watcher::NotifyClosed() { | 39 void Watcher::NotifyClosed() { |
39 static const HandleSignalsState closed_state = {0, 0}; | 40 static const HandleSignalsState closed_state = {0, 0}; |
40 RequestContext::current()->AddWatchNotifyFinalizer( | 41 RequestContext::current()->AddWatchNotifyFinalizer( |
41 make_scoped_refptr(this), MOJO_RESULT_CANCELLED, closed_state); | 42 make_scoped_refptr(this), MOJO_RESULT_CANCELLED, closed_state); |
42 } | 43 } |
43 | 44 |
44 void Watcher::Cancel() { | 45 void Watcher::Cancel() { |
45 base::AutoLock lock(lock_); | 46 base::AutoLock lock(lock_); |
46 is_cancelled_ = true; | 47 is_cancelled_ = true; |
47 } | 48 } |
48 | 49 |
49 Watcher::~Watcher() {} | 50 Watcher::~Watcher() {} |
50 | 51 |
51 } // namespace edk | 52 } // namespace edk |
52 } // namespace mojo | 53 } // namespace mojo |
OLD | NEW |