buffet: Make ExportedPropertySet threadsafe
In Chrome, we have both a DBus thread and some main thread (an 'origin'
thread). Objects related to DBus functionality need to accomodate this
so that we can send this upstream. This mostly just means that we need
to add assertions that developers are using the API correctly, so that
the use of weak pointers is safe.
BUG=chromium:360831
TEST=Unittests pass. buffet_BasicDBusAPI still passes.
Change-Id: Ibb48a5e65c7cb02e5edce9cbf85432bed70d7686
Reviewed-on: https://chromium-review.googlesource.com/193505
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/dbus_utils.cc b/buffet/dbus_utils.cc
index fcda628..673afe3 100644
--- a/buffet/dbus_utils.cc
+++ b/buffet/dbus_utils.cc
@@ -2,14 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <base/logging.h>
-
#include "buffet/dbus_utils.h"
+#include <base/logging.h>
+#include <base/bind.h>
+
namespace buffet {
namespace dbus_utils {
+namespace {
+
+// Passes |method_call| to |handler| and passes the response to
+// |response_sender|. If |handler| returns NULL, an empty response is created
+// and sent.
+void HandleSynchronousDBusMethodCall(
+ base::Callback<scoped_ptr<dbus::Response>(dbus::MethodCall*)> handler,
+ dbus::MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender) {
+ auto response = handler.Run(method_call);
+ if (!response)
+ response = dbus::Response::FromMethodCall(method_call);
+
+ response_sender.Run(response.Pass());
+}
+
+} // namespace
+
scoped_ptr<dbus::Response> GetBadArgsError(dbus::MethodCall* method_call,
const std::string& message) {
LOG(ERROR) << "Error while handling DBus call: " << message;
@@ -18,6 +37,11 @@
return scoped_ptr<dbus::Response>(resp.release());
}
+dbus::ExportedObject::MethodCallCallback GetExportableDBusMethod(
+ base::Callback<scoped_ptr<dbus::Response>(dbus::MethodCall*)> handler) {
+ return base::Bind(&HandleSynchronousDBusMethodCall, handler);
+}
+
} // namespace dbus_utils
} // namespace buffet