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

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

Issue 10546162: NetLogEventParameter to Callback refactoring 9. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Update comment Created 8 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
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 #include "net/socket/ssl_server_socket_nss.h" 5 #include "net/socket/ssl_server_socket_nss.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <winsock2.h> 8 #include <winsock2.h>
9 #endif 9 #endif
10 10
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 111 }
112 112
113 SSLServerSocketNSS::~SSLServerSocketNSS() { 113 SSLServerSocketNSS::~SSLServerSocketNSS() {
114 if (nss_fd_ != NULL) { 114 if (nss_fd_ != NULL) {
115 PR_Close(nss_fd_); 115 PR_Close(nss_fd_);
116 nss_fd_ = NULL; 116 nss_fd_ = NULL;
117 } 117 }
118 } 118 }
119 119
120 int SSLServerSocketNSS::Handshake(const CompletionCallback& callback) { 120 int SSLServerSocketNSS::Handshake(const CompletionCallback& callback) {
121 net_log_.BeginEvent(NetLog::TYPE_SSL_SERVER_HANDSHAKE, NULL); 121 net_log_.BeginEvent(NetLog::TYPE_SSL_SERVER_HANDSHAKE);
122 122
123 int rv = Init(); 123 int rv = Init();
124 if (rv != OK) { 124 if (rv != OK) {
125 LOG(ERROR) << "Failed to initialize NSS"; 125 LOG(ERROR) << "Failed to initialize NSS";
126 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_SERVER_HANDSHAKE, rv); 126 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_SERVER_HANDSHAKE, rv);
127 return rv; 127 return rv;
128 } 128 }
129 129
130 rv = InitializeSSLOptions(); 130 rv = InitializeSSLOptions();
131 if (rv != OK) { 131 if (rv != OK) {
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 DCHECK_GT(user_read_buf_len_, 0); 602 DCHECK_GT(user_read_buf_len_, 0);
603 int rv = PR_Read(nss_fd_, user_read_buf_->data(), user_read_buf_len_); 603 int rv = PR_Read(nss_fd_, user_read_buf_->data(), user_read_buf_len_);
604 if (rv >= 0) 604 if (rv >= 0)
605 return rv; 605 return rv;
606 PRErrorCode prerr = PR_GetError(); 606 PRErrorCode prerr = PR_GetError();
607 if (prerr == PR_WOULD_BLOCK_ERROR) { 607 if (prerr == PR_WOULD_BLOCK_ERROR) {
608 return ERR_IO_PENDING; 608 return ERR_IO_PENDING;
609 } 609 }
610 rv = MapNSSError(prerr); 610 rv = MapNSSError(prerr);
611 net_log_.AddEvent(NetLog::TYPE_SSL_READ_ERROR, 611 net_log_.AddEvent(NetLog::TYPE_SSL_READ_ERROR,
612 make_scoped_refptr(new SSLErrorParams(rv, prerr))); 612 CreateNetLogSSLErrorCallback(rv, prerr));
613 return rv; 613 return rv;
614 } 614 }
615 615
616 int SSLServerSocketNSS::DoPayloadWrite() { 616 int SSLServerSocketNSS::DoPayloadWrite() {
617 DCHECK(user_write_buf_); 617 DCHECK(user_write_buf_);
618 int rv = PR_Write(nss_fd_, user_write_buf_->data(), user_write_buf_len_); 618 int rv = PR_Write(nss_fd_, user_write_buf_->data(), user_write_buf_len_);
619 if (rv >= 0) 619 if (rv >= 0)
620 return rv; 620 return rv;
621 PRErrorCode prerr = PR_GetError(); 621 PRErrorCode prerr = PR_GetError();
622 if (prerr == PR_WOULD_BLOCK_ERROR) { 622 if (prerr == PR_WOULD_BLOCK_ERROR) {
623 return ERR_IO_PENDING; 623 return ERR_IO_PENDING;
624 } 624 }
625 rv = MapNSSError(prerr); 625 rv = MapNSSError(prerr);
626 net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR, 626 net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR,
627 make_scoped_refptr(new SSLErrorParams(rv, prerr))); 627 CreateNetLogSSLErrorCallback(rv, prerr));
628 return rv; 628 return rv;
629 } 629 }
630 630
631 int SSLServerSocketNSS::DoHandshakeLoop(int last_io_result) { 631 int SSLServerSocketNSS::DoHandshakeLoop(int last_io_result) {
632 int rv = last_io_result; 632 int rv = last_io_result;
633 do { 633 do {
634 // Default to STATE_NONE for next state. 634 // Default to STATE_NONE for next state.
635 // (This is a quirk carried over from the windows 635 // (This is a quirk carried over from the windows
636 // implementation. It makes reading the logs a bit harder.) 636 // implementation. It makes reading the logs a bit harder.)
637 // State handlers can and often do call GotoState just 637 // State handlers can and often do call GotoState just
(...skipping 27 matching lines...) Expand all
665 DCHECK(completed_handshake_); 665 DCHECK(completed_handshake_);
666 DCHECK(next_handshake_state_ == STATE_NONE); 666 DCHECK(next_handshake_state_ == STATE_NONE);
667 667
668 if (result < 0) 668 if (result < 0)
669 return result; 669 return result;
670 670
671 if (!nss_bufs_) { 671 if (!nss_bufs_) {
672 LOG(DFATAL) << "!nss_bufs_"; 672 LOG(DFATAL) << "!nss_bufs_";
673 int rv = ERR_UNEXPECTED; 673 int rv = ERR_UNEXPECTED;
674 net_log_.AddEvent(NetLog::TYPE_SSL_READ_ERROR, 674 net_log_.AddEvent(NetLog::TYPE_SSL_READ_ERROR,
675 make_scoped_refptr(new SSLErrorParams(rv, 0))); 675 CreateNetLogSSLErrorCallback(rv, 0));
676 return rv; 676 return rv;
677 } 677 }
678 678
679 bool network_moved; 679 bool network_moved;
680 int rv; 680 int rv;
681 do { 681 do {
682 rv = DoPayloadRead(); 682 rv = DoPayloadRead();
683 network_moved = DoTransportIO(); 683 network_moved = DoTransportIO();
684 } while (rv == ERR_IO_PENDING && network_moved); 684 } while (rv == ERR_IO_PENDING && network_moved);
685 return rv; 685 return rv;
686 } 686 }
687 687
688 int SSLServerSocketNSS::DoWriteLoop(int result) { 688 int SSLServerSocketNSS::DoWriteLoop(int result) {
689 DCHECK(completed_handshake_); 689 DCHECK(completed_handshake_);
690 DCHECK(next_handshake_state_ == STATE_NONE); 690 DCHECK(next_handshake_state_ == STATE_NONE);
691 691
692 if (result < 0) 692 if (result < 0)
693 return result; 693 return result;
694 694
695 if (!nss_bufs_) { 695 if (!nss_bufs_) {
696 LOG(DFATAL) << "!nss_bufs_"; 696 LOG(DFATAL) << "!nss_bufs_";
697 int rv = ERR_UNEXPECTED; 697 int rv = ERR_UNEXPECTED;
698 net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR, 698 net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR,
699 make_scoped_refptr(new SSLErrorParams(rv, 0))); 699 CreateNetLogSSLErrorCallback(rv, 0));
700 return rv; 700 return rv;
701 } 701 }
702 702
703 bool network_moved; 703 bool network_moved;
704 int rv; 704 int rv;
705 do { 705 do {
706 rv = DoPayloadWrite(); 706 rv = DoPayloadWrite();
707 network_moved = DoTransportIO(); 707 network_moved = DoTransportIO();
708 } while (rv == ERR_IO_PENDING && network_moved); 708 } while (rv == ERR_IO_PENDING && network_moved);
709 return rv; 709 return rv;
710 } 710 }
711 711
712 int SSLServerSocketNSS::DoHandshake() { 712 int SSLServerSocketNSS::DoHandshake() {
713 int net_error = OK; 713 int net_error = OK;
714 SECStatus rv = SSL_ForceHandshake(nss_fd_); 714 SECStatus rv = SSL_ForceHandshake(nss_fd_);
715 715
716 if (rv == SECSuccess) { 716 if (rv == SECSuccess) {
717 completed_handshake_ = true; 717 completed_handshake_ = true;
718 } else { 718 } else {
719 PRErrorCode prerr = PR_GetError(); 719 PRErrorCode prerr = PR_GetError();
720 net_error = MapNSSError(prerr); 720 net_error = MapNSSError(prerr);
721 721
722 // If not done, stay in this state 722 // If not done, stay in this state
723 if (net_error == ERR_IO_PENDING) { 723 if (net_error == ERR_IO_PENDING) {
724 GotoState(STATE_HANDSHAKE); 724 GotoState(STATE_HANDSHAKE);
725 } else { 725 } else {
726 LOG(ERROR) << "handshake failed; NSS error code " << prerr 726 LOG(ERROR) << "handshake failed; NSS error code " << prerr
727 << ", net_error " << net_error; 727 << ", net_error " << net_error;
728 net_log_.AddEvent( 728 net_log_.AddEvent(NetLog::TYPE_SSL_HANDSHAKE_ERROR,
729 NetLog::TYPE_SSL_HANDSHAKE_ERROR, 729 CreateNetLogSSLErrorCallback(net_error, prerr));
730 make_scoped_refptr(new SSLErrorParams(net_error, prerr)));
731 } 730 }
732 } 731 }
733 return net_error; 732 return net_error;
734 } 733 }
735 734
736 void SSLServerSocketNSS::DoHandshakeCallback(int rv) { 735 void SSLServerSocketNSS::DoHandshakeCallback(int rv) {
737 DCHECK_NE(rv, ERR_IO_PENDING); 736 DCHECK_NE(rv, ERR_IO_PENDING);
738 737
739 CompletionCallback c = user_handshake_callback_; 738 CompletionCallback c = user_handshake_callback_;
740 user_handshake_callback_.Reset(); 739 user_handshake_callback_.Reset();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 // initializes the NSS base library. 794 // initializes the NSS base library.
796 EnsureNSSSSLInit(); 795 EnsureNSSSSLInit();
797 if (!NSS_IsInitialized()) 796 if (!NSS_IsInitialized())
798 return ERR_UNEXPECTED; 797 return ERR_UNEXPECTED;
799 798
800 EnableSSLServerSockets(); 799 EnableSSLServerSockets();
801 return OK; 800 return OK;
802 } 801 }
803 802
804 } // namespace net 803 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698