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 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't | 5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't |
6 // constantly adding and subtracting header sizes; this is ugly and error- | 6 // constantly adding and subtracting header sizes; this is ugly and error- |
7 // prone. | 7 // prone. |
8 | 8 |
9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
10 | 10 |
(...skipping 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 // Assume that the problem was the header block was too large for the | 1958 // Assume that the problem was the header block was too large for the |
1959 // visitor. | 1959 // visitor. |
1960 set_error(SPDY_CONTROL_PAYLOAD_TOO_LARGE); | 1960 set_error(SPDY_CONTROL_PAYLOAD_TOO_LARGE); |
1961 } | 1961 } |
1962 } | 1962 } |
1963 return read_successfully; | 1963 return read_successfully; |
1964 } | 1964 } |
1965 | 1965 |
1966 void SpdyFramer::SerializeNameValueBlockWithoutCompression( | 1966 void SpdyFramer::SerializeNameValueBlockWithoutCompression( |
1967 SpdyFrameBuilder* builder, | 1967 SpdyFrameBuilder* builder, |
1968 const SpdyFrameWithNameValueBlockIR& frame) const { | 1968 const SpdyNameValueBlock& name_value_block) const { |
1969 const SpdyNameValueBlock* name_value_block = &(frame.name_value_block()); | |
1970 | |
1971 // Serialize number of headers. | 1969 // Serialize number of headers. |
1972 if (protocol_version() < 3) { | 1970 if (protocol_version() < 3) { |
1973 builder->WriteUInt16(name_value_block->size()); | 1971 builder->WriteUInt16(name_value_block.size()); |
1974 } else { | 1972 } else { |
1975 builder->WriteUInt32(name_value_block->size()); | 1973 builder->WriteUInt32(name_value_block.size()); |
1976 } | 1974 } |
1977 | 1975 |
1978 // Serialize each header. | 1976 // Serialize each header. |
1979 for (SpdyHeaderBlock::const_iterator it = name_value_block->begin(); | 1977 for (SpdyHeaderBlock::const_iterator it = name_value_block.begin(); |
1980 it != name_value_block->end(); | 1978 it != name_value_block.end(); |
1981 ++it) { | 1979 ++it) { |
1982 if (protocol_version() < 3) { | 1980 if (protocol_version() < 3) { |
1983 builder->WriteString(it->first); | 1981 builder->WriteString(it->first); |
1984 builder->WriteString(it->second); | 1982 builder->WriteString(it->second); |
1985 } else { | 1983 } else { |
1986 builder->WriteStringPiece32(it->first); | 1984 builder->WriteStringPiece32(it->first); |
1987 builder->WriteStringPiece32(it->second); | 1985 builder->WriteStringPiece32(it->second); |
1988 } | 1986 } |
1989 } | 1987 } |
1990 } | 1988 } |
1991 | 1989 |
1992 void SpdyFramer::SerializeNameValueBlock( | 1990 void SpdyFramer::SerializeNameValueBlock( |
1993 SpdyFrameBuilder* builder, | 1991 SpdyFrameBuilder* builder, |
1994 const SpdyFrameWithNameValueBlockIR& frame) { | 1992 const SpdyFrameWithNameValueBlockIR& frame) { |
1995 if (!enable_compression_) { | 1993 if (!enable_compression_) { |
1996 return SerializeNameValueBlockWithoutCompression(builder, frame); | 1994 return SerializeNameValueBlockWithoutCompression(builder, |
| 1995 frame.name_value_block()); |
1997 } | 1996 } |
1998 | 1997 |
1999 // First build an uncompressed version to be fed into the compressor. | 1998 // First build an uncompressed version to be fed into the compressor. |
2000 const size_t uncompressed_len = GetSerializedLength( | 1999 const size_t uncompressed_len = GetSerializedLength( |
2001 protocol_version(), &(frame.name_value_block())); | 2000 protocol_version(), &(frame.name_value_block())); |
2002 SpdyFrameBuilder uncompressed_builder(uncompressed_len); | 2001 SpdyFrameBuilder uncompressed_builder(uncompressed_len); |
2003 SerializeNameValueBlockWithoutCompression(&uncompressed_builder, frame); | 2002 SerializeNameValueBlockWithoutCompression(&uncompressed_builder, |
| 2003 frame.name_value_block()); |
2004 scoped_ptr<SpdyFrame> uncompressed_payload(uncompressed_builder.take()); | 2004 scoped_ptr<SpdyFrame> uncompressed_payload(uncompressed_builder.take()); |
2005 | 2005 |
2006 z_stream* compressor = GetHeaderCompressor(); | 2006 z_stream* compressor = GetHeaderCompressor(); |
2007 if (!compressor) { | 2007 if (!compressor) { |
2008 LOG(DFATAL) << "Could not obtain compressor."; | 2008 LOG(DFATAL) << "Could not obtain compressor."; |
2009 return; | 2009 return; |
2010 } | 2010 } |
2011 | 2011 |
2012 base::StatsCounter compressed_frames("spdy.CompressedFrames"); | 2012 base::StatsCounter compressed_frames("spdy.CompressedFrames"); |
2013 base::StatsCounter pre_compress_bytes("spdy.PreCompressSize"); | 2013 base::StatsCounter pre_compress_bytes("spdy.PreCompressSize"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2054 post_compress_bytes.Add(compressed_size); | 2054 post_compress_bytes.Add(compressed_size); |
2055 | 2055 |
2056 compressed_frames.Increment(); | 2056 compressed_frames.Increment(); |
2057 | 2057 |
2058 if (debug_visitor_ != NULL) { | 2058 if (debug_visitor_ != NULL) { |
2059 debug_visitor_->OnCompressedHeaderBlock(uncompressed_len, compressed_size); | 2059 debug_visitor_->OnCompressedHeaderBlock(uncompressed_len, compressed_size); |
2060 } | 2060 } |
2061 } | 2061 } |
2062 | 2062 |
2063 } // namespace net | 2063 } // namespace net |
OLD | NEW |