OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 329 |
330 net::Error SpdySession::InitializeWithSocket( | 330 net::Error SpdySession::InitializeWithSocket( |
331 ClientSocketHandle* connection, | 331 ClientSocketHandle* connection, |
332 bool is_secure, | 332 bool is_secure, |
333 int certificate_error_code) { | 333 int certificate_error_code) { |
334 base::StatsCounter spdy_sessions("spdy.sessions"); | 334 base::StatsCounter spdy_sessions("spdy.sessions"); |
335 spdy_sessions.Increment(); | 335 spdy_sessions.Increment(); |
336 | 336 |
337 state_ = CONNECTED; | 337 state_ = CONNECTED; |
338 connection_.reset(connection); | 338 connection_.reset(connection); |
| 339 connection_->AddLayeredPool(this); |
339 is_secure_ = is_secure; | 340 is_secure_ = is_secure; |
340 certificate_error_code_ = certificate_error_code; | 341 certificate_error_code_ = certificate_error_code; |
341 | 342 |
342 // Write out any data that we might have to send, such as the settings frame. | 343 // Write out any data that we might have to send, such as the settings frame. |
343 WriteSocketLater(); | 344 WriteSocketLater(); |
344 net::Error error = ReadSocket(); | 345 net::Error error = ReadSocket(); |
345 if (error == ERR_IO_PENDING) | 346 if (error == ERR_IO_PENDING) |
346 return OK; | 347 return OK; |
347 return error; | 348 return error; |
348 } | 349 } |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 return connection_->socket()->GetPeerAddress(address); | 978 return connection_->socket()->GetPeerAddress(address); |
978 } | 979 } |
979 | 980 |
980 int SpdySession::GetLocalAddress(IPEndPoint* address) const { | 981 int SpdySession::GetLocalAddress(IPEndPoint* address) const { |
981 if (!connection_->socket()) | 982 if (!connection_->socket()) |
982 return ERR_SOCKET_NOT_CONNECTED; | 983 return ERR_SOCKET_NOT_CONNECTED; |
983 | 984 |
984 return connection_->socket()->GetLocalAddress(address); | 985 return connection_->socket()->GetLocalAddress(address); |
985 } | 986 } |
986 | 987 |
| 988 bool SpdySession::CloseOneIdleConnection() { |
| 989 if (num_active_streams() == 0) { |
| 990 // Should delete this. |
| 991 RemoveFromPool(); |
| 992 return true; |
| 993 } |
| 994 return false; |
| 995 } |
| 996 |
987 void SpdySession::ActivateStream(SpdyStream* stream) { | 997 void SpdySession::ActivateStream(SpdyStream* stream) { |
988 const spdy::SpdyStreamId id = stream->stream_id(); | 998 const spdy::SpdyStreamId id = stream->stream_id(); |
989 DCHECK(!IsStreamActive(id)); | 999 DCHECK(!IsStreamActive(id)); |
990 | 1000 |
991 active_streams_[id] = stream; | 1001 active_streams_[id] = stream; |
992 } | 1002 } |
993 | 1003 |
994 void SpdySession::DeleteStream(spdy::SpdyStreamId id, int status) { | 1004 void SpdySession::DeleteStream(spdy::SpdyStreamId id, int status) { |
995 // For push streams, if they are being deleted normally, we leave | 1005 // For push streams, if they are being deleted normally, we leave |
996 // the stream in the unclaimed_pushed_streams_ list. However, if | 1006 // the stream in the unclaimed_pushed_streams_ list. However, if |
(...skipping 14 matching lines...) Expand all Loading... |
1011 ActiveStreamMap::iterator it2 = active_streams_.find(id); | 1021 ActiveStreamMap::iterator it2 = active_streams_.find(id); |
1012 if (it2 == active_streams_.end()) | 1022 if (it2 == active_streams_.end()) |
1013 return; | 1023 return; |
1014 | 1024 |
1015 // If this is an active stream, call the callback. | 1025 // If this is an active stream, call the callback. |
1016 const scoped_refptr<SpdyStream> stream(it2->second); | 1026 const scoped_refptr<SpdyStream> stream(it2->second); |
1017 active_streams_.erase(it2); | 1027 active_streams_.erase(it2); |
1018 if (stream) | 1028 if (stream) |
1019 stream->OnClose(status); | 1029 stream->OnClose(status); |
1020 ProcessPendingCreateStreams(); | 1030 ProcessPendingCreateStreams(); |
| 1031 if (num_active_streams() == 0 && connection_->is_initialized() && |
| 1032 connection_->IsPoolStalled()) { |
| 1033 // Should delete this. |
| 1034 RemoveFromPool(); |
| 1035 } |
1021 } | 1036 } |
1022 | 1037 |
1023 void SpdySession::RemoveFromPool() { | 1038 void SpdySession::RemoveFromPool() { |
1024 if (spdy_session_pool_) { | 1039 if (spdy_session_pool_) { |
1025 spdy_session_pool_->Remove(make_scoped_refptr(this)); | 1040 SpdySessionPool* pool = spdy_session_pool_; |
1026 spdy_session_pool_ = NULL; | 1041 spdy_session_pool_ = NULL; |
| 1042 pool->Remove(make_scoped_refptr(this)); |
1027 } | 1043 } |
1028 } | 1044 } |
1029 | 1045 |
1030 scoped_refptr<SpdyStream> SpdySession::GetActivePushStream( | 1046 scoped_refptr<SpdyStream> SpdySession::GetActivePushStream( |
1031 const std::string& path) { | 1047 const std::string& path) { |
1032 base::StatsCounter used_push_streams("spdy.claimed_push_streams"); | 1048 base::StatsCounter used_push_streams("spdy.claimed_push_streams"); |
1033 | 1049 |
1034 PushedStreamMap::iterator it = unclaimed_pushed_streams_.find(path); | 1050 PushedStreamMap::iterator it = unclaimed_pushed_streams_.find(path); |
1035 if (it != unclaimed_pushed_streams_.end()) { | 1051 if (it != unclaimed_pushed_streams_.end()) { |
1036 net_log_.AddEvent(NetLog::TYPE_SPDY_STREAM_ADOPTED_PUSH_STREAM, NULL); | 1052 net_log_.AddEvent(NetLog::TYPE_SPDY_STREAM_ADOPTED_PUSH_STREAM, NULL); |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1738 if (it == pending_callback_map_.end()) | 1754 if (it == pending_callback_map_.end()) |
1739 return; | 1755 return; |
1740 | 1756 |
1741 OldCompletionCallback* callback = it->second.callback; | 1757 OldCompletionCallback* callback = it->second.callback; |
1742 int result = it->second.result; | 1758 int result = it->second.result; |
1743 pending_callback_map_.erase(it); | 1759 pending_callback_map_.erase(it); |
1744 callback->Run(result); | 1760 callback->Run(result); |
1745 } | 1761 } |
1746 | 1762 |
1747 } // namespace net | 1763 } // namespace net |
OLD | NEW |