Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BLIMP_NET_COMPRESSED_PACKET_READER_H_ | |
| 6 #define BLIMP_NET_COMPRESSED_PACKET_READER_H_ | |
| 7 | |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "blimp/net/blimp_net_export.h" | |
| 10 #include "blimp/net/packet_reader.h" | |
| 11 #include "net/base/completion_callback.h" | |
| 12 #include "net/base/io_buffer.h" | |
| 13 #include "third_party/zlib/zlib.h" | |
| 14 | |
| 15 namespace blimp { | |
| 16 | |
| 17 // Filter object which wraps a PacketReader, adding a DEFLATE decompression step | |
| 18 // to received packets. | |
| 19 // Details about the encoding format are available in the CompressedPacketWriter | |
| 20 // header. | |
| 21 class BLIMP_NET_EXPORT CompressedPacketReader : public PacketReader { | |
| 22 public: | |
| 23 // |source|: The source which from which compressed packets are read. | |
| 24 explicit CompressedPacketReader(scoped_ptr<PacketReader> source); | |
| 25 | |
| 26 ~CompressedPacketReader() override; | |
| 27 | |
| 28 // PacketReader implementation. | |
| 29 void ReadPacket(const scoped_refptr<net::GrowableIOBuffer>& decompressed_buf, | |
| 30 const net::CompletionCallback& cb) override; | |
| 31 | |
| 32 private: | |
| 33 // Called when source->ReadPacket() has completed. | |
| 34 // |buf|: The buffer which will receive decompressed data. | |
| 35 // |cb|: Callback which is triggered after decompression has finished. | |
| 36 // |result|: The result of the read operation. | |
| 37 void ReadCompressedPacketDone( | |
|
Wez
2016/03/29 00:45:40
nit: OnCompressedPacketReceived or OnCompressedRea
Kevin M
2016/03/29 20:36:24
Done.
| |
| 38 const scoped_refptr<net::GrowableIOBuffer> decompressed_buf, | |
| 39 const net::CompletionCallback& cb, | |
| 40 int result); | |
| 41 | |
| 42 // Decompresses the contents of |compressed| to the buffer |decompressed|. | |
| 43 // |decompressed_size| is set to the size of the decompressed payload. | |
| 44 // On success, returns a >= 0 value indicating the size of the | |
| 45 // decompressed payload. | |
| 46 // On failure, returns a negative value indicating the error code | |
| 47 // (see net_errors.h). | |
| 48 int DecompressPacket( | |
| 49 char* compressed, | |
| 50 int compressed_size, | |
|
Wez
2016/03/29 00:45:40
nit: Could you just pass the IOBuffer into which t
Kevin M
2016/03/29 20:36:23
Done.
| |
| 51 const scoped_refptr<net::GrowableIOBuffer>& decompressed); | |
| 52 | |
| 53 scoped_ptr<PacketReader> source_; | |
| 54 scoped_refptr<net::GrowableIOBuffer> compressed_buf_; | |
| 55 z_stream zlib_stream_; | |
|
Wez
2016/03/29 00:45:40
nit: I'm not familiar with all the C++11 rules, bu
Kevin M
2016/03/29 20:36:24
{} seems to do the trick.
| |
| 56 base::WeakPtrFactory<CompressedPacketReader> weak_factory_; | |
|
Wez
2016/03/29 00:45:40
nit: Suggest a comment preceding |weak_factory_|,
Kevin M
2016/03/29 20:36:23
Done.
| |
| 57 | |
| 58 DISALLOW_COPY_AND_ASSIGN(CompressedPacketReader); | |
| 59 }; | |
| 60 | |
| 61 } // namespace blimp | |
| 62 | |
| 63 #endif // BLIMP_NET_COMPRESSED_PACKET_READER_H_ | |
| OLD | NEW |