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

Unified 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, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/watcher_set.cc
diff --git a/mojo/edk/system/watcher_set.cc b/mojo/edk/system/watcher_set.cc
new file mode 100644
index 0000000000000000000000000000000000000000..878f29a54b2987b6bc956820aa7619777d0f33a7
--- /dev/null
+++ b/mojo/edk/system/watcher_set.cc
@@ -0,0 +1,57 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/edk/system/watcher_set.h"
+
+#include "mojo/edk/system/request_context.h"
+#include "mojo/public/c/system/types.h"
+
+namespace mojo {
+namespace edk {
+
+WatcherSet::WatcherSet() {}
+
+WatcherSet::~WatcherSet() {}
+
+void WatcherSet::NotifyForStateChange(const HandleSignalsState& state) {
+ for (const auto& entry : watchers_)
+ entry.second->NotifyForStateChange(state);
+}
+
+void WatcherSet::NotifyClosed() {
+ for (const auto& entry : watchers_)
+ entry.second->NotifyClosed();
+}
+
+MojoResult WatcherSet::Add(MojoHandleSignals signals,
+ const Watcher::WatchCallback& callback,
+ uintptr_t context,
+ const HandleSignalsState& current_state) {
+ auto it = watchers_.find(context);
+ if (it != watchers_.end())
+ return MOJO_RESULT_ALREADY_EXISTS;
+
+ if (!current_state.can_satisfy(signals))
+ return MOJO_RESULT_FAILED_PRECONDITION;
+
+ scoped_refptr<Watcher> watcher(new Watcher(signals, callback));
+ watchers_.insert(std::make_pair(context, watcher));
+
+ watcher->NotifyForStateChange(current_state);
+
+ return MOJO_RESULT_OK;
+}
+
+MojoResult WatcherSet::Remove(uintptr_t context) {
+ auto it = watchers_.find(context);
+ if (it == watchers_.end())
+ return MOJO_RESULT_INVALID_ARGUMENT;
+
+ RequestContext::current()->AddWatchCancelFinalizer(it->second);
+ watchers_.erase(it);
+ return MOJO_RESULT_OK;
+}
+
+} // namespace edk
+} // namespace mojo
« 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