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

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: 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
Index: dbus/bus.cc
===================================================================
--- dbus/bus.cc (revision 197157)
+++ dbus/bus.cc (working copy)
@@ -836,6 +836,65 @@
}
}
+std::string Bus::GetServiceOwnerAndBlock(const std::string& service_name,
+ bool suppress_errors) {
+ AssertOnDBusThread();
+
+ std::string service_owner;
satorux1 2013/04/30 04:50:00 please move this to right before PopString
Lei Zhang 2013/04/30 20:49:23 Done.
+
+ 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 (!suppress_errors)
+ LOG(ERROR) << "Failed to get name owner.";
+ return service_owner;
satorux1 2013/04/30 04:50:00 nit: return "" is a bit clearer.
Lei Zhang 2013/04/30 20:49:23 Done.
+ }
+
+ ScopedDBusError error;
+ DBusMessage* response_message =
+ SendWithReplyAndBlock(get_name_owner_call.raw_message(),
+ ObjectProxy::TIMEOUT_USE_DEFAULT,
+ error.get());
+ if (!response_message) {
+ if (!suppress_errors) {
+ LOG(ERROR) << "Failed to get name owner. Got " << error.name() << ": "
+ << error.message();
+ }
+ return service_owner;
satorux1 2013/04/30 04:50:00 ditto.
Lei Zhang 2013/04/30 20:49:23 Done.
+ }
+
+ scoped_ptr<Response> response(Response::FromRawMessage(response_message));
+ MessageReader reader(response.get());
+
+ 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, true);
+ PostTaskToOriginThread(FROM_HERE, base::Bind(callback, service_owner));
+}
+
dbus_bool_t Bus::OnAddWatch(DBusWatch* raw_watch) {
AssertOnDBusThread();

Powered by Google App Engine
This is Rietveld 408576698