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 // TODO(satorux): | 5 // TODO(satorux): |
6 // - Handle "disconnected" signal. | 6 // - Handle "disconnected" signal. |
7 | 7 |
8 #include "dbus/bus.h" | 8 #include "dbus/bus.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 return iter->second; | 228 return iter->second; |
229 } | 229 } |
230 | 230 |
231 scoped_refptr<ObjectProxy> object_proxy = | 231 scoped_refptr<ObjectProxy> object_proxy = |
232 new ObjectProxy(this, service_name, object_path, options); | 232 new ObjectProxy(this, service_name, object_path, options); |
233 object_proxy_table_[key] = object_proxy; | 233 object_proxy_table_[key] = object_proxy; |
234 | 234 |
235 return object_proxy.get(); | 235 return object_proxy.get(); |
236 } | 236 } |
237 | 237 |
| 238 bool Bus::RemoveObjectProxy(const std::string& service_name, |
| 239 const ObjectPath& object_path, |
| 240 const base::Closure& callback) { |
| 241 return RemoveObjectProxyWithOptions(service_name, object_path, |
| 242 ObjectProxy::DEFAULT_OPTIONS, |
| 243 callback); |
| 244 } |
| 245 |
| 246 bool Bus::RemoveObjectProxyWithOptions(const std::string& service_name, |
| 247 const dbus::ObjectPath& object_path, |
| 248 int options, |
| 249 const base::Closure& callback) { |
| 250 AssertOnOriginThread(); |
| 251 |
| 252 // Check if we have the requested object proxy. |
| 253 const ObjectProxyTable::key_type key(service_name + object_path.value(), |
| 254 options); |
| 255 ObjectProxyTable::iterator iter = object_proxy_table_.find(key); |
| 256 if (iter != object_proxy_table_.end()) { |
| 257 // Object is present. Remove it now and Detach in the DBus thread. |
| 258 PostTaskToDBusThread(FROM_HERE, base::Bind( |
| 259 &Bus::RemoveObjectProxyInternal, |
| 260 this, iter->second, callback)); |
| 261 |
| 262 object_proxy_table_.erase(iter); |
| 263 return true; |
| 264 } |
| 265 return false; |
| 266 } |
| 267 |
| 268 void Bus::RemoveObjectProxyInternal( |
| 269 scoped_refptr<dbus::ObjectProxy> object_proxy, |
| 270 const base::Closure& callback) { |
| 271 AssertOnDBusThread(); |
| 272 |
| 273 object_proxy.get()->Detach(); |
| 274 |
| 275 PostTaskToOriginThread(FROM_HERE, callback); |
| 276 } |
| 277 |
238 ExportedObject* Bus::GetExportedObject(const ObjectPath& object_path) { | 278 ExportedObject* Bus::GetExportedObject(const ObjectPath& object_path) { |
239 AssertOnOriginThread(); | 279 AssertOnOriginThread(); |
240 | 280 |
241 // Check if we already have the requested exported object. | 281 // Check if we already have the requested exported object. |
242 ExportedObjectTable::iterator iter = exported_object_table_.find(object_path); | 282 ExportedObjectTable::iterator iter = exported_object_table_.find(object_path); |
243 if (iter != exported_object_table_.end()) { | 283 if (iter != exported_object_table_.end()) { |
244 return iter->second; | 284 return iter->second; |
245 } | 285 } |
246 | 286 |
247 scoped_refptr<ExportedObject> exported_object = | 287 scoped_refptr<ExportedObject> exported_object = |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 443 |
404 void Bus::RequestOwnershipInternal(const std::string& service_name, | 444 void Bus::RequestOwnershipInternal(const std::string& service_name, |
405 OnOwnershipCallback on_ownership_callback) { | 445 OnOwnershipCallback on_ownership_callback) { |
406 AssertOnDBusThread(); | 446 AssertOnDBusThread(); |
407 | 447 |
408 bool success = Connect(); | 448 bool success = Connect(); |
409 if (success) | 449 if (success) |
410 success = RequestOwnershipAndBlock(service_name); | 450 success = RequestOwnershipAndBlock(service_name); |
411 | 451 |
412 PostTaskToOriginThread(FROM_HERE, | 452 PostTaskToOriginThread(FROM_HERE, |
413 base::Bind(&Bus::OnOwnership, | 453 base::Bind(on_ownership_callback, |
414 this, | |
415 on_ownership_callback, | |
416 service_name, | 454 service_name, |
417 success)); | 455 success)); |
418 } | 456 } |
419 | 457 |
420 void Bus::OnOwnership(OnOwnershipCallback on_ownership_callback, | |
421 const std::string& service_name, | |
422 bool success) { | |
423 AssertOnOriginThread(); | |
424 | |
425 on_ownership_callback.Run(service_name, success); | |
426 } | |
427 | |
428 bool Bus::RequestOwnershipAndBlock(const std::string& service_name) { | 458 bool Bus::RequestOwnershipAndBlock(const std::string& service_name) { |
429 DCHECK(connection_); | 459 DCHECK(connection_); |
430 // dbus_bus_request_name() is a blocking call. | 460 // dbus_bus_request_name() is a blocking call. |
431 AssertOnDBusThread(); | 461 AssertOnDBusThread(); |
432 | 462 |
433 // Check if we already own the service name. | 463 // Check if we already own the service name. |
434 if (owned_service_names_.find(service_name) != owned_service_names_.end()) { | 464 if (owned_service_names_.find(service_name) != owned_service_names_.end()) { |
435 return true; | 465 return true; |
436 } | 466 } |
437 | 467 |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 } | 873 } |
844 | 874 |
845 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, | 875 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, |
846 DBusDispatchStatus status, | 876 DBusDispatchStatus status, |
847 void* data) { | 877 void* data) { |
848 Bus* self = static_cast<Bus*>(data); | 878 Bus* self = static_cast<Bus*>(data); |
849 self->OnDispatchStatusChanged(connection, status); | 879 self->OnDispatchStatusChanged(connection, status); |
850 } | 880 } |
851 | 881 |
852 } // namespace dbus | 882 } // namespace dbus |
OLD | NEW |