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_statistics.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 (blimp_connection_statistics_) { |
| 78 blimp_connection_statistics_->Add(BlimpConnectionStatistics::BYTES_SENT, |
| 79 compress_result); |
| 80 } |
| 81 |
76 #if !defined(NDEBUG) | 82 #if !defined(NDEBUG) |
77 uncompressed_size_total_ += uncompressed_size; | 83 uncompressed_size_total_ += uncompressed_size; |
78 compressed_size_total_ += compress_result; | 84 compressed_size_total_ += compress_result; |
79 #endif // !defined(NDEBUG) | 85 #endif // !defined(NDEBUG) |
80 | 86 |
81 scoped_refptr<net::DrainableIOBuffer> compressed_outbuf( | 87 scoped_refptr<net::DrainableIOBuffer> compressed_outbuf( |
82 new net::DrainableIOBuffer(compressed_buf_.get(), compress_result)); | 88 new net::DrainableIOBuffer(compressed_buf_.get(), compress_result)); |
83 sink_->WritePacket(compressed_outbuf, callback); | 89 sink_->WritePacket(compressed_outbuf, callback); |
84 DVLOG(4) << "deflate packet: " << uncompressed_size << " in, " | 90 DVLOG(4) << "deflate packet: " << uncompressed_size << " in, " |
85 << compress_result << " out."; | 91 << compress_result << " out."; |
(...skipping 28 matching lines...) Expand all Loading... |
114 if (zlib_stream_.avail_in > 0) { | 120 if (zlib_stream_.avail_in > 0) { |
115 DLOG(ERROR) << "deflate() did not consume all data, remainder: " | 121 DLOG(ERROR) << "deflate() did not consume all data, remainder: " |
116 << zlib_stream_.avail_in << " bytes."; | 122 << zlib_stream_.avail_in << " bytes."; |
117 return net::ERR_UNEXPECTED; | 123 return net::ERR_UNEXPECTED; |
118 } | 124 } |
119 | 125 |
120 return zlib_output_ubound - zlib_stream_.avail_out; | 126 return zlib_output_ubound - zlib_stream_.avail_out; |
121 } | 127 } |
122 | 128 |
123 } // namespace blimp | 129 } // namespace blimp |
OLD | NEW |