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

Side by Side Diff: net/socket_stream/socket_stream.cc

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/socket/unix_domain_socket_posix.cc ('k') | net/spdy/spdy_http_stream.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 (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 // TODO(ukai): code is similar with http_network_transaction.cc. We should 5 // TODO(ukai): code is similar with http_network_transaction.cc. We should
6 // think about ways to share code, if possible. 6 // think about ways to share code, if possible.
7 7
8 #include "net/socket_stream/socket_stream.h" 8 #include "net/socket_stream/socket_stream.h"
9 9
10 #include <set> 10 #include <set>
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 DCHECK(base::MessageLoop::current()) 211 DCHECK(base::MessageLoop::current())
212 << "The current base::MessageLoop must exist"; 212 << "The current base::MessageLoop must exist";
213 DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type()) 213 DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type())
214 << "The current base::MessageLoop must be TYPE_IO"; 214 << "The current base::MessageLoop must be TYPE_IO";
215 DCHECK_GT(len, 0); 215 DCHECK_GT(len, 0);
216 216
217 if (!socket_.get() || !socket_->IsConnected() || next_state_ == STATE_NONE) 217 if (!socket_.get() || !socket_->IsConnected() || next_state_ == STATE_NONE)
218 return false; 218 return false;
219 219
220 int total_buffered_bytes = len; 220 int total_buffered_bytes = len;
221 if (current_write_buf_) { 221 if (current_write_buf_.get()) {
222 // Since 222 // Since
223 // - the purpose of this check is to limit the amount of buffer used by 223 // - the purpose of this check is to limit the amount of buffer used by
224 // this instance. 224 // this instance.
225 // - the DrainableIOBuffer doesn't release consumed memory. 225 // - the DrainableIOBuffer doesn't release consumed memory.
226 // we need to use not BytesRemaining() but size() here. 226 // we need to use not BytesRemaining() but size() here.
227 total_buffered_bytes += current_write_buf_->size(); 227 total_buffered_bytes += current_write_buf_->size();
228 } 228 }
229 total_buffered_bytes += GetTotalSizeOfPendingWriteBufs(); 229 total_buffered_bytes += GetTotalSizeOfPendingWriteBufs();
230 if (total_buffered_bytes > max_pending_send_allowed_) 230 if (total_buffered_bytes > max_pending_send_allowed_)
231 return false; 231 return false;
232 232
233 // TODO(tyoshino): Split data into smaller chunks e.g. 8KiB to free consumed 233 // TODO(tyoshino): Split data into smaller chunks e.g. 8KiB to free consumed
234 // buffer progressively 234 // buffer progressively
235 pending_write_bufs_.push_back(make_scoped_refptr( 235 pending_write_bufs_.push_back(make_scoped_refptr(
236 new IOBufferWithSize(len))); 236 new IOBufferWithSize(len)));
237 memcpy(pending_write_bufs_.back()->data(), data, len); 237 memcpy(pending_write_bufs_.back()->data(), data, len);
238 238
239 // If current_write_buf_ is not NULL, it means that a) there's ongoing write 239 // If current_write_buf_ is not NULL, it means that a) there's ongoing write
240 // operation or b) the connection is being closed. If a), the buffer we just 240 // operation or b) the connection is being closed. If a), the buffer we just
241 // pushed will be automatically handled when the completion callback runs 241 // pushed will be automatically handled when the completion callback runs
242 // the loop, and therefore we don't need to enqueue DoLoop(). If b), it's ok 242 // the loop, and therefore we don't need to enqueue DoLoop(). If b), it's ok
243 // to do nothing. If current_write_buf_ is NULL, to make sure DoLoop() is 243 // to do nothing. If current_write_buf_ is NULL, to make sure DoLoop() is
244 // ran soon, enequeue it. 244 // ran soon, enequeue it.
245 if (!current_write_buf_) { 245 if (!current_write_buf_.get()) {
246 // Send pending data asynchronously, so that delegate won't be called 246 // Send pending data asynchronously, so that delegate won't be called
247 // back before returning from SendData(). 247 // back before returning from SendData().
248 base::MessageLoop::current()->PostTask( 248 base::MessageLoop::current()->PostTask(
249 FROM_HERE, base::Bind(&SocketStream::DoLoop, this, OK)); 249 FROM_HERE, base::Bind(&SocketStream::DoLoop, this, OK));
250 } 250 }
251 251
252 return true; 252 return true;
253 } 253 }
254 254
255 void SocketStream::Close() { 255 void SocketStream::Close() {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // waiting for restarting. In these states, we'll close the SocketStream 341 // waiting for restarting. In these states, we'll close the SocketStream
342 // now. 342 // now.
343 if (next_state_ == STATE_TCP_CONNECT || next_state_ == STATE_AUTH_REQUIRED) { 343 if (next_state_ == STATE_TCP_CONNECT || next_state_ == STATE_AUTH_REQUIRED) {
344 DoLoop(ERR_ABORTED); 344 DoLoop(ERR_ABORTED);
345 return; 345 return;
346 } 346 }
347 // If next_state_ is STATE_READ_WRITE, we'll run DoLoop and close 347 // If next_state_ is STATE_READ_WRITE, we'll run DoLoop and close
348 // the SocketStream. 348 // the SocketStream.
349 // If it's writing now, we should defer the closing after the current 349 // If it's writing now, we should defer the closing after the current
350 // writing is completed. 350 // writing is completed.
351 if (next_state_ == STATE_READ_WRITE && !current_write_buf_) 351 if (next_state_ == STATE_READ_WRITE && !current_write_buf_.get())
352 DoLoop(ERR_ABORTED); 352 DoLoop(ERR_ABORTED);
353 353
354 // In other next_state_, we'll wait for callback of other APIs, such as 354 // In other next_state_, we'll wait for callback of other APIs, such as
355 // ResolveProxy(). 355 // ResolveProxy().
356 } 356 }
357 357
358 void SocketStream::Finish(int result) { 358 void SocketStream::Finish(int result) {
359 DCHECK(base::MessageLoop::current()) 359 DCHECK(base::MessageLoop::current())
360 << "The current base::MessageLoop must exist"; 360 << "The current base::MessageLoop must exist";
361 DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type()) 361 DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type())
(...skipping 24 matching lines...) Expand all
386 metrics_->OnConnected(); 386 metrics_->OnConnected();
387 387
388 net_log_.EndEvent(NetLog::TYPE_SOCKET_STREAM_CONNECT); 388 net_log_.EndEvent(NetLog::TYPE_SOCKET_STREAM_CONNECT);
389 if (delegate_) 389 if (delegate_)
390 delegate_->OnConnected(this, max_pending_send_allowed_); 390 delegate_->OnConnected(this, max_pending_send_allowed_);
391 391
392 return OK; 392 return OK;
393 } 393 }
394 394
395 int SocketStream::DidReceiveData(int result) { 395 int SocketStream::DidReceiveData(int result) {
396 DCHECK(read_buf_); 396 DCHECK(read_buf_.get());
397 DCHECK_GT(result, 0); 397 DCHECK_GT(result, 0);
398 net_log_.AddEvent(NetLog::TYPE_SOCKET_STREAM_RECEIVED); 398 net_log_.AddEvent(NetLog::TYPE_SOCKET_STREAM_RECEIVED);
399 int len = result; 399 int len = result;
400 metrics_->OnRead(len); 400 metrics_->OnRead(len);
401 if (delegate_) { 401 if (delegate_) {
402 // Notify recevied data to delegate. 402 // Notify recevied data to delegate.
403 delegate_->OnReceivedData(this, read_buf_->data(), len); 403 delegate_->OnReceivedData(this, read_buf_->data(), len);
404 } 404 }
405 read_buf_ = NULL; 405 read_buf_ = NULL;
406 return OK; 406 return OK;
407 } 407 }
408 408
409 void SocketStream::DidSendData(int result) { 409 void SocketStream::DidSendData(int result) {
410 DCHECK_GT(result, 0); 410 DCHECK_GT(result, 0);
411 DCHECK(current_write_buf_); 411 DCHECK(current_write_buf_.get());
412 net_log_.AddEvent(NetLog::TYPE_SOCKET_STREAM_SENT); 412 net_log_.AddEvent(NetLog::TYPE_SOCKET_STREAM_SENT);
413 413
414 int bytes_sent = result; 414 int bytes_sent = result;
415 415
416 metrics_->OnWrite(bytes_sent); 416 metrics_->OnWrite(bytes_sent);
417 417
418 current_write_buf_->DidConsume(result); 418 current_write_buf_->DidConsume(result);
419 419
420 if (current_write_buf_->BytesRemaining()) 420 if (current_write_buf_->BytesRemaining())
421 return; 421 return;
(...skipping 11 matching lines...) Expand all
433 433
434 void SocketStream::OnIOCompleted(int result) { 434 void SocketStream::OnIOCompleted(int result) {
435 DoLoop(result); 435 DoLoop(result);
436 } 436 }
437 437
438 void SocketStream::OnReadCompleted(int result) { 438 void SocketStream::OnReadCompleted(int result) {
439 if (result == 0) { 439 if (result == 0) {
440 // 0 indicates end-of-file, so socket was closed. 440 // 0 indicates end-of-file, so socket was closed.
441 // Don't close the socket if it's still writing. 441 // Don't close the socket if it's still writing.
442 server_closed_ = true; 442 server_closed_ = true;
443 } else if (result > 0 && read_buf_) { 443 } else if (result > 0 && read_buf_.get()) {
444 result = DidReceiveData(result); 444 result = DidReceiveData(result);
445 } 445 }
446 DoLoop(result); 446 DoLoop(result);
447 } 447 }
448 448
449 void SocketStream::OnWriteCompleted(int result) { 449 void SocketStream::OnWriteCompleted(int result) {
450 waiting_for_write_completion_ = false; 450 waiting_for_write_completion_ = false;
451 if (result > 0) { 451 if (result > 0) {
452 DidSendData(result); 452 DidSendData(result);
453 result = OK; 453 result = OK;
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 tunnel_request_headers_->headers_ = base::StringPrintf( 814 tunnel_request_headers_->headers_ = base::StringPrintf(
815 "CONNECT %s HTTP/1.1\r\n" 815 "CONNECT %s HTTP/1.1\r\n"
816 "%s", 816 "%s",
817 GetHostAndPort(url_).c_str(), 817 GetHostAndPort(url_).c_str(),
818 request_headers.ToString().c_str()); 818 request_headers.ToString().c_str());
819 } 819 }
820 tunnel_request_headers_->SetDataOffset(tunnel_request_headers_bytes_sent_); 820 tunnel_request_headers_->SetDataOffset(tunnel_request_headers_bytes_sent_);
821 int buf_len = static_cast<int>(tunnel_request_headers_->headers_.size() - 821 int buf_len = static_cast<int>(tunnel_request_headers_->headers_.size() -
822 tunnel_request_headers_bytes_sent_); 822 tunnel_request_headers_bytes_sent_);
823 DCHECK_GT(buf_len, 0); 823 DCHECK_GT(buf_len, 0);
824 return socket_->Write(tunnel_request_headers_, buf_len, io_callback_); 824 return socket_->Write(tunnel_request_headers_.get(), buf_len, io_callback_);
825 } 825 }
826 826
827 int SocketStream::DoWriteTunnelHeadersComplete(int result) { 827 int SocketStream::DoWriteTunnelHeadersComplete(int result) {
828 DCHECK_EQ(kTunnelProxy, proxy_mode_); 828 DCHECK_EQ(kTunnelProxy, proxy_mode_);
829 829
830 if (result < 0) { 830 if (result < 0) {
831 next_state_ = STATE_CLOSE; 831 next_state_ = STATE_CLOSE;
832 return result; 832 return result;
833 } 833 }
834 834
(...skipping 22 matching lines...) Expand all
857 tunnel_response_headers_capacity_ = kMaxTunnelResponseHeadersSize; 857 tunnel_response_headers_capacity_ = kMaxTunnelResponseHeadersSize;
858 tunnel_response_headers_->Realloc(tunnel_response_headers_capacity_); 858 tunnel_response_headers_->Realloc(tunnel_response_headers_capacity_);
859 tunnel_response_headers_len_ = 0; 859 tunnel_response_headers_len_ = 0;
860 } 860 }
861 861
862 int buf_len = tunnel_response_headers_capacity_ - 862 int buf_len = tunnel_response_headers_capacity_ -
863 tunnel_response_headers_len_; 863 tunnel_response_headers_len_;
864 tunnel_response_headers_->SetDataOffset(tunnel_response_headers_len_); 864 tunnel_response_headers_->SetDataOffset(tunnel_response_headers_len_);
865 CHECK(tunnel_response_headers_->data()); 865 CHECK(tunnel_response_headers_->data());
866 866
867 return socket_->Read(tunnel_response_headers_, buf_len, io_callback_); 867 return socket_->Read(tunnel_response_headers_.get(), buf_len, io_callback_);
868 } 868 }
869 869
870 int SocketStream::DoReadTunnelHeadersComplete(int result) { 870 int SocketStream::DoReadTunnelHeadersComplete(int result) {
871 DCHECK_EQ(kTunnelProxy, proxy_mode_); 871 DCHECK_EQ(kTunnelProxy, proxy_mode_);
872 872
873 if (result < 0) { 873 if (result < 0) {
874 next_state_ = STATE_CLOSE; 874 next_state_ = STATE_CLOSE;
875 return result; 875 return result;
876 } 876 }
877 877
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 return result; 1097 return result;
1098 } 1098 }
1099 if (!socket_.get() || !socket_->IsConnected()) { 1099 if (!socket_.get() || !socket_->IsConnected()) {
1100 next_state_ = STATE_CLOSE; 1100 next_state_ = STATE_CLOSE;
1101 return ERR_CONNECTION_CLOSED; 1101 return ERR_CONNECTION_CLOSED;
1102 } 1102 }
1103 1103
1104 // If client has requested close(), and there's nothing to write, then 1104 // If client has requested close(), and there's nothing to write, then
1105 // let's close the socket. 1105 // let's close the socket.
1106 // We don't care about receiving data after the socket is closed. 1106 // We don't care about receiving data after the socket is closed.
1107 if (closing_ && !current_write_buf_ && pending_write_bufs_.empty()) { 1107 if (closing_ && !current_write_buf_.get() && pending_write_bufs_.empty()) {
1108 socket_->Disconnect(); 1108 socket_->Disconnect();
1109 next_state_ = STATE_CLOSE; 1109 next_state_ = STATE_CLOSE;
1110 return OK; 1110 return OK;
1111 } 1111 }
1112 1112
1113 next_state_ = STATE_READ_WRITE; 1113 next_state_ = STATE_READ_WRITE;
1114 1114
1115 // If server already closed the socket, we don't try to read. 1115 // If server already closed the socket, we don't try to read.
1116 if (!server_closed_) { 1116 if (!server_closed_) {
1117 if (!read_buf_) { 1117 if (!read_buf_.get()) {
1118 // No read pending and server didn't close the socket. 1118 // No read pending and server didn't close the socket.
1119 read_buf_ = new IOBuffer(kReadBufferSize); 1119 read_buf_ = new IOBuffer(kReadBufferSize);
1120 result = socket_->Read(read_buf_, kReadBufferSize, 1120 result = socket_->Read(
1121 base::Bind(&SocketStream::OnReadCompleted, 1121 read_buf_.get(),
1122 base::Unretained(this))); 1122 kReadBufferSize,
1123 base::Bind(&SocketStream::OnReadCompleted, base::Unretained(this)));
1123 if (result > 0) { 1124 if (result > 0) {
1124 return DidReceiveData(result); 1125 return DidReceiveData(result);
1125 } else if (result == 0) { 1126 } else if (result == 0) {
1126 // 0 indicates end-of-file, so socket was closed. 1127 // 0 indicates end-of-file, so socket was closed.
1127 next_state_ = STATE_CLOSE; 1128 next_state_ = STATE_CLOSE;
1128 server_closed_ = true; 1129 server_closed_ = true;
1129 return ERR_CONNECTION_CLOSED; 1130 return ERR_CONNECTION_CLOSED;
1130 } 1131 }
1131 // If read is pending, try write as well. 1132 // If read is pending, try write as well.
1132 // Otherwise, return the result and do next loop (to close the 1133 // Otherwise, return the result and do next loop (to close the
1133 // connection). 1134 // connection).
1134 if (result != ERR_IO_PENDING) { 1135 if (result != ERR_IO_PENDING) {
1135 next_state_ = STATE_CLOSE; 1136 next_state_ = STATE_CLOSE;
1136 server_closed_ = true; 1137 server_closed_ = true;
1137 return result; 1138 return result;
1138 } 1139 }
1139 } 1140 }
1140 // Read is pending. 1141 // Read is pending.
1141 DCHECK(read_buf_); 1142 DCHECK(read_buf_.get());
1142 } 1143 }
1143 1144
1144 if (waiting_for_write_completion_) 1145 if (waiting_for_write_completion_)
1145 return ERR_IO_PENDING; 1146 return ERR_IO_PENDING;
1146 1147
1147 if (!current_write_buf_) { 1148 if (!current_write_buf_.get()) {
1148 if (pending_write_bufs_.empty()) { 1149 if (pending_write_bufs_.empty()) {
1149 // Nothing buffered for send. 1150 // Nothing buffered for send.
1150 return ERR_IO_PENDING; 1151 return ERR_IO_PENDING;
1151 } 1152 }
1152 1153
1153 current_write_buf_ = 1154 current_write_buf_ = new DrainableIOBuffer(
1154 new DrainableIOBuffer(pending_write_bufs_.front(), 1155 pending_write_bufs_.front().get(), pending_write_bufs_.front()->size());
1155 pending_write_bufs_.front()->size());
1156 pending_write_bufs_.pop_front(); 1156 pending_write_bufs_.pop_front();
1157 } 1157 }
1158 1158
1159 result = socket_->Write(current_write_buf_, 1159 result = socket_->Write(
1160 current_write_buf_->BytesRemaining(), 1160 current_write_buf_.get(),
1161 base::Bind(&SocketStream::OnWriteCompleted, 1161 current_write_buf_->BytesRemaining(),
1162 base::Unretained(this))); 1162 base::Bind(&SocketStream::OnWriteCompleted, base::Unretained(this)));
1163 1163
1164 if (result == ERR_IO_PENDING) { 1164 if (result == ERR_IO_PENDING) {
1165 waiting_for_write_completion_ = true; 1165 waiting_for_write_completion_ = true;
1166 } else if (result < 0) { 1166 } else if (result < 0) {
1167 // Shortcut. Enter STATE_CLOSE now by changing next_state_ here than by 1167 // Shortcut. Enter STATE_CLOSE now by changing next_state_ here than by
1168 // calling DoReadWrite() again with the error code. 1168 // calling DoReadWrite() again with the error code.
1169 next_state_ = STATE_CLOSE; 1169 next_state_ = STATE_CLOSE;
1170 } else if (result > 0) { 1170 } else if (result > 0) {
1171 // Write is not pending. Return OK and do next loop. 1171 // Write is not pending. Return OK and do next loop.
1172 DidSendData(result); 1172 DidSendData(result);
(...skipping 12 matching lines...) Expand all
1185 int SocketStream::HandleCertificateRequest(int result, SSLConfig* ssl_config) { 1185 int SocketStream::HandleCertificateRequest(int result, SSLConfig* ssl_config) {
1186 if (ssl_config->send_client_cert) { 1186 if (ssl_config->send_client_cert) {
1187 // We already have performed SSL client authentication once and failed. 1187 // We already have performed SSL client authentication once and failed.
1188 return result; 1188 return result;
1189 } 1189 }
1190 1190
1191 DCHECK(socket_.get()); 1191 DCHECK(socket_.get());
1192 scoped_refptr<SSLCertRequestInfo> cert_request_info = new SSLCertRequestInfo; 1192 scoped_refptr<SSLCertRequestInfo> cert_request_info = new SSLCertRequestInfo;
1193 SSLClientSocket* ssl_socket = 1193 SSLClientSocket* ssl_socket =
1194 static_cast<SSLClientSocket*>(socket_.get()); 1194 static_cast<SSLClientSocket*>(socket_.get());
1195 ssl_socket->GetSSLCertRequestInfo(cert_request_info); 1195 ssl_socket->GetSSLCertRequestInfo(cert_request_info.get());
1196 1196
1197 HttpTransactionFactory* factory = context_->http_transaction_factory(); 1197 HttpTransactionFactory* factory = context_->http_transaction_factory();
1198 if (!factory) 1198 if (!factory)
1199 return result; 1199 return result;
1200 scoped_refptr<HttpNetworkSession> session = factory->GetSession(); 1200 scoped_refptr<HttpNetworkSession> session = factory->GetSession();
1201 if (!session.get()) 1201 if (!session.get())
1202 return result; 1202 return result;
1203 1203
1204 // If the user selected one of the certificates in client_certs or declined 1204 // If the user selected one of the certificates in client_certs or declined
1205 // to provide one for this server before, use the past decision 1205 // to provide one for this server before, use the past decision
1206 // automatically. 1206 // automatically.
1207 scoped_refptr<X509Certificate> client_cert; 1207 scoped_refptr<X509Certificate> client_cert;
1208 if (!session->ssl_client_auth_cache()->Lookup( 1208 if (!session->ssl_client_auth_cache()->Lookup(
1209 cert_request_info->host_and_port, &client_cert)) { 1209 cert_request_info->host_and_port, &client_cert)) {
1210 return result; 1210 return result;
1211 } 1211 }
1212 1212
1213 // Note: |client_cert| may be NULL, indicating that the caller 1213 // Note: |client_cert| may be NULL, indicating that the caller
1214 // wishes to proceed anonymously (eg: continue the handshake 1214 // wishes to proceed anonymously (eg: continue the handshake
1215 // without sending a client cert) 1215 // without sending a client cert)
1216 // 1216 //
1217 // Check that the certificate selected is still a certificate the server 1217 // Check that the certificate selected is still a certificate the server
1218 // is likely to accept, based on the criteria supplied in the 1218 // is likely to accept, based on the criteria supplied in the
1219 // CertificateRequest message. 1219 // CertificateRequest message.
1220 const std::vector<std::string>& cert_authorities = 1220 const std::vector<std::string>& cert_authorities =
1221 cert_request_info->cert_authorities; 1221 cert_request_info->cert_authorities;
1222 if (client_cert && !cert_authorities.empty() && 1222 if (client_cert.get() && !cert_authorities.empty() &&
1223 !client_cert->IsIssuedByEncoded(cert_authorities)) { 1223 !client_cert->IsIssuedByEncoded(cert_authorities)) {
1224 return result; 1224 return result;
1225 } 1225 }
1226 1226
1227 ssl_config->send_client_cert = true; 1227 ssl_config->send_client_cert = true;
1228 ssl_config->client_cert = client_cert; 1228 ssl_config->client_cert = client_cert;
1229 next_state_ = STATE_TCP_CONNECT; 1229 next_state_ = STATE_TCP_CONNECT;
1230 return OK; 1230 return OK;
1231 } 1231 }
1232 1232
1233 int SocketStream::AllowCertErrorForReconnection(SSLConfig* ssl_config) { 1233 int SocketStream::AllowCertErrorForReconnection(SSLConfig* ssl_config) {
1234 DCHECK(ssl_config); 1234 DCHECK(ssl_config);
1235 // The SSL handshake didn't finish, or the server closed the SSL connection. 1235 // The SSL handshake didn't finish, or the server closed the SSL connection.
1236 // So, we should restart establishing connection with the certificate in 1236 // So, we should restart establishing connection with the certificate in
1237 // allowed bad certificates in |ssl_config|. 1237 // allowed bad certificates in |ssl_config|.
1238 // See also net/http/http_network_transaction.cc HandleCertificateError() and 1238 // See also net/http/http_network_transaction.cc HandleCertificateError() and
1239 // RestartIgnoringLastError(). 1239 // RestartIgnoringLastError().
1240 SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(socket_.get()); 1240 SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(socket_.get());
1241 SSLInfo ssl_info; 1241 SSLInfo ssl_info;
1242 ssl_socket->GetSSLInfo(&ssl_info); 1242 ssl_socket->GetSSLInfo(&ssl_info);
1243 if (ssl_info.cert == NULL || 1243 if (ssl_info.cert.get() == NULL ||
1244 ssl_config->IsAllowedBadCert(ssl_info.cert, NULL)) { 1244 ssl_config->IsAllowedBadCert(ssl_info.cert.get(), NULL)) {
1245 // If we already have the certificate in the set of allowed bad 1245 // If we already have the certificate in the set of allowed bad
1246 // certificates, we did try it and failed again, so we should not 1246 // certificates, we did try it and failed again, so we should not
1247 // retry again: the connection should fail at last. 1247 // retry again: the connection should fail at last.
1248 next_state_ = STATE_CLOSE; 1248 next_state_ = STATE_CLOSE;
1249 return ERR_UNEXPECTED; 1249 return ERR_UNEXPECTED;
1250 } 1250 }
1251 // Add the bad certificate to the set of allowed certificates in the 1251 // Add the bad certificate to the set of allowed certificates in the
1252 // SSL config object. 1252 // SSL config object.
1253 SSLConfig::CertAndStatus bad_cert; 1253 SSLConfig::CertAndStatus bad_cert;
1254 if (!X509Certificate::GetDEREncoded(ssl_info.cert->os_cert_handle(), 1254 if (!X509Certificate::GetDEREncoded(ssl_info.cert->os_cert_handle(),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 1316
1317 SSLConfigService* SocketStream::ssl_config_service() const { 1317 SSLConfigService* SocketStream::ssl_config_service() const {
1318 return context_->ssl_config_service(); 1318 return context_->ssl_config_service();
1319 } 1319 }
1320 1320
1321 ProxyService* SocketStream::proxy_service() const { 1321 ProxyService* SocketStream::proxy_service() const {
1322 return context_->proxy_service(); 1322 return context_->proxy_service();
1323 } 1323 }
1324 1324
1325 } // namespace net 1325 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/unix_domain_socket_posix.cc ('k') | net/spdy/spdy_http_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698