OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 REMOTING_HOST_SECURITY_KEY_GNUBBY_SOCKET_H_ | 5 #ifndef REMOTING_HOST_SECURITY_KEY_GNUBBY_SOCKET_H_ |
6 #define REMOTING_HOST_SECURITY_KEY_GNUBBY_SOCKET_H_ | 6 #define REMOTING_HOST_SECURITY_KEY_GNUBBY_SOCKET_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <string> | 11 #include <string> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/callback.h" | 14 #include "base/callback.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class Timer; | 20 class Timer; |
21 } // namespace base | 21 } // namespace base |
22 | 22 |
23 namespace net { | 23 namespace net { |
24 class DrainableIOBuffer; | 24 class DrainableIOBuffer; |
25 class IOBufferWithSize; | 25 class IOBufferWithSize; |
26 class StreamSocket; | 26 class StreamSocket; |
27 } // namespace net | 27 } // namespace net |
28 | 28 |
29 namespace remoting { | 29 namespace remoting { |
30 | 30 |
31 // Class that manages reading requests and sending responses. The socket can | 31 // Class that manages reading requests and sending responses. The socket can |
32 // only handle receiving one request at a time. It expects to receive no extra | 32 // only handle receiving one request at a time. It expects to receive no extra |
33 // bytes over the wire, which is checked by IsRequestTooLarge method. | 33 // bytes over the wire, which is checked by IsRequestTooLarge method. |
34 class GnubbySocket { | 34 class GnubbySocket { |
35 public: | 35 public: |
36 GnubbySocket(scoped_ptr<net::StreamSocket> socket, | 36 GnubbySocket(std::unique_ptr<net::StreamSocket> socket, |
37 base::TimeDelta timeout, | 37 base::TimeDelta timeout, |
38 const base::Closure& timeout_callback); | 38 const base::Closure& timeout_callback); |
39 ~GnubbySocket(); | 39 ~GnubbySocket(); |
40 | 40 |
41 // Returns false if the request has not yet completed, or is too large to be | 41 // Returns false if the request has not yet completed, or is too large to be |
42 // processed. Otherwise, the cached request data is copied into |data_out| and | 42 // processed. Otherwise, the cached request data is copied into |data_out| and |
43 // the internal buffer resets and is ready for the next request. | 43 // the internal buffer resets and is ready for the next request. |
44 bool GetAndClearRequestData(std::string* data_out); | 44 bool GetAndClearRequestData(std::string* data_out); |
45 | 45 |
46 // Sends response data to the socket. | 46 // Sends response data to the socket. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // Returns the response length bytes. | 79 // Returns the response length bytes. |
80 std::string GetResponseLengthAsBytes(const std::string& response) const; | 80 std::string GetResponseLengthAsBytes(const std::string& response) const; |
81 | 81 |
82 // Resets the socket activity timer. | 82 // Resets the socket activity timer. |
83 void ResetTimer(); | 83 void ResetTimer(); |
84 | 84 |
85 // Ensures GnubbySocket methods are called on the same thread. | 85 // Ensures GnubbySocket methods are called on the same thread. |
86 base::ThreadChecker thread_checker_; | 86 base::ThreadChecker thread_checker_; |
87 | 87 |
88 // The socket. | 88 // The socket. |
89 scoped_ptr<net::StreamSocket> socket_; | 89 std::unique_ptr<net::StreamSocket> socket_; |
90 | 90 |
91 // Invoked when request data has been read. | 91 // Invoked when request data has been read. |
92 base::Closure request_received_callback_; | 92 base::Closure request_received_callback_; |
93 | 93 |
94 // Indicates whether read has completed and |request_received_callback_| is | 94 // Indicates whether read has completed and |request_received_callback_| is |
95 // about to be run. | 95 // about to be run. |
96 bool read_completed_; | 96 bool read_completed_; |
97 | 97 |
98 // Request data. | 98 // Request data. |
99 std::vector<char> request_data_; | 99 std::vector<char> request_data_; |
100 | 100 |
101 scoped_refptr<net::DrainableIOBuffer> write_buffer_; | 101 scoped_refptr<net::DrainableIOBuffer> write_buffer_; |
102 | 102 |
103 scoped_refptr<net::IOBufferWithSize> read_buffer_; | 103 scoped_refptr<net::IOBufferWithSize> read_buffer_; |
104 | 104 |
105 // The activity timer. | 105 // The activity timer. |
106 scoped_ptr<base::Timer> timer_; | 106 std::unique_ptr<base::Timer> timer_; |
107 | 107 |
108 DISALLOW_COPY_AND_ASSIGN(GnubbySocket); | 108 DISALLOW_COPY_AND_ASSIGN(GnubbySocket); |
109 }; | 109 }; |
110 | 110 |
111 } // namespace remoting | 111 } // namespace remoting |
112 | 112 |
113 #endif // REMOTING_HOST_SECURITY_KEY_GNUBBY_SOCKET_H_ | 113 #endif // REMOTING_HOST_SECURITY_KEY_GNUBBY_SOCKET_H_ |
OLD | NEW |