summaryrefslogtreecommitdiffstats
path: root/base/message_pump_libevent.h
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 21:20:41 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 21:20:41 +0000
commit9cfb89a8002a2fc6b0ea3fd4eccb33b6f4dd464a (patch)
treed30b49f072edfbdb4c812a0b34dc825c936dccbf /base/message_pump_libevent.h
parent5d028b7b577d2efb96cd958ba4a7f1e5800fd9bb (diff)
downloadchromium_src-9cfb89a8002a2fc6b0ea3fd4eccb33b6f4dd464a.zip
chromium_src-9cfb89a8002a2fc6b0ea3fd4eccb33b6f4dd464a.tar.gz
chromium_src-9cfb89a8002a2fc6b0ea3fd4eccb33b6f4dd464a.tar.bz2
Reland r49188.
It was reverted due to breaking a valgrind test which has since been disabled. Review URL: http://codereview.chromium.org/2763004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49320 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_pump_libevent.h')
-rw-r--r--base/message_pump_libevent.h86
1 files changed, 60 insertions, 26 deletions
diff --git a/base/message_pump_libevent.h b/base/message_pump_libevent.h
index 8e2f77c..6516128 100644
--- a/base/message_pump_libevent.h
+++ b/base/message_pump_libevent.h
@@ -5,7 +5,9 @@
#ifndef BASE_MESSAGE_PUMP_LIBEVENT_H_
#define BASE_MESSAGE_PUMP_LIBEVENT_H_
+#include "base/basictypes.h"
#include "base/message_pump.h"
+#include "base/observer_list.h"
#include "base/time.h"
// Declare structs we need from libevent.h rather than including it
@@ -18,33 +20,19 @@ namespace base {
// TODO(dkegel): add support for background file IO somehow
class MessagePumpLibevent : public MessagePump {
public:
+ class IOObserver {
+ public:
+ IOObserver() {}
- // Object returned by WatchFileDescriptor to manage further watching.
- class FileDescriptorWatcher {
- public:
- FileDescriptorWatcher();
- ~FileDescriptorWatcher(); // Implicitly calls StopWatchingFileDescriptor.
-
- // NOTE: These methods aren't called StartWatching()/StopWatching() to
- // avoid confusion with the win32 ObjectWatcher class.
-
- // Stop watching the FD, always safe to call. No-op if there's nothing
- // to do.
- bool StopWatchingFileDescriptor();
-
- private:
- // Called by MessagePumpLibevent, ownership of |e| is transferred to this
- // object.
- void Init(event* e, bool is_persistent);
-
- // Used by MessagePumpLibevent to take ownership of event_.
- event *ReleaseEvent();
- friend class MessagePumpLibevent;
-
- private:
- bool is_persistent_; // false if this event is one-shot.
- event* event_;
- DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher);
+ // An IOObserver is an object that receives IO notifications from the
+ // MessagePump.
+ //
+ // NOTE: An IOObserver implementation should be extremely fast!
+ virtual void WillProcessIOEvent() = 0;
+ virtual void DidProcessIOEvent() = 0;
+
+ protected:
+ virtual ~IOObserver() {}
};
// Used with WatchFileDescptor to asynchronously monitor the I/O readiness of
@@ -58,6 +46,45 @@ class MessagePumpLibevent : public MessagePump {
virtual void OnFileCanWriteWithoutBlocking(int fd) = 0;
};
+ // Object returned by WatchFileDescriptor to manage further watching.
+ class FileDescriptorWatcher {
+ public:
+ FileDescriptorWatcher();
+ ~FileDescriptorWatcher(); // Implicitly calls StopWatchingFileDescriptor.
+
+ // NOTE: These methods aren't called StartWatching()/StopWatching() to
+ // avoid confusion with the win32 ObjectWatcher class.
+
+ // Stop watching the FD, always safe to call. No-op if there's nothing
+ // to do.
+ bool StopWatchingFileDescriptor();
+
+ private:
+ friend class MessagePumpLibevent;
+
+ // Called by MessagePumpLibevent, ownership of |e| is transferred to this
+ // object.
+ void Init(event* e, bool is_persistent);
+
+ // Used by MessagePumpLibevent to take ownership of event_.
+ event *ReleaseEvent();
+
+ void set_pump(MessagePumpLibevent* pump) { pump_ = pump; }
+ MessagePumpLibevent* pump() { return pump_; }
+
+ void set_watcher(Watcher* watcher) { watcher_ = watcher; }
+
+ void OnFileCanReadWithoutBlocking(int fd, MessagePumpLibevent* pump);
+ void OnFileCanWriteWithoutBlocking(int fd, MessagePumpLibevent* pump);
+
+ bool is_persistent_; // false if this event is one-shot.
+ event* event_;
+ MessagePumpLibevent* pump_;
+ Watcher* watcher_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher);
+ };
+
MessagePumpLibevent();
virtual ~MessagePumpLibevent();
@@ -84,6 +111,9 @@ class MessagePumpLibevent : public MessagePump {
FileDescriptorWatcher *controller,
Watcher *delegate);
+ void AddIOObserver(IOObserver* obs);
+ void RemoveIOObserver(IOObserver* obs);
+
// MessagePump methods:
virtual void Run(Delegate* delegate);
virtual void Quit();
@@ -91,6 +121,8 @@ class MessagePumpLibevent : public MessagePump {
virtual void ScheduleDelayedWork(const Time& delayed_work_time);
private:
+ void WillProcessIOEvent();
+ void DidProcessIOEvent();
// Risky part of constructor. Returns true on success.
bool Init();
@@ -122,6 +154,8 @@ class MessagePumpLibevent : public MessagePump {
// ... libevent wrapper for read end
event* wakeup_event_;
+ ObserverList<IOObserver> io_observers_;
+
DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent);
};