Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/edk/system/watcher.h" | |
| 6 | |
| 7 #include "mojo/edk/system/request_context.h" | |
| 8 | |
| 9 namespace mojo { | |
| 10 namespace edk { | |
| 11 | |
| 12 Watcher::Watcher(MojoHandleSignals signals, const WatchCallback& callback) | |
| 13 : signals_(signals), callback_(callback) { | |
| 14 } | |
| 15 | |
| 16 void Watcher::MaybeInvokeCallback(MojoResult result, | |
| 17 MojoHandleSignalsState state) { | |
| 18 base::AutoLock lock(lock_); | |
| 19 if (is_cancelled_) | |
| 20 return; | |
| 21 | |
| 22 callback_.Run(result, state); | |
| 23 } | |
| 24 | |
| 25 void Watcher::NotifyForStateChange(MojoHandleSignalsState signals_state) { | |
|
Anand Mistry (off Chromium)
2016/03/01 07:30:40
Can't you use mojo::HandleSignalsState here as wel
Ken Rockot(use gerrit already)
2016/03/01 08:17:44
Done here and everywhere else it's possible
| |
| 26 RequestContext* request_context = RequestContext::current(); | |
| 27 if (signals_state.satisfied_signals & signals_) { | |
| 28 request_context->AddWatchFinalizer( | |
| 29 make_scoped_refptr(this), MOJO_RESULT_OK, signals_state); | |
| 30 } else if (!(signals_state.satisfiable_signals & signals_)) { | |
| 31 request_context->AddWatchFinalizer(make_scoped_refptr(this), | |
| 32 MOJO_RESULT_FAILED_PRECONDITION, | |
| 33 signals_state); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 void Watcher::NotifyClosed() { | |
| 38 static const MojoHandleSignalsState closed_state = {0, 0}; | |
| 39 RequestContext::current()->AddWatchFinalizer( | |
| 40 make_scoped_refptr(this), MOJO_RESULT_CANCELLED, closed_state); | |
| 41 } | |
| 42 | |
| 43 void Watcher::Cancel() { | |
| 44 base::AutoLock lock(lock_); | |
| 45 is_cancelled_ = true; | |
| 46 } | |
| 47 | |
| 48 Watcher::~Watcher() {} | |
| 49 | |
| 50 } // namespace edk | |
| 51 } // namespace mojo | |
| OLD | NEW |