| Index: mojo/edk/base_edk/platform_message_loop_for_io_impl.cc
|
| diff --git a/mojo/edk/base_edk/platform_message_loop_for_io_impl.cc b/mojo/edk/base_edk/platform_message_loop_for_io_impl.cc
|
| index baea46e0c034a774de1accc4c5ba3120d527ea73..f1c36b173b64aac669d6da114411e639448da482 100644
|
| --- a/mojo/edk/base_edk/platform_message_loop_for_io_impl.cc
|
| +++ b/mojo/edk/base_edk/platform_message_loop_for_io_impl.cc
|
| @@ -6,14 +6,57 @@
|
|
|
| #include <utility>
|
|
|
| +#include "base/logging.h"
|
| +#include "base/macros.h"
|
| #include "mojo/edk/base_edk/platform_task_runner_impl.h"
|
| +#include "mojo/edk/util/make_unique.h"
|
|
|
| +using mojo::platform::PlatformHandle;
|
| +using mojo::platform::PlatformHandleWatcher;
|
| using mojo::platform::TaskRunner;
|
| using mojo::util::MakeRefCounted;
|
| +using mojo::util::MakeUnique;
|
| using mojo::util::RefPtr;
|
|
|
| namespace base_edk {
|
|
|
| +namespace {
|
| +
|
| +class WatchTokenImpl : public PlatformHandleWatcher::WatchToken,
|
| + public base::MessageLoopForIO::Watcher {
|
| + public:
|
| + WatchTokenImpl(std::function<void()>&& read_callback,
|
| + std::function<void()>&& write_callback)
|
| + : read_callback_(std::move(read_callback)),
|
| + write_callback_(std::move(write_callback)) {}
|
| + ~WatchTokenImpl() override {}
|
| +
|
| + base::MessageLoopForIO::FileDescriptorWatcher* base_fd_watcher() {
|
| + return &base_fd_watcher_;
|
| + }
|
| +
|
| + private:
|
| + // |base::MessageLoopForIO::Watcher| implementation:
|
| + void OnFileCanReadWithoutBlocking(int /*fd*/) override {
|
| + DCHECK(read_callback_);
|
| + read_callback_();
|
| + }
|
| +
|
| + void OnFileCanWriteWithoutBlocking(int /*fd*/) override {
|
| + DCHECK(write_callback_);
|
| + write_callback_();
|
| + }
|
| +
|
| + const std::function<void()> read_callback_;
|
| + const std::function<void()> write_callback_;
|
| +
|
| + base::MessageLoopForIO::FileDescriptorWatcher base_fd_watcher_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(WatchTokenImpl);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| PlatformMessageLoopForIOImpl::PlatformMessageLoopForIOImpl()
|
| : task_runner_(MakeRefCounted<PlatformTaskRunnerImpl>(
|
| base_message_loop_for_io_.task_runner())) {}
|
| @@ -45,4 +88,28 @@ bool PlatformMessageLoopForIOImpl::IsRunningOnCurrentThread() const {
|
| base_message_loop_for_io_.is_running();
|
| }
|
|
|
| +std::unique_ptr<PlatformHandleWatcher::WatchToken>
|
| +PlatformMessageLoopForIOImpl::Watch(PlatformHandle platform_handle,
|
| + bool persistent,
|
| + std::function<void()>&& read_callback,
|
| + std::function<void()>&& write_callback) {
|
| + DCHECK(platform_handle.is_valid());
|
| + DCHECK(read_callback || write_callback);
|
| +
|
| + base::MessageLoopForIO::Mode mode;
|
| + if (read_callback && write_callback) {
|
| + mode = base::MessageLoopForIO::WATCH_READ_WRITE;
|
| + } else if (read_callback) {
|
| + mode = base::MessageLoopForIO::WATCH_READ;
|
| + } else {
|
| + DCHECK(write_callback);
|
| + mode = base::MessageLoopForIO::WATCH_WRITE;
|
| + }
|
| + auto rv = MakeUnique<WatchTokenImpl>(std::move(read_callback),
|
| + std::move(write_callback));
|
| + CHECK(base_message_loop_for_io_.WatchFileDescriptor(
|
| + platform_handle.fd, persistent, mode, rv->base_fd_watcher(), rv.get()));
|
| + return std::move(rv);
|
| +}
|
| +
|
| } // namespace base_edk
|
|
|