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

Unified Diff: chromeos/dbus/biod_record_client.cc

Issue 2581403002: cros: Remaining interfaces for DBUS biometrics client. (Closed)
Patch Set: Remove chromeos.gyp. Created 3 years, 9 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
« chromeos/dbus/biod_record_client.h ('K') | « chromeos/dbus/biod_record_client.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/biod_record_client.cc
diff --git a/chromeos/dbus/biod_record_client.cc b/chromeos/dbus/biod_record_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..80c330ed983e751fa062396b1c9d557de9a795cb
--- /dev/null
+++ b/chromeos/dbus/biod_record_client.cc
@@ -0,0 +1,121 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/dbus/biod_record_client.h"
+
+#include <stdint.h>
+
+#include "base/bind.h"
+#include "base/macros.h"
+#include "dbus/bus.h"
+#include "dbus/message.h"
+#include "dbus/object_path.h"
+#include "dbus/object_proxy.h"
+#include "third_party/cros_system_api/dbus/service_constants.h"
+
+namespace chromeos {
+
+// The BiodRecordClient implementation used in production.
+class BiodRecordClientImpl : public BiodRecordClient {
+ public:
+ BiodRecordClientImpl() : weak_ptr_factory_(this) {}
+
+ ~BiodRecordClientImpl() override {}
+
+ void SetLabel(const dbus::ObjectPath& record_path,
+ const std::string& label) override {
+ dbus::MethodCall method_call(biod::kRecordInterface,
+ biod::kRecordSetLabelMethod);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(label);
+
+ dbus::ObjectProxy* record_proxy =
+ bus_->GetObjectProxy(biod::kBiodServiceName, record_path);
+ record_proxy->CallMethod(&method_call,
+ dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ dbus::ObjectProxy::EmptyResponseCallback());
+ }
+
+ void Remove(const dbus::ObjectPath& record_path) override {
+ dbus::MethodCall method_call(biod::kRecordInterface,
+ biod::kRecordRemoveMethod);
+
+ dbus::ObjectProxy* record_proxy =
+ bus_->GetObjectProxy(biod::kBiodServiceName, record_path);
+ record_proxy->CallMethod(&method_call,
+ dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ dbus::ObjectProxy::EmptyResponseCallback());
+ }
+
+ void GetLabel(const dbus::ObjectPath& record_path,
+ const StringCallback& callback) override {
+ dbus::MethodCall method_call(dbus::kDBusPropertiesInterface,
+ dbus::kDBusPropertiesGet);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(biod::kRecordInterface);
+ writer.AppendString(biod::kRecordLabelProperty);
+
+ dbus::ObjectProxy* record_proxy =
+ bus_->GetObjectProxy(biod::kBiodServiceName, record_path);
+ record_proxy->CallMethod(
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&BiodRecordClientImpl::OnGetLabel,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+ }
+
+ std::string GetLabelBlocking(const dbus::ObjectPath& record_path) override {
+ dbus::MethodCall method_call(dbus::kDBusPropertiesInterface,
+ dbus::kDBusPropertiesGet);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(biod::kRecordInterface);
+ writer.AppendString(biod::kRecordLabelProperty);
+
+ dbus::ObjectProxy* record_proxy =
+ bus_->GetObjectProxy(biod::kBiodServiceName, record_path);
+ std::unique_ptr<dbus::Response> response = record_proxy->CallMethodAndBlock(
+ &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
+
+ if (!response)
+ return "";
+
+ dbus::MessageReader reader(response.get());
+ std::string result;
+ if (!reader.PopVariantOfString(&result)) {
+ return "";
+ }
+
+ return result;
+ }
+
+ protected:
+ void Init(dbus::Bus* bus) override { bus_ = bus; }
+
+ private:
+ void OnGetLabel(const StringCallback& callback, dbus::Response* response) {
+ dbus::MessageReader reader(response);
+ std::string result;
+ if (reader.PopVariantOfString(&result)) {
+ callback.Run(result);
+ }
+ }
+
+ dbus::Bus* bus_;
+
+ // Note: This should remain the last member so it'll be destroyed and
+ // invalidate its weak pointers before any other members are destroyed.
+ base::WeakPtrFactory<BiodRecordClientImpl> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(BiodRecordClientImpl);
+};
+
+BiodRecordClient::BiodRecordClient() {}
+
+BiodRecordClient::~BiodRecordClient() {}
+
+// static
+BiodRecordClient* BiodRecordClient::Create(DBusClientImplementationType type) {
+ return new BiodRecordClientImpl();
+}
+
+} // namespace chromeos
« chromeos/dbus/biod_record_client.h ('K') | « chromeos/dbus/biod_record_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698