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