| Index: device/u2f/u2f_enumerate.cc
|
| diff --git a/device/u2f/u2f_enumerate.cc b/device/u2f/u2f_enumerate.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a68bd611d5b882944c82e4188a67722b5a79ffd2
|
| --- /dev/null
|
| +++ b/device/u2f/u2f_enumerate.cc
|
| @@ -0,0 +1,52 @@
|
| +// 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 "u2f_enumerate.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "device/base/device_client.h"
|
| +#include "u2f_hid_device.h"
|
| +
|
| +namespace device {
|
| +
|
| +U2fEnumerate::U2fEnumerate()
|
| + : hid_service_observer_(this), weak_factory_(this) {
|
| + filter_.SetUsagePage(0xf1d0);
|
| +}
|
| +
|
| +U2fEnumerate::~U2fEnumerate() {}
|
| +
|
| +void U2fEnumerate::EnumerateU2fDevices(
|
| + U2fEnumerate::U2fEnumerateCallback enumerate_cb) {
|
| + HidService* hid_service = DeviceClient::Get()->GetHidService();
|
| + DCHECK(hid_service);
|
| + hid_service_observer_.Add(hid_service);
|
| + hid_service->GetDevices(base::Bind(&U2fEnumerate::OnHidEnumerationComplete,
|
| + weak_factory_.GetWeakPtr(),
|
| + base::Passed(&enumerate_cb)));
|
| +}
|
| +
|
| +void U2fEnumerate::OnHidEnumerationComplete(
|
| + U2fEnumerate::U2fEnumerateCallback callback,
|
| + const std::vector<scoped_refptr<HidDeviceInfo>>& devices) {
|
| + std::list<std::unique_ptr<U2fDevice>> u2f_devices;
|
| + for (const scoped_refptr<HidDeviceInfo>& device_info : devices) {
|
| + if (filter_.Matches(device_info))
|
| + u2f_devices.push_back(base::MakeUnique<U2fHidDevice>(device_info));
|
| + }
|
| + std::move(callback).Run(std::move(u2f_devices));
|
| +}
|
| +
|
| +void U2fEnumerate::OnDeviceAdded(scoped_refptr<HidDeviceInfo> device_info) {
|
| + if (device_added_cb_ && filter_.Matches(device_info))
|
| + device_added_cb_.Run(base::MakeUnique<U2fHidDevice>(device_info));
|
| +}
|
| +
|
| +void U2fEnumerate::OnDeviceRemoved(scoped_refptr<HidDeviceInfo> device_info) {
|
| + if (device_removed_cb_ && filter_.Matches(device_info))
|
| + device_removed_cb_.Run(base::MakeUnique<U2fHidDevice>(device_info));
|
| +}
|
| +
|
| +} // namespace device
|
|
|