| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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_spdy_session.h" | 5 #include "net/quic/core/quic_spdy_session.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "net/quic/core/quic_flags.h" | 9 #include "net/quic/core/quic_flags.h" |
| 10 #include "net/quic/core/quic_headers_stream.h" | 10 #include "net/quic/core/quic_headers_stream.h" |
| 11 #include "net/quic/platform/api/quic_bug_tracker.h" | 11 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 12 #include "net/quic/platform/api/quic_logging.h" |
| 12 #include "net/quic/platform/api/quic_str_cat.h" | 13 #include "net/quic/platform/api/quic_str_cat.h" |
| 13 | 14 |
| 14 using base::StringPiece; | 15 using base::StringPiece; |
| 15 using std::string; | 16 using std::string; |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 class HeaderTableDebugVisitor | 22 class HeaderTableDebugVisitor |
| 22 : public HpackHeaderTable::DebugVisitorInterface { | 23 : public HpackHeaderTable::DebugVisitorInterface { |
| 23 public: | 24 public: |
| 24 HeaderTableDebugVisitor(const QuicClock* clock, | 25 HeaderTableDebugVisitor(const QuicClock* clock, |
| 25 std::unique_ptr<QuicHpackDebugVisitor> visitor) | 26 std::unique_ptr<QuicHpackDebugVisitor> visitor) |
| 26 : clock_(clock), headers_stream_hpack_visitor_(std::move(visitor)) {} | 27 : clock_(clock), headers_stream_hpack_visitor_(std::move(visitor)) {} |
| 27 | 28 |
| 28 int64_t OnNewEntry(const HpackEntry& entry) override { | 29 int64_t OnNewEntry(const HpackEntry& entry) override { |
| 29 DVLOG(1) << entry.GetDebugString(); | 30 QUIC_DVLOG(1) << entry.GetDebugString(); |
| 30 return (clock_->ApproximateNow() - QuicTime::Zero()).ToMicroseconds(); | 31 return (clock_->ApproximateNow() - QuicTime::Zero()).ToMicroseconds(); |
| 31 } | 32 } |
| 32 | 33 |
| 33 void OnUseEntry(const HpackEntry& entry) override { | 34 void OnUseEntry(const HpackEntry& entry) override { |
| 34 const QuicTime::Delta elapsed( | 35 const QuicTime::Delta elapsed( |
| 35 clock_->ApproximateNow() - | 36 clock_->ApproximateNow() - |
| 36 QuicTime::Delta::FromMicroseconds(entry.time_added()) - | 37 QuicTime::Delta::FromMicroseconds(entry.time_added()) - |
| 37 QuicTime::Zero()); | 38 QuicTime::Zero()); |
| 38 DVLOG(1) << entry.GetDebugString() << " " << elapsed.ToMilliseconds() | 39 QUIC_DVLOG(1) << entry.GetDebugString() << " " << elapsed.ToMilliseconds() |
| 39 << " ms"; | 40 << " ms"; |
| 40 headers_stream_hpack_visitor_->OnUseEntry(elapsed); | 41 headers_stream_hpack_visitor_->OnUseEntry(elapsed); |
| 41 } | 42 } |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 const QuicClock* clock_; | 45 const QuicClock* clock_; |
| 45 std::unique_ptr<QuicHpackDebugVisitor> headers_stream_hpack_visitor_; | 46 std::unique_ptr<QuicHpackDebugVisitor> headers_stream_hpack_visitor_; |
| 46 | 47 |
| 47 DISALLOW_COPY_AND_ASSIGN(HeaderTableDebugVisitor); | 48 DISALLOW_COPY_AND_ASSIGN(HeaderTableDebugVisitor); |
| 48 }; | 49 }; |
| 49 | 50 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // SpdyFramerDebugVisitorInterface implementation | 264 // SpdyFramerDebugVisitorInterface implementation |
| 264 void OnSendCompressedFrame(SpdyStreamId stream_id, | 265 void OnSendCompressedFrame(SpdyStreamId stream_id, |
| 265 SpdyFrameType type, | 266 SpdyFrameType type, |
| 266 size_t payload_len, | 267 size_t payload_len, |
| 267 size_t frame_len) override { | 268 size_t frame_len) override { |
| 268 if (payload_len == 0) { | 269 if (payload_len == 0) { |
| 269 QUIC_BUG << "Zero payload length."; | 270 QUIC_BUG << "Zero payload length."; |
| 270 return; | 271 return; |
| 271 } | 272 } |
| 272 int compression_pct = 100 - (100 * frame_len) / payload_len; | 273 int compression_pct = 100 - (100 * frame_len) / payload_len; |
| 273 DVLOG(1) << "Net.QuicHpackCompressionPercentage: " << compression_pct; | 274 QUIC_DVLOG(1) << "Net.QuicHpackCompressionPercentage: " << compression_pct; |
| 274 } | 275 } |
| 275 | 276 |
| 276 void OnReceiveCompressedFrame(SpdyStreamId stream_id, | 277 void OnReceiveCompressedFrame(SpdyStreamId stream_id, |
| 277 SpdyFrameType type, | 278 SpdyFrameType type, |
| 278 size_t frame_len) override { | 279 size_t frame_len) override { |
| 279 if (session_->IsConnected()) { | 280 if (session_->IsConnected()) { |
| 280 session_->OnCompressedFrameSize(frame_len); | 281 session_->OnCompressedFrameSize(frame_len); |
| 281 } | 282 } |
| 282 } | 283 } |
| 283 | 284 |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 const char* data, | 589 const char* data, |
| 589 size_t len, | 590 size_t len, |
| 590 bool fin) { | 591 bool fin) { |
| 591 QuicSpdyStream* stream = GetSpdyDataStream(stream_id); | 592 QuicSpdyStream* stream = GetSpdyDataStream(stream_id); |
| 592 if (stream == nullptr) { | 593 if (stream == nullptr) { |
| 593 return; | 594 return; |
| 594 } | 595 } |
| 595 const QuicStreamOffset offset = | 596 const QuicStreamOffset offset = |
| 596 stream->flow_controller()->highest_received_byte_offset(); | 597 stream->flow_controller()->highest_received_byte_offset(); |
| 597 const QuicStreamFrame frame(stream_id, fin, offset, StringPiece(data, len)); | 598 const QuicStreamFrame frame(stream_id, fin, offset, StringPiece(data, len)); |
| 598 DVLOG(1) << "De-encapsulating DATA frame for stream " << stream_id | 599 QUIC_DVLOG(1) << "De-encapsulating DATA frame for stream " << stream_id |
| 599 << " offset " << offset << " len " << len << " fin " << fin; | 600 << " offset " << offset << " len " << len << " fin " << fin; |
| 600 OnStreamFrame(frame); | 601 OnStreamFrame(frame); |
| 601 } | 602 } |
| 602 | 603 |
| 603 bool QuicSpdySession::ShouldReleaseHeadersStreamSequencerBuffer() { | 604 bool QuicSpdySession::ShouldReleaseHeadersStreamSequencerBuffer() { |
| 604 return false; | 605 return false; |
| 605 } | 606 } |
| 606 | 607 |
| 607 void QuicSpdySession::OnHeaders(SpdyStreamId stream_id, | 608 void QuicSpdySession::OnHeaders(SpdyStreamId stream_id, |
| 608 bool has_priority, | 609 bool has_priority, |
| 609 SpdyPriority priority, | 610 SpdyPriority priority, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 631 void QuicSpdySession::OnPushPromise(SpdyStreamId stream_id, | 632 void QuicSpdySession::OnPushPromise(SpdyStreamId stream_id, |
| 632 SpdyStreamId promised_stream_id, | 633 SpdyStreamId promised_stream_id, |
| 633 bool end) { | 634 bool end) { |
| 634 DCHECK_EQ(kInvalidStreamId, stream_id_); | 635 DCHECK_EQ(kInvalidStreamId, stream_id_); |
| 635 DCHECK_EQ(kInvalidStreamId, promised_stream_id_); | 636 DCHECK_EQ(kInvalidStreamId, promised_stream_id_); |
| 636 stream_id_ = stream_id; | 637 stream_id_ = stream_id; |
| 637 promised_stream_id_ = promised_stream_id; | 638 promised_stream_id_ = promised_stream_id; |
| 638 } | 639 } |
| 639 | 640 |
| 640 void QuicSpdySession::OnHeaderList(const QuicHeaderList& header_list) { | 641 void QuicSpdySession::OnHeaderList(const QuicHeaderList& header_list) { |
| 641 DVLOG(1) << "Received header list for stream " << stream_id_ << ": " | 642 QUIC_DVLOG(1) << "Received header list for stream " << stream_id_ << ": " |
| 642 << header_list.DebugString(); | 643 << header_list.DebugString(); |
| 643 if (prev_max_timestamp_ > cur_max_timestamp_) { | 644 if (prev_max_timestamp_ > cur_max_timestamp_) { |
| 644 // prev_max_timestamp_ > cur_max_timestamp_ implies that | 645 // prev_max_timestamp_ > cur_max_timestamp_ implies that |
| 645 // headers from lower numbered streams actually came off the | 646 // headers from lower numbered streams actually came off the |
| 646 // wire after headers for the current stream, hence there was | 647 // wire after headers for the current stream, hence there was |
| 647 // HOL blocking. | 648 // HOL blocking. |
| 648 QuicTime::Delta delta = prev_max_timestamp_ - cur_max_timestamp_; | 649 QuicTime::Delta delta = prev_max_timestamp_ - cur_max_timestamp_; |
| 649 DVLOG(1) << "stream " << stream_id_ | 650 QUIC_DLOG(INFO) << "stream " << stream_id_ |
| 650 << ": Net.QuicSession.HeadersHOLBlockedTime " | 651 << ": Net.QuicSession.HeadersHOLBlockedTime " |
| 651 << delta.ToMilliseconds(); | 652 << delta.ToMilliseconds(); |
| 652 OnHeadersHeadOfLineBlocking(delta); | 653 OnHeadersHeadOfLineBlocking(delta); |
| 653 } | 654 } |
| 654 prev_max_timestamp_ = std::max(prev_max_timestamp_, cur_max_timestamp_); | 655 prev_max_timestamp_ = std::max(prev_max_timestamp_, cur_max_timestamp_); |
| 655 cur_max_timestamp_ = QuicTime::Zero(); | 656 cur_max_timestamp_ = QuicTime::Zero(); |
| 656 if (promised_stream_id_ == kInvalidStreamId) { | 657 if (promised_stream_id_ == kInvalidStreamId) { |
| 657 OnStreamHeaderList(stream_id_, fin_, frame_len_, header_list); | 658 OnStreamHeaderList(stream_id_, fin_, frame_len_, header_list); |
| 658 } else { | 659 } else { |
| 659 OnPromiseHeaderList(stream_id_, promised_stream_id_, frame_len_, | 660 OnPromiseHeaderList(stream_id_, promised_stream_id_, frame_len_, |
| 660 header_list); | 661 header_list); |
| 661 } | 662 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 | 700 |
| 700 bool QuicSpdySession::OnDataFrameHeader(QuicStreamId stream_id, | 701 bool QuicSpdySession::OnDataFrameHeader(QuicStreamId stream_id, |
| 701 size_t length, | 702 size_t length, |
| 702 bool fin) { | 703 bool fin) { |
| 703 if (!force_hol_blocking()) { | 704 if (!force_hol_blocking()) { |
| 704 return false; | 705 return false; |
| 705 } | 706 } |
| 706 if (!IsConnected()) { | 707 if (!IsConnected()) { |
| 707 return true; | 708 return true; |
| 708 } | 709 } |
| 709 DVLOG(1) << "DATA frame header for stream " << stream_id << " length " | 710 QUIC_DVLOG(1) << "DATA frame header for stream " << stream_id << " length " |
| 710 << length << " fin " << fin; | 711 << length << " fin " << fin; |
| 711 fin_ = fin; | 712 fin_ = fin; |
| 712 frame_len_ = length; | 713 frame_len_ = length; |
| 713 if (fin && length == 0) { | 714 if (fin && length == 0) { |
| 714 OnStreamFrameData(stream_id, "", 0); | 715 OnStreamFrameData(stream_id, "", 0); |
| 715 } | 716 } |
| 716 return true; | 717 return true; |
| 717 } | 718 } |
| 718 | 719 |
| 719 bool QuicSpdySession::OnStreamFrameData(QuicStreamId stream_id, | 720 bool QuicSpdySession::OnStreamFrameData(QuicStreamId stream_id, |
| 720 const char* data, | 721 const char* data, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 737 set_max_uncompressed_header_bytes); | 738 set_max_uncompressed_header_bytes); |
| 738 } | 739 } |
| 739 | 740 |
| 740 void QuicSpdySession::CloseConnectionWithDetails(QuicErrorCode error, | 741 void QuicSpdySession::CloseConnectionWithDetails(QuicErrorCode error, |
| 741 const string& details) { | 742 const string& details) { |
| 742 connection()->CloseConnection( | 743 connection()->CloseConnection( |
| 743 error, details, ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 744 error, details, ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 744 } | 745 } |
| 745 | 746 |
| 746 } // namespace net | 747 } // namespace net |
| OLD | NEW |