diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-22 09:37:27 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-22 09:37:27 +0000 |
commit | 795cbf848605eefc41317a572797518afbf7409f (patch) | |
tree | a9f7873c09492165a674292f9a90042ba5a077a0 /net/spdy/spdy_http_stream.cc | |
parent | 7504bb326ecc376f0a45670740aba2b06cf9b3dc (diff) | |
download | chromium_src-795cbf848605eefc41317a572797518afbf7409f.zip chromium_src-795cbf848605eefc41317a572797518afbf7409f.tar.gz chromium_src-795cbf848605eefc41317a572797518afbf7409f.tar.bz2 |
[SPDY] Use WeakPtr<SpdySession> everywhere but SpdySessionPool
Make SpdyHttpStream cache it's SPDY stream's LoadTimingInfo
on close. Also, make SpdyHttpStream query SpdySession::IsReused()
when it's constructed and cache the value, as that's closer to the
intent of its use.
Avoid uses of SpdySession::IsClosed() in non-test code and add
TODO to remove uses from test code. This is more correct since
testing the WeakPtr is a stronger condition than testing openness
and SpdySession functions already do the right thing if the
SpdySession is already closed.
Tweak some tests that implicitly depended on
having refs to SpdySession.
BUG=255701
R=rch@chromium.org
Review URL: https://codereview.chromium.org/18546008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212858 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy/spdy_http_stream.cc')
-rw-r--r-- | net/spdy/spdy_http_stream.cc | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/net/spdy/spdy_http_stream.cc b/net/spdy/spdy_http_stream.cc index 69127d1..8f0f171 100644 --- a/net/spdy/spdy_http_stream.cc +++ b/net/spdy/spdy_http_stream.cc @@ -25,9 +25,11 @@ namespace net { -SpdyHttpStream::SpdyHttpStream(SpdySession* spdy_session, bool direct) +SpdyHttpStream::SpdyHttpStream(const base::WeakPtr<SpdySession>& spdy_session, + bool direct) : weak_factory_(this), spdy_session_(spdy_session), + is_reused_(spdy_session_->IsReused()), stream_closed_(false), closed_stream_status_(ERR_FAILED), closed_stream_id_(0), @@ -53,7 +55,9 @@ int SpdyHttpStream::InitializeStream(const HttpRequestInfo* request_info, RequestPriority priority, const BoundNetLog& stream_net_log, const CompletionCallback& callback) { - DCHECK(!stream_.get()); + DCHECK(!stream_); + if (!spdy_session_) + return ERR_CONNECTION_CLOSED; request_info_ = request_info; if (request_info_->method == "GET") { @@ -161,7 +165,7 @@ bool SpdyHttpStream::CanFindEndOfResponse() const { } bool SpdyHttpStream::IsConnectionReused() const { - return spdy_session_->IsReused(); + return is_reused_; } void SpdyHttpStream::SetConnectionReused() { @@ -174,19 +178,21 @@ bool SpdyHttpStream::IsConnectionReusable() const { } bool SpdyHttpStream::GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const { + if (stream_closed_) { + if (!closed_stream_has_load_timing_info_) + return false; + *load_timing_info = closed_stream_load_timing_info_; + return true; + } + // If |stream_| has yet to be created, or does not yet have an ID, fail. // The reused flag can only be correctly set once a stream has an ID. Streams // get their IDs once the request has been successfully sent, so this does not // behave that differently from other stream types. - if (!spdy_session_.get() || (!stream_.get() && !stream_closed_)) - return false; - - SpdyStreamId stream_id = - stream_closed_ ? closed_stream_id_ : stream_->stream_id(); - if (stream_id == 0) + if (!stream_ || stream_->stream_id() == 0) return false; - return spdy_session_->GetLoadTimingInfo(stream_id, load_timing_info); + return stream_->GetLoadTimingInfo(load_timing_info); } int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, @@ -317,7 +323,7 @@ SpdyResponseHeadersStatus SpdyHttpStream::OnResponseHeadersUpdated( response_info_->npn_negotiated_protocol = SSLClientSocket::NextProtoToString(protocol_negotiated); response_info_->request_time = stream_->GetRequestTime(); - switch (spdy_session_->GetProtocolVersion()) { + switch (stream_->GetProtocolVersion()) { case SPDY2: response_info_->connection_info = HttpResponseInfo::CONNECTION_INFO_SPDY2; break; @@ -368,6 +374,8 @@ void SpdyHttpStream::OnClose(int status) { stream_closed_ = true; closed_stream_status_ = status; closed_stream_id_ = stream_->stream_id(); + closed_stream_has_load_timing_info_ = + stream_->GetLoadTimingInfo(&closed_stream_load_timing_info_); } stream_.reset(); bool invoked_callback = false; |