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