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 #include "base/memory/scoped_ptr.h" | |
| 6 #include "net/filter/gzip_header.h" | |
| 7 #include "net/filter/stream_source.h" | |
| 8 | |
| 9 typedef struct z_stream_s z_stream; | |
|
mmenke
2016/03/04 21:15:56
I don't think we want this in the global namespace
xunjieli
2016/04/20 19:16:09
I tried this suggestion, but the code failed to co
| |
| 10 | |
| 11 namespace net { | |
| 12 | |
| 13 class BlockBuffer; | |
| 14 | |
| 15 class GzipStreamSource : public StreamSource { | |
| 16 public: | |
| 17 enum GzipStreamSourceMode { | |
| 18 GZIP_STREAM_SOURCE_DEFLATE, | |
| 19 GZIP_STREAM_SOURCE_GZIP, | |
| 20 }; | |
| 21 | |
| 22 GzipStreamSource(scoped_ptr<StreamSource> previous); | |
|
mmenke
2016/03/04 21:15:56
explicit
xunjieli
2016/04/20 19:16:09
Done.
| |
| 23 ~GzipStreamSource() override; | |
| 24 | |
| 25 bool Init(GzipStreamSourceMode mode, bool gzip_fallback); | |
|
mmenke
2016/03/04 21:15:56
These arguments need to be documented.
xunjieli
2016/04/20 19:16:09
Done.
| |
| 26 | |
| 27 private: | |
| 28 enum GzipStreamState { | |
| 29 GZIP_STREAM_ERROR, | |
| 30 GZIP_STREAM_MORE_INPUT, | |
| 31 GZIP_STREAM_MORE_OUTPUT_SPACE, | |
| 32 }; | |
| 33 | |
| 34 // StreamSource implementation | |
| 35 Error ReadInternal(IOBuffer* dest_buffer, | |
| 36 size_t buffer_size, | |
| 37 size_t* bytes_read) override; | |
| 38 | |
| 39 GzipStreamState Decompress(IOBuffer* dest_buffer, | |
| 40 size_t buffer_size, | |
| 41 size_t* bytes_read); | |
| 42 | |
| 43 GzipStreamState Passthrough(IOBuffer* dest_buffer, | |
| 44 size_t buffer_size, | |
| 45 size_t* bytes_read); | |
| 46 | |
| 47 void OnReadComplete(const OnReadCompleteCallback& callback, | |
| 48 IOBuffer* dest_buffer, | |
| 49 size_t dest_buffer_size, | |
| 50 Error error, | |
| 51 size_t bytes_read); | |
| 52 | |
| 53 bool InsertZlibHeader(); | |
| 54 | |
| 55 // Returns whether an invalid GZip header has been observed. This method | |
| 56 // returns true as soon as an invalid GZip header is observed; it returns | |
| 57 // false if a complete, valid header has been observed, or not enough bytes | |
| 58 // have been seen to be sure. This method pulls its input from |buffer_|. | |
| 59 bool IsGzipHeaderInvalid(); | |
| 60 | |
| 61 // Returns whether this stream looks like it could be plain text (ie, not | |
| 62 // actually gzipped). Right now this uses an extremely simple heuristic; see | |
| 63 // the source for details. This method checks the input in |buffer_|, but does | |
| 64 // not drain from it. | |
| 65 bool ShouldFallbackToPlain(); | |
| 66 | |
| 67 // Skips gzip footer bytes if necessary. Might drain input from |buffer_| if | |
| 68 // there are still footer bytes to read. | |
| 69 void SkipGzipFooterIfNeeded(); | |
| 70 | |
| 71 scoped_refptr<IOBuffer> pending_read_buffer_; | |
| 72 | |
| 73 scoped_ptr<z_stream> zlib_stream_; | |
| 74 bool zlib_eof_; | |
| 75 bool zlib_header_added_; | |
| 76 | |
| 77 GZipHeader gzip_header_; | |
| 78 bool gzip_header_unchecked_; | |
| 79 bool gzip_fallback_unchecked_; | |
|
mmenke
2016/03/04 21:15:56
These need to be documented. Also, "unchecked" is
xunjieli
2016/04/20 19:16:09
Done.
| |
| 80 size_t gzip_footer_bytes_left_; | |
| 81 }; | |
| 82 | |
| 83 } // namespace net | |
| OLD | NEW |