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

Unified Diff: mojo/edk/system/watcher_set.cc

Issue 2750373002: Revert of Mojo: Armed Watchers (Closed)
Patch Set: Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/system/watcher_set.h ('k') | mojo/edk/system/watcher_unittest.cc » ('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
index 0355b58795f2287b1c845b06bf17ed530eaebaf0..878f29a54b2987b6bc956820aa7619777d0f33a7 100644
--- a/mojo/edk/system/watcher_set.cc
+++ b/mojo/edk/system/watcher_set.cc
@@ -4,79 +4,54 @@
#include "mojo/edk/system/watcher_set.h"
-#include <utility>
+#include "mojo/edk/system/request_context.h"
+#include "mojo/public/c/system/types.h"
namespace mojo {
namespace edk {
-WatcherSet::WatcherSet(Dispatcher* owner) : owner_(owner) {}
+WatcherSet::WatcherSet() {}
-WatcherSet::~WatcherSet() = default;
+WatcherSet::~WatcherSet() {}
-void WatcherSet::NotifyState(const HandleSignalsState& state) {
- // Avoid notifying watchers if they have already seen this state.
- if (last_known_state_.has_value() && state.equals(last_known_state_.value()))
- return;
- last_known_state_ = state;
+void WatcherSet::NotifyForStateChange(const HandleSignalsState& state) {
for (const auto& entry : watchers_)
- entry.first->NotifyHandleState(owner_, state);
+ entry.second->NotifyForStateChange(state);
}
void WatcherSet::NotifyClosed() {
for (const auto& entry : watchers_)
- entry.first->NotifyHandleClosed(owner_);
+ entry.second->NotifyClosed();
}
-MojoResult WatcherSet::Add(const scoped_refptr<WatcherDispatcher>& watcher,
+MojoResult WatcherSet::Add(MojoHandleSignals signals,
+ const Watcher::WatchCallback& callback,
uintptr_t context,
const HandleSignalsState& current_state) {
- auto it = watchers_.find(watcher.get());
- if (it == watchers_.end()) {
- auto result =
- watchers_.insert(std::make_pair(watcher.get(), Entry{watcher}));
- it = result.first;
- }
-
- if (!it->second.contexts.insert(context).second)
+ auto it = watchers_.find(context);
+ if (it != watchers_.end())
return MOJO_RESULT_ALREADY_EXISTS;
- if (last_known_state_.has_value() &&
- !current_state.equals(last_known_state_.value())) {
- // This new state may be relevant to everyone, in which case we just
- // notify everyone.
- NotifyState(current_state);
- } else {
- // Otherwise only notify the newly added Watcher.
- watcher->NotifyHandleState(owner_, current_state);
- }
- return MOJO_RESULT_OK;
-}
+ if (!current_state.can_satisfy(signals))
+ return MOJO_RESULT_FAILED_PRECONDITION;
-MojoResult WatcherSet::Remove(WatcherDispatcher* watcher, uintptr_t context) {
- auto it = watchers_.find(watcher);
- if (it == watchers_.end())
- return MOJO_RESULT_NOT_FOUND;
+ scoped_refptr<Watcher> watcher(new Watcher(signals, callback));
+ watchers_.insert(std::make_pair(context, watcher));
- ContextSet& contexts = it->second.contexts;
- auto context_it = contexts.find(context);
- if (context_it == contexts.end())
- return MOJO_RESULT_NOT_FOUND;
-
- contexts.erase(context_it);
- if (contexts.empty())
- watchers_.erase(it);
+ watcher->NotifyForStateChange(current_state);
return MOJO_RESULT_OK;
}
-WatcherSet::Entry::Entry(const scoped_refptr<WatcherDispatcher>& dispatcher)
- : dispatcher(dispatcher) {}
+MojoResult WatcherSet::Remove(uintptr_t context) {
+ auto it = watchers_.find(context);
+ if (it == watchers_.end())
+ return MOJO_RESULT_INVALID_ARGUMENT;
-WatcherSet::Entry::Entry(Entry&& other) = default;
-
-WatcherSet::Entry::~Entry() = default;
-
-WatcherSet::Entry& WatcherSet::Entry::operator=(Entry&& other) = default;
+ 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/system/watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698