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

Side by Side Diff: mojo/edk/system/watcher_set.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_set.h ('k') | mojo/edk/test/mojo_test_base.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_set.h"
6
7 #include "mojo/edk/system/request_context.h"
8 #include "mojo/public/c/system/types.h"
9
10 namespace mojo {
11 namespace edk {
12
13 WatcherSet::WatcherSet() {}
14
15 WatcherSet::~WatcherSet() {}
16
17 void WatcherSet::NotifyForStateChange(const HandleSignalsState& state) {
18 for (const auto& entry : watchers_)
19 entry.second->NotifyForStateChange(state);
20 }
21
22 void WatcherSet::NotifyClosed() {
23 for (const auto& entry : watchers_)
24 entry.second->NotifyClosed();
25 }
26
27 MojoResult WatcherSet::Add(MojoHandleSignals signals,
28 const Watcher::WatchCallback& callback,
29 uintptr_t context,
30 const HandleSignalsState& current_state) {
31 auto it = watchers_.find(context);
32 if (it != watchers_.end())
33 return MOJO_RESULT_ALREADY_EXISTS;
34
35 if (!current_state.can_satisfy(signals))
36 return MOJO_RESULT_FAILED_PRECONDITION;
37
38 scoped_refptr<Watcher> watcher(new Watcher(signals, callback));
39 watchers_.insert(std::make_pair(context, watcher));
40
41 watcher->NotifyForStateChange(current_state);
42
43 return MOJO_RESULT_OK;
44 }
45
46 MojoResult WatcherSet::Remove(uintptr_t context) {
47 auto it = watchers_.find(context);
48 if (it == watchers_.end())
49 return MOJO_RESULT_INVALID_ARGUMENT;
50
51 RequestContext::current()->AddWatchCancelFinalizer(it->second);
52 watchers_.erase(it);
53 return MOJO_RESULT_OK;
54 }
55
56 } // namespace edk
57 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/watcher_set.h ('k') | mojo/edk/test/mojo_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698