| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spdy/spdy_framer.h" | 5 #include "net/spdy/spdy_framer.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cctype> | 10 #include <cctype> |
| 11 #include <ios> | 11 #include <ios> |
| 12 #include <iterator> | 12 #include <iterator> |
| 13 #include <list> | 13 #include <list> |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <new> | 15 #include <new> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
| 20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
| 22 #include "base/metrics/histogram_macros.h" | 22 #include "base/metrics/histogram_macros.h" |
| 23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 24 #include "base/trace_event/memory_usage_estimator.h" |
| 24 #include "net/quic/core/quic_flags.h" | 25 #include "net/quic/core/quic_flags.h" |
| 25 #include "net/spdy/hpack/hpack_constants.h" | 26 #include "net/spdy/hpack/hpack_constants.h" |
| 26 #include "net/spdy/hpack/hpack_decoder.h" | 27 #include "net/spdy/hpack/hpack_decoder.h" |
| 27 #include "net/spdy/hpack/hpack_decoder2.h" | 28 #include "net/spdy/hpack/hpack_decoder2.h" |
| 28 #include "net/spdy/hpack/hpack_decoder3.h" | 29 #include "net/spdy/hpack/hpack_decoder3.h" |
| 29 #include "net/spdy/http2_frame_decoder_adapter.h" | 30 #include "net/spdy/http2_frame_decoder_adapter.h" |
| 30 #include "net/spdy/spdy_bitmasks.h" | 31 #include "net/spdy/spdy_bitmasks.h" |
| 31 #include "net/spdy/spdy_bug_tracker.h" | 32 #include "net/spdy/spdy_bug_tracker.h" |
| 32 #include "net/spdy/spdy_flags.h" | 33 #include "net/spdy/spdy_flags.h" |
| 33 #include "net/spdy/spdy_frame_builder.h" | 34 #include "net/spdy/spdy_frame_builder.h" |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 void SpdyFramer::CharBuffer::CopyFrom(const char* data, size_t size) { | 556 void SpdyFramer::CharBuffer::CopyFrom(const char* data, size_t size) { |
| 556 DCHECK_GE(capacity_, len_ + size); | 557 DCHECK_GE(capacity_, len_ + size); |
| 557 memcpy(buffer_.get() + len_, data, size); | 558 memcpy(buffer_.get() + len_, data, size); |
| 558 len_ += size; | 559 len_ += size; |
| 559 } | 560 } |
| 560 | 561 |
| 561 void SpdyFramer::CharBuffer::Rewind() { | 562 void SpdyFramer::CharBuffer::Rewind() { |
| 562 len_ = 0; | 563 len_ = 0; |
| 563 } | 564 } |
| 564 | 565 |
| 566 size_t SpdyFramer::CharBuffer::EstimateMemoryUsage() const { |
| 567 return capacity_; |
| 568 } |
| 569 |
| 565 SpdyFramer::SpdySettingsScratch::SpdySettingsScratch() | 570 SpdyFramer::SpdySettingsScratch::SpdySettingsScratch() |
| 566 : buffer(8), last_setting_id(-1) {} | 571 : buffer(8), last_setting_id(-1) {} |
| 567 | 572 |
| 568 void SpdyFramer::SpdySettingsScratch::Reset() { | 573 void SpdyFramer::SpdySettingsScratch::Reset() { |
| 569 buffer.Rewind(); | 574 buffer.Rewind(); |
| 570 last_setting_id = -1; | 575 last_setting_id = -1; |
| 571 } | 576 } |
| 572 | 577 |
| 578 size_t SpdyFramer::SpdySettingsScratch::EstimateMemoryUsage() const { |
| 579 return base::trace_event::EstimateMemoryUsage(buffer); |
| 580 } |
| 581 |
| 573 SpdyFrameType SpdyFramer::ValidateFrameHeader(bool is_control_frame, | 582 SpdyFrameType SpdyFramer::ValidateFrameHeader(bool is_control_frame, |
| 574 int frame_type_field, | 583 int frame_type_field, |
| 575 size_t payload_length_field) { | 584 size_t payload_length_field) { |
| 576 if (!IsDefinedFrameType(frame_type_field)) { | 585 if (!IsDefinedFrameType(frame_type_field)) { |
| 577 // We ignore unknown frame types for extensibility, as long as | 586 // We ignore unknown frame types for extensibility, as long as |
| 578 // the rest of the control frame header is valid. | 587 // the rest of the control frame header is valid. |
| 579 // We rely on the visitor to check validity of current_frame_stream_id_. | 588 // We rely on the visitor to check validity of current_frame_stream_id_. |
| 580 bool valid_stream = | 589 bool valid_stream = |
| 581 visitor_->OnUnknownFrame(current_frame_stream_id_, frame_type_field); | 590 visitor_->OnUnknownFrame(current_frame_stream_id_, frame_type_field); |
| 582 if (expect_continuation_) { | 591 if (expect_continuation_) { |
| (...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2344 } else { | 2353 } else { |
| 2345 GetHpackDecoder()->SetHeaderTableDebugVisitor(std::move(visitor)); | 2354 GetHpackDecoder()->SetHeaderTableDebugVisitor(std::move(visitor)); |
| 2346 } | 2355 } |
| 2347 } | 2356 } |
| 2348 | 2357 |
| 2349 void SpdyFramer::SetEncoderHeaderTableDebugVisitor( | 2358 void SpdyFramer::SetEncoderHeaderTableDebugVisitor( |
| 2350 std::unique_ptr<HpackHeaderTable::DebugVisitorInterface> visitor) { | 2359 std::unique_ptr<HpackHeaderTable::DebugVisitorInterface> visitor) { |
| 2351 GetHpackEncoder()->SetHeaderTableDebugVisitor(std::move(visitor)); | 2360 GetHpackEncoder()->SetHeaderTableDebugVisitor(std::move(visitor)); |
| 2352 } | 2361 } |
| 2353 | 2362 |
| 2363 size_t SpdyFramer::EstimateMemoryUsage() const { |
| 2364 return base::trace_event::EstimateMemoryUsage(current_frame_buffer_) + |
| 2365 base::trace_event::EstimateMemoryUsage(settings_scratch_) + |
| 2366 base::trace_event::EstimateMemoryUsage(altsvc_scratch_) + |
| 2367 base::trace_event::EstimateMemoryUsage(hpack_encoder_) + |
| 2368 base::trace_event::EstimateMemoryUsage(hpack_decoder_) + |
| 2369 base::trace_event::EstimateMemoryUsage(decoder_adapter_); |
| 2370 } |
| 2371 |
| 2354 void SpdyFramer::UpdateHeaderEncoderTableSize(uint32_t value) { | 2372 void SpdyFramer::UpdateHeaderEncoderTableSize(uint32_t value) { |
| 2355 GetHpackEncoder()->ApplyHeaderTableSizeSetting(value); | 2373 GetHpackEncoder()->ApplyHeaderTableSizeSetting(value); |
| 2356 } | 2374 } |
| 2357 | 2375 |
| 2358 void SpdyFramer::UpdateHeaderDecoderTableSize(uint32_t value) { | 2376 void SpdyFramer::UpdateHeaderDecoderTableSize(uint32_t value) { |
| 2359 GetHpackDecoder()->ApplyHeaderTableSizeSetting(value); | 2377 GetHpackDecoder()->ApplyHeaderTableSizeSetting(value); |
| 2360 } | 2378 } |
| 2361 | 2379 |
| 2362 size_t SpdyFramer::header_encoder_table_size() const { | 2380 size_t SpdyFramer::header_encoder_table_size() const { |
| 2363 if (hpack_encoder_ == nullptr) { | 2381 if (hpack_encoder_ == nullptr) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2374 builder->WriteUInt32(header_block.size()); | 2392 builder->WriteUInt32(header_block.size()); |
| 2375 | 2393 |
| 2376 // Serialize each header. | 2394 // Serialize each header. |
| 2377 for (const auto& header : header_block) { | 2395 for (const auto& header : header_block) { |
| 2378 builder->WriteStringPiece32(base::ToLowerASCII(header.first)); | 2396 builder->WriteStringPiece32(base::ToLowerASCII(header.first)); |
| 2379 builder->WriteStringPiece32(header.second); | 2397 builder->WriteStringPiece32(header.second); |
| 2380 } | 2398 } |
| 2381 } | 2399 } |
| 2382 | 2400 |
| 2383 } // namespace net | 2401 } // namespace net |
| OLD | NEW |