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/logging.h" | 10 #include "base/logging.h" |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 414 |
415 net::Error SpdySession::InitializeWithSocket( | 415 net::Error SpdySession::InitializeWithSocket( |
416 ClientSocketHandle* connection, | 416 ClientSocketHandle* connection, |
417 bool is_secure, | 417 bool is_secure, |
418 int certificate_error_code) { | 418 int certificate_error_code) { |
419 base::StatsCounter spdy_sessions("spdy.sessions"); | 419 base::StatsCounter spdy_sessions("spdy.sessions"); |
420 spdy_sessions.Increment(); | 420 spdy_sessions.Increment(); |
421 | 421 |
422 state_ = CONNECTED; | 422 state_ = CONNECTED; |
423 connection_.reset(connection); | 423 connection_.reset(connection); |
| 424 connection_->AddLayeredPool(this); |
424 is_secure_ = is_secure; | 425 is_secure_ = is_secure; |
425 certificate_error_code_ = certificate_error_code; | 426 certificate_error_code_ = certificate_error_code; |
426 | 427 |
427 SSLClientSocket::NextProto protocol = g_default_protocol; | 428 SSLClientSocket::NextProto protocol = g_default_protocol; |
428 if (is_secure_) { | 429 if (is_secure_) { |
429 SSLClientSocket* ssl_socket = GetSSLClientSocket(); | 430 SSLClientSocket* ssl_socket = GetSSLClientSocket(); |
430 | 431 |
431 SSLClientSocket::NextProto protocol_negotiated = | 432 SSLClientSocket::NextProto protocol_negotiated = |
432 ssl_socket->protocol_negotiated(); | 433 ssl_socket->protocol_negotiated(); |
433 if (protocol_negotiated != SSLClientSocket::kProtoUnknown) { | 434 if (protocol_negotiated != SSLClientSocket::kProtoUnknown) { |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 return connection_->socket()->GetPeerAddress(address); | 1212 return connection_->socket()->GetPeerAddress(address); |
1212 } | 1213 } |
1213 | 1214 |
1214 int SpdySession::GetLocalAddress(IPEndPoint* address) const { | 1215 int SpdySession::GetLocalAddress(IPEndPoint* address) const { |
1215 if (!connection_->socket()) | 1216 if (!connection_->socket()) |
1216 return ERR_SOCKET_NOT_CONNECTED; | 1217 return ERR_SOCKET_NOT_CONNECTED; |
1217 | 1218 |
1218 return connection_->socket()->GetLocalAddress(address); | 1219 return connection_->socket()->GetLocalAddress(address); |
1219 } | 1220 } |
1220 | 1221 |
| 1222 bool SpdySession::CloseOneIdleConnection() { |
| 1223 if (spdy_session_pool_ && num_active_streams() == 0) { |
| 1224 bool ret = HasOneRef(); |
| 1225 // Will remove a reference to this. |
| 1226 RemoveFromPool(); |
| 1227 // Since the underlying socket is only returned when |this| is destroyed |
| 1228 // we should only return true if RemoveFromPool() removed the last ref. |
| 1229 return ret; |
| 1230 } |
| 1231 return false; |
| 1232 } |
| 1233 |
1221 void SpdySession::ActivateStream(SpdyStream* stream) { | 1234 void SpdySession::ActivateStream(SpdyStream* stream) { |
1222 const SpdyStreamId id = stream->stream_id(); | 1235 const SpdyStreamId id = stream->stream_id(); |
1223 DCHECK(!IsStreamActive(id)); | 1236 DCHECK(!IsStreamActive(id)); |
1224 | 1237 |
1225 active_streams_[id] = stream; | 1238 active_streams_[id] = stream; |
1226 } | 1239 } |
1227 | 1240 |
1228 void SpdySession::DeleteStream(SpdyStreamId id, int status) { | 1241 void SpdySession::DeleteStream(SpdyStreamId id, int status) { |
1229 // For push streams, if they are being deleted normally, we leave | 1242 // For push streams, if they are being deleted normally, we leave |
1230 // the stream in the unclaimed_pushed_streams_ list. However, if | 1243 // the stream in the unclaimed_pushed_streams_ list. However, if |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 SSLClientSocket* SpdySession::GetSSLClientSocket() const { | 1963 SSLClientSocket* SpdySession::GetSSLClientSocket() const { |
1951 if (!is_secure_) | 1964 if (!is_secure_) |
1952 return NULL; | 1965 return NULL; |
1953 SSLClientSocket* ssl_socket = | 1966 SSLClientSocket* ssl_socket = |
1954 reinterpret_cast<SSLClientSocket*>(connection_->socket()); | 1967 reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
1955 DCHECK(ssl_socket); | 1968 DCHECK(ssl_socket); |
1956 return ssl_socket; | 1969 return ssl_socket; |
1957 } | 1970 } |
1958 | 1971 |
1959 } // namespace net | 1972 } // namespace net |
OLD | NEW |