summaryrefslogtreecommitdiffstats
path: root/dbus/bus.cc
diff options
context:
space:
mode:
authorkeybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-10 01:12:52 +0000
committerkeybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-10 01:12:52 +0000
commit15e7b16ff24684e2678fe1b4964125b42a4c4018 (patch)
tree5f53e19b8a27e5af437e342d5464b110f4980a48 /dbus/bus.cc
parent093fcf536f77186f754119854ab729e68c31f784 (diff)
downloadchromium_src-15e7b16ff24684e2678fe1b4964125b42a4c4018.zip
chromium_src-15e7b16ff24684e2678fe1b4964125b42a4c4018.tar.gz
chromium_src-15e7b16ff24684e2678fe1b4964125b42a4c4018.tar.bz2
dbus: remove service name from ExportedObject
Well-known names in D-Bus are merely aliases to unique connection ids maintained by the bus, they have no purpose in qualifying object paths or interfaces and it's perfectly legimiate for a client to make requests to the unique connection id (e.g. in response to a signal, which does not reference the well-known name of the origin connection). Remove the service_name member from dbus::ExportedObject, from its constructor and from dbus::Bus::GetExportedObject and require code to call dbus::Bus::RequestOwnership if a well-known name is desired. This requires making that function callable from the origin thread with a callback for the return value. BUG=chromium-os:27101 TEST=dbus_unittests Change-Id: Ib91de8b68ad9c3b432e224a2c715f0c2ca1af463 Review URL: http://codereview.chromium.org/9668018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125970 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/bus.cc')
-rw-r--r--dbus/bus.cc45
1 files changed, 38 insertions, 7 deletions
diff --git a/dbus/bus.cc b/dbus/bus.cc
index 3b2f059..e391bc5 100644
--- a/dbus/bus.cc
+++ b/dbus/bus.cc
@@ -233,20 +233,18 @@ ObjectProxy* Bus::GetObjectProxyWithOptions(const std::string& service_name,
return object_proxy.get();
}
-ExportedObject* Bus::GetExportedObject(const std::string& service_name,
- const ObjectPath& object_path) {
+ExportedObject* Bus::GetExportedObject(const ObjectPath& object_path) {
AssertOnOriginThread();
// Check if we already have the requested exported object.
- const std::string key = service_name + object_path.value();
- ExportedObjectTable::iterator iter = exported_object_table_.find(key);
+ ExportedObjectTable::iterator iter = exported_object_table_.find(object_path);
if (iter != exported_object_table_.end()) {
return iter->second;
}
scoped_refptr<ExportedObject> exported_object =
- new ExportedObject(this, service_name, object_path);
- exported_object_table_[key] = exported_object;
+ new ExportedObject(this, object_path);
+ exported_object_table_[object_path] = exported_object;
return exported_object.get();
}
@@ -339,7 +337,40 @@ void Bus::ShutdownOnDBusThreadAndBlock() {
LOG_IF(ERROR, !signaled) << "Failed to shutdown the bus";
}
-bool Bus::RequestOwnership(const std::string& service_name) {
+void Bus::RequestOwnership(const std::string& service_name,
+ OnOwnershipCallback on_ownership_callback) {
+ AssertOnOriginThread();
+
+ PostTaskToDBusThread(FROM_HERE, base::Bind(
+ &Bus::RequestOwnershipInternal,
+ this, service_name, on_ownership_callback));
+}
+
+void Bus::RequestOwnershipInternal(const std::string& service_name,
+ OnOwnershipCallback on_ownership_callback) {
+ AssertOnDBusThread();
+
+ bool success = Connect();
+ if (success)
+ success = RequestOwnershipAndBlock(service_name);
+
+ PostTaskToOriginThread(FROM_HERE,
+ base::Bind(&Bus::OnOwnership,
+ this,
+ on_ownership_callback,
+ service_name,
+ success));
+}
+
+void Bus::OnOwnership(OnOwnershipCallback on_ownership_callback,
+ const std::string& service_name,
+ bool success) {
+ AssertOnOriginThread();
+
+ on_ownership_callback.Run(service_name, success);
+}
+
+bool Bus::RequestOwnershipAndBlock(const std::string& service_name) {
DCHECK(connection_);
// dbus_bus_request_name() is a blocking call.
AssertOnDBusThread();