| 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" | |
| 10 #include "base/third_party/valgrind/memcheck.h" | 9 #include "base/third_party/valgrind/memcheck.h" |
| 11 #include "net/spdy/spdy_frame_builder.h" | 10 #include "net/spdy/spdy_frame_builder.h" |
| 12 #include "net/spdy/spdy_frame_reader.h" | 11 #include "net/spdy/spdy_frame_reader.h" |
| 13 #include "net/spdy/spdy_bitmasks.h" | 12 #include "net/spdy/spdy_bitmasks.h" |
| 14 #include "third_party/zlib/zlib.h" | 13 #include "third_party/zlib/zlib.h" |
| 15 | 14 |
| 16 using base::StringPiece; | 15 using base::StringPiece; |
| 17 using std::string; | 16 using std::string; |
| 18 using std::vector; | 17 using std::vector; |
| 19 | 18 |
| (...skipping 3219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3239 SpdyFrameBuilder uncompressed_builder(uncompressed_len, protocol_version()); | 3238 SpdyFrameBuilder uncompressed_builder(uncompressed_len, protocol_version()); |
| 3240 SerializeNameValueBlockWithoutCompression(&uncompressed_builder, | 3239 SerializeNameValueBlockWithoutCompression(&uncompressed_builder, |
| 3241 frame.name_value_block()); | 3240 frame.name_value_block()); |
| 3242 scoped_ptr<SpdyFrame> uncompressed_payload(uncompressed_builder.take()); | 3241 scoped_ptr<SpdyFrame> uncompressed_payload(uncompressed_builder.take()); |
| 3243 | 3242 |
| 3244 z_stream* compressor = GetHeaderCompressor(); | 3243 z_stream* compressor = GetHeaderCompressor(); |
| 3245 if (!compressor) { | 3244 if (!compressor) { |
| 3246 LOG(DFATAL) << "Could not obtain compressor."; | 3245 LOG(DFATAL) << "Could not obtain compressor."; |
| 3247 return; | 3246 return; |
| 3248 } | 3247 } |
| 3249 | |
| 3250 base::StatsCounter compressed_frames("spdy.CompressedFrames"); | |
| 3251 base::StatsCounter pre_compress_bytes("spdy.PreCompressSize"); | |
| 3252 base::StatsCounter post_compress_bytes("spdy.PostCompressSize"); | |
| 3253 | |
| 3254 // Create an output frame. | 3248 // Create an output frame. |
| 3255 // Since we'll be performing lots of flushes when compressing the data, | 3249 // Since we'll be performing lots of flushes when compressing the data, |
| 3256 // zlib's lower bounds may be insufficient. | 3250 // zlib's lower bounds may be insufficient. |
| 3257 // | 3251 // |
| 3258 // TODO(akalin): Avoid the duplicate calculation with | 3252 // TODO(akalin): Avoid the duplicate calculation with |
| 3259 // GetSerializedLength(const SpdyHeaderBlock&). | 3253 // GetSerializedLength(const SpdyHeaderBlock&). |
| 3260 const int compressed_max_size = | 3254 const int compressed_max_size = |
| 3261 2 * deflateBound(compressor, uncompressed_len); | 3255 2 * deflateBound(compressor, uncompressed_len); |
| 3262 | 3256 |
| 3263 // TODO(phajdan.jr): Clean up after we no longer need | 3257 // TODO(phajdan.jr): Clean up after we no longer need |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3280 // TODO(akalin): Upstream this return. | 3274 // TODO(akalin): Upstream this return. |
| 3281 return; | 3275 return; |
| 3282 } | 3276 } |
| 3283 #else | 3277 #else |
| 3284 WriteHeaderBlockToZ(&frame.name_value_block(), compressor); | 3278 WriteHeaderBlockToZ(&frame.name_value_block(), compressor); |
| 3285 #endif // defined(USE_SYSTEM_ZLIB) | 3279 #endif // defined(USE_SYSTEM_ZLIB) |
| 3286 | 3280 |
| 3287 int compressed_size = compressed_max_size - compressor->avail_out; | 3281 int compressed_size = compressed_max_size - compressor->avail_out; |
| 3288 builder->Seek(compressed_size); | 3282 builder->Seek(compressed_size); |
| 3289 builder->RewriteLength(*this); | 3283 builder->RewriteLength(*this); |
| 3290 | |
| 3291 pre_compress_bytes.Add(uncompressed_len); | |
| 3292 post_compress_bytes.Add(compressed_size); | |
| 3293 | |
| 3294 compressed_frames.Increment(); | |
| 3295 } | 3284 } |
| 3296 | 3285 |
| 3297 } // namespace net | 3286 } // namespace net |
| OLD | NEW |