chaps: Check for D-Bus acquire_name() method

DBus::Connection::acquire_name() does not exist in the upstream version
of libdbus-c++, so check for it and stick to the original request_name()
method if not present.

BUG=None
TEST=Chaps unit tests (with ASAN) plus PKCS11 tests

Change-Id: If2b2dd875d6a3f109331306035a0b1db20856213
Reviewed-on: https://chromium-review.googlesource.com/221931
Reviewed-by: Darren Krahn <dkrahn@chromium.org>
Commit-Queue: David Drysdale <drysdale@google.com>
Tested-by: David Drysdale <drysdale@google.com>
diff --git a/chaps/Makefile b/chaps/Makefile
index ffc9e20..6e6d333 100644
--- a/chaps/Makefile
+++ b/chaps/Makefile
@@ -130,6 +130,12 @@
 else
 DBUS_POLICY = "group=\"pkcs11\""
 endif
+DBUS_FLAGS := $(call check_compile_cxx, \
+	'\#include <dbus-c++/dbus.h>\nint main(){\
+	DBus::Connection::SystemBus().acquire_name("dummy");\
+	return 0;}',,-DNO_DBUS_ACQUIRE_NAME)
+CXXFLAGS += $(DBUS_FLAGS)
+
 .PHONY: $(OUT)/org.chromium.Chaps.conf
 $(OUT)/org.chromium.Chaps.conf :
 	sed -e "s/@POLICY_PERMISSIONS@/$(DBUS_POLICY)/" \
diff --git a/chaps/chaps_adaptor.cc b/chaps/chaps_adaptor.cc
index 3e02d24..7f3eb2b 100644
--- a/chaps/chaps_adaptor.cc
+++ b/chaps/chaps_adaptor.cc
@@ -25,7 +25,11 @@
 // Helper used when calling the ObjectAdaptor constructor.
 static DBus::Connection& GetConnection() {
   static DBus::Connection connection = DBus::Connection::SystemBus();
+#ifdef NO_DBUS_ACQUIRE_NAME
+  connection.request_name(kChapsServiceName);
+#else
   CHECK(connection.acquire_name(kChapsServiceName));
+#endif
   return connection;
 }