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

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

Issue 2743623006: Modify U2F apdu classes to use unique pointers (Closed)
Patch Set: Use more concise form of base::Passed Created 3 years, 9 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
« no previous file with comments | « device/u2f/u2f_device.cc ('k') | device/u2f/u2f_hid_device.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "device/hid/hid_service.h" 10 #include "device/hid/hid_service.h"
11 #include "u2f_device.h" 11 #include "u2f_device.h"
12 12
13 namespace net { 13 namespace net {
14 class IOBuffer; 14 class IOBuffer;
15 } // namespace net 15 } // namespace net
16 16
17 namespace device { 17 namespace device {
18 18
19 class U2fMessage; 19 class U2fMessage;
20 class HidConnection; 20 class HidConnection;
21 class HidDeviceInfo; 21 class HidDeviceInfo;
22 22
23 class U2fHidDevice : public U2fDevice { 23 class U2fHidDevice : public U2fDevice {
24 public: 24 public:
25 U2fHidDevice(scoped_refptr<HidDeviceInfo>); 25 U2fHidDevice(scoped_refptr<HidDeviceInfo>);
26 ~U2fHidDevice(); 26 ~U2fHidDevice();
27 27
28 // Send a U2f command to this device 28 // Send a U2f command to this device
29 void DeviceTransact(scoped_refptr<U2fApduCommand> command, 29 void DeviceTransact(std::unique_ptr<U2fApduCommand> command,
30 const DeviceCallback& callback) final; 30 const DeviceCallback& callback) final;
31 // Send a wink command if supported 31 // Send a wink command if supported
32 void TryWink(const WinkCallback& callback) final; 32 void TryWink(const WinkCallback& callback) final;
33 // Use a string identifier to compare to other devices 33 // Use a string identifier to compare to other devices
34 std::string GetId() final; 34 std::string GetId() final;
35 // Command line flag to enable tests on actual U2f HID hardware 35 // Command line flag to enable tests on actual U2f HID hardware
36 static bool IsTestEnabled(); 36 static bool IsTestEnabled();
37 37
38 private: 38 private:
39 FRIEND_TEST_ALL_PREFIXES(U2fHidDeviceTest, TestConnectionFailure); 39 FRIEND_TEST_ALL_PREFIXES(U2fHidDeviceTest, TestConnectionFailure);
40 FRIEND_TEST_ALL_PREFIXES(U2fHidDeviceTest, TestDeviceError); 40 FRIEND_TEST_ALL_PREFIXES(U2fHidDeviceTest, TestDeviceError);
41 41
42 // Internal state machine states 42 // Internal state machine states
43 enum class State { INIT, CONNECTED, BUSY, IDLE, DEVICE_ERROR }; 43 enum class State { INIT, CONNECTED, BUSY, IDLE, DEVICE_ERROR };
44 44
45 using U2fHidMessageCallback = 45 using U2fHidMessageCallback =
46 base::OnceCallback<void(bool, scoped_refptr<U2fMessage>)>; 46 base::OnceCallback<void(bool, scoped_refptr<U2fMessage>)>;
47 47
48 // Open a connection to this device 48 // Open a connection to this device
49 void Connect(const HidService::ConnectCallback& callback); 49 void Connect(const HidService::ConnectCallback& callback);
50 void OnConnect(scoped_refptr<U2fApduCommand> command, 50 void OnConnect(std::unique_ptr<U2fApduCommand> command,
51 const DeviceCallback& callback, 51 const DeviceCallback& callback,
52 scoped_refptr<HidConnection> connection); 52 scoped_refptr<HidConnection> connection);
53 // Ask device to allocate a unique channel id for this connection 53 // Ask device to allocate a unique channel id for this connection
54 void AllocateChannel(scoped_refptr<U2fApduCommand> command, 54 void AllocateChannel(std::unique_ptr<U2fApduCommand> command,
55 const DeviceCallback& callback); 55 const DeviceCallback& callback);
56 void OnAllocateChannel(std::vector<uint8_t> nonce, 56 void OnAllocateChannel(std::vector<uint8_t> nonce,
57 scoped_refptr<U2fApduCommand> command, 57 std::unique_ptr<U2fApduCommand> command,
58 const DeviceCallback& callback, 58 const DeviceCallback& callback,
59 bool success, 59 bool success,
60 scoped_refptr<U2fMessage> message); 60 scoped_refptr<U2fMessage> message);
61 void Transition(scoped_refptr<U2fApduCommand> command, 61 void Transition(std::unique_ptr<U2fApduCommand> command,
62 const DeviceCallback& callback); 62 const DeviceCallback& callback);
63 // Write all message packets to device, and read response if expected 63 // Write all message packets to device, and read response if expected
64 void WriteMessage(scoped_refptr<U2fMessage> message, 64 void WriteMessage(scoped_refptr<U2fMessage> message,
65 bool response_expected, 65 bool response_expected,
66 U2fHidMessageCallback callback); 66 U2fHidMessageCallback callback);
67 void PacketWritten(scoped_refptr<U2fMessage> message, 67 void PacketWritten(scoped_refptr<U2fMessage> message,
68 bool response_expected, 68 bool response_expected,
69 U2fHidMessageCallback callback, 69 U2fHidMessageCallback callback,
70 bool success); 70 bool success);
71 // Read all response message packets from device 71 // Read all response message packets from device
72 void ReadMessage(U2fHidMessageCallback callback); 72 void ReadMessage(U2fHidMessageCallback callback);
73 void MessageReceived(const DeviceCallback& callback, 73 void MessageReceived(const DeviceCallback& callback,
74 bool success, 74 bool success,
75 scoped_refptr<U2fMessage> message); 75 scoped_refptr<U2fMessage> message);
76 void OnRead(U2fHidMessageCallback callback, 76 void OnRead(U2fHidMessageCallback callback,
77 bool success, 77 bool success,
78 scoped_refptr<net::IOBuffer> buf, 78 scoped_refptr<net::IOBuffer> buf,
79 size_t size); 79 size_t size);
80 void OnReadContinuation(scoped_refptr<U2fMessage> message, 80 void OnReadContinuation(scoped_refptr<U2fMessage> message,
81 U2fHidMessageCallback, 81 U2fHidMessageCallback,
82 bool success, 82 bool success,
83 scoped_refptr<net::IOBuffer> buf, 83 scoped_refptr<net::IOBuffer> buf,
84 size_t size); 84 size_t size);
85 void OnWink(const WinkCallback& callback, 85 void OnWink(const WinkCallback& callback,
86 bool success, 86 bool success,
87 scoped_refptr<U2fMessage> response); 87 scoped_refptr<U2fMessage> response);
88 88
89 State state_; 89 State state_;
90 std::list<std::pair<scoped_refptr<U2fApduCommand>, DeviceCallback>> 90 std::list<std::pair<std::unique_ptr<U2fApduCommand>, DeviceCallback>>
91 pending_transactions_; 91 pending_transactions_;
92 scoped_refptr<HidDeviceInfo> device_info_; 92 scoped_refptr<HidDeviceInfo> device_info_;
93 scoped_refptr<HidConnection> connection_; 93 scoped_refptr<HidConnection> connection_;
94 base::WeakPtrFactory<U2fHidDevice> weak_factory_; 94 base::WeakPtrFactory<U2fHidDevice> weak_factory_;
95 95
96 DISALLOW_COPY_AND_ASSIGN(U2fHidDevice); 96 DISALLOW_COPY_AND_ASSIGN(U2fHidDevice);
97 }; 97 };
98 98
99 } // namespace device 99 } // namespace device
100 100
101 #endif // DEVICE_U2F_U2F_HID_DEVICE_H_ 101 #endif // DEVICE_U2F_U2F_HID_DEVICE_H_
OLDNEW
« no previous file with comments | « device/u2f/u2f_device.cc ('k') | device/u2f/u2f_hid_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698