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

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: Fix a typo 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 an upstream
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 int 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();
57
58 // Helper method used as a callback in |upstream_->Read()|.
59 void OnNextReadCompleted(int result);
60
61 // Subclasses should implement this method to filter data from
62 // |input_buffer| and write to |output_buffer|.
63 // This method must complete synchronously (i.e. It cannot return
64 // ERR_IO_PENDING).
mmenke 2016/08/18 16:18:42 Mention explicitly that it will continue to be cal
mmenke 2016/08/18 16:18:42 Also, should we explicitly say what the filter sho
xunjieli 2016/08/19 14:31:39 I am not sure if we can enforce that for this inte
xunjieli 2016/08/19 14:31:39 Done.
65 virtual int FilterData(IOBuffer* output_buffer,
66 size_t output_buffer_size,
67 DrainableIOBuffer* input_buffer) = 0;
68
69 // Returns a string representation of the type of this FilterSourceStream.
70 // This is for UMA logging.
71 virtual std::string GetTypeAsString() const = 0;
mmenke 2016/08/18 16:18:42 include <string>
xunjieli 2016/08/19 14:31:39 Done.
72
73 // The SourceStream from which |this| will read data from. Data flows from
74 // |upstream_| to |this_|.
75 std::unique_ptr<SourceStream> upstream_;
76
77 State next_state_;
78
79 // Buffer for reading data out of |upstream_| and then for use by |this|
80 // before the filtered data is returned through Read().
81 scoped_refptr<IOBuffer> input_buffer_;
mmenke 2016/08/18 16:18:42 include base/memory/ref_counted.h
xunjieli 2016/08/19 14:31:39 Done.
82
83 // Keep this as a member because subclass might not drain everything in a
84 // single FilterData().
85 scoped_refptr<DrainableIOBuffer> drainable_input_buffer_;
86
87 // Not null if there is a pending Read.
88 scoped_refptr<IOBuffer> output_buffer_;
89 size_t output_buffer_size_;
90 CompletionCallback callback_;
91
92 // Reading from |upstream_| has returned 0 byte or an error code.
93 bool upstream_end_reached_;
94
95 DISALLOW_COPY_AND_ASSIGN(FilterSourceStream);
96 };
97
98 } // namespace net
99
100 #endif // NET_FILTER_FILTER_SOURCE_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698