OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/location.h" | 10 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
11 #include "base/sys_byteorder.h" | 12 #include "base/sys_byteorder.h" |
12 #include "content/common/p2p_messages.h" | 13 #include "content/common/p2p_messages.h" |
13 #include "ipc/ipc_sender.h" | 14 #include "ipc/ipc_sender.h" |
14 #include "jingle/glue/fake_ssl_client_socket.h" | 15 #include "jingle/glue/fake_ssl_client_socket.h" |
15 #include "jingle/glue/proxy_resolving_client_socket.h" | 16 #include "jingle/glue/proxy_resolving_client_socket.h" |
16 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 if (result != net::OK) { | 150 if (result != net::OK) { |
150 LOG(WARNING) << "Error from connecting socket, result=" << result; | 151 LOG(WARNING) << "Error from connecting socket, result=" << result; |
151 OnError(); | 152 OnError(); |
152 return; | 153 return; |
153 } | 154 } |
154 | 155 |
155 if (IsTlsClientSocket(type_)) { | 156 if (IsTlsClientSocket(type_)) { |
156 state_ = STATE_TLS_CONNECTING; | 157 state_ = STATE_TLS_CONNECTING; |
157 StartTls(); | 158 StartTls(); |
158 } else if (IsPseudoTlsClientSocket(type_)) { | 159 } else if (IsPseudoTlsClientSocket(type_)) { |
159 scoped_ptr<net::StreamSocket> transport_socket = socket_.Pass(); | 160 scoped_ptr<net::StreamSocket> transport_socket = std::move(socket_); |
160 socket_.reset( | 161 socket_.reset( |
161 new jingle_glue::FakeSSLClientSocket(transport_socket.Pass())); | 162 new jingle_glue::FakeSSLClientSocket(std::move(transport_socket))); |
162 state_ = STATE_TLS_CONNECTING; | 163 state_ = STATE_TLS_CONNECTING; |
163 int status = socket_->Connect( | 164 int status = socket_->Connect( |
164 base::Bind(&P2PSocketHostTcpBase::ProcessTlsSslConnectDone, | 165 base::Bind(&P2PSocketHostTcpBase::ProcessTlsSslConnectDone, |
165 base::Unretained(this))); | 166 base::Unretained(this))); |
166 if (status != net::ERR_IO_PENDING) { | 167 if (status != net::ERR_IO_PENDING) { |
167 ProcessTlsSslConnectDone(status); | 168 ProcessTlsSslConnectDone(status); |
168 } | 169 } |
169 } else { | 170 } else { |
170 // If we are not doing TLS, we are ready to send data now. | 171 // If we are not doing TLS, we are ready to send data now. |
171 // In case of TLS, SignalConnect will be sent only after TLS handshake is | 172 // In case of TLS, SignalConnect will be sent only after TLS handshake is |
172 // successful. So no buffering will be done at socket handlers if any | 173 // successful. So no buffering will be done at socket handlers if any |
173 // packets sent before that by the application. | 174 // packets sent before that by the application. |
174 OnOpen(); | 175 OnOpen(); |
175 } | 176 } |
176 } | 177 } |
177 | 178 |
178 void P2PSocketHostTcpBase::StartTls() { | 179 void P2PSocketHostTcpBase::StartTls() { |
179 DCHECK_EQ(state_, STATE_TLS_CONNECTING); | 180 DCHECK_EQ(state_, STATE_TLS_CONNECTING); |
180 DCHECK(socket_.get()); | 181 DCHECK(socket_.get()); |
181 | 182 |
182 scoped_ptr<net::ClientSocketHandle> socket_handle( | 183 scoped_ptr<net::ClientSocketHandle> socket_handle( |
183 new net::ClientSocketHandle()); | 184 new net::ClientSocketHandle()); |
184 socket_handle->SetSocket(socket_.Pass()); | 185 socket_handle->SetSocket(std::move(socket_)); |
185 | 186 |
186 net::SSLClientSocketContext context; | 187 net::SSLClientSocketContext context; |
187 context.cert_verifier = url_context_->GetURLRequestContext()->cert_verifier(); | 188 context.cert_verifier = url_context_->GetURLRequestContext()->cert_verifier(); |
188 context.transport_security_state = | 189 context.transport_security_state = |
189 url_context_->GetURLRequestContext()->transport_security_state(); | 190 url_context_->GetURLRequestContext()->transport_security_state(); |
190 DCHECK(context.transport_security_state); | 191 DCHECK(context.transport_security_state); |
191 | 192 |
192 // Default ssl config. | 193 // Default ssl config. |
193 const net::SSLConfig ssl_config; | 194 const net::SSLConfig ssl_config; |
194 net::HostPortPair dest_host_port_pair; | 195 net::HostPortPair dest_host_port_pair; |
195 | 196 |
196 // Calling net::HostPortPair::FromIPEndPoint will crash if the IP address is | 197 // Calling net::HostPortPair::FromIPEndPoint will crash if the IP address is |
197 // empty. | 198 // empty. |
198 if (!remote_address_.ip_address.address().empty()) { | 199 if (!remote_address_.ip_address.address().empty()) { |
199 net::HostPortPair::FromIPEndPoint(remote_address_.ip_address); | 200 net::HostPortPair::FromIPEndPoint(remote_address_.ip_address); |
200 } else { | 201 } else { |
201 dest_host_port_pair.set_port(remote_address_.ip_address.port()); | 202 dest_host_port_pair.set_port(remote_address_.ip_address.port()); |
202 } | 203 } |
203 if (!remote_address_.hostname.empty()) | 204 if (!remote_address_.hostname.empty()) |
204 dest_host_port_pair.set_host(remote_address_.hostname); | 205 dest_host_port_pair.set_host(remote_address_.hostname); |
205 | 206 |
206 net::ClientSocketFactory* socket_factory = | 207 net::ClientSocketFactory* socket_factory = |
207 net::ClientSocketFactory::GetDefaultFactory(); | 208 net::ClientSocketFactory::GetDefaultFactory(); |
208 DCHECK(socket_factory); | 209 DCHECK(socket_factory); |
209 | 210 |
210 socket_ = socket_factory->CreateSSLClientSocket( | 211 socket_ = socket_factory->CreateSSLClientSocket( |
211 socket_handle.Pass(), dest_host_port_pair, ssl_config, context); | 212 std::move(socket_handle), dest_host_port_pair, ssl_config, context); |
212 int status = socket_->Connect( | 213 int status = socket_->Connect( |
213 base::Bind(&P2PSocketHostTcpBase::ProcessTlsSslConnectDone, | 214 base::Bind(&P2PSocketHostTcpBase::ProcessTlsSslConnectDone, |
214 base::Unretained(this))); | 215 base::Unretained(this))); |
215 | 216 |
216 if (status != net::ERR_IO_PENDING) { | 217 if (status != net::ERR_IO_PENDING) { |
217 ProcessTlsSslConnectDone(status); | 218 ProcessTlsSslConnectDone(status); |
218 } | 219 } |
219 } | 220 } |
220 | 221 |
221 void P2PSocketHostTcpBase::ProcessTlsSslConnectDone(int status) { | 222 void P2PSocketHostTcpBase::ProcessTlsSslConnectDone(int status) { |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 } else { | 633 } else { |
633 packet_size += kTurnChannelDataHeaderSize; | 634 packet_size += kTurnChannelDataHeaderSize; |
634 // Calculate any padding if present. | 635 // Calculate any padding if present. |
635 if (packet_size % 4) | 636 if (packet_size % 4) |
636 *pad_bytes = 4 - packet_size % 4; | 637 *pad_bytes = 4 - packet_size % 4; |
637 } | 638 } |
638 return packet_size; | 639 return packet_size; |
639 } | 640 } |
640 | 641 |
641 } // namespace content | 642 } // namespace content |
OLD | NEW |