Index: mojo/edk/system/watcher.cc |
diff --git a/mojo/edk/system/watcher.cc b/mojo/edk/system/watcher.cc |
index 25c227641efafc4f09081efbad8c037e15f99c1d..7853bd2183ca4cf3fa449b45e833bb8a18a7bd15 100644 |
--- a/mojo/edk/system/watcher.cc |
+++ b/mojo/edk/system/watcher.cc |
@@ -17,19 +17,21 @@ Watcher::Watcher(MojoHandleSignals signals, const WatchCallback& callback) |
void Watcher::MaybeInvokeCallback(MojoResult result, |
const HandleSignalsState& state, |
MojoWatchNotificationFlags flags) { |
- base::AutoLock lock(lock_); |
+ base::AutoLock lock(notification_lock_); |
if (is_cancelled_) |
return; |
callback_.Run(result, state, flags); |
} |
-void Watcher::NotifyForStateChange(const HandleSignalsState& signals_state) { |
+void Watcher::NotifyState(const HandleSignalsState& signals_state) { |
RequestContext* request_context = RequestContext::current(); |
- if (signals_state.satisfies(signals_)) { |
+ if (signals_state.satisfies(signals_) && is_armed_.Get()) { |
+ is_armed_.Set(false); |
request_context->AddWatchNotifyFinalizer( |
make_scoped_refptr(this), MOJO_RESULT_OK, signals_state); |
- } else if (!signals_state.can_satisfy(signals_)) { |
+ } else if (!signals_state.can_satisfy(signals_) && is_armed_.Get()) { |
+ is_armed_.Set(false); |
request_context->AddWatchNotifyFinalizer( |
make_scoped_refptr(this), MOJO_RESULT_FAILED_PRECONDITION, |
signals_state); |
@@ -42,8 +44,21 @@ void Watcher::NotifyClosed() { |
make_scoped_refptr(this), MOJO_RESULT_CANCELLED, closed_state); |
} |
+MojoResult Watcher::Arm(const HandleSignalsState& current_state) { |
+ if (is_armed_.Get()) |
+ return MOJO_RESULT_OK; |
+ |
+ if (current_state.satisfies(signals_)) |
+ return MOJO_RESULT_ALREADY_EXISTS; |
+ else if (!current_state.can_satisfy(signals_)) |
+ return MOJO_RESULT_FAILED_PRECONDITION; |
+ |
+ is_armed_.Set(true); |
+ return MOJO_RESULT_OK; |
+} |
+ |
void Watcher::Cancel() { |
- base::AutoLock lock(lock_); |
+ base::AutoLock lock(notification_lock_); |
is_cancelled_ = true; |
} |