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

Side by Side Diff: net/filter/filter_source_stream.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: add filter_source_stream_unittest.cc and address other comments Created 4 years, 4 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_FILTER_SOURCE_STREAM_H_
6 #define NET_FILTER_FILTER_SOURCE_STREAM_H_
7
8 #include <memory>
9
10 #include "base/macros.h"
11 #include "net/base/completion_callback.h"
12 #include "net/base/io_buffer.h"
13 #include "net/base/net_errors.h"
14 #include "net/base/net_export.h"
15 #include "net/filter/source_stream.h"
16
17 namespace net {
18
19 class IOBuffer;
20
21 // FilterSourceStream represents SourceStreams that always have a next
22 // stream from which undecoded input can be read. Except the last stream in
Randy Smith (Not in Mondays) 2016/08/09 20:28:30 Suggestion: I'm struggling around the nomenclature
xunjieli 2016/08/15 15:19:07 Thanks for the suggestion. I have considered it, b
23 // the filter chain, all other streams should implement FilterSourceStream
24 // instead of SourceStream.
25 class NET_EXPORT_PRIVATE FilterSourceStream : public SourceStream {
26 public:
27 // |next| is the next SourceStream in the chain. |next| cannot be
28 // null.
29 FilterSourceStream(SourceType type, std::unique_ptr<SourceStream> next);
30
31 ~FilterSourceStream() override;
32
33 int Read(IOBuffer* read_buffer,
34 size_t read_buffer_size,
35 const CompletionCallback& callback) override;
36
37 std::string OrderedTypeStringList() const override;
38
39 private:
40 enum State {
41 STATE_NONE,
42 // Reading data from |next|.
43 STATE_READ_DATA,
44 // Reading data from |next| completed.
45 STATE_READ_DATA_COMPLETE,
46 // Filtering data contained in |buffer_|.
47 STATE_FILTER_DATA,
48 // Filtering data contained in |buffer_| completed.
49 STATE_FILTER_DATA_COMPLETE,
50 STATE_DONE,
51 };
52
53 int DoLoop(int result);
54 int DoReadData();
55 int DoReadDataComplete(int result);
56 int DoFilterData(int result);
57
58 void DoCallback(int result);
59
60 // Helper method used as a callback when |next_stream_| is to complete a read
Randy Smith (Not in Mondays) 2016/08/09 20:28:30 nit: Did you meant "... |next_stream_->Read()| is
xunjieli 2016/08/15 15:19:07 Done. I rephrased. Please let me know if it's clea
61 // asynchronously.
62 void OnNextReadCompleted(int result);
Randy Smith (Not in Mondays) 2016/08/09 20:28:30 nit, suggestion: I find these classes easier to re
xunjieli 2016/08/15 15:19:07 Done.
63 // Subclasses should implement this method to filter data from
64 // |input_buffer| and write to |output_buffer|.
65 // This method must complete synchronously (i.e. It cannot return
66 // ERR_IO_PENDING).
67 virtual int FilterData(IOBuffer* output_buffer,
68 size_t output_buffer_size,
69 DrainableIOBuffer* input_buffer) = 0;
70
71 // Returns a string representation of the type of this FilterSourceStream.
72 // This is for UMA logging.
73 virtual std::string GetTypeAsString() const = 0;
74
75 // Next SourceStream in the chain that is lower in the stack (closer to the
76 // HttpTransaction).
77 std::unique_ptr<SourceStream> next_stream_;
78
79 State next_state_;
80
81 // Buffer for reading data out of |next_stream_| and then for use by |this|
82 // before the filtered data is returned through Read().
83 scoped_refptr<IOBuffer> input_buffer_;
Randy Smith (Not in Mondays) 2016/08/09 20:28:30 nit, suggestion: Same as above--a line of vertical
xunjieli 2016/08/15 15:19:07 Done.
84 // Keep this as a member because subclass might not drain everything in a
85 // single FilterData().
86 scoped_refptr<DrainableIOBuffer> drainable_input_buffer_;
87
88 // Not null if there is a pending Read.
89 scoped_refptr<IOBuffer> output_buffer_;
90 size_t output_buffer_size_;
91 CompletionCallback callback_;
92
93 // Reading from |next_stream_| has returned 0 byte or an error code.
94 bool next_stream_end_reached_;
95
96 DISALLOW_COPY_AND_ASSIGN(FilterSourceStream);
97 };
98
99 } // namespace net
100
101 #endif // NET_FILTER_FILTER_SOURCE_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698