OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/biod/biod_client.h" | 5 #include "chromeos/dbus/biod/biod_client.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 dbus::MessageWriter writer(&method_call); | 92 dbus::MessageWriter writer(&method_call); |
93 writer.AppendString(biod::kBiometricsManagerInterface); | 93 writer.AppendString(biod::kBiometricsManagerInterface); |
94 writer.AppendString(biod::kBiometricsManagerBiometricTypeProperty); | 94 writer.AppendString(biod::kBiometricsManagerBiometricTypeProperty); |
95 | 95 |
96 biod_proxy_->CallMethod( | 96 biod_proxy_->CallMethod( |
97 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 97 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
98 base::Bind(&BiodClientImpl::OnRequestType, | 98 base::Bind(&BiodClientImpl::OnRequestType, |
99 weak_ptr_factory_.GetWeakPtr(), callback)); | 99 weak_ptr_factory_.GetWeakPtr(), callback)); |
100 } | 100 } |
101 | 101 |
102 void CancelEnrollSession( | |
103 const dbus::ObjectPath& enroll_session_path) override { | |
104 dbus::MethodCall method_call(biod::kEnrollSessionInterface, | |
105 biod::kEnrollSessionCancelMethod); | |
106 | |
107 dbus::ObjectProxy* enroll_session_proxy = | |
108 bus_->GetObjectProxy(biod::kBiodServiceName, enroll_session_path); | |
109 enroll_session_proxy->CallMethod( | |
110 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
111 dbus::ObjectProxy::EmptyResponseCallback()); | |
112 } | |
113 | |
114 void EndAuthSession(const dbus::ObjectPath& auth_session_path) override { | |
115 dbus::MethodCall method_call(biod::kAuthSessionInterface, | |
116 biod::kAuthSessionEndMethod); | |
117 | |
118 dbus::ObjectProxy* auth_session_proxy = | |
119 bus_->GetObjectProxy(biod::kBiodServiceName, auth_session_path); | |
120 auth_session_proxy->CallMethod(&method_call, | |
121 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
122 dbus::ObjectProxy::EmptyResponseCallback()); | |
123 } | |
124 | |
125 void SetRecordLabel(const dbus::ObjectPath& record_path, | |
126 const std::string& label) override { | |
127 dbus::MethodCall method_call(biod::kRecordInterface, | |
128 biod::kRecordSetLabelMethod); | |
129 dbus::MessageWriter writer(&method_call); | |
130 writer.AppendString(label); | |
131 | |
132 dbus::ObjectProxy* record_proxy = | |
133 bus_->GetObjectProxy(biod::kBiodServiceName, record_path); | |
134 record_proxy->CallMethod(&method_call, | |
135 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
136 dbus::ObjectProxy::EmptyResponseCallback()); | |
137 } | |
138 | |
139 void RemoveRecord(const dbus::ObjectPath& record_path) override { | |
140 dbus::MethodCall method_call(biod::kRecordInterface, | |
141 biod::kRecordRemoveMethod); | |
142 | |
143 dbus::ObjectProxy* record_proxy = | |
144 bus_->GetObjectProxy(biod::kBiodServiceName, record_path); | |
145 record_proxy->CallMethod(&method_call, | |
146 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
147 dbus::ObjectProxy::EmptyResponseCallback()); | |
148 } | |
149 | |
150 void RequestRecordLabel(const dbus::ObjectPath& record_path, | |
151 const LabelCallback& callback) override { | |
152 dbus::MethodCall method_call(dbus::kDBusPropertiesInterface, | |
153 dbus::kDBusPropertiesGet); | |
154 dbus::MessageWriter writer(&method_call); | |
155 writer.AppendString(biod::kRecordInterface); | |
156 writer.AppendString(biod::kRecordLabelProperty); | |
157 | |
158 dbus::ObjectProxy* record_proxy = | |
159 bus_->GetObjectProxy(biod::kBiodServiceName, record_path); | |
160 record_proxy->CallMethod( | |
161 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
162 base::Bind(&BiodClientImpl::OnRequestRecordLabel, | |
163 weak_ptr_factory_.GetWeakPtr(), callback)); | |
164 } | |
165 | |
102 protected: | 166 protected: |
103 void Init(dbus::Bus* bus) override { | 167 void Init(dbus::Bus* bus) override { |
168 bus_ = bus; | |
169 | |
104 biod_proxy_ = bus->GetObjectProxy(biod::kBiodServiceName, | 170 biod_proxy_ = bus->GetObjectProxy(biod::kBiodServiceName, |
105 dbus::ObjectPath(biod::kBiodServicePath)); | 171 dbus::ObjectPath(biod::kBiodServicePath)); |
106 | 172 |
107 biod_proxy_->SetNameOwnerChangedCallback( | 173 biod_proxy_->SetNameOwnerChangedCallback( |
108 base::Bind(&BiodClientImpl::NameOwnerChangedReceived, | 174 base::Bind(&BiodClientImpl::NameOwnerChangedReceived, |
109 weak_ptr_factory_.GetWeakPtr())); | 175 weak_ptr_factory_.GetWeakPtr())); |
110 | 176 |
111 biod_proxy_->ConnectToSignal( | 177 biod_proxy_->ConnectToSignal( |
112 biod::kBiometricsManagerInterface, | 178 biod::kBiometricsManagerInterface, |
113 biod::kBiometricsManagerEnrollScanDoneSignal, | 179 biod::kBiometricsManagerEnrollScanDoneSignal, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 dbus::MessageReader reader(response); | 250 dbus::MessageReader reader(response); |
185 if (!reader.PopVariantOfUint32(&result)) { | 251 if (!reader.PopVariantOfUint32(&result)) { |
186 LOG(ERROR) << biod::kBiometricsManagerBiometricTypeProperty | 252 LOG(ERROR) << biod::kBiometricsManagerBiometricTypeProperty |
187 << " had incorrect response."; | 253 << " had incorrect response."; |
188 } | 254 } |
189 } | 255 } |
190 | 256 |
191 callback.Run(static_cast<biod::BiometricType>(result)); | 257 callback.Run(static_cast<biod::BiometricType>(result)); |
192 } | 258 } |
193 | 259 |
260 void OnRequestRecordLabel(const LabelCallback& callback, | |
261 dbus::Response* response) { | |
262 std::string result; | |
263 if (response) { | |
264 dbus::MessageReader reader(response); | |
265 if (!reader.PopString(&result)) | |
266 LOG(ERROR) << biod::kRecordLabelProperty << " had incorrect response."; | |
267 } | |
268 | |
269 callback.Run(result); | |
270 } | |
271 | |
194 // Called when the biometrics signal is initially connected. | 272 // Called when the biometrics signal is initially connected. |
195 void OnSignalConnected(const std::string& interface_name, | 273 void OnSignalConnected(const std::string& interface_name, |
196 const std::string& signal_name, | 274 const std::string& signal_name, |
197 bool success) { | 275 bool success) { |
198 LOG_IF(ERROR, !success) | 276 LOG_IF(ERROR, !success) |
199 << "Failed to connect to biometrics signal: " << signal_name; | 277 << "Failed to connect to biometrics signal: " << signal_name; |
200 } | 278 } |
201 | 279 |
202 void NameOwnerChangedReceived(const std::string& /* old_owner */, | 280 void NameOwnerChangedReceived(const std::string& /* old_owner */, |
203 const std::string& new_owner) { | 281 const std::string& new_owner) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 observer.BiodAuthScanDoneReceived( | 333 observer.BiodAuthScanDoneReceived( |
256 static_cast<biod::ScanResult>(scan_result), matches); | 334 static_cast<biod::ScanResult>(scan_result), matches); |
257 } | 335 } |
258 } | 336 } |
259 | 337 |
260 void SessionFailedReceived(dbus::Signal* signal) { | 338 void SessionFailedReceived(dbus::Signal* signal) { |
261 for (auto& observer : observers_) | 339 for (auto& observer : observers_) |
262 observer.BiodSessionFailedReceived(); | 340 observer.BiodSessionFailedReceived(); |
263 } | 341 } |
264 | 342 |
343 dbus::Bus* bus_; | |
Daniel Erat
2017/04/03 19:58:18
nit: add " = nullptr;" here
sammiequon
2017/04/03 21:35:09
Done.
| |
265 dbus::ObjectProxy* biod_proxy_; | 344 dbus::ObjectProxy* biod_proxy_; |
Daniel Erat
2017/04/03 19:58:18
and here (you'll need to remove initialization fro
sammiequon
2017/04/03 21:35:09
Done.
| |
266 base::ObserverList<Observer> observers_; | 345 base::ObserverList<Observer> observers_; |
267 | 346 |
268 // Note: This should remain the last member so it'll be destroyed and | 347 // Note: This should remain the last member so it'll be destroyed and |
269 // invalidate its weak pointers before any other members are destroyed. | 348 // invalidate its weak pointers before any other members are destroyed. |
270 base::WeakPtrFactory<BiodClientImpl> weak_ptr_factory_; | 349 base::WeakPtrFactory<BiodClientImpl> weak_ptr_factory_; |
271 | 350 |
272 DISALLOW_COPY_AND_ASSIGN(BiodClientImpl); | 351 DISALLOW_COPY_AND_ASSIGN(BiodClientImpl); |
273 }; | 352 }; |
274 | 353 |
275 BiodClient::BiodClient() {} | 354 BiodClient::BiodClient() {} |
276 | 355 |
277 BiodClient::~BiodClient() {} | 356 BiodClient::~BiodClient() {} |
278 | 357 |
279 // static | 358 // static |
280 BiodClient* BiodClient::Create(DBusClientImplementationType /* type */) { | 359 BiodClient* BiodClient::Create(DBusClientImplementationType /* type */) { |
281 return new BiodClientImpl(); | 360 return new BiodClientImpl(); |
282 } | 361 } |
283 | 362 |
284 } // namespace chromeos | 363 } // namespace chromeos |
OLD | NEW |