| 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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/stats_counters.h" | 9 #include "base/metrics/stats_counters.h" |
| 10 #include "base/third_party/valgrind/memcheck.h" | 10 #include "base/third_party/valgrind/memcheck.h" |
| (...skipping 2381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2392 builder.WriteUInt8(MapPriorityToWeight(priority)); | 2392 builder.WriteUInt8(MapPriorityToWeight(priority)); |
| 2393 } | 2393 } |
| 2394 DCHECK_EQ(GetSynStreamMinimumSize(), builder.length()); | 2394 DCHECK_EQ(GetSynStreamMinimumSize(), builder.length()); |
| 2395 if (protocol_version() > SPDY3) { | 2395 if (protocol_version() > SPDY3) { |
| 2396 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size()); | 2396 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size()); |
| 2397 } else { | 2397 } else { |
| 2398 SerializeNameValueBlock(&builder, syn_stream); | 2398 SerializeNameValueBlock(&builder, syn_stream); |
| 2399 } | 2399 } |
| 2400 | 2400 |
| 2401 if (debug_visitor_) { | 2401 if (debug_visitor_) { |
| 2402 const size_t payload_len = protocol_version() > SPDY3 ? | 2402 const size_t payload_len = |
| 2403 hpack_encoding.size() : | |
| 2404 GetSerializedLength(protocol_version(), | 2403 GetSerializedLength(protocol_version(), |
| 2405 &(syn_stream.name_value_block())); | 2404 &(syn_stream.name_value_block())); |
| 2406 // SPDY 4 reports this compression as a SYN_STREAM compression. | 2405 // SPDY 4 reports this compression as a SYN_STREAM compression. |
| 2407 debug_visitor_->OnSendCompressedFrame(syn_stream.stream_id(), | 2406 debug_visitor_->OnSendCompressedFrame(syn_stream.stream_id(), |
| 2408 SYN_STREAM, | 2407 SYN_STREAM, |
| 2409 payload_len, | 2408 payload_len, |
| 2410 builder.length()); | 2409 builder.length()); |
| 2411 } | 2410 } |
| 2412 | 2411 |
| 2413 return builder.take(); | 2412 return builder.take(); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2716 SpdyFrame* SpdyFramer::SerializePushPromise( | 2715 SpdyFrame* SpdyFramer::SerializePushPromise( |
| 2717 const SpdyPushPromiseIR& push_promise) { | 2716 const SpdyPushPromiseIR& push_promise) { |
| 2718 DCHECK_LT(SPDY3, protocol_version()); | 2717 DCHECK_LT(SPDY3, protocol_version()); |
| 2719 uint8 flags = 0; | 2718 uint8 flags = 0; |
| 2720 // This will get overwritten if we overflow into a CONTINUATION frame. | 2719 // This will get overwritten if we overflow into a CONTINUATION frame. |
| 2721 flags |= PUSH_PROMISE_FLAG_END_PUSH_PROMISE; | 2720 flags |= PUSH_PROMISE_FLAG_END_PUSH_PROMISE; |
| 2722 // The size of this frame, including variable-length name-value block. | 2721 // The size of this frame, including variable-length name-value block. |
| 2723 size_t size = GetPushPromiseMinimumSize(); | 2722 size_t size = GetPushPromiseMinimumSize(); |
| 2724 | 2723 |
| 2725 string hpack_encoding; | 2724 string hpack_encoding; |
| 2726 if (protocol_version() > SPDY3) { | 2725 if (enable_compression_) { |
| 2727 if (enable_compression_) { | 2726 GetHpackEncoder()->EncodeHeaderSet( |
| 2728 GetHpackEncoder()->EncodeHeaderSet( | 2727 push_promise.name_value_block(), &hpack_encoding); |
| 2729 push_promise.name_value_block(), &hpack_encoding); | |
| 2730 } else { | |
| 2731 GetHpackEncoder()->EncodeHeaderSetWithoutCompression( | |
| 2732 push_promise.name_value_block(), &hpack_encoding); | |
| 2733 } | |
| 2734 size += hpack_encoding.size(); | |
| 2735 if (size > GetControlFrameBufferMaxSize()) { | |
| 2736 size += GetNumberRequiredContinuationFrames(size) * | |
| 2737 GetContinuationMinimumSize(); | |
| 2738 flags &= ~PUSH_PROMISE_FLAG_END_PUSH_PROMISE; | |
| 2739 } | |
| 2740 } else { | 2728 } else { |
| 2741 size += GetSerializedLength(push_promise.name_value_block()); | 2729 GetHpackEncoder()->EncodeHeaderSetWithoutCompression( |
| 2730 push_promise.name_value_block(), &hpack_encoding); |
| 2731 } |
| 2732 size += hpack_encoding.size(); |
| 2733 if (size > GetControlFrameBufferMaxSize()) { |
| 2734 size += GetNumberRequiredContinuationFrames(size) * |
| 2735 GetContinuationMinimumSize(); |
| 2736 flags &= ~PUSH_PROMISE_FLAG_END_PUSH_PROMISE; |
| 2742 } | 2737 } |
| 2743 | 2738 |
| 2744 SpdyFrameBuilder builder(size, protocol_version()); | 2739 SpdyFrameBuilder builder(size, protocol_version()); |
| 2745 builder.BeginNewFrame(*this, | 2740 builder.BeginNewFrame(*this, |
| 2746 PUSH_PROMISE, | 2741 PUSH_PROMISE, |
| 2747 flags, | 2742 flags, |
| 2748 push_promise.stream_id()); | 2743 push_promise.stream_id()); |
| 2749 builder.WriteUInt32(push_promise.promised_stream_id()); | 2744 builder.WriteUInt32(push_promise.promised_stream_id()); |
| 2750 DCHECK_EQ(GetPushPromiseMinimumSize(), builder.length()); | 2745 DCHECK_EQ(GetPushPromiseMinimumSize(), builder.length()); |
| 2751 | 2746 |
| 2752 if (protocol_version() > SPDY3) { | 2747 WritePayloadWithContinuation(&builder, |
| 2753 WritePayloadWithContinuation(&builder, | 2748 hpack_encoding, |
| 2754 hpack_encoding, | 2749 push_promise.stream_id(), |
| 2755 push_promise.stream_id(), | 2750 PUSH_PROMISE); |
| 2756 PUSH_PROMISE); | |
| 2757 } else { | |
| 2758 SerializeNameValueBlock(&builder, push_promise); | |
| 2759 } | |
| 2760 | 2751 |
| 2761 if (debug_visitor_) { | 2752 if (debug_visitor_) { |
| 2762 const size_t payload_len = protocol_version() > SPDY3 ? | |
| 2763 hpack_encoding.size() : | |
| 2764 GetSerializedLength(protocol_version(), | |
| 2765 &(push_promise.name_value_block())); | |
| 2766 debug_visitor_->OnSendCompressedFrame(push_promise.stream_id(), | 2753 debug_visitor_->OnSendCompressedFrame(push_promise.stream_id(), |
| 2767 PUSH_PROMISE, payload_len, builder.length()); | 2754 PUSH_PROMISE, hpack_encoding.size(), builder.length()); |
| 2768 } | 2755 } |
| 2769 | 2756 |
| 2770 return builder.take(); | 2757 return builder.take(); |
| 2771 } | 2758 } |
| 2772 | 2759 |
| 2773 // TODO(jgraettinger): This implementation is incorrect. The continuation | 2760 // TODO(jgraettinger): This implementation is incorrect. The continuation |
| 2774 // frame continues a previously-begun HPACK encoding; it doesn't begin a | 2761 // frame continues a previously-begun HPACK encoding; it doesn't begin a |
| 2775 // new one. Figure out whether it makes sense to keep SerializeContinuation(). | 2762 // new one. Figure out whether it makes sense to keep SerializeContinuation(). |
| 2776 SpdyFrame* SpdyFramer::SerializeContinuation( | 2763 SpdyFrame* SpdyFramer::SerializeContinuation( |
| 2777 const SpdyContinuationIR& continuation) { | 2764 const SpdyContinuationIR& continuation) { |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3238 builder->Seek(compressed_size); | 3225 builder->Seek(compressed_size); |
| 3239 builder->RewriteLength(*this); | 3226 builder->RewriteLength(*this); |
| 3240 | 3227 |
| 3241 pre_compress_bytes.Add(uncompressed_len); | 3228 pre_compress_bytes.Add(uncompressed_len); |
| 3242 post_compress_bytes.Add(compressed_size); | 3229 post_compress_bytes.Add(compressed_size); |
| 3243 | 3230 |
| 3244 compressed_frames.Increment(); | 3231 compressed_frames.Increment(); |
| 3245 } | 3232 } |
| 3246 | 3233 |
| 3247 } // namespace net | 3234 } // namespace net |
| OLD | NEW |