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

Unified Diff: base/message_pump_io_ios.h

Issue 11412101: Provide an iOS message pump for IO implementation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to review Created 8 years, 1 month 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: base/message_pump_io_ios.h
diff --git a/base/message_pump_libevent.h b/base/message_pump_io_ios.h
similarity index 48%
copy from base/message_pump_libevent.h
copy to base/message_pump_io_ios.h
index 7c689b91c6ae2cfaca20b71a6d77254f2ef60fdb..a7ca87f3c4d4b27fd62b32933dac0d6559acf9e8 100644
--- a/base/message_pump_libevent.h
+++ b/base/message_pump_io_ios.h
@@ -1,27 +1,22 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 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 BASE_MESSAGE_PUMP_LIBEVENT_H_
-#define BASE_MESSAGE_PUMP_LIBEVENT_H_
+#ifndef BASE_MESSAGE_PUMP_IO_IOS_H_
+#define BASE_MESSAGE_PUMP_IO_IOS_H_
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
+#include "base/base_export.h"
+#include "base/mac/scoped_cffiledescriptorref.h"
+#include "base/mac/scoped_cftyperef.h"
#include "base/memory/weak_ptr.h"
-#include "base/message_pump.h"
+#include "base/message_pump_mac.h"
#include "base/observer_list.h"
-#include "base/threading/thread_checker.h"
-#include "base/time.h"
-
-// Declare structs we need from libevent.h rather than including it
-struct event_base;
-struct event;
namespace base {
-// Class to monitor sockets and issue callbacks when sockets are ready for I/O
-// TODO(dkegel): add support for background file IO somehow
-class BASE_EXPORT MessagePumpLibevent : public MessagePump {
+// This file introduces a class to monitor sockets and issue callbacks when
+// sockets are ready for I/O on iOS.
+class BASE_EXPORT MessagePumpIOSForIO : public MessagePumpNSRunLoop {
public:
class IOObserver {
public:
@@ -38,19 +33,16 @@ class BASE_EXPORT MessagePumpLibevent : public MessagePump {
virtual ~IOObserver() {}
};
- class FileDescriptorWatcher;
-
- // Used with WatchFileDescriptor to asynchronously monitor the I/O readiness
- // of a file descriptor.
+ // Used with WatchFileDescptor to asynchronously monitor the I/O readiness of
+ // a File Descriptor.
class Watcher {
public:
+ virtual ~Watcher() {}
+
// Called from MessageLoop::Run when an FD can be read from/written to
// without blocking
virtual void OnFileCanReadWithoutBlocking(int fd) = 0;
virtual void OnFileCanWriteWithoutBlocking(int fd) = 0;
-
- protected:
- virtual ~Watcher() {}
};
// Object returned by WatchFileDescriptor to manage further watching.
@@ -67,26 +59,29 @@ class BASE_EXPORT MessagePumpLibevent : public MessagePump {
bool StopWatchingFileDescriptor();
private:
- friend class MessagePumpLibevent;
- friend class MessagePumpLibeventTest;
-
- // Called by MessagePumpLibevent, ownership of |e| is transferred to this
- // object.
- void Init(event* e);
+ friend class MessagePumpIOSForIO;
+ friend class MessagePumpIOSForIOTest;
- // Used by MessagePumpLibevent to take ownership of event_.
- event* ReleaseEvent();
+ // Called by MessagePumpIOSForIO, ownership of |fdref| and |fd_source|
+ // is transferred to this object.
+ void Init(CFFileDescriptorRef fdref,
+ CFOptionFlags callback_types,
+ CFRunLoopSourceRef fd_source,
+ bool is_persistent);
- void set_pump(MessagePumpLibevent* pump) { pump_ = pump; }
- MessagePumpLibevent* pump() { return pump_; }
+ void set_pump(MessagePumpIOSForIO* pump) { pump_ = pump; }
+ MessagePumpIOSForIO* pump() const { return pump_; }
void set_watcher(Watcher* watcher) { watcher_ = watcher; }
- void OnFileCanReadWithoutBlocking(int fd, MessagePumpLibevent* pump);
- void OnFileCanWriteWithoutBlocking(int fd, MessagePumpLibevent* pump);
+ void OnFileCanReadWithoutBlocking(int fd, MessagePumpIOSForIO* pump);
+ void OnFileCanWriteWithoutBlocking(int fd, MessagePumpIOSForIO* pump);
- event* event_;
- MessagePumpLibevent* pump_;
+ bool is_persistent_; // false if this event is one-shot.
+ base::mac::ScopedCFFileDescriptorRef fdref_;
+ CFOptionFlags callback_types_;
+ base::mac::ScopedCFTypeRef<CFRunLoopSourceRef> fd_source_;
+ MessagePumpIOSForIO* pump_;
Watcher* watcher_;
base::WeakPtrFactory<FileDescriptorWatcher> weak_factory_;
@@ -99,7 +94,7 @@ class BASE_EXPORT MessagePumpLibevent : public MessagePump {
WATCH_READ_WRITE = WATCH_READ | WATCH_WRITE
};
- MessagePumpLibevent();
+ MessagePumpIOSForIO();
// Have the current thread's message loop watch for a a situation in which
// reading/writing to the FD can be performed without blocking.
@@ -112,70 +107,36 @@ class BASE_EXPORT MessagePumpLibevent : public MessagePump {
// event previously attached to |controller| is aborted.
// Returns true on success.
// Must be called on the same thread the message_pump is running on.
- // TODO(dkegel): switch to edge-triggered readiness notification
bool WatchFileDescriptor(int fd,
bool persistent,
- Mode mode,
+ int mode,
FileDescriptorWatcher *controller,
Watcher *delegate);
+ void RemoveRunLoopSource(CFRunLoopSourceRef source);
+
void AddIOObserver(IOObserver* obs);
void RemoveIOObserver(IOObserver* obs);
- // MessagePump methods:
- virtual void Run(Delegate* delegate) OVERRIDE;
- virtual void Quit() OVERRIDE;
- virtual void ScheduleWork() OVERRIDE;
- virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE;
-
protected:
- virtual ~MessagePumpLibevent();
+ virtual ~MessagePumpIOSForIO();
private:
- friend class MessagePumpLibeventTest;
+ friend class MessagePumpIOSForIOTest;
void WillProcessIOEvent();
void DidProcessIOEvent();
- // Risky part of constructor. Returns true on success.
- bool Init();
-
- // Called by libevent to tell us a registered FD can be read/written to.
- static void OnLibeventNotification(int fd, short flags,
- void* context);
-
- // Unix pipe used to implement ScheduleWork()
- // ... callback; called by libevent inside Run() when pipe is ready to read
- static void OnWakeup(int socket, short flags, void* context);
-
- // This flag is set to false when Run should return.
- bool keep_running_;
-
- // This flag is set when inside Run.
- bool in_run_;
-
- // This flag is set if libevent has processed I/O events.
- bool processed_io_events_;
-
- // The time at which we should call DoDelayedWork.
- TimeTicks delayed_work_time_;
-
- // Libevent dispatcher. Watches all sockets registered with it, and sends
- // readiness callbacks when a socket is ready for I/O.
- event_base* event_base_;
-
- // ... write end; ScheduleWork() writes a single byte to it
- int wakeup_pipe_in_;
- // ... read end; OnWakeup reads it and then breaks Run() out of its sleep
- int wakeup_pipe_out_;
- // ... libevent wrapper for read end
- event* wakeup_event_;
+ static void HandleFdIOEvent(CFFileDescriptorRef fdref,
+ CFOptionFlags callback_types,
+ void* context);
ObserverList<IOObserver> io_observers_;
ThreadChecker watch_file_descriptor_caller_checker_;
- DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent);
+
+ DISALLOW_COPY_AND_ASSIGN(MessagePumpIOSForIO);
};
} // namespace base
-#endif // BASE_MESSAGE_PUMP_LIBEVENT_H_
+#endif // BASE_MESSAGE_PUMP_IO_IOS_H_
« no previous file with comments | « base/message_loop.cc ('k') | base/message_pump_io_ios.cc » ('j') | base/message_pump_io_ios.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698