| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/quic/core/quic_client_session_base.h" | 5 #include "net/quic/core/quic_client_session_base.h" |
| 6 | 6 |
| 7 #include "net/quic/core/quic_client_promised_info.h" | 7 #include "net/quic/core/quic_client_promised_info.h" |
| 8 #include "net/quic/core/quic_flags.h" | 8 #include "net/quic/core/quic_flags.h" |
| 9 #include "net/quic/core/spdy_utils.h" | 9 #include "net/quic/core/spdy_utils.h" |
| 10 #include "net/quic/platform/api/quic_logging.h" | |
| 11 | 10 |
| 12 using base::StringPiece; | 11 using base::StringPiece; |
| 13 using std::string; | 12 using std::string; |
| 14 | 13 |
| 15 namespace net { | 14 namespace net { |
| 16 | 15 |
| 17 QuicClientSessionBase::QuicClientSessionBase( | 16 QuicClientSessionBase::QuicClientSessionBase( |
| 18 QuicConnection* connection, | 17 QuicConnection* connection, |
| 19 QuicClientPushPromiseIndex* push_promise_index, | 18 QuicClientPushPromiseIndex* push_promise_index, |
| 20 const QuicConfig& config) | 19 const QuicConfig& config) |
| 21 : QuicSpdySession(connection, nullptr, config), | 20 : QuicSpdySession(connection, nullptr, config), |
| 22 push_promise_index_(push_promise_index), | 21 push_promise_index_(push_promise_index), |
| 23 largest_promised_stream_id_(kInvalidStreamId) {} | 22 largest_promised_stream_id_(kInvalidStreamId) {} |
| 24 | 23 |
| 25 QuicClientSessionBase::~QuicClientSessionBase() { | 24 QuicClientSessionBase::~QuicClientSessionBase() { |
| 26 // all promised streams for this session | 25 // all promised streams for this session |
| 27 for (auto& it : promised_by_id_) { | 26 for (auto& it : promised_by_id_) { |
| 28 QUIC_DVLOG(1) << "erase stream " << it.first << " url " << it.second->url(); | 27 DVLOG(1) << "erase stream " << it.first << " url " << it.second->url(); |
| 29 push_promise_index_->promised_by_url()->erase(it.second->url()); | 28 push_promise_index_->promised_by_url()->erase(it.second->url()); |
| 30 } | 29 } |
| 31 delete connection(); | 30 delete connection(); |
| 32 } | 31 } |
| 33 | 32 |
| 34 void QuicClientSessionBase::OnConfigNegotiated() { | 33 void QuicClientSessionBase::OnConfigNegotiated() { |
| 35 QuicSpdySession::OnConfigNegotiated(); | 34 QuicSpdySession::OnConfigNegotiated(); |
| 36 } | 35 } |
| 37 | 36 |
| 38 void QuicClientSessionBase::OnCryptoHandshakeEvent(CryptoHandshakeEvent event) { | 37 void QuicClientSessionBase::OnCryptoHandshakeEvent(CryptoHandshakeEvent event) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 79 |
| 81 bool QuicClientSessionBase::HandlePromised(QuicStreamId /* associated_id */, | 80 bool QuicClientSessionBase::HandlePromised(QuicStreamId /* associated_id */, |
| 82 QuicStreamId id, | 81 QuicStreamId id, |
| 83 const SpdyHeaderBlock& headers) { | 82 const SpdyHeaderBlock& headers) { |
| 84 // Due to pathalogical packet re-ordering, it is possible that | 83 // Due to pathalogical packet re-ordering, it is possible that |
| 85 // frames for the promised stream have already arrived, and the | 84 // frames for the promised stream have already arrived, and the |
| 86 // promised stream could be active or closed. | 85 // promised stream could be active or closed. |
| 87 if (IsClosedStream(id)) { | 86 if (IsClosedStream(id)) { |
| 88 // There was a RST on the data stream already, perhaps | 87 // There was a RST on the data stream already, perhaps |
| 89 // QUIC_REFUSED_STREAM? | 88 // QUIC_REFUSED_STREAM? |
| 90 QUIC_DVLOG(1) << "Promise ignored for stream " << id | 89 DVLOG(1) << "Promise ignored for stream " << id |
| 91 << " that is already closed"; | 90 << " that is already closed"; |
| 92 return false; | 91 return false; |
| 93 } | 92 } |
| 94 | 93 |
| 95 if (push_promise_index_->promised_by_url()->size() >= get_max_promises()) { | 94 if (push_promise_index_->promised_by_url()->size() >= get_max_promises()) { |
| 96 QUIC_DVLOG(1) << "Too many promises, rejecting promise for stream " << id; | 95 DVLOG(1) << "Too many promises, rejecting promise for stream " << id; |
| 97 ResetPromised(id, QUIC_REFUSED_STREAM); | 96 ResetPromised(id, QUIC_REFUSED_STREAM); |
| 98 return false; | 97 return false; |
| 99 } | 98 } |
| 100 | 99 |
| 101 const string url = SpdyUtils::GetUrlFromHeaderBlock(headers); | 100 const string url = SpdyUtils::GetUrlFromHeaderBlock(headers); |
| 102 QuicClientPromisedInfo* old_promised = GetPromisedByUrl(url); | 101 QuicClientPromisedInfo* old_promised = GetPromisedByUrl(url); |
| 103 if (old_promised) { | 102 if (old_promised) { |
| 104 QUIC_DVLOG(1) << "Promise for stream " << id << " is duplicate URL " << url | 103 DVLOG(1) << "Promise for stream " << id << " is duplicate URL " << url |
| 105 << " of previous promise for stream " << old_promised->id(); | 104 << " of previous promise for stream " << old_promised->id(); |
| 106 ResetPromised(id, QUIC_DUPLICATE_PROMISE_URL); | 105 ResetPromised(id, QUIC_DUPLICATE_PROMISE_URL); |
| 107 return false; | 106 return false; |
| 108 } | 107 } |
| 109 | 108 |
| 110 if (GetPromisedById(id)) { | 109 if (GetPromisedById(id)) { |
| 111 // OnPromiseHeadersComplete() would have closed the connection if | 110 // OnPromiseHeadersComplete() would have closed the connection if |
| 112 // promised id is a duplicate. | 111 // promised id is a duplicate. |
| 113 QUIC_BUG << "Duplicate promise for id " << id; | 112 QUIC_BUG << "Duplicate promise for id " << id; |
| 114 return false; | 113 return false; |
| 115 } | 114 } |
| 116 | 115 |
| 117 QuicClientPromisedInfo* promised = new QuicClientPromisedInfo(this, id, url); | 116 QuicClientPromisedInfo* promised = new QuicClientPromisedInfo(this, id, url); |
| 118 std::unique_ptr<QuicClientPromisedInfo> promised_owner(promised); | 117 std::unique_ptr<QuicClientPromisedInfo> promised_owner(promised); |
| 119 promised->Init(); | 118 promised->Init(); |
| 120 QUIC_DVLOG(1) << "stream " << id << " emplace url " << url; | 119 DVLOG(1) << "stream " << id << " emplace url " << url; |
| 121 (*push_promise_index_->promised_by_url())[url] = promised; | 120 (*push_promise_index_->promised_by_url())[url] = promised; |
| 122 promised_by_id_[id] = std::move(promised_owner); | 121 promised_by_id_[id] = std::move(promised_owner); |
| 123 promised->OnPromiseHeaders(headers); | 122 promised->OnPromiseHeaders(headers); |
| 124 return true; | 123 return true; |
| 125 } | 124 } |
| 126 | 125 |
| 127 QuicClientPromisedInfo* QuicClientSessionBase::GetPromisedByUrl( | 126 QuicClientPromisedInfo* QuicClientSessionBase::GetPromisedByUrl( |
| 128 const string& url) { | 127 const string& url) { |
| 129 QuicPromisedByUrlMap::iterator it = | 128 QuicPromisedByUrlMap::iterator it = |
| 130 push_promise_index_->promised_by_url()->find(url); | 129 push_promise_index_->promised_by_url()->find(url); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 bool locally_reset) { | 173 bool locally_reset) { |
| 175 QuicSpdySession::CloseStreamInner(stream_id, locally_reset); | 174 QuicSpdySession::CloseStreamInner(stream_id, locally_reset); |
| 176 headers_stream()->MaybeReleaseSequencerBuffer(); | 175 headers_stream()->MaybeReleaseSequencerBuffer(); |
| 177 } | 176 } |
| 178 | 177 |
| 179 bool QuicClientSessionBase::ShouldReleaseHeadersStreamSequencerBuffer() { | 178 bool QuicClientSessionBase::ShouldReleaseHeadersStreamSequencerBuffer() { |
| 180 return num_active_requests() == 0 && promised_by_id_.empty(); | 179 return num_active_requests() == 0 && promised_by_id_.empty(); |
| 181 } | 180 } |
| 182 | 181 |
| 183 } // namespace net | 182 } // namespace net |
| OLD | NEW |