| Index: blimp/net/compressed_packet_reader.h
|
| diff --git a/blimp/net/compressed_packet_reader.h b/blimp/net/compressed_packet_reader.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8c684adde0065a972316598a35a050ed33eaf1c7
|
| --- /dev/null
|
| +++ b/blimp/net/compressed_packet_reader.h
|
| @@ -0,0 +1,61 @@
|
| +// 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_READER_H_
|
| +#define BLIMP_NET_COMPRESSED_PACKET_READER_H_
|
| +
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "blimp/net/blimp_net_export.h"
|
| +#include "blimp/net/packet_reader.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 PacketReader, adding a DEFLATE decompression step
|
| +// to received packets.
|
| +// Details about the encoding format are available in the CompressedPacketWriter
|
| +// header.
|
| +class BLIMP_NET_EXPORT CompressedPacketReader : public PacketReader {
|
| + public:
|
| + // |source|: The source which from which compressed packets are read.
|
| + explicit CompressedPacketReader(scoped_ptr<PacketReader> source);
|
| +
|
| + ~CompressedPacketReader() override;
|
| +
|
| + // PacketReader implementation.
|
| + void ReadPacket(const scoped_refptr<net::GrowableIOBuffer>& decompressed_buf,
|
| + const net::CompletionCallback& cb) override;
|
| +
|
| + private:
|
| + // Called when source->ReadPacket() has completed.
|
| + // |buf|: The buffer which will receive decompressed data.
|
| + // |cb|: Callback which is triggered after decompression has finished.
|
| + // |result|: The result of the read operation.
|
| + void ReadCompressedPacketDone(
|
| + const scoped_refptr<net::GrowableIOBuffer> decompressed_buf,
|
| + const net::CompletionCallback& cb,
|
| + int result);
|
| +
|
| + // Decompresses the contents of |compressed| to the buffer |decompressed|.
|
| + // |decompressed_size| is set to the size of the decompressed payload.
|
| + // Returns true if decompression completed successfully.
|
| + bool DecompressPacket(
|
| + char* compressed,
|
| + int compressed_size,
|
| + const scoped_refptr<net::GrowableIOBuffer>& decompressed,
|
| + size_t* decompressed_size);
|
| +
|
| + scoped_ptr<PacketReader> source_;
|
| + scoped_refptr<net::GrowableIOBuffer> compressed_buf_;
|
| + z_stream zlib_stream_;
|
| + base::WeakPtrFactory<CompressedPacketReader> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CompressedPacketReader);
|
| +};
|
| +
|
| +} // namespace blimp
|
| +
|
| +#endif // BLIMP_NET_COMPRESSED_PACKET_READER_H_
|
|
|