OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "chrome/browser/extensions/api/api_resource.h" | 17 #include "chrome/browser/extensions/api/api_resource.h" |
18 #include "chrome/browser/extensions/api/api_resource_manager.h" | 18 #include "chrome/browser/extensions/api/api_resource_manager.h" |
19 #include "chrome/browser/extensions/api/cast_channel/cast_channel.pb.h" | |
19 #include "chrome/common/extensions/api/cast_channel.h" | 20 #include "chrome/common/extensions/api/cast_channel.h" |
20 #include "net/base/completion_callback.h" | 21 #include "net/base/completion_callback.h" |
21 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
22 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
23 #include "net/base/net_log.h" | 24 #include "net/base/net_log.h" |
24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
25 | 26 |
26 namespace net { | 27 namespace net { |
27 class AddressList; | 28 class AddressList; |
28 class CertVerifier; | 29 class CertVerifier; |
29 class SSLClientSocket; | 30 class SSLClientSocket; |
31 class StreamSocket; | |
30 class TCPClientSocket; | 32 class TCPClientSocket; |
31 class TransportSecurityState; | 33 class TransportSecurityState; |
32 } | 34 } |
33 | 35 |
34 namespace extensions { | 36 namespace extensions { |
35 namespace api { | 37 namespace api { |
36 namespace cast_channel { | 38 namespace cast_channel { |
37 | 39 |
38 class CastMessage; | |
39 | |
40 // Size, in bytes, of the largest allowed message payload on the wire (without | 40 // Size, in bytes, of the largest allowed message payload on the wire (without |
41 // the header). | 41 // the header). |
42 extern const uint32 kMaxMessageSize; | 42 extern const uint32 kMaxMessageSize; |
43 | 43 |
44 // This class implements a channel between Chrome and a Cast device using a TCP | 44 // This class implements a channel between Chrome and a Cast device using a TCP |
45 // socket. The channel may be unauthenticated (cast://) or authenticated | 45 // socket. The channel may be unauthenticated (cast://) or authenticated |
46 // (casts://). All CastSocket objects must be used only on the IO thread. | 46 // (casts://). All CastSocket objects must be used only on the IO thread. |
47 // | 47 // |
48 // NOTE: Not called "CastChannel" to reduce confusion with the generated API | 48 // NOTE: Not called "CastChannel" to reduce confusion with the generated API |
49 // code. | 49 // code. |
50 class CastSocket : public ApiResource, | 50 class CastSocket : public ApiResource, |
51 public base::SupportsWeakPtr<CastSocket> { | 51 public base::SupportsWeakPtr<CastSocket> { |
52 public: | 52 public: |
53 // Object to be informed of incoming messages and errors. | 53 // Object to be informed of incoming messages and errors. |
54 class Delegate { | 54 class Delegate { |
55 public: | 55 public: |
56 // An error occurred on the channel. | 56 // An error occurred on the channel. |
57 // It is fine to delete the socket in this callback. | |
57 virtual void OnError(const CastSocket* socket, | 58 virtual void OnError(const CastSocket* socket, |
58 ChannelError error) = 0; | 59 ChannelError error) = 0; |
59 // A string message was received on the channel. | 60 // A message was received on the channel. |
61 // Do NOT delete the socket in this callback. | |
60 virtual void OnMessage(const CastSocket* socket, | 62 virtual void OnMessage(const CastSocket* socket, |
61 const MessageInfo& message) = 0; | 63 const MessageInfo& message) = 0; |
62 protected: | 64 protected: |
63 virtual ~Delegate() {} | 65 virtual ~Delegate() {} |
64 }; | 66 }; |
65 | 67 |
66 // Creates a new CastSocket to |url|. |owner_extension_id| is the id of the | 68 // Creates a new CastSocket to |url|. |owner_extension_id| is the id of the |
67 // extension that opened the socket. | 69 // extension that opened the socket. |
68 CastSocket(const std::string& owner_extension_id, | 70 CastSocket(const std::string& owner_extension_id, |
69 const GURL& url, | 71 const GURL& url, |
70 CastSocket::Delegate* delegate, | 72 CastSocket::Delegate* delegate, |
71 net::NetLog* net_log); | 73 net::NetLog* net_log); |
72 virtual ~CastSocket(); | 74 virtual ~CastSocket(); |
73 | 75 |
74 // The URL for the channel. | 76 // The URL for the channel. |
75 const GURL& url() const; | 77 const GURL& url() const; |
76 | 78 |
77 // Whether to perform receiver authentication. | 79 // Whether to perform receiver authentication. |
78 bool auth_required() const { return auth_required_; } | 80 bool auth_required() const { return auth_required_; } |
79 | 81 |
80 // Channel id for the ApiResourceManager. | 82 // Channel id for the ApiResourceManager. |
81 int id() const { return channel_id_; } | 83 int id() const { return channel_id_; } |
82 | 84 |
83 // Sets the channel id. | 85 // Sets the channel id. |
84 void set_id(int channel_id) { channel_id_ = channel_id; } | 86 void set_id(int channel_id) { channel_id_ = channel_id; } |
85 | 87 |
86 // Returns the state of the channel. | 88 // Returns the state of the channel. |
87 ReadyState ready_state() const { return ready_state_; } | 89 ReadyState ready_state() const { return ready_state_; } |
88 | 90 |
89 // Returns the last error that occurred on this channel, or CHANNEL_ERROR_NONE | 91 // Returns the last error that occurred on this channel, or |
90 // if no error has occurred. | 92 // CHANNEL_ERROR_NONE if no error has occurred. |
91 ChannelError error_state() const { return error_state_; } | 93 ChannelError error_state() const { return error_state_; } |
92 | 94 |
93 // Connects the channel to the peer. If successful, the channel will be in | 95 // Connects the channel to the peer. If successful, the channel will be in |
94 // READY_STATE_OPEN. | 96 // READY_STATE_OPEN. |
97 // It is fine to delete the CastSocket object in |callback|. | |
95 virtual void Connect(const net::CompletionCallback& callback); | 98 virtual void Connect(const net::CompletionCallback& callback); |
96 | 99 |
97 // Sends a message over a connected channel. The channel must be in | 100 // Sends a message over a connected channel. The channel must be in |
98 // READY_STATE_OPEN. | 101 // READY_STATE_OPEN. |
102 // | |
103 // Note that if an error occurs the following happens: | |
104 // 1. Completion callbacks for all pending writes are invoked with error. | |
105 // 2. Delegate::OnError is called once. | |
106 // 3. Castsocket is closed. | |
107 // | |
108 // DO NOT delete the CastSocket object in write completion callback. | |
109 // But it is fine to delete the socket in Delegate::OnError | |
99 virtual void SendMessage(const MessageInfo& message, | 110 virtual void SendMessage(const MessageInfo& message, |
100 const net::CompletionCallback& callback); | 111 const net::CompletionCallback& callback); |
101 | 112 |
102 // Closes the channel. On completion, the channel will be in | 113 // Closes the channel. On completion, the channel will be in |
103 // READY_STATE_CLOSED. | 114 // READY_STATE_CLOSED. |
115 // It is fine to delete the CastSocket object in |callback|. | |
104 virtual void Close(const net::CompletionCallback& callback); | 116 virtual void Close(const net::CompletionCallback& callback); |
105 | 117 |
106 // Fills |channel_info| with the status of this channel. | 118 // Fills |channel_info| with the status of this channel. |
107 virtual void FillChannelInfo(ChannelInfo* channel_info) const; | 119 virtual void FillChannelInfo(ChannelInfo* channel_info) const; |
108 | 120 |
109 protected: | 121 protected: |
110 // Creates an instance of TCPClientSocket. | 122 // Creates an instance of TCPClientSocket. |
111 virtual scoped_ptr<net::TCPClientSocket> CreateTcpSocket(); | 123 virtual scoped_ptr<net::TCPClientSocket> CreateTcpSocket(); |
112 // Creates an instance of SSLClientSocket. | 124 // Creates an instance of SSLClientSocket with the given underlying |socket|. |
113 virtual scoped_ptr<net::SSLClientSocket> CreateSslSocket(); | 125 virtual scoped_ptr<net::SSLClientSocket> CreateSslSocket( |
126 scoped_ptr<net::StreamSocket> socket); | |
127 // Returns IPEndPoint for the URL to connect to. | |
128 const net::IPEndPoint& ip_endpoint() const { return ip_endpoint_; } | |
114 // Extracts peer certificate from SSLClientSocket instance when the socket | 129 // Extracts peer certificate from SSLClientSocket instance when the socket |
115 // is in cert error state. | 130 // is in cert error state. |
116 // Returns whether certificate is successfully extracted. | 131 // Returns whether certificate is successfully extracted. |
117 virtual bool ExtractPeerCert(std::string* cert); | 132 virtual bool ExtractPeerCert(std::string* cert); |
118 // Sends a challenge request to the receiver. | |
119 virtual int SendAuthChallenge(); | |
120 // Reads auth challenge reply from the receiver. | |
121 virtual int ReadAuthChallengeReply(); | |
122 // Verifies whether the challenge reply received from the peer is valid: | 133 // Verifies whether the challenge reply received from the peer is valid: |
123 // 1. Signature in the reply is valid. | 134 // 1. Signature in the reply is valid. |
124 // 2. Certificate is rooted to a trusted CA. | 135 // 2. Certificate is rooted to a trusted CA. |
125 virtual bool VerifyChallengeReply(); | 136 virtual bool VerifyChallengeReply(); |
126 | 137 |
127 // Returns whether we are executing in a valid thread. | |
128 virtual bool CalledOnValidThread() const; | |
129 | |
130 private: | 138 private: |
131 friend class ApiResourceManager<CastSocket>; | 139 friend class ApiResourceManager<CastSocket>; |
132 friend class CastSocketTest; | 140 friend class CastSocketTest; |
133 | 141 |
134 static const char* service_name() { | 142 static const char* service_name() { |
135 return "CastSocketManager"; | 143 return "CastSocketManager"; |
136 } | 144 } |
137 | 145 |
138 // Internal connection states. | 146 // Internal connection states. |
139 enum ConnectionState { | 147 enum ConnectionState { |
140 CONN_STATE_NONE, | 148 CONN_STATE_NONE, |
141 CONN_STATE_TCP_CONNECT, | 149 CONN_STATE_TCP_CONNECT, |
142 CONN_STATE_TCP_CONNECT_COMPLETE, | 150 CONN_STATE_TCP_CONNECT_COMPLETE, |
143 CONN_STATE_SSL_CONNECT, | 151 CONN_STATE_SSL_CONNECT, |
144 CONN_STATE_SSL_CONNECT_COMPLETE, | 152 CONN_STATE_SSL_CONNECT_COMPLETE, |
145 CONN_STATE_AUTH_CHALLENGE_SEND, | 153 CONN_STATE_AUTH_CHALLENGE_SEND, |
146 CONN_STATE_AUTH_CHALLENGE_SEND_COMPLETE, | 154 CONN_STATE_AUTH_CHALLENGE_SEND_COMPLETE, |
147 CONN_STATE_AUTH_CHALLENGE_REPLY_COMPLETE, | 155 CONN_STATE_AUTH_CHALLENGE_REPLY_COMPLETE, |
148 }; | 156 }; |
149 | 157 |
158 // Internal write states. | |
159 enum WriteState { | |
160 WRITE_STATE_NONE, | |
161 WRITE_STATE_WRITE, | |
162 WRITE_STATE_WRITE_COMPLETE, | |
163 WRITE_STATE_DO_CALLBACK, | |
164 WRITE_STATE_ERROR, | |
165 }; | |
166 | |
167 // Internal read states. | |
168 enum ReadState { | |
169 READ_STATE_NONE, | |
170 READ_STATE_READ, | |
171 READ_STATE_READ_COMPLETE, | |
172 READ_STATE_DO_CALLBACK, | |
173 READ_STATE_ERROR, | |
174 }; | |
175 | |
150 ///////////////////////////////////////////////////////////////////////////// | 176 ///////////////////////////////////////////////////////////////////////////// |
151 // Following methods work together to implement the following flow: | 177 // Following methods work together to implement the following flow: |
152 // 1. Create a new TCP socket and connect to it | 178 // 1. Create a new TCP socket and connect to it |
153 // 2. Create a new SSL socket and try connecting to it | 179 // 2. Create a new SSL socket and try connecting to it |
154 // 3. If connection fails due to invalid cert authority, then extract the | 180 // 3. If connection fails due to invalid cert authority, then extract the |
155 // peer certificate from the error. | 181 // peer certificate from the error. |
156 // 4. Whitelist the peer certificate and try #1 and #2 again. | 182 // 4. Whitelist the peer certificate and try #1 and #2 again. |
157 // 5. If SSL socket is connected successfully, and if protocol is casts:// | 183 // 5. If SSL socket is connected successfully, and if protocol is casts:// |
158 // then issue an auth challenge request. | 184 // then issue an auth challenge request. |
159 // 6. Validate the auth challenge response. | 185 // 6. Validate the auth challenge response. |
160 | 186 // |
161 // Main method that performs connection state transitions. | 187 // Main method that performs connection state transitions. |
162 int DoConnectLoop(int result); | 188 void DoConnectLoop(int result); |
163 // Each of the below Do* method is executed in the corresponding | 189 // Each of the below Do* method is executed in the corresponding |
164 // connection state. For e.g. when connection state is TCP_CONNECT | 190 // connection state. For example when connection state is TCP_CONNECT |
165 // DoTcpConnect is called, and so on. | 191 // DoTcpConnect is called, and so on. |
166 int DoTcpConnect(); | 192 int DoTcpConnect(); |
167 int DoTcpConnectComplete(int result); | 193 int DoTcpConnectComplete(int result); |
168 int DoSslConnect(); | 194 int DoSslConnect(); |
169 int DoSslConnectComplete(int result); | 195 int DoSslConnectComplete(int result); |
170 int DoAuthChallengeSend(); | 196 int DoAuthChallengeSend(); |
171 int DoAuthChallengeSendComplete(int result); | 197 int DoAuthChallengeSendComplete(int result); |
172 int DoAuthChallengeReplyComplete(int result); | 198 int DoAuthChallengeReplyComplete(int result); |
173 ///////////////////////////////////////////////////////////////////////////// | 199 ///////////////////////////////////////////////////////////////////////////// |
174 | 200 |
175 // Callback method for callbacks from underlying sockets. | 201 ///////////////////////////////////////////////////////////////////////////// |
176 void OnConnectComplete(int result); | 202 // Following methods work together to implement write flow. |
203 // | |
204 // Main method that performs write flow state transitions. | |
205 void DoWriteLoop(int result); | |
206 // Each of the below Do* method is executed in the corresponding | |
207 // write state. For e.g. when write state is WRITE_STATE_WRITE_COMPLETE | |
Ryan Sleevi
2013/12/12 00:48:14
Still says "For e.g." (and there are multiple occu
Munjal (Google)
2013/12/12 17:53:47
Done.
| |
208 // DowriteComplete is called, and so on. | |
209 int DoWrite(); | |
210 int DoWriteComplete(int result); | |
211 int DoWriteCallback(); | |
212 int DoWriteError(int result); | |
213 ///////////////////////////////////////////////////////////////////////////// | |
177 | 214 |
178 // Callback method when a challenge request is sent or a reply is received. | 215 ///////////////////////////////////////////////////////////////////////////// |
179 void OnChallengeEvent(int result); | 216 // Following methods work together to implement read flow. |
217 // | |
218 // Main method that performs write flow state transitions. | |
219 void DoReadLoop(int result); | |
220 // Each of the below Do* method is executed in the corresponding | |
221 // write state. For e.g. when write state is READ_STATE_READ_COMPLETE | |
222 // DoReadComplete is called, and so on. | |
223 int DoRead(); | |
224 int DoReadComplete(int result); | |
225 int DoReadCallback(); | |
226 int DoReadError(int result); | |
227 ///////////////////////////////////////////////////////////////////////////// | |
180 | 228 |
181 // Runs the external connection callback and resets it. | 229 // Runs the external connection callback and resets it. |
182 void DoConnectCallback(int result); | 230 void DoConnectCallback(int result); |
183 | |
184 // Verifies that the URL is a valid cast:// or casts:// URL and sets url_ to | 231 // Verifies that the URL is a valid cast:// or casts:// URL and sets url_ to |
185 // the result. | 232 // the result. |
186 bool ParseChannelUrl(const GURL& url); | 233 bool ParseChannelUrl(const GURL& url); |
187 | 234 // Adds |message| to the write queue and starts the write loop if needed. |
188 // Sends the given |message| and invokes the given callback when done. | 235 void SendCastMessageInternal(const CastMessage& message, |
189 int SendMessageInternal(const CastMessage& message, | 236 const net::CompletionCallback& callback); |
190 const net::CompletionCallback& callback); | 237 void PostTaskToStartConnectLoop(int result); |
191 | 238 void PostTaskToStartReadLoop(); |
192 // Writes data to the socket from the WriteRequest at the head of the queue. | 239 void StartReadLoop(); |
193 // Calls OnWriteData() on completion. | 240 // Parses the contents of header_read_buffer_ and sets current_message_size_ |
194 int WriteData(); | 241 // to the size of the body of the message. |
195 void OnWriteData(int result); | |
196 | |
197 // Reads data from the socket into one of the read buffers. Calls | |
198 // OnReadData() on completion. | |
199 int ReadData(); | |
200 void OnReadData(int result); | |
201 | |
202 // Processes the contents of header_read_buffer_ and returns true on success. | |
203 bool ProcessHeader(); | 242 bool ProcessHeader(); |
204 // Processes the contents of body_read_buffer_ and returns true on success. | 243 // Parses the contents of body_read_buffer_ and sets current_message_ to |
244 // the message received. | |
205 bool ProcessBody(); | 245 bool ProcessBody(); |
206 // Parses the message held in body_read_buffer_ and notifies |delegate_| if a | 246 // Closes socket, updating the error state and signaling the delegate that |
207 // message was extracted from the buffer. Returns true on success. | 247 // |error| has occurred. |
208 bool ParseMessageFromBody(); | 248 void CloseWithError(ChannelError error); |
209 | |
210 // Serializes the content of message_proto (with a header) to |message_data|. | 249 // Serializes the content of message_proto (with a header) to |message_data|. |
211 static bool Serialize(const CastMessage& message_proto, | 250 static bool Serialize(const CastMessage& message_proto, |
212 std::string* message_data); | 251 std::string* message_data); |
213 | 252 |
214 // Closes the socket and sets |error_state_|. Also signals |error| via | 253 // Returns whether we are executing in a valid thread. |
Ryan Sleevi
2013/12/12 00:48:14
You introduced another pronoun comment.
It's also
Munjal (Google)
2013/12/12 17:53:47
- Removed comment since it felt redundant anyway.
| |
215 // |delegate_|. | 254 virtual bool CalledOnValidThread() const; |
216 void CloseWithError(ChannelError error); | |
217 | 255 |
218 base::ThreadChecker thread_checker_; | 256 base::ThreadChecker thread_checker_; |
219 | 257 |
220 // The id of the channel. | 258 // The id of the channel. |
221 int channel_id_; | 259 int channel_id_; |
222 | 260 |
223 // The URL of the peer (cast:// or casts://). | 261 // The URL of the peer (cast:// or casts://). |
224 GURL url_; | 262 GURL url_; |
225 // Delegate to inform of incoming messages and errors. | 263 // Delegate to inform of incoming messages and errors. |
226 Delegate* delegate_; | 264 Delegate* delegate_; |
227 // True if we should perform receiver authentication. | 265 // True if we should perform receiver authentication. |
228 bool auth_required_; | 266 bool auth_required_; |
229 // The IP endpoint of the peer. | 267 // The IP endpoint of the peer. |
230 net::IPEndPoint ip_endpoint_; | 268 net::IPEndPoint ip_endpoint_; |
231 // The last error encountered by the channel. | |
232 ChannelError error_state_; | |
233 // The current status of the channel. | |
234 ReadyState ready_state_; | |
235 | |
236 // True when there is a write callback pending. | |
237 bool write_callback_pending_; | |
238 // True when there is a read callback pending. | |
239 bool read_callback_pending_; | |
240 | 269 |
241 // IOBuffer for reading the message header. | 270 // IOBuffer for reading the message header. |
242 scoped_refptr<net::GrowableIOBuffer> header_read_buffer_; | 271 scoped_refptr<net::GrowableIOBuffer> header_read_buffer_; |
243 // IOBuffer for reading the message body. | 272 // IOBuffer for reading the message body. |
244 scoped_refptr<net::GrowableIOBuffer> body_read_buffer_; | 273 scoped_refptr<net::GrowableIOBuffer> body_read_buffer_; |
245 // IOBuffer we are currently reading into. | 274 // IOBuffer we are currently reading into. |
246 scoped_refptr<net::GrowableIOBuffer> current_read_buffer_; | 275 scoped_refptr<net::GrowableIOBuffer> current_read_buffer_; |
247 // The number of bytes in the current message body. | 276 // The number of bytes in the current message body. |
248 uint32 current_message_size_; | 277 uint32 current_message_size_; |
278 // Last message received on the socket. | |
279 CastMessage current_message_; | |
249 | 280 |
250 // The NetLog for this service. | 281 // The NetLog for this service. |
251 net::NetLog* net_log_; | 282 net::NetLog* net_log_; |
252 // The NetLog source for this service. | 283 // The NetLog source for this service. |
253 net::NetLog::Source net_log_source_; | 284 net::NetLog::Source net_log_source_; |
254 | 285 |
255 // Next connection state to transition to. | |
256 ConnectionState next_state_; | |
257 // Owned ptr to the underlying TCP socket. | 286 // Owned ptr to the underlying TCP socket. |
258 scoped_ptr<net::TCPClientSocket> tcp_socket_; | 287 scoped_ptr<net::TCPClientSocket> tcp_socket_; |
259 // Owned ptr to the underlying SSL socket. | 288 // Owned ptr to the underlying SSL socket. |
260 scoped_ptr<net::SSLClientSocket> socket_; | 289 scoped_ptr<net::SSLClientSocket> socket_; |
261 // Certificate of the peer. This field may be empty if the peer | 290 // Certificate of the peer. This field may be empty if the peer |
262 // certificate is not yet fetched. | 291 // certificate is not yet fetched. |
263 std::string peer_cert_; | 292 std::string peer_cert_; |
264 scoped_ptr<net::CertVerifier> cert_verifier_; | 293 scoped_ptr<net::CertVerifier> cert_verifier_; |
265 scoped_ptr<net::TransportSecurityState> transport_security_state_; | 294 scoped_ptr<net::TransportSecurityState> transport_security_state_; |
266 // Reply received from the receiver to a challenge request. | 295 // Reply received from the receiver to a challenge request. |
267 scoped_ptr<CastMessage> challenge_reply_; | 296 scoped_ptr<CastMessage> challenge_reply_; |
268 | 297 |
269 // Callback invoked when the socket is connected. | 298 // Callback invoked when the socket is connected. |
270 net::CompletionCallback connect_callback_; | 299 net::CompletionCallback connect_callback_; |
271 | 300 |
301 // Connection flow state machine state. | |
302 ConnectionState connect_state_; | |
303 // Write flow state machine state. | |
304 WriteState write_state_; | |
305 // Read flow state machine state. | |
306 ReadState read_state_; | |
307 // The last error encountered by the channel. | |
308 ChannelError error_state_; | |
309 // The current status of the channel. | |
310 ReadyState ready_state_; | |
311 | |
272 // Message header struct. If fields are added, be sure to update | 312 // Message header struct. If fields are added, be sure to update |
273 // kMessageHeaderSize in the .cc. | 313 // kMessageHeaderSize in the .cc. |
274 struct MessageHeader { | 314 struct MessageHeader { |
275 MessageHeader(); | 315 MessageHeader(); |
276 // Sets the message size. | 316 // Sets the message size. |
277 void SetMessageSize(size_t message_size); | 317 void SetMessageSize(size_t message_size); |
278 // Prepends this header to |str|. | 318 // Prepends this header to |str|. |
279 void PrependToString(std::string* str); | 319 void PrependToString(std::string* str); |
280 // Reads |header| from the beginning of |buffer|. | 320 // Reads |header| from the beginning of |buffer|. |
281 static void ReadFromIOBuffer(net::GrowableIOBuffer* buffer, | 321 static void ReadFromIOBuffer(net::GrowableIOBuffer* buffer, |
(...skipping 12 matching lines...) Expand all Loading... | |
294 // and prepending the header. Must only be called once. | 334 // and prepending the header. Must only be called once. |
295 bool SetContent(const CastMessage& message_proto); | 335 bool SetContent(const CastMessage& message_proto); |
296 | 336 |
297 net::CompletionCallback callback; | 337 net::CompletionCallback callback; |
298 scoped_refptr<net::DrainableIOBuffer> io_buffer; | 338 scoped_refptr<net::DrainableIOBuffer> io_buffer; |
299 }; | 339 }; |
300 // Queue of pending writes. The message at the front of the queue is the one | 340 // Queue of pending writes. The message at the front of the queue is the one |
301 // being written. | 341 // being written. |
302 std::queue<WriteRequest> write_queue_; | 342 std::queue<WriteRequest> write_queue_; |
303 | 343 |
304 // Used to protect against DoConnectLoop() re-entrancy. | |
305 bool in_connect_loop_; | |
306 | |
307 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestCastURLs); | 344 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestCastURLs); |
308 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestRead); | 345 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestRead); |
309 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadMany); | 346 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadMany); |
347 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestFullSecureConnectionFlowAsync); | |
310 DISALLOW_COPY_AND_ASSIGN(CastSocket); | 348 DISALLOW_COPY_AND_ASSIGN(CastSocket); |
311 }; | 349 }; |
312 | 350 |
313 } // namespace cast_channel | 351 } // namespace cast_channel |
314 } // namespace api | 352 } // namespace api |
315 } // namespace extensions | 353 } // namespace extensions |
316 | 354 |
317 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ | 355 #endif // CHROME_BROWSER_EXTENSIONS_API_CAST_CHANNEL_CAST_SOCKET_H_ |
OLD | NEW |