OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_headers_stream.h" | 5 #include "net/quic/core/quic_headers_stream.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 #include <string> |
7 #include <utility> | 9 #include <utility> |
8 | 10 |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
13 #include "net/quic/core/quic_bug_tracker.h" | 15 #include "net/quic/core/quic_bug_tracker.h" |
14 #include "net/quic/core/quic_flags.h" | 16 #include "net/quic/core/quic_flags.h" |
15 #include "net/quic/core/quic_header_list.h" | 17 #include "net/quic/core/quic_header_list.h" |
16 #include "net/quic/core/quic_server_session_base.h" | 18 #include "net/quic/core/quic_server_session_base.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 SpdyPriority priority, | 120 SpdyPriority priority, |
119 bool fin, | 121 bool fin, |
120 bool unidirectional) override { | 122 bool unidirectional) override { |
121 CloseConnection("SPDY SYN_STREAM frame received."); | 123 CloseConnection("SPDY SYN_STREAM frame received."); |
122 } | 124 } |
123 | 125 |
124 void OnSynReply(SpdyStreamId stream_id, bool fin) override { | 126 void OnSynReply(SpdyStreamId stream_id, bool fin) override { |
125 CloseConnection("SPDY SYN_REPLY frame received."); | 127 CloseConnection("SPDY SYN_REPLY frame received."); |
126 } | 128 } |
127 | 129 |
128 bool OnControlFrameHeaderData(SpdyStreamId stream_id, | |
129 const char* header_data, | |
130 size_t len) override { | |
131 if (!stream_->IsConnected()) { | |
132 return false; | |
133 } | |
134 stream_->OnControlFrameHeaderData(stream_id, header_data, len); | |
135 return true; | |
136 } | |
137 | |
138 void OnStreamFrameData(SpdyStreamId stream_id, | 130 void OnStreamFrameData(SpdyStreamId stream_id, |
139 const char* data, | 131 const char* data, |
140 size_t len) override { | 132 size_t len) override { |
141 if (stream_->OnStreamFrameData(stream_id, data, len)) { | 133 if (stream_->OnStreamFrameData(stream_id, data, len)) { |
142 return; | 134 return; |
143 } | 135 } |
144 CloseConnection("SPDY DATA frame received."); | 136 CloseConnection("SPDY DATA frame received."); |
145 } | 137 } |
146 | 138 |
147 void OnStreamEnd(SpdyStreamId stream_id) override { | 139 void OnStreamEnd(SpdyStreamId stream_id) override { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 306 } |
315 } | 307 } |
316 | 308 |
317 void set_max_uncompressed_header_bytes( | 309 void set_max_uncompressed_header_bytes( |
318 size_t set_max_uncompressed_header_bytes) { | 310 size_t set_max_uncompressed_header_bytes) { |
319 header_list_.set_max_uncompressed_header_bytes( | 311 header_list_.set_max_uncompressed_header_bytes( |
320 set_max_uncompressed_header_bytes); | 312 set_max_uncompressed_header_bytes); |
321 } | 313 } |
322 | 314 |
323 private: | 315 private: |
324 void CloseConnection(const string& details) { | 316 void CloseConnection(const std::string& details) { |
325 if (stream_->IsConnected()) { | 317 if (stream_->IsConnected()) { |
326 stream_->CloseConnectionWithDetails(QUIC_INVALID_HEADERS_STREAM_DATA, | 318 stream_->CloseConnectionWithDetails(QUIC_INVALID_HEADERS_STREAM_DATA, |
327 details); | 319 details); |
328 } | 320 } |
329 } | 321 } |
330 | 322 |
331 private: | 323 private: |
332 QuicHeadersStream* stream_; | 324 QuicHeadersStream* stream_; |
333 QuicHeaderList header_list_; | 325 QuicHeaderList header_list_; |
334 | 326 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 | 496 |
505 void QuicHeadersStream::OnPushPromise(SpdyStreamId stream_id, | 497 void QuicHeadersStream::OnPushPromise(SpdyStreamId stream_id, |
506 SpdyStreamId promised_stream_id, | 498 SpdyStreamId promised_stream_id, |
507 bool end) { | 499 bool end) { |
508 DCHECK_EQ(kInvalidStreamId, stream_id_); | 500 DCHECK_EQ(kInvalidStreamId, stream_id_); |
509 DCHECK_EQ(kInvalidStreamId, promised_stream_id_); | 501 DCHECK_EQ(kInvalidStreamId, promised_stream_id_); |
510 stream_id_ = stream_id; | 502 stream_id_ = stream_id; |
511 promised_stream_id_ = promised_stream_id; | 503 promised_stream_id_ = promised_stream_id; |
512 } | 504 } |
513 | 505 |
514 void QuicHeadersStream::OnControlFrameHeaderData(SpdyStreamId stream_id, | |
515 const char* header_data, | |
516 size_t len) { | |
517 DCHECK_EQ(stream_id_, stream_id); | |
518 if (len == 0) { | |
519 DCHECK_NE(0u, stream_id_); | |
520 DCHECK_NE(0u, frame_len_); | |
521 if (prev_max_timestamp_ > cur_max_timestamp_) { | |
522 // prev_max_timestamp_ > cur_max_timestamp_ implies that | |
523 // headers from lower numbered streams actually came off the | |
524 // wire after headers for the current stream, hence there was | |
525 // HOL blocking. | |
526 QuicTime::Delta delta = prev_max_timestamp_ - cur_max_timestamp_; | |
527 DVLOG(1) << "stream " << stream_id | |
528 << ": Net.QuicSession.HeadersHOLBlockedTime " | |
529 << delta.ToMilliseconds(); | |
530 spdy_session_->OnHeadersHeadOfLineBlocking(delta); | |
531 } | |
532 prev_max_timestamp_ = std::max(prev_max_timestamp_, cur_max_timestamp_); | |
533 cur_max_timestamp_ = QuicTime::Zero(); | |
534 if (promised_stream_id_ == kInvalidStreamId) { | |
535 spdy_session_->OnStreamHeadersComplete(stream_id_, fin_, frame_len_); | |
536 } else { | |
537 spdy_session_->OnPromiseHeadersComplete(stream_id_, promised_stream_id_, | |
538 frame_len_); | |
539 } | |
540 if (uncompressed_frame_len_ != 0) { | |
541 int compression_pct = 100 - (100 * frame_len_) / uncompressed_frame_len_; | |
542 DVLOG(1) << "Net.QuicHpackDecompressionPercentage: " << compression_pct; | |
543 UMA_HISTOGRAM_PERCENTAGE("Net.QuicHpackDecompressionPercentage", | |
544 compression_pct); | |
545 } | |
546 // Reset state for the next frame. | |
547 promised_stream_id_ = kInvalidStreamId; | |
548 stream_id_ = kInvalidStreamId; | |
549 fin_ = false; | |
550 frame_len_ = 0; | |
551 uncompressed_frame_len_ = 0; | |
552 } else { | |
553 uncompressed_frame_len_ += len; | |
554 if (promised_stream_id_ == kInvalidStreamId) { | |
555 spdy_session_->OnStreamHeaders(stream_id_, StringPiece(header_data, len)); | |
556 } else { | |
557 spdy_session_->OnPromiseHeaders(stream_id_, | |
558 StringPiece(header_data, len)); | |
559 } | |
560 } | |
561 } | |
562 | |
563 void QuicHeadersStream::OnHeaderList(const QuicHeaderList& header_list) { | 506 void QuicHeadersStream::OnHeaderList(const QuicHeaderList& header_list) { |
564 DVLOG(1) << "Received header list for stream " << stream_id_ << ": " | 507 DVLOG(1) << "Received header list for stream " << stream_id_ << ": " |
565 << header_list.DebugString(); | 508 << header_list.DebugString(); |
566 if (prev_max_timestamp_ > cur_max_timestamp_) { | 509 if (prev_max_timestamp_ > cur_max_timestamp_) { |
567 // prev_max_timestamp_ > cur_max_timestamp_ implies that | 510 // prev_max_timestamp_ > cur_max_timestamp_ implies that |
568 // headers from lower numbered streams actually came off the | 511 // headers from lower numbered streams actually came off the |
569 // wire after headers for the current stream, hence there was | 512 // wire after headers for the current stream, hence there was |
570 // HOL blocking. | 513 // HOL blocking. |
571 QuicTime::Delta delta = prev_max_timestamp_ - cur_max_timestamp_; | 514 QuicTime::Delta delta = prev_max_timestamp_ - cur_max_timestamp_; |
572 DVLOG(1) << "stream " << stream_id_ | 515 DVLOG(1) << "stream " << stream_id_ |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 return true; | 598 return true; |
656 } | 599 } |
657 frame_len_ -= len; | 600 frame_len_ -= len; |
658 // Ignore fin_ while there is more data coming, if frame_len_ > 0. | 601 // Ignore fin_ while there is more data coming, if frame_len_ > 0. |
659 spdy_session_->OnStreamFrameData(stream_id, data, len, | 602 spdy_session_->OnStreamFrameData(stream_id, data, len, |
660 frame_len_ > 0 ? false : fin_); | 603 frame_len_ > 0 ? false : fin_); |
661 return true; | 604 return true; |
662 } | 605 } |
663 | 606 |
664 } // namespace net | 607 } // namespace net |
OLD | NEW |