| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 largest_promised_stream_id_ = promised_stream_id; | 103 largest_promised_stream_id_ = promised_stream_id; |
| 104 | 104 |
| 105 QuicSpdyStream* stream = GetSpdyDataStream(stream_id); | 105 QuicSpdyStream* stream = GetSpdyDataStream(stream_id); |
| 106 if (!stream) { | 106 if (!stream) { |
| 107 // It's quite possible to receive headers after a stream has been reset. | 107 // It's quite possible to receive headers after a stream has been reset. |
| 108 return; | 108 return; |
| 109 } | 109 } |
| 110 stream->OnPromiseHeaderList(promised_stream_id, frame_len, header_list); | 110 stream->OnPromiseHeaderList(promised_stream_id, frame_len, header_list); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void QuicClientSessionBase::HandlePromised(QuicStreamId /* associated_id */, | 113 bool QuicClientSessionBase::HandlePromised(QuicStreamId /* associated_id */, |
| 114 QuicStreamId id, | 114 QuicStreamId id, |
| 115 const SpdyHeaderBlock& headers) { | 115 const SpdyHeaderBlock& headers) { |
| 116 // Due to pathalogical packet re-ordering, it is possible that | 116 // Due to pathalogical packet re-ordering, it is possible that |
| 117 // frames for the promised stream have already arrived, and the | 117 // frames for the promised stream have already arrived, and the |
| 118 // promised stream could be active or closed. | 118 // promised stream could be active or closed. |
| 119 if (IsClosedStream(id)) { | 119 if (IsClosedStream(id)) { |
| 120 // There was a RST on the data stream already, perhaps | 120 // There was a RST on the data stream already, perhaps |
| 121 // QUIC_REFUSED_STREAM? | 121 // QUIC_REFUSED_STREAM? |
| 122 DVLOG(1) << "Promise ignored for stream " << id | 122 DVLOG(1) << "Promise ignored for stream " << id |
| 123 << " that is already closed"; | 123 << " that is already closed"; |
| 124 return; | 124 return false; |
| 125 } | 125 } |
| 126 | 126 |
| 127 if (push_promise_index_->promised_by_url()->size() >= get_max_promises()) { | 127 if (push_promise_index_->promised_by_url()->size() >= get_max_promises()) { |
| 128 DVLOG(1) << "Too many promises, rejecting promise for stream " << id; | 128 DVLOG(1) << "Too many promises, rejecting promise for stream " << id; |
| 129 ResetPromised(id, QUIC_REFUSED_STREAM); | 129 ResetPromised(id, QUIC_REFUSED_STREAM); |
| 130 return; | 130 return false; |
| 131 } | 131 } |
| 132 | 132 |
| 133 const string url = SpdyUtils::GetUrlFromHeaderBlock(headers); | 133 const string url = SpdyUtils::GetUrlFromHeaderBlock(headers); |
| 134 QuicClientPromisedInfo* old_promised = GetPromisedByUrl(url); | 134 QuicClientPromisedInfo* old_promised = GetPromisedByUrl(url); |
| 135 if (old_promised) { | 135 if (old_promised) { |
| 136 DVLOG(1) << "Promise for stream " << id << " is duplicate URL " << url | 136 DVLOG(1) << "Promise for stream " << id << " is duplicate URL " << url |
| 137 << " of previous promise for stream " << old_promised->id(); | 137 << " of previous promise for stream " << old_promised->id(); |
| 138 ResetPromised(id, QUIC_DUPLICATE_PROMISE_URL); | 138 ResetPromised(id, QUIC_DUPLICATE_PROMISE_URL); |
| 139 return; | 139 return false; |
| 140 } | 140 } |
| 141 | 141 |
| 142 if (GetPromisedById(id)) { | 142 if (GetPromisedById(id)) { |
| 143 // OnPromiseHeadersComplete() would have closed the connection if | 143 // OnPromiseHeadersComplete() would have closed the connection if |
| 144 // promised id is a duplicate. | 144 // promised id is a duplicate. |
| 145 QUIC_BUG << "Duplicate promise for id " << id; | 145 QUIC_BUG << "Duplicate promise for id " << id; |
| 146 return; | 146 return false; |
| 147 } | 147 } |
| 148 | 148 |
| 149 QuicClientPromisedInfo* promised = new QuicClientPromisedInfo(this, id, url); | 149 QuicClientPromisedInfo* promised = new QuicClientPromisedInfo(this, id, url); |
| 150 std::unique_ptr<QuicClientPromisedInfo> promised_owner(promised); | 150 std::unique_ptr<QuicClientPromisedInfo> promised_owner(promised); |
| 151 promised->Init(); | 151 promised->Init(); |
| 152 DVLOG(1) << "stream " << id << " emplace url " << url; | 152 DVLOG(1) << "stream " << id << " emplace url " << url; |
| 153 (*push_promise_index_->promised_by_url())[url] = promised; | 153 (*push_promise_index_->promised_by_url())[url] = promised; |
| 154 promised_by_id_[id] = std::move(promised_owner); | 154 promised_by_id_[id] = std::move(promised_owner); |
| 155 promised->OnPromiseHeaders(headers); | 155 promised->OnPromiseHeaders(headers); |
| 156 return true; |
| 156 } | 157 } |
| 157 | 158 |
| 158 QuicClientPromisedInfo* QuicClientSessionBase::GetPromisedByUrl( | 159 QuicClientPromisedInfo* QuicClientSessionBase::GetPromisedByUrl( |
| 159 const string& url) { | 160 const string& url) { |
| 160 QuicPromisedByUrlMap::iterator it = | 161 QuicPromisedByUrlMap::iterator it = |
| 161 push_promise_index_->promised_by_url()->find(url); | 162 push_promise_index_->promised_by_url()->find(url); |
| 162 if (it != push_promise_index_->promised_by_url()->end()) { | 163 if (it != push_promise_index_->promised_by_url()->end()) { |
| 163 return it->second; | 164 return it->second; |
| 164 } | 165 } |
| 165 return nullptr; | 166 return nullptr; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 bool locally_reset) { | 209 bool locally_reset) { |
| 209 QuicSpdySession::CloseStreamInner(stream_id, locally_reset); | 210 QuicSpdySession::CloseStreamInner(stream_id, locally_reset); |
| 210 headers_stream()->MaybeReleaseSequencerBuffer(); | 211 headers_stream()->MaybeReleaseSequencerBuffer(); |
| 211 } | 212 } |
| 212 | 213 |
| 213 bool QuicClientSessionBase::ShouldReleaseHeadersStreamSequencerBuffer() { | 214 bool QuicClientSessionBase::ShouldReleaseHeadersStreamSequencerBuffer() { |
| 214 return num_active_requests() == 0 && promised_by_id_.empty(); | 215 return num_active_requests() == 0 && promised_by_id_.empty(); |
| 215 } | 216 } |
| 216 | 217 |
| 217 } // namespace net | 218 } // namespace net |
| OLD | NEW |