Chromium Code Reviews| Index: blimp/net/compressed_packet_writer.h |
| diff --git a/blimp/net/compressed_packet_writer.h b/blimp/net/compressed_packet_writer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..269bea79da715244243f570ea38e503edffb4c77 |
| --- /dev/null |
| +++ b/blimp/net/compressed_packet_writer.h |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BLIMP_NET_COMPRESSED_PACKET_WRITER_H_ |
| +#define BLIMP_NET_COMPRESSED_PACKET_WRITER_H_ |
| + |
| +#include "base/memory/weak_ptr.h" |
| +#include "blimp/net/blimp_net_export.h" |
| +#include "blimp/net/packet_writer.h" |
| +#include "net/base/completion_callback.h" |
| +#include "net/base/io_buffer.h" |
| +#include "third_party/zlib/zlib.h" |
| + |
| +namespace blimp { |
| + |
| +// Filter object which wraps a PacketWriter, adding a DEFLATE compression step |
| +// to outgoing packets. |
| +// |
| +// Each packet is appended as a DEFLATE block to a long-lived compression |
| +// stream. |
| +// Each block is prefixed with a 32-bit word representing the length of the |
| +// decompressed payload, used for sizing output buffers. |
|
Wez
2016/03/29 21:38:38
Looks like you got rid of that in the latest patch
Kevin M
2016/03/29 23:48:24
Done.
|
| +// Blocks are explicitly flushed at each packet boundary, which prevents zlib's |
| +// internal buffers from introducing unwanted output latency. |
| +// Gzip headers and CRC checks are omitted from the stream output. |
| +class BLIMP_NET_EXPORT CompressedPacketWriter : public PacketWriter { |
| + public: |
| + // |source|: The PacketWriter which will receive compressed packets. |
| + explicit CompressedPacketWriter(scoped_ptr<PacketWriter> sink); |
| + ~CompressedPacketWriter() override; |
| + |
| + // PacketWriter implementation. |
| + void WritePacket(const scoped_refptr<net::DrainableIOBuffer>& buf, |
| + const net::CompletionCallback& cb) override; |
| + |
| + private: |
| + // Compresses |src_buf| into |dest_buf|, and sets |compressed_size| with the |
|
Wez
2016/03/29 21:38:38
There is no |compressed_size| - you mean it return
Kevin M
2016/03/29 23:48:24
Done.
|
| + // length of the compressed packet (including decompressed length). |
|
Wez
2016/03/29 21:38:38
Not sure what "including decompressed length means
Kevin M
2016/03/29 23:48:24
I meant "decompressed length header." But that's N
|
| + // On success, returns a >= 0 value indicating the size of the |
| + // compressed payload. |
| + // On failure, returns a negative value indicating the error code |
| + // (see net_errors.h). |
| + int Compress(const scoped_refptr<net::DrainableIOBuffer>& src_buf, |
| + const scoped_refptr<net::GrowableIOBuffer>& dest_buf); |
| + |
| + z_stream zlib_stream_{}; |
| + scoped_ptr<PacketWriter> sink_; |
| + scoped_refptr<net::GrowableIOBuffer> compressed_buf_; |
| + size_t uncompressed_size_total_ = 0; |
|
Wez
2016/03/29 21:38:38
nit: Do these need to be unsigned literals?
Kevin M
2016/03/29 23:48:24
Done.
Kevin M
2016/03/29 23:48:24
Done.
|
| + size_t compressed_size_total_ = 0; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CompressedPacketWriter); |
| +}; |
| + |
| +} // namespace blimp |
| + |
| +#endif // BLIMP_NET_COMPRESSED_PACKET_WRITER_H_ |