Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: mojo/edk/system/watcher.cc

Issue 1748503002: [mojo-edk] Add MojoWatch and MojoCancelWatch APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert RequestContext usage, nits Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/watcher.h ('k') | mojo/edk/system/watcher_set.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/handle_signals_state.h"
8 #include "mojo/edk/system/request_context.h"
9
10 namespace mojo {
11 namespace edk {
12
13 Watcher::Watcher(MojoHandleSignals signals, const WatchCallback& callback)
14 : signals_(signals), callback_(callback) {
15 }
16
17 void Watcher::MaybeInvokeCallback(MojoResult result,
18 const HandleSignalsState& state) {
19 base::AutoLock lock(lock_);
20 if (is_cancelled_)
21 return;
22
23 callback_.Run(result, state);
24 }
25
26 void Watcher::NotifyForStateChange(const HandleSignalsState& signals_state) {
27 RequestContext* request_context = RequestContext::current();
28 if (signals_state.satisfies(signals_)) {
29 request_context->AddWatchNotifyFinalizer(
30 make_scoped_refptr(this), MOJO_RESULT_OK, signals_state);
31 } else if (!signals_state.can_satisfy(signals_)) {
32 request_context->AddWatchNotifyFinalizer(make_scoped_refptr(this),
33 MOJO_RESULT_FAILED_PRECONDITION,
34 signals_state);
35 }
36 }
37
38 void Watcher::NotifyClosed() {
39 static const HandleSignalsState closed_state = {0, 0};
40 RequestContext::current()->AddWatchNotifyFinalizer(
41 make_scoped_refptr(this), MOJO_RESULT_CANCELLED, closed_state);
42 }
43
44 void Watcher::Cancel() {
45 base::AutoLock lock(lock_);
46 is_cancelled_ = true;
47 }
48
49 Watcher::~Watcher() {}
50
51 } // namespace edk
52 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/watcher.h ('k') | mojo/edk/system/watcher_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698