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

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

Issue 2824803003: Add timeout task to U2F HID state machine (Closed)
Patch Set: 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
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 #ifndef DEVICE_U2F_U2F_HID_DEVICE_H_ 5 #ifndef DEVICE_U2F_U2F_HID_DEVICE_H_
6 #define DEVICE_U2F_U2F_HID_DEVICE_H_ 6 #define DEVICE_U2F_U2F_HID_DEVICE_H_
7 7
8 #include <list> 8 #include <list>
9 9
10 #include "base/cancelable_callback.h"
10 #include "device/hid/hid_service.h" 11 #include "device/hid/hid_service.h"
11 #include "u2f_device.h" 12 #include "u2f_device.h"
12 13
13 namespace net { 14 namespace net {
14 class IOBuffer; 15 class IOBuffer;
15 } // namespace net 16 } // namespace net
16 17
17 namespace device { 18 namespace device {
18 19
19 class U2fMessage; 20 class U2fMessage;
20 class HidConnection; 21 class HidConnection;
21 class HidDeviceInfo; 22 class HidDeviceInfo;
22 23
23 class U2fHidDevice : public U2fDevice { 24 class U2fHidDevice : public U2fDevice {
24 public: 25 public:
25 U2fHidDevice(scoped_refptr<HidDeviceInfo>); 26 U2fHidDevice(scoped_refptr<HidDeviceInfo>);
26 ~U2fHidDevice(); 27 ~U2fHidDevice() final;
27 28
28 // Send a U2f command to this device 29 // Send a U2f command to this device
29 void DeviceTransact(std::unique_ptr<U2fApduCommand> command, 30 void DeviceTransact(std::unique_ptr<U2fApduCommand> command,
30 const DeviceCallback& callback) final; 31 const DeviceCallback& callback) final;
31 // Send a wink command if supported 32 // Send a wink command if supported
32 void TryWink(const WinkCallback& callback) final; 33 void TryWink(const WinkCallback& callback) final;
33 // Use a string identifier to compare to other devices 34 // Use a string identifier to compare to other devices
34 std::string GetId() final; 35 std::string GetId() final;
35 // Command line flag to enable tests on actual U2f HID hardware 36 // Command line flag to enable tests on actual U2f HID hardware
36 static bool IsTestEnabled(); 37 static bool IsTestEnabled();
(...skipping 26 matching lines...) Expand all
63 // Write all message packets to device, and read response if expected 64 // Write all message packets to device, and read response if expected
64 void WriteMessage(std::unique_ptr<U2fMessage> message, 65 void WriteMessage(std::unique_ptr<U2fMessage> message,
65 bool response_expected, 66 bool response_expected,
66 U2fHidMessageCallback callback); 67 U2fHidMessageCallback callback);
67 void PacketWritten(std::unique_ptr<U2fMessage> message, 68 void PacketWritten(std::unique_ptr<U2fMessage> message,
68 bool response_expected, 69 bool response_expected,
69 U2fHidMessageCallback callback, 70 U2fHidMessageCallback callback,
70 bool success); 71 bool success);
71 // Read all response message packets from device 72 // Read all response message packets from device
72 void ReadMessage(U2fHidMessageCallback callback); 73 void ReadMessage(U2fHidMessageCallback callback);
73 void MessageReceived(const DeviceCallback& callback, 74 void MessageReceived(DeviceCallback callback,
Reilly Grant (use Gerrit) 2017/04/17 22:25:17 DeviceCallback is not a OnceCallback so it should
Casey Piper 2017/04/17 23:02:38 Done.
74 bool success, 75 bool success,
75 std::unique_ptr<U2fMessage> message); 76 std::unique_ptr<U2fMessage> message);
76 void OnRead(U2fHidMessageCallback callback, 77 void OnRead(U2fHidMessageCallback callback,
77 bool success, 78 bool success,
78 scoped_refptr<net::IOBuffer> buf, 79 scoped_refptr<net::IOBuffer> buf,
79 size_t size); 80 size_t size);
80 void OnReadContinuation(std::unique_ptr<U2fMessage> message, 81 void OnReadContinuation(std::unique_ptr<U2fMessage> message,
81 U2fHidMessageCallback, 82 U2fHidMessageCallback,
82 bool success, 83 bool success,
83 scoped_refptr<net::IOBuffer> buf, 84 scoped_refptr<net::IOBuffer> buf,
84 size_t size); 85 size_t size);
85 void OnWink(const WinkCallback& callback, 86 void OnWink(const WinkCallback& callback,
86 bool success, 87 bool success,
87 std::unique_ptr<U2fMessage> response); 88 std::unique_ptr<U2fMessage> response);
89 void OnTimeout(DeviceCallback callback);
90 void OnDeviceTransact(bool success,
91 std::unique_ptr<U2fApduResponse> response);
88 92
89 State state_; 93 State state_;
94 base::CancelableClosure timeout_callback_;
90 std::list<std::pair<std::unique_ptr<U2fApduCommand>, DeviceCallback>> 95 std::list<std::pair<std::unique_ptr<U2fApduCommand>, DeviceCallback>>
91 pending_transactions_; 96 pending_transactions_;
92 scoped_refptr<HidDeviceInfo> device_info_; 97 scoped_refptr<HidDeviceInfo> device_info_;
93 scoped_refptr<HidConnection> connection_; 98 scoped_refptr<HidConnection> connection_;
94 base::WeakPtrFactory<U2fHidDevice> weak_factory_; 99 base::WeakPtrFactory<U2fHidDevice> weak_factory_;
95 100
96 DISALLOW_COPY_AND_ASSIGN(U2fHidDevice); 101 DISALLOW_COPY_AND_ASSIGN(U2fHidDevice);
97 }; 102 };
98 103
99 } // namespace device 104 } // namespace device
100 105
101 #endif // DEVICE_U2F_U2F_HID_DEVICE_H_ 106 #endif // DEVICE_U2F_U2F_HID_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698