Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_FILTER_FILTER_SOURCE_STREAM_H_ | 5 #ifndef NET_FILTER_FILTER_SOURCE_STREAM_H_ |
| 6 #define NET_FILTER_FILTER_SOURCE_STREAM_H_ | 6 #define NET_FILTER_FILTER_SOURCE_STREAM_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
| 16 #include "net/filter/source_stream.h" | 16 #include "net/filter/source_stream.h" |
| 17 | 17 |
| 18 namespace base { | |
| 19 namespace trace_event { | |
| 20 class MemoryAllocatorDump; | |
| 21 } | |
| 22 } | |
| 23 | |
| 18 namespace net { | 24 namespace net { |
| 19 | 25 |
| 20 class DrainableIOBuffer; | 26 class DrainableIOBuffer; |
| 21 class IOBuffer; | 27 class IOBuffer; |
| 22 | 28 |
| 23 // FilterSourceStream represents SourceStreams that always have an upstream | 29 // FilterSourceStream represents SourceStreams that always have an upstream |
| 24 // from which undecoded input can be read. Except the ultimate upstream in | 30 // from which undecoded input can be read. Except the ultimate upstream in |
| 25 // the filter chain, all other streams should implement FilterSourceStream | 31 // the filter chain, all other streams should implement FilterSourceStream |
| 26 // instead of SourceStream. | 32 // instead of SourceStream. |
| 27 class NET_EXPORT_PRIVATE FilterSourceStream : public SourceStream { | 33 class NET_EXPORT_PRIVATE FilterSourceStream : public SourceStream { |
| 28 public: | 34 public: |
| 29 // |upstream| is the SourceStream from which |this| will read data. | 35 // |upstream| is the SourceStream from which |this| will read data. |
| 30 // |upstream| cannot be null. | 36 // |upstream| cannot be null. |
| 31 FilterSourceStream(SourceType type, std::unique_ptr<SourceStream> upstream); | 37 FilterSourceStream(SourceType type, std::unique_ptr<SourceStream> upstream); |
| 32 | 38 |
| 33 ~FilterSourceStream() override; | 39 ~FilterSourceStream() override; |
| 34 | 40 |
| 35 int Read(IOBuffer* read_buffer, | 41 int Read(IOBuffer* read_buffer, |
| 36 int read_buffer_size, | 42 int read_buffer_size, |
| 37 const CompletionCallback& callback) override; | 43 const CompletionCallback& callback) override; |
| 38 | 44 |
| 39 std::string Description() const override; | 45 std::string Description() const override; |
| 40 | 46 |
| 47 void DumpMemoryStats( | |
| 48 base::trace_event::MemoryAllocatorDump* dump) const override; | |
| 49 | |
| 41 private: | 50 private: |
| 42 enum State { | 51 enum State { |
| 43 STATE_NONE, | 52 STATE_NONE, |
| 44 // Reading data from |upstream_| into |input_buffer_|. | 53 // Reading data from |upstream_| into |input_buffer_|. |
| 45 STATE_READ_DATA, | 54 STATE_READ_DATA, |
| 46 // Reading data from |upstream_| completed. | 55 // Reading data from |upstream_| completed. |
| 47 STATE_READ_DATA_COMPLETE, | 56 STATE_READ_DATA_COMPLETE, |
| 48 // Filtering data contained in |input_buffer_|. | 57 // Filtering data contained in |input_buffer_|. |
| 49 STATE_FILTER_DATA, | 58 STATE_FILTER_DATA, |
| 50 // Filtering data contained in |input_buffer_| completed. | 59 // Filtering data contained in |input_buffer_| completed. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 71 // with |upstream_eof_reached| = true. | 80 // with |upstream_eof_reached| = true. |
| 72 // TODO(xunjieli): consider allowing asynchronous response via callback | 81 // TODO(xunjieli): consider allowing asynchronous response via callback |
| 73 // to support off-thread decompression. | 82 // to support off-thread decompression. |
| 74 virtual int FilterData(IOBuffer* output_buffer, | 83 virtual int FilterData(IOBuffer* output_buffer, |
| 75 int output_buffer_size, | 84 int output_buffer_size, |
| 76 IOBuffer* input_buffer, | 85 IOBuffer* input_buffer, |
| 77 int input_buffer_size, | 86 int input_buffer_size, |
| 78 int* consumed_bytes, | 87 int* consumed_bytes, |
| 79 bool upstream_eof_reached) = 0; | 88 bool upstream_eof_reached) = 0; |
| 80 | 89 |
| 90 // Subclasses can implement this method to dump memory allocation stats. | |
|
eroman
2016/12/01 21:04:37
Can you mention what the default implementation do
| |
| 91 // |dump| is the memory allocator dump of the URLRequestJob. | |
| 92 // Subclasses should override this method instead of DumpMemoryStats | |
| 93 // so the whole chain of FilterSourceStream can be accounted for. | |
| 94 virtual void DumpMemoryStatsImpl( | |
| 95 base::trace_event::MemoryAllocatorDump* dump) const; | |
| 96 | |
| 81 // Returns a string representation of the type of this FilterSourceStream. | 97 // Returns a string representation of the type of this FilterSourceStream. |
| 82 // This is for UMA logging. | 98 // This is for UMA logging. |
| 83 virtual std::string GetTypeAsString() const = 0; | 99 virtual std::string GetTypeAsString() const = 0; |
| 84 | 100 |
| 85 // Returns whether |this| still needs more input data from |upstream_|. | 101 // Returns whether |this| still needs more input data from |upstream_|. |
| 86 // By default, |this| will continue reading until |upstream_| returns an error | 102 // By default, |this| will continue reading until |upstream_| returns an error |
| 87 // or EOF. Subclass can override this to return false to skip reading all the | 103 // or EOF. Subclass can override this to return false to skip reading all the |
| 88 // input from |upstream_|. | 104 // input from |upstream_|. |
| 89 virtual bool NeedMoreData() const; | 105 virtual bool NeedMoreData() const; |
| 90 | 106 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 110 | 126 |
| 111 // Reading from |upstream_| has returned 0 byte or an error code. | 127 // Reading from |upstream_| has returned 0 byte or an error code. |
| 112 bool upstream_end_reached_; | 128 bool upstream_end_reached_; |
| 113 | 129 |
| 114 DISALLOW_COPY_AND_ASSIGN(FilterSourceStream); | 130 DISALLOW_COPY_AND_ASSIGN(FilterSourceStream); |
| 115 }; | 131 }; |
| 116 | 132 |
| 117 } // namespace net | 133 } // namespace net |
| 118 | 134 |
| 119 #endif // NET_FILTER_FILTER_SOURCE_STREAM_H_ | 135 #endif // NET_FILTER_FILTER_SOURCE_STREAM_H_ |
| OLD | NEW |