Chromium Code Reviews| 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 case DATA: | 462 case DATA: |
| 463 return "DATA"; | 463 return "DATA"; |
| 464 case SYN_STREAM: | 464 case SYN_STREAM: |
| 465 return "SYN_STREAM"; | 465 return "SYN_STREAM"; |
| 466 case SYN_REPLY: | 466 case SYN_REPLY: |
| 467 return "SYN_REPLY"; | 467 return "SYN_REPLY"; |
| 468 case RST_STREAM: | 468 case RST_STREAM: |
| 469 return "RST_STREAM"; | 469 return "RST_STREAM"; |
| 470 case SETTINGS: | 470 case SETTINGS: |
| 471 return "SETTINGS"; | 471 return "SETTINGS"; |
| 472 case NOOP: | |
| 473 return "NOOP"; | |
| 474 case PING: | 472 case PING: |
| 475 return "PING"; | 473 return "PING"; |
| 476 case GOAWAY: | 474 case GOAWAY: |
| 477 return "GOAWAY"; | 475 return "GOAWAY"; |
| 478 case HEADERS: | 476 case HEADERS: |
| 479 return "HEADERS"; | 477 return "HEADERS"; |
| 480 case WINDOW_UPDATE: | 478 case WINDOW_UPDATE: |
| 481 return "WINDOW_UPDATE"; | 479 return "WINDOW_UPDATE"; |
| 482 case CREDENTIAL: | 480 case CREDENTIAL: |
| 483 return "CREDENTIAL"; | 481 return "CREDENTIAL"; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 | 652 |
| 655 // Using a scoped_ptr here since we may need to create a new SpdyFrameReader | 653 // Using a scoped_ptr here since we may need to create a new SpdyFrameReader |
| 656 // when processing DATA frames below. | 654 // when processing DATA frames below. |
| 657 scoped_ptr<SpdyFrameReader> reader( | 655 scoped_ptr<SpdyFrameReader> reader( |
| 658 new SpdyFrameReader(current_frame_buffer_.get(), | 656 new SpdyFrameReader(current_frame_buffer_.get(), |
| 659 current_frame_buffer_length_)); | 657 current_frame_buffer_length_)); |
| 660 | 658 |
| 661 uint16 version = 0; | 659 uint16 version = 0; |
| 662 bool is_control_frame = false; | 660 bool is_control_frame = false; |
| 663 | 661 |
| 664 uint16 control_frame_type_field = DATA; | 662 uint16 control_frame_type_field = |
| 663 SpdyConstants::DataFrameType(protocol_version()); | |
| 665 // ProcessControlFrameHeader() will set current_frame_type_ to the | 664 // ProcessControlFrameHeader() will set current_frame_type_ to the |
| 666 // correct value if this is a valid control frame. | 665 // correct value if this is a valid control frame. |
| 667 current_frame_type_ = DATA; | 666 current_frame_type_ = DATA; |
| 668 if (protocol_version() <= SPDY3) { | 667 if (protocol_version() <= SPDY3) { |
| 669 bool successful_read = reader->ReadUInt16(&version); | 668 bool successful_read = reader->ReadUInt16(&version); |
| 670 DCHECK(successful_read); | 669 DCHECK(successful_read); |
| 671 is_control_frame = (version & kControlFlagMask) != 0; | 670 is_control_frame = (version & kControlFlagMask) != 0; |
| 672 version &= ~kControlFlagMask; // Only valid for control frames. | 671 version &= ~kControlFlagMask; // Only valid for control frames. |
| 673 if (is_control_frame) { | 672 if (is_control_frame) { |
| 674 // We check version before we check validity: version can never be | 673 // We check version before we check validity: version can never be |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 702 successful_read = reader->ReadUInt24(&length_field); | 701 successful_read = reader->ReadUInt24(&length_field); |
| 703 DCHECK(successful_read); | 702 DCHECK(successful_read); |
| 704 remaining_data_length_ = length_field; | 703 remaining_data_length_ = length_field; |
| 705 current_frame_length_ = remaining_data_length_ + reader->GetBytesConsumed(); | 704 current_frame_length_ = remaining_data_length_ + reader->GetBytesConsumed(); |
| 706 } else { | 705 } else { |
| 707 version = protocol_version(); | 706 version = protocol_version(); |
| 708 uint16 length_field = 0; | 707 uint16 length_field = 0; |
| 709 bool successful_read = reader->ReadUInt16(&length_field); | 708 bool successful_read = reader->ReadUInt16(&length_field); |
| 710 DCHECK(successful_read); | 709 DCHECK(successful_read); |
| 711 | 710 |
| 712 uint8 control_frame_type_field_uint8 = DATA; | 711 uint8 control_frame_type_field_uint8 = |
| 712 SpdyConstants::DataFrameType(protocol_version()); | |
| 713 successful_read = reader->ReadUInt8(&control_frame_type_field_uint8); | 713 successful_read = reader->ReadUInt8(&control_frame_type_field_uint8); |
| 714 DCHECK(successful_read); | 714 DCHECK(successful_read); |
| 715 // We check control_frame_type_field's validity in | 715 // We check control_frame_type_field's validity in |
| 716 // ProcessControlFrameHeader(). | 716 // ProcessControlFrameHeader(). |
| 717 control_frame_type_field = control_frame_type_field_uint8; | 717 control_frame_type_field = control_frame_type_field_uint8; |
| 718 is_control_frame = (control_frame_type_field != DATA); | 718 is_control_frame = (protocol_version() > SPDY3) ? |
| 719 control_frame_type_field != | |
| 720 SpdyConstants::SerializeFrameType(protocol_version(), DATA) : | |
| 721 control_frame_type_field != 0; | |
|
Ryan Hamilton
2014/06/25 22:31:33
This is a bit complicated. Consider adding SpdyCon
Johnny
2014/06/26 15:57:24
Hmm. Think this needs a deeper re-factor. It's pro
| |
| 719 | 722 |
| 720 if (is_control_frame) { | 723 if (is_control_frame) { |
| 721 current_frame_length_ = length_field + GetControlFrameHeaderSize(); | 724 current_frame_length_ = length_field + GetControlFrameHeaderSize(); |
| 722 } else { | 725 } else { |
| 723 current_frame_length_ = length_field + GetDataFrameMinimumSize(); | 726 current_frame_length_ = length_field + GetDataFrameMinimumSize(); |
| 724 } | 727 } |
| 725 | 728 |
| 726 successful_read = reader->ReadUInt8(¤t_frame_flags_); | 729 successful_read = reader->ReadUInt8(¤t_frame_flags_); |
| 727 DCHECK(successful_read); | 730 DCHECK(successful_read); |
| 728 | 731 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 ProcessControlFrameHeader(control_frame_type_field); | 808 ProcessControlFrameHeader(control_frame_type_field); |
| 806 } | 809 } |
| 807 | 810 |
| 808 return original_len - len; | 811 return original_len - len; |
| 809 } | 812 } |
| 810 | 813 |
| 811 void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) { | 814 void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) { |
| 812 DCHECK_EQ(SPDY_NO_ERROR, error_code_); | 815 DCHECK_EQ(SPDY_NO_ERROR, error_code_); |
| 813 DCHECK_LE(GetControlFrameHeaderSize(), current_frame_buffer_length_); | 816 DCHECK_LE(GetControlFrameHeaderSize(), current_frame_buffer_length_); |
| 814 | 817 |
| 818 // TODO(mlavan): Either remove credential frames from the code entirely, | |
| 819 // or add them to parsing + serialization methods for SPDY3. | |
| 815 // Early detection of deprecated frames that we ignore. | 820 // Early detection of deprecated frames that we ignore. |
| 816 if (protocol_version() <= SPDY3) { | 821 if (protocol_version() <= SPDY3) { |
| 817 if (control_frame_type_field == NOOP) { | |
| 818 current_frame_type_ = NOOP; | |
| 819 DVLOG(1) << "NOOP control frame found. Ignoring."; | |
| 820 CHANGE_STATE(SPDY_AUTO_RESET); | |
| 821 return; | |
| 822 } | |
| 823 | 822 |
| 824 if (control_frame_type_field == CREDENTIAL) { | 823 if (control_frame_type_field == CREDENTIAL) { |
| 825 current_frame_type_ = CREDENTIAL; | 824 current_frame_type_ = CREDENTIAL; |
| 826 DCHECK_EQ(SPDY3, protocol_version()); | 825 DCHECK_EQ(SPDY3, protocol_version()); |
| 827 DVLOG(1) << "CREDENTIAL control frame found. Ignoring."; | 826 DVLOG(1) << "CREDENTIAL control frame found. Ignoring."; |
| 828 CHANGE_STATE(SPDY_IGNORE_REMAINING_PAYLOAD); | 827 CHANGE_STATE(SPDY_IGNORE_REMAINING_PAYLOAD); |
| 829 return; | 828 return; |
| 830 } | 829 } |
| 831 } | 830 } |
| 832 | 831 |
| (...skipping 2406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3239 builder->Seek(compressed_size); | 3238 builder->Seek(compressed_size); |
| 3240 builder->RewriteLength(*this); | 3239 builder->RewriteLength(*this); |
| 3241 | 3240 |
| 3242 pre_compress_bytes.Add(uncompressed_len); | 3241 pre_compress_bytes.Add(uncompressed_len); |
| 3243 post_compress_bytes.Add(compressed_size); | 3242 post_compress_bytes.Add(compressed_size); |
| 3244 | 3243 |
| 3245 compressed_frames.Increment(); | 3244 compressed_frames.Increment(); |
| 3246 } | 3245 } |
| 3247 | 3246 |
| 3248 } // namespace net | 3247 } // namespace net |
| OLD | NEW |