| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "dbus/bus.h" | 5 #include "dbus/bus.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // Returns true if the underlying file descriptor is ready to be watched. | 43 // Returns true if the underlying file descriptor is ready to be watched. |
| 44 bool IsReadyToBeWatched() { | 44 bool IsReadyToBeWatched() { |
| 45 return dbus_watch_get_enabled(raw_watch_); | 45 return dbus_watch_get_enabled(raw_watch_); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Starts watching the underlying file descriptor. | 48 // Starts watching the underlying file descriptor. |
| 49 void StartWatching() { | 49 void StartWatching() { |
| 50 const int file_descriptor = dbus_watch_get_unix_fd(raw_watch_); | 50 const int file_descriptor = dbus_watch_get_unix_fd(raw_watch_); |
| 51 const int flags = dbus_watch_get_flags(raw_watch_); | 51 const int flags = dbus_watch_get_flags(raw_watch_); |
| 52 | 52 |
| 53 MessageLoopForIO::Mode mode = MessageLoopForIO::WATCH_READ; | 53 base::MessageLoopForIO::Mode mode = base::MessageLoopForIO::WATCH_READ; |
| 54 if ((flags & DBUS_WATCH_READABLE) && (flags & DBUS_WATCH_WRITABLE)) | 54 if ((flags & DBUS_WATCH_READABLE) && (flags & DBUS_WATCH_WRITABLE)) |
| 55 mode = MessageLoopForIO::WATCH_READ_WRITE; | 55 mode = base::MessageLoopForIO::WATCH_READ_WRITE; |
| 56 else if (flags & DBUS_WATCH_READABLE) | 56 else if (flags & DBUS_WATCH_READABLE) |
| 57 mode = MessageLoopForIO::WATCH_READ; | 57 mode = base::MessageLoopForIO::WATCH_READ; |
| 58 else if (flags & DBUS_WATCH_WRITABLE) | 58 else if (flags & DBUS_WATCH_WRITABLE) |
| 59 mode = MessageLoopForIO::WATCH_WRITE; | 59 mode = base::MessageLoopForIO::WATCH_WRITE; |
| 60 else | 60 else |
| 61 NOTREACHED(); | 61 NOTREACHED(); |
| 62 | 62 |
| 63 const bool persistent = true; // Watch persistently. | 63 const bool persistent = true; // Watch persistently. |
| 64 const bool success = MessageLoopForIO::current()->WatchFileDescriptor( | 64 const bool success = base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 65 file_descriptor, | 65 file_descriptor, persistent, mode, &file_descriptor_watcher_, this); |
| 66 persistent, | |
| 67 mode, | |
| 68 &file_descriptor_watcher_, | |
| 69 this); | |
| 70 CHECK(success) << "Unable to allocate memory"; | 66 CHECK(success) << "Unable to allocate memory"; |
| 71 } | 67 } |
| 72 | 68 |
| 73 // Stops watching the underlying file descriptor. | 69 // Stops watching the underlying file descriptor. |
| 74 void StopWatching() { | 70 void StopWatching() { |
| 75 file_descriptor_watcher_.StopWatchingFileDescriptor(); | 71 file_descriptor_watcher_.StopWatchingFileDescriptor(); |
| 76 } | 72 } |
| 77 | 73 |
| 78 private: | 74 private: |
| 79 // Implement MessagePumpLibevent::Watcher. | 75 // Implement MessagePumpLibevent::Watcher. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 async_operations_set_up_(false), | 185 async_operations_set_up_(false), |
| 190 shutdown_completed_(false), | 186 shutdown_completed_(false), |
| 191 num_pending_watches_(0), | 187 num_pending_watches_(0), |
| 192 num_pending_timeouts_(0), | 188 num_pending_timeouts_(0), |
| 193 address_(options.address), | 189 address_(options.address), |
| 194 on_disconnected_closure_(options.disconnected_callback) { | 190 on_disconnected_closure_(options.disconnected_callback) { |
| 195 // This is safe to call multiple times. | 191 // This is safe to call multiple times. |
| 196 dbus_threads_init_default(); | 192 dbus_threads_init_default(); |
| 197 // The origin message loop is unnecessary if the client uses synchronous | 193 // The origin message loop is unnecessary if the client uses synchronous |
| 198 // functions only. | 194 // functions only. |
| 199 if (MessageLoop::current()) | 195 if (base::MessageLoop::current()) |
| 200 origin_task_runner_ = MessageLoop::current()->message_loop_proxy(); | 196 origin_task_runner_ = base::MessageLoop::current()->message_loop_proxy(); |
| 201 } | 197 } |
| 202 | 198 |
| 203 Bus::~Bus() { | 199 Bus::~Bus() { |
| 204 DCHECK(!connection_); | 200 DCHECK(!connection_); |
| 205 DCHECK(owned_service_names_.empty()); | 201 DCHECK(owned_service_names_.empty()); |
| 206 DCHECK(match_rules_added_.empty()); | 202 DCHECK(match_rules_added_.empty()); |
| 207 DCHECK(filter_functions_added_.empty()); | 203 DCHECK(filter_functions_added_.empty()); |
| 208 DCHECK(registered_object_paths_.empty()); | 204 DCHECK(registered_object_paths_.empty()); |
| 209 DCHECK_EQ(0, num_pending_watches_); | 205 DCHECK_EQ(0, num_pending_watches_); |
| 210 // TODO(satorux): This check fails occasionally in browser_tests for tests | 206 // TODO(satorux): This check fails occasionally in browser_tests for tests |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 kDisconnectedSignal)) { | 970 kDisconnectedSignal)) { |
| 975 Bus* self = static_cast<Bus*>(data); | 971 Bus* self = static_cast<Bus*>(data); |
| 976 self->AssertOnDBusThread(); | 972 self->AssertOnDBusThread(); |
| 977 self->OnConnectionDisconnected(connection); | 973 self->OnConnectionDisconnected(connection); |
| 978 return DBUS_HANDLER_RESULT_HANDLED; | 974 return DBUS_HANDLER_RESULT_HANDLED; |
| 979 } | 975 } |
| 980 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 976 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 981 } | 977 } |
| 982 | 978 |
| 983 } // namespace dbus | 979 } // namespace dbus |
| OLD | NEW |