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

Side by Side Diff: device/u2f/u2f_request.h

Issue 2821263005: Add U2F request state machines (Closed)
Patch Set: Move return code to own header. Fix review comments Created 3 years, 8 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
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 #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 = base::Callback<void(U2fReturnCode status_code,
18 std::vector<uint8_t> response)>;
19
20 U2fRequest(const ResponseCallback& callback);
21 virtual ~U2fRequest();
22
23 void Start();
24 void AddDeviceForTesting(std::unique_ptr<U2fDevice> device);
25
26 protected:
27 enum class State {
28 INIT,
29 BUSY,
30 WINK,
31 IDLE,
32 OFF,
33 COMPLETE,
34 };
35
36 void Transition();
37 virtual void TryDevice() = 0;
38
39 std::unique_ptr<U2fDevice> current_device_;
40 State state_;
41 ResponseCallback cb_;
42
43 private:
44 FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestAddRemoveDevice);
45 FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestIterateDevice);
46 FRIEND_TEST_ALL_PREFIXES(U2fRequestTest, TestBasicMachine);
47
48 void Enumerate();
49 void IterateDevice();
50 void OnWaitComplete();
51 void AddDevice(std::unique_ptr<U2fDevice> device);
52 void OnDeviceAdded(scoped_refptr<HidDeviceInfo> device_info) override;
53 void OnDeviceRemoved(scoped_refptr<HidDeviceInfo> device_info) override;
54 void OnEnumerate(const std::vector<scoped_refptr<HidDeviceInfo>>& devices);
55
56 std::list<std::unique_ptr<U2fDevice>> devices_;
57 std::list<std::unique_ptr<U2fDevice>> attempted_devices_;
58 base::CancelableClosure delay_callback_;
59 HidDeviceFilter filter_;
60 ScopedObserver<HidService, HidService::Observer> hid_service_observer_;
61 base::WeakPtrFactory<U2fRequest> weak_factory_;
62 };
63 } // namespace device
64
65 #endif // DEVICE_U2F_U2F_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698