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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 371 |
372 net::Error SpdySession::InitializeWithSocket( | 372 net::Error SpdySession::InitializeWithSocket( |
373 ClientSocketHandle* connection, | 373 ClientSocketHandle* connection, |
374 bool is_secure, | 374 bool is_secure, |
375 int certificate_error_code) { | 375 int certificate_error_code) { |
376 base::StatsCounter spdy_sessions("spdy.sessions"); | 376 base::StatsCounter spdy_sessions("spdy.sessions"); |
377 spdy_sessions.Increment(); | 377 spdy_sessions.Increment(); |
378 | 378 |
379 state_ = CONNECTED; | 379 state_ = CONNECTED; |
380 connection_.reset(connection); | 380 connection_.reset(connection); |
| 381 connection_->AddLayeredPool(this); |
381 is_secure_ = is_secure; | 382 is_secure_ = is_secure; |
382 certificate_error_code_ = certificate_error_code; | 383 certificate_error_code_ = certificate_error_code; |
383 | 384 |
384 if (is_secure_) { | 385 if (is_secure_) { |
385 SSLClientSocket* ssl_socket = | 386 SSLClientSocket* ssl_socket = |
386 reinterpret_cast<SSLClientSocket*>(connection_->socket()); | 387 reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
387 DCHECK(ssl_socket); | 388 DCHECK(ssl_socket); |
388 | 389 |
389 SSLClientSocket::NextProto protocol_negotiated = | 390 SSLClientSocket::NextProto protocol_negotiated = |
390 ssl_socket->protocol_negotiated(); | 391 ssl_socket->protocol_negotiated(); |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 return connection_->socket()->GetPeerAddress(address); | 1152 return connection_->socket()->GetPeerAddress(address); |
1152 } | 1153 } |
1153 | 1154 |
1154 int SpdySession::GetLocalAddress(IPEndPoint* address) const { | 1155 int SpdySession::GetLocalAddress(IPEndPoint* address) const { |
1155 if (!connection_->socket()) | 1156 if (!connection_->socket()) |
1156 return ERR_SOCKET_NOT_CONNECTED; | 1157 return ERR_SOCKET_NOT_CONNECTED; |
1157 | 1158 |
1158 return connection_->socket()->GetLocalAddress(address); | 1159 return connection_->socket()->GetLocalAddress(address); |
1159 } | 1160 } |
1160 | 1161 |
| 1162 bool SpdySession::CloseOneIdleConnection() { |
| 1163 if (spdy_session_pool_ && num_active_streams() == 0) { |
| 1164 // Should delete this. |
| 1165 RemoveFromPool(); |
| 1166 return true; |
| 1167 } |
| 1168 return false; |
| 1169 } |
| 1170 |
1161 void SpdySession::ActivateStream(SpdyStream* stream) { | 1171 void SpdySession::ActivateStream(SpdyStream* stream) { |
1162 const spdy::SpdyStreamId id = stream->stream_id(); | 1172 const spdy::SpdyStreamId id = stream->stream_id(); |
1163 DCHECK(!IsStreamActive(id)); | 1173 DCHECK(!IsStreamActive(id)); |
1164 | 1174 |
1165 active_streams_[id] = stream; | 1175 active_streams_[id] = stream; |
1166 } | 1176 } |
1167 | 1177 |
1168 void SpdySession::DeleteStream(spdy::SpdyStreamId id, int status) { | 1178 void SpdySession::DeleteStream(spdy::SpdyStreamId id, int status) { |
1169 // For push streams, if they are being deleted normally, we leave | 1179 // For push streams, if they are being deleted normally, we leave |
1170 // the stream in the unclaimed_pushed_streams_ list. However, if | 1180 // the stream in the unclaimed_pushed_streams_ list. However, if |
(...skipping 14 matching lines...) Expand all Loading... |
1185 ActiveStreamMap::iterator it2 = active_streams_.find(id); | 1195 ActiveStreamMap::iterator it2 = active_streams_.find(id); |
1186 if (it2 == active_streams_.end()) | 1196 if (it2 == active_streams_.end()) |
1187 return; | 1197 return; |
1188 | 1198 |
1189 // If this is an active stream, call the callback. | 1199 // If this is an active stream, call the callback. |
1190 const scoped_refptr<SpdyStream> stream(it2->second); | 1200 const scoped_refptr<SpdyStream> stream(it2->second); |
1191 active_streams_.erase(it2); | 1201 active_streams_.erase(it2); |
1192 if (stream) | 1202 if (stream) |
1193 stream->OnClose(status); | 1203 stream->OnClose(status); |
1194 ProcessPendingCreateStreams(); | 1204 ProcessPendingCreateStreams(); |
| 1205 if (num_active_streams() == 0 && connection_->is_initialized() && |
| 1206 connection_->IsPoolStalled()) { |
| 1207 // Should delete this. |
| 1208 RemoveFromPool(); |
| 1209 } |
1195 } | 1210 } |
1196 | 1211 |
1197 void SpdySession::RemoveFromPool() { | 1212 void SpdySession::RemoveFromPool() { |
1198 if (spdy_session_pool_) { | 1213 if (spdy_session_pool_) { |
1199 SpdySessionPool* pool = spdy_session_pool_; | 1214 SpdySessionPool* pool = spdy_session_pool_; |
1200 spdy_session_pool_ = NULL; | 1215 spdy_session_pool_ = NULL; |
1201 pool->Remove(make_scoped_refptr(this)); | 1216 pool->Remove(make_scoped_refptr(this)); |
1202 } | 1217 } |
1203 } | 1218 } |
1204 | 1219 |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1901 if (it == pending_callback_map_.end()) | 1916 if (it == pending_callback_map_.end()) |
1902 return; | 1917 return; |
1903 | 1918 |
1904 CompletionCallback callback = it->second.callback; | 1919 CompletionCallback callback = it->second.callback; |
1905 int result = it->second.result; | 1920 int result = it->second.result; |
1906 pending_callback_map_.erase(it); | 1921 pending_callback_map_.erase(it); |
1907 callback.Run(result); | 1922 callback.Run(result); |
1908 } | 1923 } |
1909 | 1924 |
1910 } // namespace net | 1925 } // namespace net |
OLD | NEW |