Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Unified Diff: dbus/bus.cc

Issue 14568005: Add a method to check if a D-Bus service has an owner. Use it for mtpd. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix cros compile Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/bus.h ('k') | dbus/object_proxy.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/bus.cc
===================================================================
--- dbus/bus.cc (revision 197465)
+++ dbus/bus.cc (working copy)
@@ -836,6 +836,64 @@
}
}
+std::string Bus::GetServiceOwnerAndBlock(const std::string& service_name,
+ GetServiceOwnerOption options) {
+ AssertOnDBusThread();
+
+ MethodCall get_name_owner_call("org.freedesktop.DBus", "GetNameOwner");
+ MessageWriter writer(&get_name_owner_call);
+ writer.AppendString(service_name);
+ VLOG(1) << "Method call: " << get_name_owner_call.ToString();
+
+ const ObjectPath obj_path("/org/freedesktop/DBus");
+ if (!get_name_owner_call.SetDestination("org.freedesktop.DBus") ||
+ !get_name_owner_call.SetPath(obj_path)) {
+ if (options == REPORT_ERRORS)
+ LOG(ERROR) << "Failed to get name owner.";
+ return "";
+ }
+
+ ScopedDBusError error;
+ DBusMessage* response_message =
+ SendWithReplyAndBlock(get_name_owner_call.raw_message(),
+ ObjectProxy::TIMEOUT_USE_DEFAULT,
+ error.get());
+ if (!response_message) {
+ if (options == REPORT_ERRORS) {
+ LOG(ERROR) << "Failed to get name owner. Got " << error.name() << ": "
+ << error.message();
+ }
+ return "";
+ }
+
+ scoped_ptr<Response> response(Response::FromRawMessage(response_message));
+ MessageReader reader(response.get());
+
+ std::string service_owner;
+ if (!reader.PopString(&service_owner))
+ service_owner.clear();
+ return service_owner;
+}
+
+void Bus::GetServiceOwner(const std::string& service_name,
+ const GetServiceOwnerCallback& callback) {
+ AssertOnOriginThread();
+
+ PostTaskToDBusThread(
+ FROM_HERE,
+ base::Bind(&Bus::GetServiceOwnerInternal, this, service_name, callback));
+}
+
+void Bus::GetServiceOwnerInternal(const std::string& service_name,
+ const GetServiceOwnerCallback& callback) {
+ AssertOnDBusThread();
+
+ std::string service_owner;
+ if (Connect())
+ service_owner = GetServiceOwnerAndBlock(service_name, REPORT_ERRORS);
+ PostTaskToOriginThread(FROM_HERE, base::Bind(callback, service_owner));
+}
+
dbus_bool_t Bus::OnAddWatch(DBusWatch* raw_watch) {
AssertOnDBusThread();
« no previous file with comments | « dbus/bus.h ('k') | dbus/object_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698