OLD | NEW |
---|---|
(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 #ifndef DEVICE_U2F_U2F_REQUEST_H_ | |
6 #define DEVICE_U2F_U2F_REQUEST_H_ | |
7 | |
8 #include "base/cancelable_callback.h" | |
9 #include "base/scoped_observer.h" | |
10 #include "device/hid/hid_device_filter.h" | |
11 #include "device/hid/hid_service.h" | |
12 #include "u2f_device.h" | |
13 | |
14 namespace device { | |
15 class U2fRequest : HidService::Observer { | |
16 public: | |
17 using ResponseCallback = | |
18 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
| |
19 | |
20 U2fRequest(const ResponseCallback& callback); | |
21 virtual ~U2fRequest(); | |
22 | |
23 void Start(); | |
24 | |
25 protected: | |
26 enum class State { | |
27 INIT, | |
28 BUSY, | |
29 WINK, | |
30 IDLE, | |
31 OFF, | |
32 COMPLETE, | |
33 }; | |
34 | |
35 void Transition(); | |
36 virtual void TryDevice() = 0; | |
37 | |
38 std::unique_ptr<U2fDevice> current_device_; | |
39 State state_; | |
40 const ResponseCallback& cb_; | |
41 | |
42 private: | |
43 FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestAddRemoveDevice); | |
44 FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestIterateDevice); | |
45 FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestBasicMachine); | |
46 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestSimpleSign); | |
47 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestMultipleHandles); | |
48 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestSignSuccess); | |
49 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestDelayedSuccess); | |
50 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestMultipleDevices); | |
51 FRIEND_TEST_ALL_PREFIXES(U2fSignTest, TestFakeEnroll); | |
52 FRIEND_TEST_ALL_PREFIXES(U2fRegisterTest, TestRegisterSuccess); | |
53 FRIEND_TEST_ALL_PREFIXES(U2fRegisterTest, TestDelayedSuccess); | |
54 FRIEND_TEST_ALL_PREFIXES(U2fRegisterTest, TestMultipleDevices); | |
55 | |
56 void Enumerate(); | |
57 void IterateDevice(); | |
58 void OnWaitComplete(); | |
59 void OnDeviceAdded(scoped_refptr<HidDeviceInfo> device_info) override; | |
60 void OnDeviceRemoved(scoped_refptr<HidDeviceInfo> device_info) override; | |
61 void OnEnumerate(const std::vector<scoped_refptr<HidDeviceInfo>>& devices); | |
62 | |
63 std::list<std::unique_ptr<U2fDevice>> devices_; | |
64 std::list<std::unique_ptr<U2fDevice>> attempted_devices_; | |
65 base::CancelableClosure delay_callback_; | |
66 HidDeviceFilter filter_; | |
67 ScopedObserver<HidService, HidService::Observer> hid_service_observer_; | |
68 base::WeakPtrFactory<U2fRequest> weak_factory_; | |
69 }; | |
70 } // namespace device | |
71 | |
72 #endif // DEVICE_U2F_U2F_REQUEST_H_ | |
OLD | NEW |