| 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/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 dbus_timeout_set_data(raw_timeout_, this, NULL); | 116 dbus_timeout_set_data(raw_timeout_, this, NULL); |
| 117 AddRef(); // Balanced on Complete(). | 117 AddRef(); // Balanced on Complete(). |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Returns true if the timeout is ready to be monitored. | 120 // Returns true if the timeout is ready to be monitored. |
| 121 bool IsReadyToBeMonitored() { | 121 bool IsReadyToBeMonitored() { |
| 122 return dbus_timeout_get_enabled(raw_timeout_); | 122 return dbus_timeout_get_enabled(raw_timeout_); |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Starts monitoring the timeout. | 125 // Starts monitoring the timeout. |
| 126 void StartMonitoring(dbus::Bus* bus) { | 126 void StartMonitoring(Bus* bus) { |
| 127 bus->PostDelayedTaskToDBusThread(FROM_HERE, | 127 bus->PostDelayedTaskToDBusThread(FROM_HERE, |
| 128 base::Bind(&Timeout::HandleTimeout, | 128 base::Bind(&Timeout::HandleTimeout, |
| 129 this), | 129 this), |
| 130 GetInterval()); | 130 GetInterval()); |
| 131 monitoring_is_active_ = true; | 131 monitoring_is_active_ = true; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Stops monitoring the timeout. | 134 // Stops monitoring the timeout. |
| 135 void StopMonitoring() { | 135 void StopMonitoring() { |
| 136 // We cannot take back the delayed task we posted in | 136 // We cannot take back the delayed task we posted in |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 // DCHECK_EQ(0, num_pending_timeouts_); | 220 // DCHECK_EQ(0, num_pending_timeouts_); |
| 221 } | 221 } |
| 222 | 222 |
| 223 ObjectProxy* Bus::GetObjectProxy(const std::string& service_name, | 223 ObjectProxy* Bus::GetObjectProxy(const std::string& service_name, |
| 224 const ObjectPath& object_path) { | 224 const ObjectPath& object_path) { |
| 225 return GetObjectProxyWithOptions(service_name, object_path, | 225 return GetObjectProxyWithOptions(service_name, object_path, |
| 226 ObjectProxy::DEFAULT_OPTIONS); | 226 ObjectProxy::DEFAULT_OPTIONS); |
| 227 } | 227 } |
| 228 | 228 |
| 229 ObjectProxy* Bus::GetObjectProxyWithOptions(const std::string& service_name, | 229 ObjectProxy* Bus::GetObjectProxyWithOptions(const std::string& service_name, |
| 230 const dbus::ObjectPath& object_path, | 230 const ObjectPath& object_path, |
| 231 int options) { | 231 int options) { |
| 232 AssertOnOriginThread(); | 232 AssertOnOriginThread(); |
| 233 | 233 |
| 234 // Check if we already have the requested object proxy. | 234 // Check if we already have the requested object proxy. |
| 235 const ObjectProxyTable::key_type key(service_name + object_path.value(), | 235 const ObjectProxyTable::key_type key(service_name + object_path.value(), |
| 236 options); | 236 options); |
| 237 ObjectProxyTable::iterator iter = object_proxy_table_.find(key); | 237 ObjectProxyTable::iterator iter = object_proxy_table_.find(key); |
| 238 if (iter != object_proxy_table_.end()) { | 238 if (iter != object_proxy_table_.end()) { |
| 239 return iter->second.get(); | 239 return iter->second.get(); |
| 240 } | 240 } |
| 241 | 241 |
| 242 scoped_refptr<ObjectProxy> object_proxy = | 242 scoped_refptr<ObjectProxy> object_proxy = |
| 243 new ObjectProxy(this, service_name, object_path, options); | 243 new ObjectProxy(this, service_name, object_path, options); |
| 244 object_proxy_table_[key] = object_proxy; | 244 object_proxy_table_[key] = object_proxy; |
| 245 | 245 |
| 246 return object_proxy.get(); | 246 return object_proxy.get(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 bool Bus::RemoveObjectProxy(const std::string& service_name, | 249 bool Bus::RemoveObjectProxy(const std::string& service_name, |
| 250 const ObjectPath& object_path, | 250 const ObjectPath& object_path, |
| 251 const base::Closure& callback) { | 251 const base::Closure& callback) { |
| 252 return RemoveObjectProxyWithOptions(service_name, object_path, | 252 return RemoveObjectProxyWithOptions(service_name, object_path, |
| 253 ObjectProxy::DEFAULT_OPTIONS, | 253 ObjectProxy::DEFAULT_OPTIONS, |
| 254 callback); | 254 callback); |
| 255 } | 255 } |
| 256 | 256 |
| 257 bool Bus::RemoveObjectProxyWithOptions(const std::string& service_name, | 257 bool Bus::RemoveObjectProxyWithOptions(const std::string& service_name, |
| 258 const dbus::ObjectPath& object_path, | 258 const ObjectPath& object_path, |
| 259 int options, | 259 int options, |
| 260 const base::Closure& callback) { | 260 const base::Closure& callback) { |
| 261 AssertOnOriginThread(); | 261 AssertOnOriginThread(); |
| 262 | 262 |
| 263 // Check if we have the requested object proxy. | 263 // Check if we have the requested object proxy. |
| 264 const ObjectProxyTable::key_type key(service_name + object_path.value(), | 264 const ObjectProxyTable::key_type key(service_name + object_path.value(), |
| 265 options); | 265 options); |
| 266 ObjectProxyTable::iterator iter = object_proxy_table_.find(key); | 266 ObjectProxyTable::iterator iter = object_proxy_table_.find(key); |
| 267 if (iter != object_proxy_table_.end()) { | 267 if (iter != object_proxy_table_.end()) { |
| 268 // Object is present. Remove it now and Detach in the DBus thread. | 268 // Object is present. Remove it now and Detach in the DBus thread. |
| 269 PostTaskToDBusThread(FROM_HERE, base::Bind( | 269 PostTaskToDBusThread(FROM_HERE, base::Bind( |
| 270 &Bus::RemoveObjectProxyInternal, | 270 &Bus::RemoveObjectProxyInternal, |
| 271 this, iter->second, callback)); | 271 this, iter->second, callback)); |
| 272 | 272 |
| 273 object_proxy_table_.erase(iter); | 273 object_proxy_table_.erase(iter); |
| 274 return true; | 274 return true; |
| 275 } | 275 } |
| 276 return false; | 276 return false; |
| 277 } | 277 } |
| 278 | 278 |
| 279 void Bus::RemoveObjectProxyInternal( | 279 void Bus::RemoveObjectProxyInternal(scoped_refptr<ObjectProxy> object_proxy, |
| 280 scoped_refptr<dbus::ObjectProxy> object_proxy, | 280 const base::Closure& callback) { |
| 281 const base::Closure& callback) { | |
| 282 AssertOnDBusThread(); | 281 AssertOnDBusThread(); |
| 283 | 282 |
| 284 object_proxy.get()->Detach(); | 283 object_proxy.get()->Detach(); |
| 285 | 284 |
| 286 PostTaskToOriginThread(FROM_HERE, callback); | 285 PostTaskToOriginThread(FROM_HERE, callback); |
| 287 } | 286 } |
| 288 | 287 |
| 289 ExportedObject* Bus::GetExportedObject(const ObjectPath& object_path) { | 288 ExportedObject* Bus::GetExportedObject(const ObjectPath& object_path) { |
| 290 AssertOnOriginThread(); | 289 AssertOnOriginThread(); |
| 291 | 290 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 318 // Since the registration also happens on the D-Bus thread in | 317 // Since the registration also happens on the D-Bus thread in |
| 319 // TryRegisterObjectPath(), and the task runner we post to is a | 318 // TryRegisterObjectPath(), and the task runner we post to is a |
| 320 // SequencedTaskRunner, there is a guarantee that this will happen before any | 319 // SequencedTaskRunner, there is a guarantee that this will happen before any |
| 321 // future registration call. | 320 // future registration call. |
| 322 PostTaskToDBusThread(FROM_HERE, | 321 PostTaskToDBusThread(FROM_HERE, |
| 323 base::Bind(&Bus::UnregisterExportedObjectInternal, | 322 base::Bind(&Bus::UnregisterExportedObjectInternal, |
| 324 this, exported_object)); | 323 this, exported_object)); |
| 325 } | 324 } |
| 326 | 325 |
| 327 void Bus::UnregisterExportedObjectInternal( | 326 void Bus::UnregisterExportedObjectInternal( |
| 328 scoped_refptr<dbus::ExportedObject> exported_object) { | 327 scoped_refptr<ExportedObject> exported_object) { |
| 329 AssertOnDBusThread(); | 328 AssertOnDBusThread(); |
| 330 | 329 |
| 331 exported_object->Unregister(); | 330 exported_object->Unregister(); |
| 332 } | 331 } |
| 333 | 332 |
| 334 ObjectManager* Bus::GetObjectManager(const std::string& service_name, | 333 ObjectManager* Bus::GetObjectManager(const std::string& service_name, |
| 335 const ObjectPath& object_path) { | 334 const ObjectPath& object_path) { |
| 336 AssertOnOriginThread(); | 335 AssertOnOriginThread(); |
| 337 | 336 |
| 338 // Check if we already have the requested object manager. | 337 // Check if we already have the requested object manager. |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 // As mentioned at the class comment in .h file, connection_ can be NULL. | 774 // As mentioned at the class comment in .h file, connection_ can be NULL. |
| 776 if (!connection_) | 775 if (!connection_) |
| 777 return; | 776 return; |
| 778 | 777 |
| 779 // It is safe and necessary to call dbus_connection_get_dispatch_status even | 778 // It is safe and necessary to call dbus_connection_get_dispatch_status even |
| 780 // if the connection is lost. Otherwise we will miss "Disconnected" signal. | 779 // if the connection is lost. Otherwise we will miss "Disconnected" signal. |
| 781 // (crbug.com/174431) | 780 // (crbug.com/174431) |
| 782 if (dbus_connection_get_dispatch_status(connection_) == | 781 if (dbus_connection_get_dispatch_status(connection_) == |
| 783 DBUS_DISPATCH_DATA_REMAINS) { | 782 DBUS_DISPATCH_DATA_REMAINS) { |
| 784 while (dbus_connection_dispatch(connection_) == | 783 while (dbus_connection_dispatch(connection_) == |
| 785 DBUS_DISPATCH_DATA_REMAINS); | 784 DBUS_DISPATCH_DATA_REMAINS) { |
| 785 } |
| 786 } | 786 } |
| 787 } | 787 } |
| 788 | 788 |
| 789 void Bus::PostTaskToDBusThreadAndReply( | 789 void Bus::PostTaskToDBusThreadAndReply( |
| 790 const tracked_objects::Location& from_here, | 790 const tracked_objects::Location& from_here, |
| 791 const base::Closure& task, | 791 const base::Closure& task, |
| 792 const base::Closure& reply) { | 792 const base::Closure& reply) { |
| 793 AssertOnOriginThread(); | 793 AssertOnOriginThread(); |
| 794 | 794 |
| 795 if (dbus_task_runner_.get()) { | 795 if (dbus_task_runner_.get()) { |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 kNameOwnerChangedSignal)) { | 1224 kNameOwnerChangedSignal)) { |
| 1225 Bus* self = static_cast<Bus*>(data); | 1225 Bus* self = static_cast<Bus*>(data); |
| 1226 self->OnServiceOwnerChanged(message); | 1226 self->OnServiceOwnerChanged(message); |
| 1227 } | 1227 } |
| 1228 // Always return unhandled to let others, e.g. ObjectProxies, handle the same | 1228 // Always return unhandled to let others, e.g. ObjectProxies, handle the same |
| 1229 // signal. | 1229 // signal. |
| 1230 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 1230 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 1231 } | 1231 } |
| 1232 | 1232 |
| 1233 } // namespace dbus | 1233 } // namespace dbus |
| OLD | NEW |