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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 net::Error SpdySession::InitializeWithSocket( | 331 net::Error SpdySession::InitializeWithSocket( |
332 ClientSocketHandle* connection, | 332 ClientSocketHandle* connection, |
333 bool is_secure, | 333 bool is_secure, |
334 int certificate_error_code) { | 334 int certificate_error_code) { |
335 base::StatsCounter spdy_sessions("spdy.sessions"); | 335 base::StatsCounter spdy_sessions("spdy.sessions"); |
336 spdy_sessions.Increment(); | 336 spdy_sessions.Increment(); |
337 | 337 |
338 state_ = CONNECTED; | 338 state_ = CONNECTED; |
339 connection_.reset(connection); | 339 connection_.reset(connection); |
340 connection_->AddLayeredPool(this); | |
341 is_secure_ = is_secure; | 340 is_secure_ = is_secure; |
342 certificate_error_code_ = certificate_error_code; | 341 certificate_error_code_ = certificate_error_code; |
343 | 342 |
344 if (is_secure_) { | 343 if (is_secure_) { |
345 SSLClientSocket* ssl_socket = | 344 SSLClientSocket* ssl_socket = |
346 reinterpret_cast<SSLClientSocket*>(connection_->socket()); | 345 reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
347 DCHECK(ssl_socket); | 346 DCHECK(ssl_socket); |
348 if (ssl_socket->protocol_negotiated() == SSLClientSocket::kProtoSPDY21) | 347 if (ssl_socket->protocol_negotiated() == SSLClientSocket::kProtoSPDY21) |
349 flow_control_ = true; | 348 flow_control_ = true; |
350 } | 349 } |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 return connection_->socket()->GetPeerAddress(address); | 994 return connection_->socket()->GetPeerAddress(address); |
996 } | 995 } |
997 | 996 |
998 int SpdySession::GetLocalAddress(IPEndPoint* address) const { | 997 int SpdySession::GetLocalAddress(IPEndPoint* address) const { |
999 if (!connection_->socket()) | 998 if (!connection_->socket()) |
1000 return ERR_SOCKET_NOT_CONNECTED; | 999 return ERR_SOCKET_NOT_CONNECTED; |
1001 | 1000 |
1002 return connection_->socket()->GetLocalAddress(address); | 1001 return connection_->socket()->GetLocalAddress(address); |
1003 } | 1002 } |
1004 | 1003 |
1005 bool SpdySession::CloseOneIdleConnection() { | |
1006 if (num_active_streams() == 0) { | |
1007 // Should delete this. | |
1008 RemoveFromPool(); | |
1009 return true; | |
1010 } | |
1011 return false; | |
1012 } | |
1013 | |
1014 void SpdySession::ActivateStream(SpdyStream* stream) { | 1004 void SpdySession::ActivateStream(SpdyStream* stream) { |
1015 const spdy::SpdyStreamId id = stream->stream_id(); | 1005 const spdy::SpdyStreamId id = stream->stream_id(); |
1016 DCHECK(!IsStreamActive(id)); | 1006 DCHECK(!IsStreamActive(id)); |
1017 | 1007 |
1018 active_streams_[id] = stream; | 1008 active_streams_[id] = stream; |
1019 } | 1009 } |
1020 | 1010 |
1021 void SpdySession::DeleteStream(spdy::SpdyStreamId id, int status) { | 1011 void SpdySession::DeleteStream(spdy::SpdyStreamId id, int status) { |
1022 // For push streams, if they are being deleted normally, we leave | 1012 // For push streams, if they are being deleted normally, we leave |
1023 // the stream in the unclaimed_pushed_streams_ list. However, if | 1013 // the stream in the unclaimed_pushed_streams_ list. However, if |
(...skipping 14 matching lines...) Expand all Loading... |
1038 ActiveStreamMap::iterator it2 = active_streams_.find(id); | 1028 ActiveStreamMap::iterator it2 = active_streams_.find(id); |
1039 if (it2 == active_streams_.end()) | 1029 if (it2 == active_streams_.end()) |
1040 return; | 1030 return; |
1041 | 1031 |
1042 // If this is an active stream, call the callback. | 1032 // If this is an active stream, call the callback. |
1043 const scoped_refptr<SpdyStream> stream(it2->second); | 1033 const scoped_refptr<SpdyStream> stream(it2->second); |
1044 active_streams_.erase(it2); | 1034 active_streams_.erase(it2); |
1045 if (stream) | 1035 if (stream) |
1046 stream->OnClose(status); | 1036 stream->OnClose(status); |
1047 ProcessPendingCreateStreams(); | 1037 ProcessPendingCreateStreams(); |
1048 if (num_active_streams() == 0 && connection_->is_initialized() && | |
1049 connection_->IsPoolStalled()) { | |
1050 // Should delete this. | |
1051 RemoveFromPool(); | |
1052 } | |
1053 } | 1038 } |
1054 | 1039 |
1055 void SpdySession::RemoveFromPool() { | 1040 void SpdySession::RemoveFromPool() { |
1056 if (spdy_session_pool_) { | 1041 if (spdy_session_pool_) { |
1057 SpdySessionPool* pool = spdy_session_pool_; | 1042 SpdySessionPool* pool = spdy_session_pool_; |
1058 spdy_session_pool_ = NULL; | 1043 spdy_session_pool_ = NULL; |
1059 pool->Remove(make_scoped_refptr(this)); | 1044 pool->Remove(make_scoped_refptr(this)); |
1060 } | 1045 } |
1061 } | 1046 } |
1062 | 1047 |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1766 if (it == pending_callback_map_.end()) | 1751 if (it == pending_callback_map_.end()) |
1767 return; | 1752 return; |
1768 | 1753 |
1769 CompletionCallback callback = it->second.callback; | 1754 CompletionCallback callback = it->second.callback; |
1770 int result = it->second.result; | 1755 int result = it->second.result; |
1771 pending_callback_map_.erase(it); | 1756 pending_callback_map_.erase(it); |
1772 callback.Run(result); | 1757 callback.Run(result); |
1773 } | 1758 } |
1774 | 1759 |
1775 } // namespace net | 1760 } // namespace net |
OLD | NEW |