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

Side by Side Diff: chromeos/dbus/biod_record_client.cc

Issue 2581403002: cros: Remaining interfaces for DBUS biometrics client. (Closed)
Patch Set: Rebased. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chromeos/dbus/biod_record_client.h"
6
7 #include <stdint.h>
8
9 #include "base/bind.h"
10 #include "base/macros.h"
11 #include "dbus/bus.h"
12 #include "dbus/message.h"
13 #include "dbus/object_path.h"
14 #include "dbus/object_proxy.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h"
16
17 namespace chromeos {
18
19 // The BiodRecordClient implementation used in production.
20 class BiodRecordClientImpl : public BiodRecordClient {
21 public:
22 BiodRecordClientImpl() : weak_ptr_factory_(this) {}
23
24 ~BiodRecordClientImpl() override {}
25
26 void SetLabel(const dbus::ObjectPath& record_path,
27 const std::string& label) override {
28 dbus::MethodCall method_call(biod::kRecordInterface,
29 biod::kRecordSetLabelMethod);
30 dbus::MessageWriter writer(&method_call);
31 writer.AppendString(label);
32
33 dbus::ObjectProxy* record_proxy =
34 bus_->GetObjectProxy(biod::kBiodServiceName, record_path);
35 record_proxy->CallMethod(&method_call,
36 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
37 dbus::ObjectProxy::EmptyResponseCallback());
38 }
39
40 void Remove(const dbus::ObjectPath& record_path) override {
41 dbus::MethodCall method_call(biod::kRecordInterface,
42 biod::kRecordRemoveMethod);
43
44 dbus::ObjectProxy* record_proxy =
45 bus_->GetObjectProxy(biod::kBiodServiceName, record_path);
46 record_proxy->CallMethod(&method_call,
47 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
48 dbus::ObjectProxy::EmptyResponseCallback());
49 }
50
51 void RequestLabel(const dbus::ObjectPath& record_path,
52 const LabelCallback& callback) override {
53 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface,
54 dbus::kDBusPropertiesGet);
55 dbus::MessageWriter writer(&method_call);
56 writer.AppendString(biod::kRecordInterface);
57 writer.AppendString(biod::kRecordLabelProperty);
58
59 dbus::ObjectProxy* record_proxy =
60 bus_->GetObjectProxy(biod::kBiodServiceName, record_path);
61 record_proxy->CallMethod(
62 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
63 base::Bind(&BiodRecordClientImpl::OnRequestLabel,
64 weak_ptr_factory_.GetWeakPtr(), callback));
65 }
66
67 protected:
68 void Init(dbus::Bus* bus) override { bus_ = bus; }
69
70 private:
71 void OnRequestLabel(const LabelCallback& callback, dbus::Response* response) {
72 dbus::MessageReader reader(response);
stevenjb 2017/03/22 20:57:53 I forget what happens if the request fails, do we
sammiequon 2017/03/23 18:30:37 It seems like response might be empty and it could
73 std::string result;
74 if (reader.PopVariantOfString(&result)) {
75 callback.Run(result);
stevenjb 2017/03/22 20:57:53 We should log an error and call the callback with
sammiequon 2017/03/23 18:30:37 Done.
76 }
77 }
78
79 dbus::Bus* bus_;
80
81 // Note: This should remain the last member so it'll be destroyed and
82 // invalidate its weak pointers before any other members are destroyed.
83 base::WeakPtrFactory<BiodRecordClientImpl> weak_ptr_factory_;
84
85 DISALLOW_COPY_AND_ASSIGN(BiodRecordClientImpl);
86 };
87
88 BiodRecordClient::BiodRecordClient() {}
89
90 BiodRecordClient::~BiodRecordClient() {}
91
92 // static
93 BiodRecordClient* BiodRecordClient::Create(
94 DBusClientImplementationType /* type */) {
95 return new BiodRecordClientImpl();
96 }
97
98 } // namespace chromeos
OLDNEW
« chromeos/dbus/biod_enroll_session_client.cc ('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