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

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

Issue 2581403002: cros: Remaining interfaces for DBUS biometrics client. (Closed)
Patch Set: Fixed patch set 7 errors. 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
« no previous file with comments | « chromeos/dbus/biod_record_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 SetRecordLabel(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 RemoveRecord(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 RequestRecordLabel(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::OnRequestRecordLabel,
64 weak_ptr_factory_.GetWeakPtr(), callback));
65 }
66
67 protected:
68 void Init(dbus::Bus* bus) override { bus_ = bus; }
69
70 private:
71 void OnRequestRecordLabel(const LabelCallback& callback,
72 dbus::Response* response) {
73 dbus::MessageReader reader(response);
74 std::string result;
75 if (!response) {
76 LOG(ERROR) << "Error calling " << biod::kRecordLabelProperty;
stevenjb 2017/03/23 20:23:34 Shouldn't we check this before constructing |reade
sammiequon 2017/03/23 21:12:25 Done.
77 } else if (!reader.PopVariantOfString(&result)) {
78 LOG(ERROR) << "Error reading response from biod: "
79 << response->ToString();
80 }
81 callback.Run(result);
82 }
83
84 dbus::Bus* bus_;
85
86 // Note: This should remain the last member so it'll be destroyed and
87 // invalidate its weak pointers before any other members are destroyed.
88 base::WeakPtrFactory<BiodRecordClientImpl> weak_ptr_factory_;
89
90 DISALLOW_COPY_AND_ASSIGN(BiodRecordClientImpl);
91 };
92
93 BiodRecordClient::BiodRecordClient() {}
94
95 BiodRecordClient::~BiodRecordClient() {}
96
97 // static
98 BiodRecordClient* BiodRecordClient::Create(
99 DBusClientImplementationType /* type */) {
100 return new BiodRecordClientImpl();
101 }
102
103 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/biod_record_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698