| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "blimp/net/compressed_packet_writer.h" | 5 #include "blimp/net/compressed_packet_writer.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| 11 #include "base/sys_byteorder.h" | 11 #include "base/sys_byteorder.h" |
| 12 #include "blimp/net/blimp_connection_details.h" |
| 12 #include "blimp/net/common.h" | 13 #include "blimp/net/common.h" |
| 13 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
| 14 #include "third_party/zlib/zlib.h" | 15 #include "third_party/zlib/zlib.h" |
| 15 | 16 |
| 16 namespace blimp { | 17 namespace blimp { |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // Allocate the maxmimum amount of memory to deflate (512KB) for higher | 20 // Allocate the maxmimum amount of memory to deflate (512KB) for higher |
| 20 // compression. (See zconf.h for details on memLevel semantics.) | 21 // compression. (See zconf.h for details on memLevel semantics.) |
| 21 const int kZlibMemoryLevel = 9; | 22 const int kZlibMemoryLevel = 9; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 callback.Run(net::ERR_FILE_TOO_BIG); | 67 callback.Run(net::ERR_FILE_TOO_BIG); |
| 67 return; | 68 return; |
| 68 } | 69 } |
| 69 | 70 |
| 70 int compress_result = Compress(write_buffer, compressed_buf_); | 71 int compress_result = Compress(write_buffer, compressed_buf_); |
| 71 if (compress_result < 0) { | 72 if (compress_result < 0) { |
| 72 callback.Run(compress_result); | 73 callback.Run(compress_result); |
| 73 return; | 74 return; |
| 74 } | 75 } |
| 75 | 76 |
| 77 if (connection_details_) { |
| 78 connection_details_->OnPacketSent(compress_result); |
| 79 } |
| 80 |
| 76 #if !defined(NDEBUG) | 81 #if !defined(NDEBUG) |
| 77 uncompressed_size_total_ += uncompressed_size; | 82 uncompressed_size_total_ += uncompressed_size; |
| 78 compressed_size_total_ += compress_result; | 83 compressed_size_total_ += compress_result; |
| 79 #endif // !defined(NDEBUG) | 84 #endif // !defined(NDEBUG) |
| 80 | 85 |
| 81 scoped_refptr<net::DrainableIOBuffer> compressed_outbuf( | 86 scoped_refptr<net::DrainableIOBuffer> compressed_outbuf( |
| 82 new net::DrainableIOBuffer(compressed_buf_.get(), compress_result)); | 87 new net::DrainableIOBuffer(compressed_buf_.get(), compress_result)); |
| 83 sink_->WritePacket(compressed_outbuf, callback); | 88 sink_->WritePacket(compressed_outbuf, callback); |
| 84 DVLOG(4) << "deflate packet: " << uncompressed_size << " in, " | 89 DVLOG(4) << "deflate packet: " << uncompressed_size << " in, " |
| 85 << compress_result << " out."; | 90 << compress_result << " out."; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 114 if (zlib_stream_.avail_in > 0) { | 119 if (zlib_stream_.avail_in > 0) { |
| 115 DLOG(ERROR) << "deflate() did not consume all data, remainder: " | 120 DLOG(ERROR) << "deflate() did not consume all data, remainder: " |
| 116 << zlib_stream_.avail_in << " bytes."; | 121 << zlib_stream_.avail_in << " bytes."; |
| 117 return net::ERR_UNEXPECTED; | 122 return net::ERR_UNEXPECTED; |
| 118 } | 123 } |
| 119 | 124 |
| 120 return zlib_output_ubound - zlib_stream_.avail_out; | 125 return zlib_output_ubound - zlib_stream_.avail_out; |
| 121 } | 126 } |
| 122 | 127 |
| 123 } // namespace blimp | 128 } // namespace blimp |
| OLD | NEW |