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