Index: dbus/bus.cc |
diff --git a/dbus/bus.cc b/dbus/bus.cc |
index a86971736f78e8d232fe43c0e9a28cbc4b6dfecf..673441656180686b4bd889a35011f68abcdc25a0 100644 |
--- a/dbus/bus.cc |
+++ b/dbus/bus.cc |
@@ -6,9 +6,11 @@ |
#include <stddef.h> |
+#include <memory> |
+ |
#include "base/bind.h" |
+#include "base/files/file_descriptor_watcher_posix.h" |
#include "base/logging.h" |
-#include "base/message_loop/message_loop.h" |
#include "base/stl_util.h" |
#include "base/strings/stringprintf.h" |
#include "base/threading/thread.h" |
@@ -42,14 +44,13 @@ const char kServiceNameOwnerChangeMatchRule[] = |
// The class is used for watching the file descriptor used for D-Bus |
// communication. |
-class Watch : public base::MessagePumpLibevent::Watcher { |
+class Watch { |
public: |
- explicit Watch(DBusWatch* watch) |
- : raw_watch_(watch), file_descriptor_watcher_(FROM_HERE) { |
+ explicit Watch(DBusWatch* watch) : raw_watch_(watch) { |
dbus_watch_set_data(raw_watch_, this, NULL); |
} |
- ~Watch() override { dbus_watch_set_data(raw_watch_, NULL, NULL); } |
+ ~Watch() { dbus_watch_set_data(raw_watch_, NULL, NULL); } |
// Returns true if the underlying file descriptor is ready to be watched. |
bool IsReadyToBeWatched() { |
@@ -61,42 +62,38 @@ class Watch : public base::MessagePumpLibevent::Watcher { |
const int file_descriptor = dbus_watch_get_unix_fd(raw_watch_); |
const int flags = dbus_watch_get_flags(raw_watch_); |
- base::MessageLoopForIO::Mode mode = base::MessageLoopForIO::WATCH_READ; |
- if ((flags & DBUS_WATCH_READABLE) && (flags & DBUS_WATCH_WRITABLE)) |
- mode = base::MessageLoopForIO::WATCH_READ_WRITE; |
- else if (flags & DBUS_WATCH_READABLE) |
- mode = base::MessageLoopForIO::WATCH_READ; |
- else if (flags & DBUS_WATCH_WRITABLE) |
- mode = base::MessageLoopForIO::WATCH_WRITE; |
- else |
- NOTREACHED(); |
- |
- const bool persistent = true; // Watch persistently. |
- const bool success = base::MessageLoopForIO::current()->WatchFileDescriptor( |
- file_descriptor, persistent, mode, &file_descriptor_watcher_, this); |
- CHECK(success) << "Unable to allocate memory"; |
+ if (flags & DBUS_WATCH_READABLE) { |
+ read_watcher_ = base::FileDescriptorWatcher::WatchReadable( |
+ file_descriptor, base::Bind(&Watch::OnFileCanReadWithoutBlocking, |
+ base::Unretained(this))); |
satorux1
2017/04/11 03:47:21
Is unretained safe here?
fdoray
2017/04/11 16:30:35
Added comment.
|
+ } |
+ if (flags & DBUS_WATCH_WRITABLE) { |
+ read_watcher_ = base::FileDescriptorWatcher::WatchReadable( |
satorux1
2017/04/11 03:47:21
WatchWritable?
Daniel Erat
2017/04/11 05:14:15
and this line should also assign to write_watcher_
fdoray
2017/04/11 16:30:35
oops... Done.
|
+ file_descriptor, base::Bind(&Watch::OnFileCanWriteWithoutBlocking, |
+ base::Unretained(this))); |
+ } |
} |
// Stops watching the underlying file descriptor. |
void StopWatching() { |
- file_descriptor_watcher_.StopWatchingFileDescriptor(); |
+ read_watcher_.reset(); |
+ write_watcher_.reset(); |
} |
private: |
- // Implement MessagePumpLibevent::Watcher. |
- void OnFileCanReadWithoutBlocking(int file_descriptor) override { |
+ void OnFileCanReadWithoutBlocking() { |
const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_READABLE); |
CHECK(success) << "Unable to allocate memory"; |
} |
- // Implement MessagePumpLibevent::Watcher. |
- void OnFileCanWriteWithoutBlocking(int file_descriptor) override { |
+ void OnFileCanWriteWithoutBlocking() { |
const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_WRITABLE); |
CHECK(success) << "Unable to allocate memory"; |
} |
DBusWatch* raw_watch_; |
- base::MessagePumpLibevent::FileDescriptorWatcher file_descriptor_watcher_; |
+ std::unique_ptr<base::FileDescriptorWatcher::Controller> read_watcher_; |
+ std::unique_ptr<base::FileDescriptorWatcher::Controller> write_watcher_; |
}; |
// The class is used for monitoring the timeout used for D-Bus method |