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

Side by Side Diff: net/spdy/spdy_session.cc

Issue 9861032: Close idle connections / SPDY sessions when needed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add instrumentation Created 8 years, 8 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/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
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 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 NetLog::TYPE_SPDY_SESSION_CLOSE, 1141 NetLog::TYPE_SPDY_SESSION_CLOSE,
1141 make_scoped_refptr( 1142 make_scoped_refptr(
1142 new NetLogSpdySessionCloseParameter(err, description))); 1143 new NetLogSpdySessionCloseParameter(err, description)));
1143 1144
1144 // Don't close twice. This can occur because we can have both 1145 // Don't close twice. This can occur because we can have both
1145 // a read and a write outstanding, and each can complete with 1146 // a read and a write outstanding, and each can complete with
1146 // an error. 1147 // an error.
1147 if (state_ != CLOSED) { 1148 if (state_ != CLOSED) {
1148 state_ = CLOSED; 1149 state_ = CLOSED;
1149 error_ = err; 1150 error_ = err;
1151 if (connection_ != NULL && connection_->is_initialized())
1152 connection_->RemoveLayeredPool(this);
1150 if (remove_from_pool) 1153 if (remove_from_pool)
1151 RemoveFromPool(); 1154 RemoveFromPool();
1152 CloseAllStreams(err); 1155 CloseAllStreams(err);
1153 } 1156 }
1154 } 1157 }
1155 1158
1156 Value* SpdySession::GetInfoAsValue() const { 1159 Value* SpdySession::GetInfoAsValue() const {
1157 DictionaryValue* dict = new DictionaryValue(); 1160 DictionaryValue* dict = new DictionaryValue();
1158 1161
1159 dict->SetInteger("source_id", net_log_.source().id); 1162 dict->SetInteger("source_id", net_log_.source().id);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 return connection_->socket()->GetPeerAddress(address); 1214 return connection_->socket()->GetPeerAddress(address);
1212 } 1215 }
1213 1216
1214 int SpdySession::GetLocalAddress(IPEndPoint* address) const { 1217 int SpdySession::GetLocalAddress(IPEndPoint* address) const {
1215 if (!connection_->socket()) 1218 if (!connection_->socket())
1216 return ERR_SOCKET_NOT_CONNECTED; 1219 return ERR_SOCKET_NOT_CONNECTED;
1217 1220
1218 return connection_->socket()->GetLocalAddress(address); 1221 return connection_->socket()->GetLocalAddress(address);
1219 } 1222 }
1220 1223
1224 bool SpdySession::CloseOneIdleConnection() {
1225 if (spdy_session_pool_ && num_active_streams() == 0) {
1226 bool ret = HasOneRef();
1227 // Will remove a reference to this.
1228 RemoveFromPool();
1229 // Since the underlying socket is only returned when |this| is destroyed
1230 // we should only return true if RemoveFromPool() removed the last ref.
1231 return ret;
1232 }
1233 return false;
1234 }
1235
1221 void SpdySession::ActivateStream(SpdyStream* stream) { 1236 void SpdySession::ActivateStream(SpdyStream* stream) {
1222 const SpdyStreamId id = stream->stream_id(); 1237 const SpdyStreamId id = stream->stream_id();
1223 DCHECK(!IsStreamActive(id)); 1238 DCHECK(!IsStreamActive(id));
1224 1239
1225 active_streams_[id] = stream; 1240 active_streams_[id] = stream;
1226 } 1241 }
1227 1242
1228 void SpdySession::DeleteStream(SpdyStreamId id, int status) { 1243 void SpdySession::DeleteStream(SpdyStreamId id, int status) {
1229 // For push streams, if they are being deleted normally, we leave 1244 // For push streams, if they are being deleted normally, we leave
1230 // the stream in the unclaimed_pushed_streams_ list. However, if 1245 // the stream in the unclaimed_pushed_streams_ list. However, if
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 SSLClientSocket* SpdySession::GetSSLClientSocket() const { 1965 SSLClientSocket* SpdySession::GetSSLClientSocket() const {
1951 if (!is_secure_) 1966 if (!is_secure_)
1952 return NULL; 1967 return NULL;
1953 SSLClientSocket* ssl_socket = 1968 SSLClientSocket* ssl_socket =
1954 reinterpret_cast<SSLClientSocket*>(connection_->socket()); 1969 reinterpret_cast<SSLClientSocket*>(connection_->socket());
1955 DCHECK(ssl_socket); 1970 DCHECK(ssl_socket);
1956 return ssl_socket; 1971 return ssl_socket;
1957 } 1972 }
1958 1973
1959 } // namespace net 1974 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698