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

Side by Side Diff: net/filter/filter_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: Address 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_STREAM_SOURCE_H_
6 #define NET_FILTER_FILTER_STREAM_SOURCE_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/stream_source.h"
16
17 namespace net {
18
19 class IOBuffer;
20
21 // FilterStreamSource represents StreamSources that always have a previous
22 // source from which undecoded input can be read. Except the first source in
23 // the filter chain, all other sources should implement FilterStreamSource
24 // instead of StreamSource.
25 class NET_EXPORT_PRIVATE FilterStreamSource : public StreamSource {
26 public:
27 // |previous| is the previous StreamSource in the chain. |previous| cannot be
28 // null.
29 FilterStreamSource(SourceType type, std::unique_ptr<StreamSource> previous);
30
31 ~FilterStreamSource() 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 |previous|.
43 STATE_READ_DATA,
44 // Reading data from |previous| 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 int DoFilterDataComplete(int result);
58
59 void DoCallback(int result);
60
61 void OnPreviousReadCompleted(int result);
62 // Subclasses should implement this method to filter data from
63 // |input_buffer_| and write to |output_buffer|.
64 // This method must complete synchronously (i.e. It cannot return
65 // ERR_IO_PENDING).
66 virtual int FilterData(IOBuffer* output_buffer,
67 size_t output_buffer_size,
68 DrainableIOBuffer* input_buffer) = 0;
69
70 // Returns a string representation of the type of this FilterStreamSource.
71 // This is for UMA logging.
72 virtual std::string GetTypeAsString() const = 0;
73
74 // Previous StreamSource in the chain.
75 std::unique_ptr<StreamSource> previous_;
76
77 State next_state_;
78
79 // Buffer for reading data out of |previous_| and then for use by |this|
80 // before the filtered data is returned through Read().
81 scoped_refptr<IOBuffer> input_buffer_;
82 // Keep this as a member because subclass might not drain everything in a
83 // single FilterData().
84 scoped_refptr<DrainableIOBuffer> drainable_input_buffer_;
85
86 // Not null if there is a pending Read.
87 scoped_refptr<IOBuffer> output_buffer_;
88 size_t output_buffer_size_;
89 CompletionCallback callback_;
90
91 // Reading from |previous_| has returned 0 byte or an error code.
92 bool previous_eof_reached_;
93
94 DISALLOW_COPY_AND_ASSIGN(FilterStreamSource);
95 };
96
97 } // namespace net
98
99 #endif // NET_FILTER_FILTER_STREAM_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698