| 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 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 largest_promised_stream_id_ = promised_stream_id; | 70 largest_promised_stream_id_ = promised_stream_id; |
| 71 | 71 |
| 72 QuicSpdyStream* stream = GetSpdyDataStream(stream_id); | 72 QuicSpdyStream* stream = GetSpdyDataStream(stream_id); |
| 73 if (!stream) { | 73 if (!stream) { |
| 74 // It's quite possible to receive headers after a stream has been reset. | 74 // It's quite possible to receive headers after a stream has been reset. |
| 75 return; | 75 return; |
| 76 } | 76 } |
| 77 stream->OnPromiseHeaderList(promised_stream_id, frame_len, header_list); | 77 stream->OnPromiseHeaderList(promised_stream_id, frame_len, header_list); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void QuicClientSessionBase::HandlePromised(QuicStreamId /* associated_id */, | 80 bool QuicClientSessionBase::HandlePromised(QuicStreamId /* associated_id */, |
| 81 QuicStreamId id, | 81 QuicStreamId id, |
| 82 const SpdyHeaderBlock& headers) { | 82 const SpdyHeaderBlock& headers) { |
| 83 // Due to pathalogical packet re-ordering, it is possible that | 83 // Due to pathalogical packet re-ordering, it is possible that |
| 84 // frames for the promised stream have already arrived, and the | 84 // frames for the promised stream have already arrived, and the |
| 85 // promised stream could be active or closed. | 85 // promised stream could be active or closed. |
| 86 if (IsClosedStream(id)) { | 86 if (IsClosedStream(id)) { |
| 87 // There was a RST on the data stream already, perhaps | 87 // There was a RST on the data stream already, perhaps |
| 88 // QUIC_REFUSED_STREAM? | 88 // QUIC_REFUSED_STREAM? |
| 89 DVLOG(1) << "Promise ignored for stream " << id | 89 DVLOG(1) << "Promise ignored for stream " << id |
| 90 << " that is already closed"; | 90 << " that is already closed"; |
| 91 return; | 91 return false; |
| 92 } | 92 } |
| 93 | 93 |
| 94 if (push_promise_index_->promised_by_url()->size() >= get_max_promises()) { | 94 if (push_promise_index_->promised_by_url()->size() >= get_max_promises()) { |
| 95 DVLOG(1) << "Too many promises, rejecting promise for stream " << id; | 95 DVLOG(1) << "Too many promises, rejecting promise for stream " << id; |
| 96 ResetPromised(id, QUIC_REFUSED_STREAM); | 96 ResetPromised(id, QUIC_REFUSED_STREAM); |
| 97 return; | 97 return false; |
| 98 } | 98 } |
| 99 | 99 |
| 100 const string url = SpdyUtils::GetUrlFromHeaderBlock(headers); | 100 const string url = SpdyUtils::GetUrlFromHeaderBlock(headers); |
| 101 QuicClientPromisedInfo* old_promised = GetPromisedByUrl(url); | 101 QuicClientPromisedInfo* old_promised = GetPromisedByUrl(url); |
| 102 if (old_promised) { | 102 if (old_promised) { |
| 103 DVLOG(1) << "Promise for stream " << id << " is duplicate URL " << url | 103 DVLOG(1) << "Promise for stream " << id << " is duplicate URL " << url |
| 104 << " of previous promise for stream " << old_promised->id(); | 104 << " of previous promise for stream " << old_promised->id(); |
| 105 ResetPromised(id, QUIC_DUPLICATE_PROMISE_URL); | 105 ResetPromised(id, QUIC_DUPLICATE_PROMISE_URL); |
| 106 return; | 106 return false; |
| 107 } | 107 } |
| 108 | 108 |
| 109 if (GetPromisedById(id)) { | 109 if (GetPromisedById(id)) { |
| 110 // OnPromiseHeadersComplete() would have closed the connection if | 110 // OnPromiseHeadersComplete() would have closed the connection if |
| 111 // promised id is a duplicate. | 111 // promised id is a duplicate. |
| 112 QUIC_BUG << "Duplicate promise for id " << id; | 112 QUIC_BUG << "Duplicate promise for id " << id; |
| 113 return; | 113 return false; |
| 114 } | 114 } |
| 115 | 115 |
| 116 QuicClientPromisedInfo* promised = new QuicClientPromisedInfo(this, id, url); | 116 QuicClientPromisedInfo* promised = new QuicClientPromisedInfo(this, id, url); |
| 117 std::unique_ptr<QuicClientPromisedInfo> promised_owner(promised); | 117 std::unique_ptr<QuicClientPromisedInfo> promised_owner(promised); |
| 118 promised->Init(); | 118 promised->Init(); |
| 119 DVLOG(1) << "stream " << id << " emplace url " << url; | 119 DVLOG(1) << "stream " << id << " emplace url " << url; |
| 120 (*push_promise_index_->promised_by_url())[url] = promised; | 120 (*push_promise_index_->promised_by_url())[url] = promised; |
| 121 promised_by_id_[id] = std::move(promised_owner); | 121 promised_by_id_[id] = std::move(promised_owner); |
| 122 promised->OnPromiseHeaders(headers); | 122 promised->OnPromiseHeaders(headers); |
| 123 return true; |
| 123 } | 124 } |
| 124 | 125 |
| 125 QuicClientPromisedInfo* QuicClientSessionBase::GetPromisedByUrl( | 126 QuicClientPromisedInfo* QuicClientSessionBase::GetPromisedByUrl( |
| 126 const string& url) { | 127 const string& url) { |
| 127 QuicPromisedByUrlMap::iterator it = | 128 QuicPromisedByUrlMap::iterator it = |
| 128 push_promise_index_->promised_by_url()->find(url); | 129 push_promise_index_->promised_by_url()->find(url); |
| 129 if (it != push_promise_index_->promised_by_url()->end()) { | 130 if (it != push_promise_index_->promised_by_url()->end()) { |
| 130 return it->second; | 131 return it->second; |
| 131 } | 132 } |
| 132 return nullptr; | 133 return nullptr; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 bool locally_reset) { | 176 bool locally_reset) { |
| 176 QuicSpdySession::CloseStreamInner(stream_id, locally_reset); | 177 QuicSpdySession::CloseStreamInner(stream_id, locally_reset); |
| 177 headers_stream()->MaybeReleaseSequencerBuffer(); | 178 headers_stream()->MaybeReleaseSequencerBuffer(); |
| 178 } | 179 } |
| 179 | 180 |
| 180 bool QuicClientSessionBase::ShouldReleaseHeadersStreamSequencerBuffer() { | 181 bool QuicClientSessionBase::ShouldReleaseHeadersStreamSequencerBuffer() { |
| 181 return num_active_requests() == 0 && promised_by_id_.empty(); | 182 return num_active_requests() == 0 && promised_by_id_.empty(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 } // namespace net | 185 } // namespace net |
| OLD | NEW |