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

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

Issue 2766723003: Use unique pointers for U2fPacket and U2fMessage (Closed)
Patch Set: Change fuzzer to use the new unique_ptr constructor 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 | « no previous file | 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"
(...skipping 25 matching lines...) Expand all
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, std::unique_ptr<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(std::unique_ptr<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(std::unique_ptr<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 std::unique_ptr<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 std::unique_ptr<U2fMessage> message);
61 void Transition(std::unique_ptr<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(std::unique_ptr<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(std::unique_ptr<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 std::unique_ptr<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(std::unique_ptr<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 std::unique_ptr<U2fMessage> response);
88 88
89 State state_; 89 State state_;
90 std::list<std::pair<std::unique_ptr<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 | « no previous file | device/u2f/u2f_hid_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698