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_STREAM_SOURCE_H | |
| 6 #define NET_FILTER_FILTER_STREAM_SOURCE_H | |
|
mmenke
2016/07/21 18:14:08
+_ (x3)
xunjieli
2016/07/27 20:32:01
Done.
| |
| 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 // Subclass override this method to perform any initialization that needs to | |
| 39 // be completed before Read() can be called. Returns whether initialization | |
| 40 // has succeeded. If failed, filter chain will not be used. | |
| 41 virtual bool Init(); | |
| 42 | |
| 43 private: | |
| 44 enum State { | |
| 45 STATE_NONE, | |
| 46 // Reading data from |previous|. | |
| 47 STATE_READ_DATA, | |
| 48 // Reading data from |previous| completed. | |
| 49 STATE_READ_DATA_COMPLETE, | |
| 50 // Filtering data contained in |buffer_|. | |
| 51 STATE_FILTER_DATA, | |
| 52 // Filtering data contained in |buffer_| completed. | |
| 53 STATE_FILTER_DATA_COMPLETE, | |
| 54 STATE_DONE, | |
| 55 }; | |
| 56 | |
| 57 int DoLoop(int result); | |
| 58 int DoReadData(); | |
| 59 int DoReadDataComplete(int result); | |
| 60 int DoFilterData(int result); | |
| 61 int DoFilterDataComplete(int result); | |
| 62 | |
| 63 void DoCallback(int result); | |
| 64 | |
| 65 void OnPreviousReadCompleted(int result); | |
| 66 // Subclasses should implement this method to filter data from | |
| 67 // |input_buffer_| and write to |output_buffer|. | |
| 68 // This method must complete synchronously (i.e. It cannot return | |
| 69 // ERR_IO_PENDING). | |
| 70 virtual int FilterData(IOBuffer* output_buffer, | |
| 71 size_t output_buffer_size, | |
| 72 DrainableIOBuffer* input_buffer) = 0; | |
| 73 | |
| 74 // Returns a string representation of the type of this FilterStreamSource. | |
| 75 // This is for UMA logging. | |
| 76 virtual std::string GetTypeAsString() const = 0; | |
| 77 | |
| 78 // Previous StreamSource in the chain. | |
| 79 std::unique_ptr<StreamSource> previous_; | |
| 80 | |
| 81 State next_state_; | |
| 82 | |
| 83 // Buffer for reading data out of |previous_| and then for use by |this| | |
| 84 // before the filtered data is returned through Read(). | |
| 85 scoped_refptr<IOBuffer> input_buffer_; | |
| 86 // Keep this as a member because subclass might not drain everything in a | |
| 87 // single FilterData(). | |
| 88 scoped_refptr<DrainableIOBuffer> drainable_input_buffer_; | |
| 89 | |
| 90 // Not null if there is a pending Read. | |
| 91 scoped_refptr<IOBuffer> output_buffer_; | |
| 92 size_t output_buffer_size_; | |
| 93 CompletionCallback callback_; | |
| 94 | |
| 95 // Reading from |previous_| has returned 0 byte or an error code. | |
| 96 bool previous_eof_reached_; | |
| 97 | |
| 98 DISALLOW_COPY_AND_ASSIGN(FilterStreamSource); | |
| 99 }; | |
| 100 | |
| 101 } // namespace net | |
| 102 | |
| 103 #endif // NET_FILTER_FILTER_STREAM_SOURCE_H | |
| OLD | NEW |