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

Unified Diff: mojo/edk/platform/platform_handle_watcher.h

Issue 1507903006: EDK: Remove mojo::platform::MessageLoopForIO and add PlatformHandleWatcher. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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
Index: mojo/edk/platform/platform_handle_watcher.h
diff --git a/mojo/edk/platform/platform_handle_watcher.h b/mojo/edk/platform/platform_handle_watcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..8d9cda07858a5292a8f81ef12d2e0cd668e067ed
--- /dev/null
+++ b/mojo/edk/platform/platform_handle_watcher.h
@@ -0,0 +1,67 @@
+// Copyright 2015 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.
+
+#ifndef MOJO_EDK_PLATFORM_PLATFORM_HANDLE_WATCHER_H_
+#define MOJO_EDK_PLATFORM_PLATFORM_HANDLE_WATCHER_H_
+
+#include <functional>
+#include <memory>
+
+#include "mojo/edk/platform/platform_handle.h"
+#include "mojo/public/cpp/system/macros.h"
+
+namespace mojo {
+namespace platform {
+
+// Interface for things that can watch |PlatformHandle|s to be readable/writable
+// without blocking. Typically, these are tied to a (particular) |MessageLoop|:
+// handles will only be watched while the loop is running and the lifetime of
+// the object is typically tied to the |MessageLoop|'s lifetime.
+class PlatformHandleWatcher {
+ public:
+ // Abstract "token" class returned by the |Watch()| (below). This object
+ // should be destroyed to cancel watching.
+ //
+ // Note: In theory, libevent (e.g.) can be used without a heap allocation on
+ // each "watch". However, in practice, including libevent's event.h pollutes
+ // the global namespace with |struct event|, which is very undesirable, so
+ // this is hidden via an indirection anyway. However, when using Chromium's
+ // |base::MessagePumpLibevent|, this leads to an extra indirection and yet
+ // another heap allocation.
+ class WatchToken {
+ public:
+ virtual ~WatchToken() {}
+
+ protected:
+ WatchToken() {}
+
+ private:
+ MOJO_DISALLOW_COPY_AND_ASSIGN(WatchToken);
+ };
+
+ ~PlatformHandleWatcher() {}
+
+ // Watches |platform_handle| to be readable and/or writable (without blocking)
+ // as indicated by the presence of |read_callback| and/or |write_callback| (at
+ // least one of which must have a valid target), respectively, at which point
+ // the respective callback will be called by the message loop. If |persistent|
+ // is true, the message loop will continue watching and calling the
+ // callback(s) as appropriate.
+ virtual std::unique_ptr<WatchToken> Watch(
+ PlatformHandle platform_handle,
+ bool persistent,
+ std::function<void()>&& read_callback,
+ std::function<void()>&& write_callback) = 0;
+
+ protected:
+ PlatformHandleWatcher() {}
+
+ private:
+ MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformHandleWatcher);
+};
+
+} // namespace platform
+} // namespace mojo
+
+#endif // MOJO_EDK_PLATFORM_PLATFORM_HANDLE_WATCHER_H_

Powered by Google App Engine
This is Rietveld 408576698