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 | |
| 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 | |
| 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_| is to complete a read | |
| 61 // asynchronously. | |
| 62 void OnNextReadCompleted(int result); | |
| 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_; | |
| 78 | |
| 79 State next_state_; | |
| 80 | |
| 81 // Buffer for reading data out of |next_| and then for use by |this| | |
| 82 // before the filtered data is returned through Read(). | |
| 83 scoped_refptr<IOBuffer> input_buffer_; | |
| 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_| has returned 0 byte or an error code. | |
| 94 bool next_end_reached_; | |
|
mmenke
2016/08/01 21:55:30
next_stream_end_reached_? (Since we also have nex
xunjieli
2016/08/02 13:44:32
Done.
| |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(FilterSourceStream); | |
| 97 }; | |
| 98 | |
| 99 } // namespace net | |
| 100 | |
| 101 #endif // NET_FILTER_FILTER_SOURCE_STREAM_H_ | |
| OLD | NEW |