| 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..407c1dbead9acb2d4f5cc7bcf09e0ffb5581287d 100644
|
| --- a/base/message_pump_libevent.h
|
| +++ b/base/message_pump_io_ios.h
|
| @@ -1,27 +1,21 @@
|
| -// 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/memory/weak_ptr.h"
|
| -#include "base/message_pump.h"
|
| +#include "base/base_export.h"
|
| +#include "base/mac/scoped_cffiledescriptorref.h"
|
| +#include "base/mac/scoped_cftyperef.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,8 +32,6 @@ class BASE_EXPORT MessagePumpLibevent : public MessagePump {
|
| virtual ~IOObserver() {}
|
| };
|
|
|
| - class FileDescriptorWatcher;
|
| -
|
| // Used with WatchFileDescriptor to asynchronously monitor the I/O readiness
|
| // of a file descriptor.
|
| class Watcher {
|
| @@ -67,28 +59,30 @@ class BASE_EXPORT MessagePumpLibevent : public MessagePump {
|
| bool StopWatchingFileDescriptor();
|
|
|
| private:
|
| - friend class MessagePumpLibevent;
|
| - friend class MessagePumpLibeventTest;
|
| + friend class MessagePumpIOSForIO;
|
| + friend class MessagePumpIOSForIOTest;
|
|
|
| - // Called by MessagePumpLibevent, ownership of |e| is transferred to this
|
| - // object.
|
| - void Init(event* e);
|
| + // 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);
|
|
|
| - // Used by MessagePumpLibevent to take ownership of event_.
|
| - event* ReleaseEvent();
|
| -
|
| - 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_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher);
|
| };
|
| @@ -99,7 +93,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 +106,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_
|
|
|