Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: net/filter/gzip_stream_source.h

Issue 1662763002: [ON HOLD] Implement pull-based design for content decoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile on mac Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 NET_FILTER_GZIP_STREAM_SOURCE_H_
6 #define NET_FILTER_GZIP_STREAM_SOURCE_H_
7
8 #include <memory>
9
10 #include "net/base/net_export.h"
11 #include "net/filter/filter_stream_source.h"
12 #include "net/filter/gzip_header.h"
13
14 typedef struct z_stream_s z_stream;
15
16 namespace net {
17
18 class BlockBuffer;
19
20 class NET_EXPORT_PRIVATE GzipStreamSource : public FilterStreamSource {
21 public:
22 enum GzipStreamSourceMode {
23 GZIP_STREAM_SOURCE_DEFLATE,
24 GZIP_STREAM_SOURCE_GZIP,
25 // Same as GZIP_STREAM_SOURCE_GZIP, but allow fallback to plain text.
26 GZIP_STREAM_SOURCE_GZIP_WITH_FALLBACK,
27 };
28
29 explicit GzipStreamSource(std::unique_ptr<StreamSource> previous,
30 GzipStreamSourceMode mode);
mmenke 2016/07/21 18:14:08 nit: explicit not needed.
xunjieli 2016/07/27 20:32:02 Done.
31 ~GzipStreamSource() override;
32
33 bool Init() override;
mmenke 2016/07/21 18:14:08 FilterStreamSource implementation.
mmenke 2016/07/21 18:14:08 Randy (And you) may disagree, but I think requirin
xunjieli 2016/07/27 20:32:01 Done. Thanks for the excellent suggestion! I could
xunjieli 2016/07/27 20:32:02 Done.
34
35 private:
36 // StreamSource implementation
mmenke 2016/07/21 18:14:08 FilterStreamSource, actually.
xunjieli 2016/07/27 20:32:02 Done.
37 std::string GetTypeAsString() const override;
38 int FilterData(IOBuffer* output_buffer,
39 size_t output_buffer_size,
40 DrainableIOBuffer* input_buffer) override;
41
42 // Synchronous decompressor. This function consumes bytes from |input_buffer|
43 // and decompresses them into |output_buffer| until it consumes all of
44 // |input_buffer|. This decompressor will decompress a zlib stream (either
45 // gzip or deflate) until the zlib reaches EOF, then will pass any further
46 // input through untouched.
47 int Decompress(IOBuffer* output_buffer,
48 size_t output_buffer_size,
49 DrainableIOBuffer* input_buffer);
50
51 // Returns how many bytes are drained from |input_buffer|.
52 size_t Passthrough(char* output_buffer,
53 size_t output_buffer_size,
54 DrainableIOBuffer* input_buffer);
55
56 // Inserts a zlib header to the data stream before calling zlib inflate.
57 // This is used to work around server bugs.
58 // The function returns true on success and false otherwise.
59 bool InsertZlibHeader();
60
61 // Returns whether an invalid GZip header has been observed. This method
62 // returns true as soon as an invalid GZip header is observed; it returns
63 // false if a complete, valid header has been observed, or not enough bytes
64 // have been seen to be sure. This method pulls its input from |buffer_|.
65 bool IsGzipHeaderInvalid(DrainableIOBuffer* input_buffer);
66
67 // Returns whether this stream looks like it could be plain text (ie, not
68 // actually gzipped). Right now this uses an extremely simple heuristic; see
69 // the source for details. This method checks the input in |buffer_|, but does
70 // not drain from it.
71 bool ShouldFallbackToPlain(DrainableIOBuffer* input_buffer);
72
73 // Skips gzip footer bytes if necessary. Might drain input from |buffer_| if
74 // there are still footer bytes to read.
75 void SkipGzipFooterIfNeeded(DrainableIOBuffer* input_buffer);
76
77 scoped_refptr<IOBuffer> pending_read_buffer_;
mmenke 2016/07/21 18:14:08 include base/memory/ref_counted.h, net/base/io_buf
xunjieli 2016/07/27 20:32:02 Done.
78
79 // Indicates the type of content decoding the stream source is performing.
80 // This variable is set only once by Init.
81 GzipStreamSourceMode mode_;
82 // The control block of zlib which actually does the decoding.
83 // This data structure is initialized by Init and updated only by
84 // Decompress, with InsertZlibHeader being the exception as a workaround.
85 std::unique_ptr<z_stream> zlib_stream_;
86 // Whether end of stream has been reached.
87 bool zlib_eof_;
88 // A flag used by Decompress to record whether we've successfully added
89 // a zlib header to this stream.
90 bool zlib_header_added_;
91 // Used to parse the gzip header in gzip stream.
92 // It is used when the decoding mode is GZIP_STREAM_SOURCE_GZIP.
93 GZipHeader gzip_header_;
94 // Whether gzip header should be checked for validity.
95 bool should_check_gzip_header_;
96 // Tracks how many bytes of gzip footer are yet to be filtered.
97 size_t gzip_footer_bytes_left_;
mmenke 2016/07/21 18:14:08 DISALLOW_COPY_AND_ASSIGN / include macros.h
xunjieli 2016/07/27 20:32:02 Done.
98 };
99
100 } // namespace net
101
102 #endif // NET_FILTER_GZIP_STREAM_SOURCE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698