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

Side by Side Diff: net/socket/ssl_client_socket_win.cc

Issue 8801004: base::Bind: Convert StreamSocket::Connect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes Created 9 years 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/ssl_client_socket_win.h ('k') | net/socket/ssl_server_socket_nss.h » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/socket/ssl_client_socket_win.h" 5 #include "net/socket/ssl_client_socket_win.h"
6 6
7 #include <schnlsp.h> 7 #include <schnlsp.h>
8 #include <map> 8 #include <map>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 : ALLOW_THIS_IN_INITIALIZER_LIST( 390 : ALLOW_THIS_IN_INITIALIZER_LIST(
391 handshake_io_callback_(this, 391 handshake_io_callback_(this,
392 &SSLClientSocketWin::OnHandshakeIOComplete)), 392 &SSLClientSocketWin::OnHandshakeIOComplete)),
393 ALLOW_THIS_IN_INITIALIZER_LIST( 393 ALLOW_THIS_IN_INITIALIZER_LIST(
394 read_callback_(this, &SSLClientSocketWin::OnReadComplete)), 394 read_callback_(this, &SSLClientSocketWin::OnReadComplete)),
395 ALLOW_THIS_IN_INITIALIZER_LIST( 395 ALLOW_THIS_IN_INITIALIZER_LIST(
396 write_callback_(this, &SSLClientSocketWin::OnWriteComplete)), 396 write_callback_(this, &SSLClientSocketWin::OnWriteComplete)),
397 transport_(transport_socket), 397 transport_(transport_socket),
398 host_and_port_(host_and_port), 398 host_and_port_(host_and_port),
399 ssl_config_(ssl_config), 399 ssl_config_(ssl_config),
400 user_connect_callback_(NULL), 400 old_user_connect_callback_(NULL),
401 user_read_callback_(NULL), 401 user_read_callback_(NULL),
402 user_read_buf_len_(0), 402 user_read_buf_len_(0),
403 user_write_callback_(NULL), 403 user_write_callback_(NULL),
404 user_write_buf_len_(0), 404 user_write_buf_len_(0),
405 next_state_(STATE_NONE), 405 next_state_(STATE_NONE),
406 cert_verifier_(context.cert_verifier), 406 cert_verifier_(context.cert_verifier),
407 creds_(NULL), 407 creds_(NULL),
408 isc_status_(SEC_E_OK), 408 isc_status_(SEC_E_OK),
409 payload_send_buffer_len_(0), 409 payload_send_buffer_len_(0),
410 bytes_sent_(0), 410 bytes_sent_(0),
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 556
557 SSLClientSocket::NextProtoStatus 557 SSLClientSocket::NextProtoStatus
558 SSLClientSocketWin::GetNextProto(std::string* proto) { 558 SSLClientSocketWin::GetNextProto(std::string* proto) {
559 proto->clear(); 559 proto->clear();
560 return kNextProtoUnsupported; 560 return kNextProtoUnsupported;
561 } 561 }
562 562
563 int SSLClientSocketWin::Connect(OldCompletionCallback* callback) { 563 int SSLClientSocketWin::Connect(OldCompletionCallback* callback) {
564 DCHECK(transport_.get()); 564 DCHECK(transport_.get());
565 DCHECK(next_state_ == STATE_NONE); 565 DCHECK(next_state_ == STATE_NONE);
566 DCHECK(!user_connect_callback_); 566 DCHECK(!old_user_connect_callback_ && user_connect_callback_.is_null());
567 567
568 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL); 568 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL);
569 569
570 int rv = InitializeSSLContext();
571 if (rv != OK) {
572 net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT, NULL);
573 return rv;
574 }
575
576 writing_first_token_ = true;
577 next_state_ = STATE_HANDSHAKE_WRITE;
578 rv = DoLoop(OK);
579 if (rv == ERR_IO_PENDING) {
580 old_user_connect_callback_ = callback;
581 } else {
582 net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT, NULL);
583 }
584 return rv;
585 }
586 int SSLClientSocketWin::Connect(const CompletionCallback& callback) {
587 DCHECK(transport_.get());
588 DCHECK(next_state_ == STATE_NONE);
589 DCHECK(!old_user_connect_callback_ && user_connect_callback_.is_null());
590
591 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL);
592
570 int rv = InitializeSSLContext(); 593 int rv = InitializeSSLContext();
571 if (rv != OK) { 594 if (rv != OK) {
572 net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT, NULL); 595 net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT, NULL);
573 return rv; 596 return rv;
574 } 597 }
575 598
576 writing_first_token_ = true; 599 writing_first_token_ = true;
577 next_state_ = STATE_HANDSHAKE_WRITE; 600 next_state_ = STATE_HANDSHAKE_WRITE;
578 rv = DoLoop(OK); 601 rv = DoLoop(OK);
579 if (rv == ERR_IO_PENDING) { 602 if (rv == ERR_IO_PENDING) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 856
834 void SSLClientSocketWin::OnHandshakeIOComplete(int result) { 857 void SSLClientSocketWin::OnHandshakeIOComplete(int result) {
835 int rv = DoLoop(result); 858 int rv = DoLoop(result);
836 859
837 // The SSL handshake has some round trips. We need to notify the caller of 860 // The SSL handshake has some round trips. We need to notify the caller of
838 // success or any error, other than waiting for IO. 861 // success or any error, other than waiting for IO.
839 if (rv != ERR_IO_PENDING) { 862 if (rv != ERR_IO_PENDING) {
840 // If there is no connect callback available to call, we are renegotiating 863 // If there is no connect callback available to call, we are renegotiating
841 // (which occurs because we are in the middle of a Read when the 864 // (which occurs because we are in the middle of a Read when the
842 // renegotiation process starts). So we complete the Read here. 865 // renegotiation process starts). So we complete the Read here.
843 if (!user_connect_callback_) { 866 if (!old_user_connect_callback_ && user_connect_callback_.is_null()) {
844 OldCompletionCallback* c = user_read_callback_; 867 OldCompletionCallback* c = user_read_callback_;
845 user_read_callback_ = NULL; 868 user_read_callback_ = NULL;
846 user_read_buf_ = NULL; 869 user_read_buf_ = NULL;
847 user_read_buf_len_ = 0; 870 user_read_buf_len_ = 0;
848 c->Run(rv); 871 c->Run(rv);
849 return; 872 return;
850 } 873 }
851 net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT, NULL); 874 net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT, NULL);
852 OldCompletionCallback* c = user_connect_callback_; 875 if (old_user_connect_callback_) {
853 user_connect_callback_ = NULL; 876 OldCompletionCallback* c = old_user_connect_callback_;
854 c->Run(rv); 877 old_user_connect_callback_ = NULL;
878 c->Run(rv);
879 } else {
880 CompletionCallback c = user_connect_callback_;
881 user_connect_callback_.Reset();
882 c.Run(rv);
883 }
855 } 884 }
856 } 885 }
857 886
858 void SSLClientSocketWin::OnReadComplete(int result) { 887 void SSLClientSocketWin::OnReadComplete(int result) {
859 DCHECK(completed_handshake()); 888 DCHECK(completed_handshake());
860 889
861 result = DoPayloadReadComplete(result); 890 result = DoPayloadReadComplete(result);
862 if (result > 0) 891 if (result > 0)
863 result = DoPayloadDecrypt(); 892 result = DoPayloadDecrypt();
864 if (result != ERR_IO_PENDING) { 893 if (result != ERR_IO_PENDING) {
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 server_cert_ = new_server_cert; 1569 server_cert_ = new_server_cert;
1541 next_state_ = STATE_VERIFY_CERT; 1570 next_state_ = STATE_VERIFY_CERT;
1542 } 1571 }
1543 CertFreeCertificateContext(server_cert_handle); 1572 CertFreeCertificateContext(server_cert_handle);
1544 return OK; 1573 return OK;
1545 } 1574 }
1546 1575
1547 // Called when a renegotiation is completed. |result| is the verification 1576 // Called when a renegotiation is completed. |result| is the verification
1548 // result of the server certificate received during renegotiation. 1577 // result of the server certificate received during renegotiation.
1549 void SSLClientSocketWin::DidCompleteRenegotiation() { 1578 void SSLClientSocketWin::DidCompleteRenegotiation() {
1550 DCHECK(!user_connect_callback_); 1579 DCHECK(!old_user_connect_callback_ && user_connect_callback_.is_null());
1551 DCHECK(user_read_callback_); 1580 DCHECK(user_read_callback_);
1552 renegotiating_ = false; 1581 renegotiating_ = false;
1553 next_state_ = STATE_COMPLETED_RENEGOTIATION; 1582 next_state_ = STATE_COMPLETED_RENEGOTIATION;
1554 } 1583 }
1555 1584
1556 void SSLClientSocketWin::LogConnectionTypeMetrics() const { 1585 void SSLClientSocketWin::LogConnectionTypeMetrics() const {
1557 UpdateConnectionTypeHistograms(CONNECTION_SSL); 1586 UpdateConnectionTypeHistograms(CONNECTION_SSL);
1558 if (server_cert_verify_result_.has_md5) 1587 if (server_cert_verify_result_.has_md5)
1559 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD5); 1588 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD5);
1560 if (server_cert_verify_result_.has_md2) 1589 if (server_cert_verify_result_.has_md2)
1561 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD2); 1590 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD2);
1562 if (server_cert_verify_result_.has_md4) 1591 if (server_cert_verify_result_.has_md4)
1563 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD4); 1592 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD4);
1564 if (server_cert_verify_result_.has_md5_ca) 1593 if (server_cert_verify_result_.has_md5_ca)
1565 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD5_CA); 1594 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD5_CA);
1566 if (server_cert_verify_result_.has_md2_ca) 1595 if (server_cert_verify_result_.has_md2_ca)
1567 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD2_CA); 1596 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD2_CA);
1568 } 1597 }
1569 1598
1570 void SSLClientSocketWin::FreeSendBuffer() { 1599 void SSLClientSocketWin::FreeSendBuffer() {
1571 SECURITY_STATUS status = FreeContextBuffer(send_buffer_.pvBuffer); 1600 SECURITY_STATUS status = FreeContextBuffer(send_buffer_.pvBuffer);
1572 DCHECK(status == SEC_E_OK); 1601 DCHECK(status == SEC_E_OK);
1573 memset(&send_buffer_, 0, sizeof(send_buffer_)); 1602 memset(&send_buffer_, 0, sizeof(send_buffer_));
1574 } 1603 }
1575 1604
1576 } // namespace net 1605 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_win.h ('k') | net/socket/ssl_server_socket_nss.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698