Chromium Code Reviews| Index: device/u2f/u2f_request.h |
| diff --git a/device/u2f/u2f_request.h b/device/u2f/u2f_request.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ff9a211b6bd1c40e9d86d4a152f8aeb714b5f01f |
| --- /dev/null |
| +++ b/device/u2f/u2f_request.h |
| @@ -0,0 +1,72 @@ |
| +// 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. |
| + |
| +#ifndef DEVICE_U2F_U2F_REQUEST_H_ |
| +#define DEVICE_U2F_U2F_REQUEST_H_ |
| + |
| +#include "base/cancelable_callback.h" |
| +#include "base/scoped_observer.h" |
| +#include "device/hid/hid_device_filter.h" |
| +#include "device/hid/hid_service.h" |
| +#include "u2f_device.h" |
| + |
| +namespace device { |
| +class U2fRequest : HidService::Observer { |
| + public: |
| + using ResponseCallback = |
| + base::Callback<void(uint8_t status_code, std::vector<uint8_t> response)>; |
|
Reilly Grant (use Gerrit)
2017/04/21 17:19:16
Any reason this takes a uint8_t instead of a U2fDe
Casey Piper
2017/04/21 18:42:26
The goal was to avoid the caller from depending on
Reilly Grant (use Gerrit)
2017/04/21 20:10:01
I think readability is improved by avoid the casts
|
| + |
| + U2fRequest(const ResponseCallback& callback); |
| + virtual ~U2fRequest(); |
| + |
| + void Start(); |
| + |
| + protected: |
| + enum class State { |
| + INIT, |
| + BUSY, |
| + WINK, |
| + IDLE, |
| + OFF, |
| + COMPLETE, |
| + }; |
| + |
| + void Transition(); |
| + virtual void TryDevice() = 0; |
| + |
| + std::unique_ptr<U2fDevice> current_device_; |
| + State state_; |
| + const ResponseCallback& cb_; |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestAddRemoveDevice); |
| + FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestIterateDevice); |
| + FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestBasicMachine); |
| + FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestSimpleSign); |
| + FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestMultipleHandles); |
| + FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestSignSuccess); |
| + FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestDelayedSuccess); |
| + FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestMultipleDevices); |
| + FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestFakeEnroll); |
| + FRIEND_TEST_ALL_PREFIXES(U2fRegisterTest, TestRegisterSuccess); |
| + FRIEND_TEST_ALL_PREFIXES(U2fRegisterTest, TestDelayedSuccess); |
| + FRIEND_TEST_ALL_PREFIXES(U2fRegisterTest, TestMultipleDevices); |
| + |
| + void Enumerate(); |
| + void IterateDevice(); |
| + void OnWaitComplete(); |
| + void OnDeviceAdded(scoped_refptr<HidDeviceInfo> device_info) override; |
| + void OnDeviceRemoved(scoped_refptr<HidDeviceInfo> device_info) override; |
| + void OnEnumerate(const std::vector<scoped_refptr<HidDeviceInfo>>& devices); |
| + |
| + std::list<std::unique_ptr<U2fDevice>> devices_; |
| + std::list<std::unique_ptr<U2fDevice>> attempted_devices_; |
| + base::CancelableClosure delay_callback_; |
| + HidDeviceFilter filter_; |
| + ScopedObserver<HidService, HidService::Observer> hid_service_observer_; |
| + base::WeakPtrFactory<U2fRequest> weak_factory_; |
| +}; |
| +} // namespace device |
| + |
| +#endif // DEVICE_U2F_U2F_REQUEST_H_ |