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/core/spdy_framer.h" | 5 #include "net/spdy/core/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> |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "net/spdy/core/hpack/hpack_constants.h" | 25 #include "net/spdy/core/hpack/hpack_constants.h" |
26 #include "net/spdy/core/hpack/hpack_decoder.h" | 26 #include "net/spdy/core/hpack/hpack_decoder.h" |
27 #include "net/spdy/core/hpack/hpack_decoder3.h" | 27 #include "net/spdy/core/hpack/hpack_decoder3.h" |
28 #include "net/spdy/core/http2_frame_decoder_adapter.h" | 28 #include "net/spdy/core/http2_frame_decoder_adapter.h" |
29 #include "net/spdy/core/spdy_bitmasks.h" | 29 #include "net/spdy/core/spdy_bitmasks.h" |
30 #include "net/spdy/core/spdy_bug_tracker.h" | 30 #include "net/spdy/core/spdy_bug_tracker.h" |
31 #include "net/spdy/core/spdy_frame_builder.h" | 31 #include "net/spdy/core/spdy_frame_builder.h" |
32 #include "net/spdy/core/spdy_frame_reader.h" | 32 #include "net/spdy/core/spdy_frame_reader.h" |
33 #include "net/spdy/core/spdy_framer_decoder_adapter.h" | 33 #include "net/spdy/core/spdy_framer_decoder_adapter.h" |
34 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" | 34 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" |
| 35 #include "net/spdy/platform/api/spdy_ptr_util.h" |
35 #include "net/spdy/platform/api/spdy_string_utils.h" | 36 #include "net/spdy/platform/api/spdy_string_utils.h" |
36 | 37 |
37 using std::vector; | 38 using std::vector; |
38 | 39 |
39 namespace net { | 40 namespace net { |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 // Pack parent stream ID and exclusive flag into the format used by HTTP/2 | 44 // Pack parent stream ID and exclusive flag into the format used by HTTP/2 |
44 // headers and priority frames. | 45 // headers and priority frames. |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 size_t SpdyFramer::ProcessAltSvcFramePayload(const char* data, size_t len) { | 1444 size_t SpdyFramer::ProcessAltSvcFramePayload(const char* data, size_t len) { |
1444 if (len == 0) { | 1445 if (len == 0) { |
1445 return 0; | 1446 return 0; |
1446 } | 1447 } |
1447 | 1448 |
1448 // Clamp to the actual remaining payload. | 1449 // Clamp to the actual remaining payload. |
1449 len = std::min(len, remaining_data_length_); | 1450 len = std::min(len, remaining_data_length_); |
1450 | 1451 |
1451 if (altsvc_scratch_ == nullptr) { | 1452 if (altsvc_scratch_ == nullptr) { |
1452 size_t capacity = current_frame_length_ - GetFrameHeaderSize(); | 1453 size_t capacity = current_frame_length_ - GetFrameHeaderSize(); |
1453 altsvc_scratch_.reset(new CharBuffer(capacity)); | 1454 altsvc_scratch_ = SpdyMakeUnique<CharBuffer>(capacity); |
1454 } | 1455 } |
1455 altsvc_scratch_->CopyFrom(data, len); | 1456 altsvc_scratch_->CopyFrom(data, len); |
1456 remaining_data_length_ -= len; | 1457 remaining_data_length_ -= len; |
1457 if (remaining_data_length_ > 0) { | 1458 if (remaining_data_length_ > 0) { |
1458 return len; | 1459 return len; |
1459 } | 1460 } |
1460 | 1461 |
1461 SpdyFrameReader reader(altsvc_scratch_->data(), altsvc_scratch_->len()); | 1462 SpdyFrameReader reader(altsvc_scratch_->data(), altsvc_scratch_->len()); |
1462 SpdyStringPiece origin; | 1463 SpdyStringPiece origin; |
1463 bool successful_read = reader.ReadStringPiece16(&origin); | 1464 bool successful_read = reader.ReadStringPiece16(&origin); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 } | 1682 } |
1682 if (!has_next_frame_) { | 1683 if (!has_next_frame_) { |
1683 SPDY_BUG << "SpdyFramer::SpdyFrameIterator::NextFrame called without " | 1684 SPDY_BUG << "SpdyFramer::SpdyFrameIterator::NextFrame called without " |
1684 << "a next frame."; | 1685 << "a next frame."; |
1685 return false; | 1686 return false; |
1686 } | 1687 } |
1687 | 1688 |
1688 size_t size_without_block = is_first_frame_ | 1689 size_t size_without_block = is_first_frame_ |
1689 ? GetFrameSizeSansBlock() | 1690 ? GetFrameSizeSansBlock() |
1690 : framer_->GetContinuationMinimumSize(); | 1691 : framer_->GetContinuationMinimumSize(); |
1691 auto encoding = base::MakeUnique<SpdyString>(); | 1692 auto encoding = SpdyMakeUnique<SpdyString>(); |
1692 encoder_->Next(kMaxControlFrameSize - size_without_block, encoding.get()); | 1693 encoder_->Next(kMaxControlFrameSize - size_without_block, encoding.get()); |
1693 has_next_frame_ = encoder_->HasNext(); | 1694 has_next_frame_ = encoder_->HasNext(); |
1694 | 1695 |
1695 if (framer_->debug_visitor_ != nullptr) { | 1696 if (framer_->debug_visitor_ != nullptr) { |
1696 debug_total_size_ += size_without_block; | 1697 debug_total_size_ += size_without_block; |
1697 debug_total_size_ += encoding->size(); | 1698 debug_total_size_ += encoding->size(); |
1698 if (!has_next_frame_) { | 1699 if (!has_next_frame_) { |
1699 // TODO(birenroy) are these (here and below) still necessary? | 1700 // TODO(birenroy) are these (here and below) still necessary? |
1700 // HTTP2 uses HPACK for header compression. However, continue to | 1701 // HTTP2 uses HPACK for header compression. However, continue to |
1701 // use GetSerializedLength() for an apples-to-apples comparision of | 1702 // use GetSerializedLength() for an apples-to-apples comparision of |
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2877 ret &= builder->WriteBytes( | 2878 ret &= builder->WriteBytes( |
2878 &hpack_encoding[hpack_encoding.size() - bytes_remaining], | 2879 &hpack_encoding[hpack_encoding.size() - bytes_remaining], |
2879 bytes_to_write); | 2880 bytes_to_write); |
2880 bytes_remaining -= bytes_to_write; | 2881 bytes_remaining -= bytes_to_write; |
2881 } | 2882 } |
2882 return ret; | 2883 return ret; |
2883 } | 2884 } |
2884 | 2885 |
2885 HpackEncoder* SpdyFramer::GetHpackEncoder() { | 2886 HpackEncoder* SpdyFramer::GetHpackEncoder() { |
2886 if (hpack_encoder_.get() == nullptr) { | 2887 if (hpack_encoder_.get() == nullptr) { |
2887 hpack_encoder_.reset(new HpackEncoder(ObtainHpackHuffmanTable())); | 2888 hpack_encoder_ = SpdyMakeUnique<HpackEncoder>(ObtainHpackHuffmanTable()); |
2888 if (!compression_enabled()) { | 2889 if (!compression_enabled()) { |
2889 hpack_encoder_->DisableCompression(); | 2890 hpack_encoder_->DisableCompression(); |
2890 } | 2891 } |
2891 } | 2892 } |
2892 return hpack_encoder_.get(); | 2893 return hpack_encoder_.get(); |
2893 } | 2894 } |
2894 | 2895 |
2895 HpackDecoderInterface* SpdyFramer::GetHpackDecoder() { | 2896 HpackDecoderInterface* SpdyFramer::GetHpackDecoder() { |
2896 if (hpack_decoder_.get() == nullptr) { | 2897 if (hpack_decoder_.get() == nullptr) { |
2897 if (FLAGS_chromium_http2_flag_spdy_use_hpack_decoder3) { | 2898 if (FLAGS_chromium_http2_flag_spdy_use_hpack_decoder3) { |
2898 hpack_decoder_.reset(new HpackDecoder3()); | 2899 hpack_decoder_ = SpdyMakeUnique<HpackDecoder3>(); |
2899 } else { | 2900 } else { |
2900 hpack_decoder_.reset(new HpackDecoder()); | 2901 hpack_decoder_ = SpdyMakeUnique<HpackDecoder>(); |
2901 } | 2902 } |
2902 } | 2903 } |
2903 return hpack_decoder_.get(); | 2904 return hpack_decoder_.get(); |
2904 } | 2905 } |
2905 | 2906 |
2906 void SpdyFramer::SetDecoderHeaderTableDebugVisitor( | 2907 void SpdyFramer::SetDecoderHeaderTableDebugVisitor( |
2907 std::unique_ptr<HpackHeaderTable::DebugVisitorInterface> visitor) { | 2908 std::unique_ptr<HpackHeaderTable::DebugVisitorInterface> visitor) { |
2908 if (decoder_adapter_ != nullptr) { | 2909 if (decoder_adapter_ != nullptr) { |
2909 decoder_adapter_->SetDecoderHeaderTableDebugVisitor(std::move(visitor)); | 2910 decoder_adapter_->SetDecoderHeaderTableDebugVisitor(std::move(visitor)); |
2910 } else { | 2911 } else { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2949 builder->WriteUInt32(header_block.size()); | 2950 builder->WriteUInt32(header_block.size()); |
2950 | 2951 |
2951 // Serialize each header. | 2952 // Serialize each header. |
2952 for (const auto& header : header_block) { | 2953 for (const auto& header : header_block) { |
2953 builder->WriteStringPiece32(base::ToLowerASCII(header.first)); | 2954 builder->WriteStringPiece32(base::ToLowerASCII(header.first)); |
2954 builder->WriteStringPiece32(header.second); | 2955 builder->WriteStringPiece32(header.second); |
2955 } | 2956 } |
2956 } | 2957 } |
2957 | 2958 |
2958 } // namespace net | 2959 } // namespace net |
OLD | NEW |