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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 #ifndef MOJO_EDK_PLATFORM_PLATFORM_HANDLE_WATCHER_H_
6 #define MOJO_EDK_PLATFORM_PLATFORM_HANDLE_WATCHER_H_
7
8 #include <functional>
9 #include <memory>
10
11 #include "mojo/edk/platform/platform_handle.h"
12 #include "mojo/public/cpp/system/macros.h"
13
14 namespace mojo {
15 namespace platform {
16
17 // Interface for things that can watch |PlatformHandle|s to be readable/writable
18 // without blocking. Typically, these are tied to a (particular) |MessageLoop|:
19 // handles will only be watched while the loop is running and the lifetime of
20 // the object is typically tied to the |MessageLoop|'s lifetime.
21 class PlatformHandleWatcher {
22 public:
23 // Abstract "token" class returned by the |Watch()| (below). This object
24 // should be destroyed to cancel watching.
25 //
26 // Note: In theory, libevent (e.g.) can be used without a heap allocation on
27 // each "watch". However, in practice, including libevent's event.h pollutes
28 // the global namespace with |struct event|, which is very undesirable, so
29 // this is hidden via an indirection anyway. However, when using Chromium's
30 // |base::MessagePumpLibevent|, this leads to an extra indirection and yet
31 // another heap allocation.
32 class WatchToken {
33 public:
34 virtual ~WatchToken() {}
35
36 protected:
37 WatchToken() {}
38
39 private:
40 MOJO_DISALLOW_COPY_AND_ASSIGN(WatchToken);
41 };
42
43 ~PlatformHandleWatcher() {}
44
45 // Watches |platform_handle| to be readable and/or writable (without blocking)
46 // as indicated by the presence of |read_callback| and/or |write_callback| (at
47 // least one of which must have a valid target), respectively, at which point
48 // the respective callback will be called by the message loop. If |persistent|
49 // is true, the message loop will continue watching and calling the
50 // callback(s) as appropriate.
51 virtual std::unique_ptr<WatchToken> Watch(
52 PlatformHandle platform_handle,
53 bool persistent,
54 std::function<void()>&& read_callback,
55 std::function<void()>&& write_callback) = 0;
56
57 protected:
58 PlatformHandleWatcher() {}
59
60 private:
61 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformHandleWatcher);
62 };
63
64 } // namespace platform
65 } // namespace mojo
66
67 #endif // MOJO_EDK_PLATFORM_PLATFORM_HANDLE_WATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698