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

Side by Side 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 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 GetLabel(const dbus::ObjectPath& record_path,
52 const StringCallback& 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::OnGetLabel,
64 weak_ptr_factory_.GetWeakPtr(), callback));
65 }
66
67 std::string GetLabelBlocking(const dbus::ObjectPath& record_path) override {
68 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface,
69 dbus::kDBusPropertiesGet);
70 dbus::MessageWriter writer(&method_call);
71 writer.AppendString(biod::kRecordInterface);
72 writer.AppendString(biod::kRecordLabelProperty);
73
74 dbus::ObjectProxy* record_proxy =
75 bus_->GetObjectProxy(biod::kBiodServiceName, record_path);
76 std::unique_ptr<dbus::Response> response = record_proxy->CallMethodAndBlock(
77 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
78
79 if (!response)
80 return "";
81
82 dbus::MessageReader reader(response.get());
83 std::string result;
84 if (!reader.PopVariantOfString(&result)) {
85 return "";
86 }
87
88 return result;
89 }
90
91 protected:
92 void Init(dbus::Bus* bus) override { bus_ = bus; }
93
94 private:
95 void OnGetLabel(const StringCallback& callback, dbus::Response* response) {
96 dbus::MessageReader reader(response);
97 std::string result;
98 if (reader.PopVariantOfString(&result)) {
99 callback.Run(result);
100 }
101 }
102
103 dbus::Bus* bus_;
104
105 // Note: This should remain the last member so it'll be destroyed and
106 // invalidate its weak pointers before any other members are destroyed.
107 base::WeakPtrFactory<BiodRecordClientImpl> weak_ptr_factory_;
108
109 DISALLOW_COPY_AND_ASSIGN(BiodRecordClientImpl);
110 };
111
112 BiodRecordClient::BiodRecordClient() {}
113
114 BiodRecordClient::~BiodRecordClient() {}
115
116 // static
117 BiodRecordClient* BiodRecordClient::Create(DBusClientImplementationType type) {
118 return new BiodRecordClientImpl();
119 }
120
121 } // namespace chromeos
OLDNEW
« 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