Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #include <string> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "net/base/completion_callback.h" | |
| 14 #include "net/base/io_buffer.h" | |
| 15 #include "net/base/net_errors.h" | |
| 16 #include "net/base/net_export.h" | |
| 17 #include "net/filter/source_stream.h" | |
| 18 | |
| 19 namespace net { | |
| 20 | |
| 21 class IOBuffer; | |
|
Randy Smith (Not in Mondays)
2016/08/22 22:37:16
Why do we need both this and the #include "net/bas
xunjieli
2016/08/29 16:25:28
Done.
| |
| 22 | |
| 23 // FilterSourceStream represents SourceStreams that always have an upstream | |
| 24 // from which undecoded input can be read. Except the ultimate upstream in | |
| 25 // the filter chain, all other streams should implement FilterSourceStream | |
| 26 // instead of SourceStream. | |
| 27 class NET_EXPORT_PRIVATE FilterSourceStream : public SourceStream { | |
| 28 public: | |
| 29 // |upstream| is the SourceStream from which |this| will read data. | |
| 30 // |upstream| cannot be null. | |
| 31 FilterSourceStream(SourceType type, std::unique_ptr<SourceStream> upstream); | |
| 32 | |
| 33 ~FilterSourceStream() override; | |
| 34 | |
| 35 int Read(IOBuffer* read_buffer, | |
| 36 int read_buffer_size, | |
| 37 const CompletionCallback& callback) override; | |
| 38 | |
| 39 std::string OrderedTypeStringList() const override; | |
| 40 | |
| 41 private: | |
| 42 enum State { | |
| 43 STATE_NONE, | |
| 44 // Reading data from |next|. | |
|
Randy Smith (Not in Mondays)
2016/08/22 22:37:16
nit, suggestion: From |upstream_| into |input_buff
Randy Smith (Not in Mondays)
2016/08/22 22:37:16
nit: Don't you mean |upstream_|?
xunjieli
2016/08/29 16:25:28
Done. Sorry about that. It's a leftover from the r
xunjieli
2016/08/29 16:25:28
Done.
| |
| 45 STATE_READ_DATA, | |
| 46 // Reading data from |next| completed. | |
| 47 STATE_READ_DATA_COMPLETE, | |
| 48 // Filtering data contained in |buffer_|. | |
|
Randy Smith (Not in Mondays)
2016/08/22 22:37:16
nit: |input_buffer_|?
xunjieli
2016/08/29 16:25:28
Done.
| |
| 49 STATE_FILTER_DATA, | |
| 50 // Filtering data contained in |buffer_| completed. | |
| 51 STATE_FILTER_DATA_COMPLETE, | |
| 52 STATE_DONE, | |
| 53 }; | |
| 54 | |
| 55 int DoLoop(int result); | |
| 56 int DoReadData(); | |
| 57 int DoReadDataComplete(int result); | |
| 58 int DoFilterData(); | |
| 59 | |
| 60 // Helper method used as a callback in |upstream_->Read()|. | |
|
Randy Smith (Not in Mondays)
2016/08/22 22:37:16
nit, suggestion: "... used as a callback *argument
xunjieli
2016/08/29 16:25:28
Done.
| |
| 61 void OnIOComplete(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). If an unrecoverable error occurred, this should return | |
| 67 // ERR_CONTENT_DECODING_FAILED or a more specific error code. | |
| 68 // | |
| 69 // FilterData() will be repeatedly invoked with the same |input_buffer| until | |
| 70 // FilterData() return 0, at which point, FilterSourceStream will read more | |
| 71 // input data from |upstream|. | |
|
Randy Smith (Not in Mondays)
2016/08/22 22:37:16
Confirming: This means that filters have no way to
xunjieli
2016/08/29 16:25:28
Yes, that is right. Filters must consume all data
mmenke
2016/08/29 16:41:03
If this is a problem, seems like there are a coupl
xunjieli
2016/08/30 17:27:21
Done. Thanks for the suggestions! I chose (1). PTA
| |
| 72 virtual int FilterData(IOBuffer* output_buffer, | |
| 73 int output_buffer_size, | |
| 74 DrainableIOBuffer* input_buffer) = 0; | |
| 75 | |
| 76 // Returns a string representation of the type of this FilterSourceStream. | |
| 77 // This is for UMA logging. | |
| 78 virtual std::string GetTypeAsString() const = 0; | |
| 79 | |
| 80 // The SourceStream from which |this| will read data from. Data flows from | |
| 81 // |upstream_| to |this_|. | |
| 82 std::unique_ptr<SourceStream> upstream_; | |
| 83 | |
| 84 State next_state_; | |
| 85 | |
| 86 // Buffer for reading data out of |upstream_| and then for use by |this| | |
| 87 // before the filtered data is returned through Read(). | |
| 88 scoped_refptr<IOBuffer> input_buffer_; | |
| 89 | |
| 90 // Keep this as a member because subclass might not drain everything in a | |
| 91 // single FilterData(). | |
|
Randy Smith (Not in Mondays)
2016/08/22 22:37:15
nit, suggestion: This comment describes why this i
xunjieli
2016/08/29 16:25:29
Done.
| |
| 92 scoped_refptr<DrainableIOBuffer> drainable_input_buffer_; | |
| 93 | |
| 94 // Not null if there is a pending Read. | |
| 95 scoped_refptr<IOBuffer> output_buffer_; | |
| 96 int output_buffer_size_; | |
| 97 CompletionCallback callback_; | |
| 98 | |
| 99 // Reading from |upstream_| has returned 0 byte or an error code. | |
| 100 bool upstream_end_reached_; | |
|
Randy Smith (Not in Mondays)
2016/08/22 22:37:16
nit, suggestion: |upstream_eof_reached_|?
xunjieli
2016/08/29 16:25:28
I changed from |eof_reached_| to |end_reached_| in
| |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(FilterSourceStream); | |
| 103 }; | |
| 104 | |
| 105 } // namespace net | |
| 106 | |
| 107 #endif // NET_FILTER_FILTER_SOURCE_STREAM_H_ | |
| OLD | NEW |