Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: net/spdy/spdy_framer.cc

Issue 353443005: SpdyFramer hooks for parsing and handling PRIORITY frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Additional override => OVERRIDE. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_framer.h ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 } 1782 }
1783 break; 1783 break;
1784 case BLOCKED: { 1784 case BLOCKED: {
1785 DCHECK_LT(SPDY3, protocol_version()); 1785 DCHECK_LT(SPDY3, protocol_version());
1786 DCHECK(reader.IsDoneReading()); 1786 DCHECK(reader.IsDoneReading());
1787 visitor_->OnBlocked(current_frame_stream_id_); 1787 visitor_->OnBlocked(current_frame_stream_id_);
1788 } 1788 }
1789 break; 1789 break;
1790 case PRIORITY: { 1790 case PRIORITY: {
1791 DCHECK_LT(SPDY3, protocol_version()); 1791 DCHECK_LT(SPDY3, protocol_version());
1792 // TODO(hkhalil): Process PRIORITY frames rather than ignore them. 1792 uint32 parent_stream_id;
1793 reader.Seek(5); 1793 uint8 weight;
1794 bool exclusive;
1795 bool successful_read = true;
1796 successful_read = reader.ReadUInt32(&parent_stream_id);
1797 DCHECK(successful_read);
1798 // Exclusivity is indicated by a single bit flag.
1799 exclusive = (parent_stream_id >> 31) != 0;
1800 // Zero out the highest-order bit to get the parent stream id.
1801 parent_stream_id &= 0x7fffffff;
1802 successful_read = reader.ReadUInt8(&weight);
1803 DCHECK(successful_read);
1794 DCHECK(reader.IsDoneReading()); 1804 DCHECK(reader.IsDoneReading());
1805 visitor_->OnPriority(
1806 current_frame_stream_id_, parent_stream_id, weight, exclusive);
1795 } 1807 }
1796 break; 1808 break;
1797 default: 1809 default:
1798 // Unreachable. 1810 // Unreachable.
1799 LOG(FATAL) << "Unhandled control frame " << current_frame_type_; 1811 LOG(FATAL) << "Unhandled control frame " << current_frame_type_;
1800 } 1812 }
1801 1813
1802 CHANGE_STATE(SPDY_IGNORE_REMAINING_PAYLOAD); 1814 CHANGE_STATE(SPDY_IGNORE_REMAINING_PAYLOAD);
1803 } 1815 }
1804 return original_len - len; 1816 return original_len - len;
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
2812 builder.WriteUInt8(altsvc.protocol_id().length()); 2824 builder.WriteUInt8(altsvc.protocol_id().length());
2813 builder.WriteBytes(altsvc.protocol_id().data(), 2825 builder.WriteBytes(altsvc.protocol_id().data(),
2814 altsvc.protocol_id().length()); 2826 altsvc.protocol_id().length());
2815 builder.WriteUInt8(altsvc.host().length()); 2827 builder.WriteUInt8(altsvc.host().length());
2816 builder.WriteBytes(altsvc.host().data(), altsvc.host().length()); 2828 builder.WriteBytes(altsvc.host().data(), altsvc.host().length());
2817 builder.WriteBytes(altsvc.origin().data(), altsvc.origin().length()); 2829 builder.WriteBytes(altsvc.origin().data(), altsvc.origin().length());
2818 DCHECK_LT(GetAltSvcMinimumSize(), builder.length()); 2830 DCHECK_LT(GetAltSvcMinimumSize(), builder.length());
2819 return builder.take(); 2831 return builder.take();
2820 } 2832 }
2821 2833
2834 SpdyFrame* SpdyFramer::SerializePriority(const SpdyPriorityIR& priority) {
2835 DCHECK_LT(SPDY3, protocol_version());
2836 size_t size = GetPrioritySize();
2837
2838 SpdyFrameBuilder builder(size, protocol_version());
2839 builder.BeginNewFrame(*this, PRIORITY, kNoFlags, priority.stream_id());
2840
2841 // Make sure the highest-order bit in the parent stream id is zeroed out.
2842 uint32 parent_stream_id = priority.parent_stream_id() & 0x7fffffff;
2843 uint32 exclusive = priority.exclusive() ? 0x80000000 : 0;
2844 // Set the one-bit exclusivity flag.
2845 uint32 flag_and_parent_id = parent_stream_id | exclusive;
2846 builder.WriteUInt32(flag_and_parent_id);
2847 builder.WriteUInt8(priority.weight());
2848 DCHECK_EQ(GetPrioritySize(), builder.length());
2849 return builder.take();
2850 }
2851
2822 namespace { 2852 namespace {
2823 2853
2824 class FrameSerializationVisitor : public SpdyFrameVisitor { 2854 class FrameSerializationVisitor : public SpdyFrameVisitor {
2825 public: 2855 public:
2826 explicit FrameSerializationVisitor(SpdyFramer* framer) : framer_(framer) {} 2856 explicit FrameSerializationVisitor(SpdyFramer* framer) : framer_(framer) {}
2827 virtual ~FrameSerializationVisitor() {} 2857 virtual ~FrameSerializationVisitor() {}
2828 2858
2829 SpdySerializedFrame* ReleaseSerializedFrame() { return frame_.release(); } 2859 SpdySerializedFrame* ReleaseSerializedFrame() { return frame_.release(); }
2830 2860
2831 virtual void VisitData(const SpdyDataIR& data) OVERRIDE { 2861 virtual void VisitData(const SpdyDataIR& data) OVERRIDE {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2863 const SpdyPushPromiseIR& push_promise) OVERRIDE { 2893 const SpdyPushPromiseIR& push_promise) OVERRIDE {
2864 frame_.reset(framer_->SerializePushPromise(push_promise)); 2894 frame_.reset(framer_->SerializePushPromise(push_promise));
2865 } 2895 }
2866 virtual void VisitContinuation( 2896 virtual void VisitContinuation(
2867 const SpdyContinuationIR& continuation) OVERRIDE { 2897 const SpdyContinuationIR& continuation) OVERRIDE {
2868 frame_.reset(framer_->SerializeContinuation(continuation)); 2898 frame_.reset(framer_->SerializeContinuation(continuation));
2869 } 2899 }
2870 virtual void VisitAltSvc(const SpdyAltSvcIR& altsvc) OVERRIDE { 2900 virtual void VisitAltSvc(const SpdyAltSvcIR& altsvc) OVERRIDE {
2871 frame_.reset(framer_->SerializeAltSvc(altsvc)); 2901 frame_.reset(framer_->SerializeAltSvc(altsvc));
2872 } 2902 }
2903 virtual void VisitPriority(const SpdyPriorityIR& priority) OVERRIDE {
2904 frame_.reset(framer_->SerializePriority(priority));
2905 }
2873 2906
2874 private: 2907 private:
2875 SpdyFramer* framer_; 2908 SpdyFramer* framer_;
2876 scoped_ptr<SpdySerializedFrame> frame_; 2909 scoped_ptr<SpdySerializedFrame> frame_;
2877 }; 2910 };
2878 2911
2879 } // namespace 2912 } // namespace
2880 2913
2881 SpdySerializedFrame* SpdyFramer::SerializeFrame(const SpdyFrameIR& frame) { 2914 SpdySerializedFrame* SpdyFramer::SerializeFrame(const SpdyFrameIR& frame) {
2882 FrameSerializationVisitor visitor(this); 2915 FrameSerializationVisitor visitor(this);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
3225 builder->Seek(compressed_size); 3258 builder->Seek(compressed_size);
3226 builder->RewriteLength(*this); 3259 builder->RewriteLength(*this);
3227 3260
3228 pre_compress_bytes.Add(uncompressed_len); 3261 pre_compress_bytes.Add(uncompressed_len);
3229 post_compress_bytes.Add(compressed_size); 3262 post_compress_bytes.Add(compressed_size);
3230 3263
3231 compressed_frames.Increment(); 3264 compressed_frames.Increment();
3232 } 3265 }
3233 3266
3234 } // namespace net 3267 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.h ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698