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

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: Created 4 years, 10 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 #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;
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);
23 ~GzipStreamSource() override;
24
25 bool Init(GzipStreamSourceMode mode, bool gzip_fallback);
26
27 // StreamSource implementation
28 net::Error Read(IOBuffer* dest_buffer,
29 size_t buffer_size,
30 size_t* bytes_read,
31 const OnReadCompleteCallback& callback) override;
32 size_t GetBytesOutput() const override;
33
34 private:
35 enum GzipStreamState {
36 GZIP_STREAM_ERROR,
37 GZIP_STREAM_MORE_INPUT,
38 GZIP_STREAM_MORE_OUTPUT_SPACE,
39 };
40
41 GzipStreamState Decompress(IOBuffer* dest_buffer,
42 size_t buffer_size,
43 size_t* bytes_read);
44
45 GzipStreamState Passthrough(IOBuffer* dest_buffer,
46 size_t buffer_size,
47 size_t* bytes_read);
48
49 void OnReadComplete(const OnReadCompleteCallback& callback,
50 IOBuffer* dest_buffer,
51 size_t dest_buffer_size,
52 Error error,
53 size_t bytes_read);
54
55 bool InsertZlibHeader();
56
57 // Returns whether an invalid GZip header has been observed. This method
58 // returns true as soon as an invalid GZip header is observed; it returns
59 // false if a complete, valid header has been observed, or not enough bytes
60 // have been seen to be sure. This method pulls its input from |buffer_|.
61 bool IsGzipHeaderInvalid();
62
63 // Returns whether this stream looks like it could be plain text (ie, not
64 // actually gzipped). Right now this uses an extremely simple heuristic; see
65 // the source for details. This method checks the input in |buffer_|, but does
66 // not drain from it.
67 bool ShouldFallbackToPlain();
68
69 // Skips gzip footer bytes if necessary. Might drain input from |buffer_| if
70 // there are still footer bytes to read.
71 void SkipGzipFooterIfNeeded();
72
73 scoped_refptr<IOBuffer> pending_read_buffer_;
74
75 scoped_ptr<BlockBuffer> buffer_;
76 scoped_ptr<StreamSource> previous_;
77 scoped_ptr<z_stream> zlib_stream_;
78 bool zlib_eof_;
79 bool zlib_header_added_;
80
81 GZipHeader gzip_header_;
82 bool gzip_header_unchecked_;
83 bool gzip_fallback_unchecked_;
84 size_t gzip_footer_bytes_left_;
85
86 size_t total_bytes_output_;
87 };
88
89 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698