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

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

Issue 2251853002: Add net::SourceStream and net::FilterSourceStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Same as PS#18 of old CL but with upstream/downstream name change 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 upstream
mmenke 2016/08/17 19:01:56 a upstream -> an upstream SourceStream?
xunjieli 2016/08/17 20:00:19 Done.
22 // from which undecoded input can be read. Except the ultimate upstream in
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 // |upstream| is the SourceStream from which |this| will read data.
28 // |upstream| cannot be null.
29 FilterSourceStream(SourceType type, std::unique_ptr<SourceStream> upstream);
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 in |upstream_->Read()|.
61 void OnNextReadCompleted(int result);
62
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> upstream_;
mmenke 2016/08/17 19:01:56 lower in the stack / "upstream" is confusing (lowe
xunjieli 2016/08/17 20:00:19 Done. Sorry for the confusion. That is a outdated
78
79 State next_state_;
80
81 // Buffer for reading data out of |upstream_| and then for use by |this|
82 // before the filtered data is returned through Read().
83 scoped_refptr<IOBuffer> input_buffer_;
84
85 // Keep this as a member because subclass might not drain everything in a
86 // single FilterData().
87 scoped_refptr<DrainableIOBuffer> drainable_input_buffer_;
88
89 // Not null if there is a pending Read.
90 scoped_refptr<IOBuffer> output_buffer_;
91 size_t output_buffer_size_;
92 CompletionCallback callback_;
93
94 // Reading from |upstream_| has returned 0 byte or an error code.
95 bool upstream_end_reached_;
96
97 DISALLOW_COPY_AND_ASSIGN(FilterSourceStream);
98 };
99
100 } // namespace net
101
102 #endif // NET_FILTER_FILTER_SOURCE_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698