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 "net/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 } | 787 } |
788 | 788 |
789 void SpdySession::StartRead() { | 789 void SpdySession::StartRead() { |
790 DCHECK_NE(state_, STATE_DO_READ_COMPLETE); | 790 DCHECK_NE(state_, STATE_DO_READ_COMPLETE); |
791 read_pending_ = false; | 791 read_pending_ = false; |
792 DoLoop(OK); | 792 DoLoop(OK); |
793 } | 793 } |
794 | 794 |
795 int SpdySession::DoLoop(int result) { | 795 int SpdySession::DoLoop(int result) { |
796 bytes_read_ = 0; | 796 bytes_read_ = 0; |
| 797 |
| 798 // The SpdyFramer will use callbacks onto |this| as it parses frames. |
| 799 // When errors occur, those callbacks can lead to teardown of all references |
| 800 // to |this|, so maintain a reference to self during this call for safe |
| 801 // cleanup. |
| 802 scoped_refptr<SpdySession> self(this); |
| 803 |
797 do { | 804 do { |
798 if (read_pending_) | 805 if (read_pending_) |
799 return OK; | 806 return OK; |
800 | 807 |
801 switch (state_) { | 808 switch (state_) { |
802 case STATE_DO_READ: | 809 case STATE_DO_READ: |
803 DCHECK_EQ(result, OK); | 810 DCHECK_EQ(result, OK); |
804 result = DoRead(); | 811 result = DoRead(); |
805 break; | 812 break; |
806 case STATE_DO_READ_COMPLETE: | 813 case STATE_DO_READ_COMPLETE: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 error = ERR_CONNECTION_CLOSED; | 862 error = ERR_CONNECTION_CLOSED; |
856 CloseSessionOnError(error, true, "result is <= 0."); | 863 CloseSessionOnError(error, true, "result is <= 0."); |
857 return ERR_CONNECTION_CLOSED; | 864 return ERR_CONNECTION_CLOSED; |
858 } | 865 } |
859 | 866 |
860 total_bytes_received_ += result; | 867 total_bytes_received_ += result; |
861 bytes_read_ += result; | 868 bytes_read_ += result; |
862 | 869 |
863 last_activity_time_ = base::TimeTicks::Now(); | 870 last_activity_time_ = base::TimeTicks::Now(); |
864 | 871 |
865 // The SpdyFramer will use callbacks onto |this| as it parses frames. | |
866 // When errors occur, those callbacks can lead to teardown of all references | |
867 // to |this|, so maintain a reference to self during this call for safe | |
868 // cleanup. | |
869 scoped_refptr<SpdySession> self(this); | |
870 | |
871 DCHECK(buffered_spdy_framer_.get()); | 872 DCHECK(buffered_spdy_framer_.get()); |
872 char *data = read_buffer_->data(); | 873 char *data = read_buffer_->data(); |
873 while (result && | 874 while (result && |
874 buffered_spdy_framer_->error_code() == | 875 buffered_spdy_framer_->error_code() == |
875 SpdyFramer::SPDY_NO_ERROR) { | 876 SpdyFramer::SPDY_NO_ERROR) { |
876 uint32 bytes_processed = | 877 uint32 bytes_processed = |
877 buffered_spdy_framer_->ProcessInput(data, result); | 878 buffered_spdy_framer_->ProcessInput(data, result); |
878 result -= bytes_processed; | 879 result -= bytes_processed; |
879 data += bytes_processed; | 880 data += bytes_processed; |
880 if (buffered_spdy_framer_->state() == SpdyFramer::SPDY_DONE) | 881 if (buffered_spdy_framer_->state() == SpdyFramer::SPDY_DONE) |
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1996 SSLClientSocket* SpdySession::GetSSLClientSocket() const { | 1997 SSLClientSocket* SpdySession::GetSSLClientSocket() const { |
1997 if (!is_secure_) | 1998 if (!is_secure_) |
1998 return NULL; | 1999 return NULL; |
1999 SSLClientSocket* ssl_socket = | 2000 SSLClientSocket* ssl_socket = |
2000 reinterpret_cast<SSLClientSocket*>(connection_->socket()); | 2001 reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
2001 DCHECK(ssl_socket); | 2002 DCHECK(ssl_socket); |
2002 return ssl_socket; | 2003 return ssl_socket; |
2003 } | 2004 } |
2004 | 2005 |
2005 } // namespace net | 2006 } // namespace net |
OLD | NEW |