OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Filter performs filtering on data streams. Sample usage: | 5 // Filter performs filtering on data streams. Sample usage: |
6 // | 6 // |
7 // IStream* pre_filter_source; | 7 // IStream* pre_filter_source; |
8 // ... | 8 // ... |
9 // Filter* filter = Filter::Factory(filter_type, size); | 9 // Filter* filter = Filter::Factory(filter_type, size); |
10 // int pre_filter_data_len = filter->stream_buffer_size(); | 10 // int pre_filter_data_len = filter->stream_buffer_size(); |
11 // pre_filter_source->read(filter->stream_buffer(), pre_filter_data_len); | 11 // pre_filter_source->read(filter->stream_buffer(), pre_filter_data_len); |
12 // | 12 // |
13 // filter->FlushStreamBuffer(pre_filter_data_len); | 13 // filter->FlushStreamBuffer(pre_filter_data_len); |
14 // | 14 // |
15 // char post_filter_buf[kBufferSize]; | 15 // char post_filter_buf[kBufferSize]; |
16 // int post_filter_data_len = kBufferSize; | 16 // int post_filter_data_len = kBufferSize; |
17 // filter->ReadFilteredData(post_filter_buf, &post_filter_data_len); | 17 // filter->ReadFilteredData(post_filter_buf, &post_filter_data_len); |
18 // | 18 // |
19 // To filter a data stream, the caller first gets filter's stream_buffer_ | 19 // To filter a data stream, the caller first gets filter's stream_buffer_ |
20 // through its accessor and fills in stream_buffer_ with pre-filter data, next | 20 // through its accessor and fills in stream_buffer_ with pre-filter data, next |
21 // calls FlushStreamBuffer to notify Filter, then calls ReadFilteredData | 21 // calls FlushStreamBuffer to notify Filter, then calls ReadFilteredData |
22 // repeatedly to get all the filtered data. After all data have been fitlered | 22 // repeatedly to get all the filtered data. After all data have been filtered |
23 // and read out, the caller may fill in stream_buffer_ again. This | 23 // and read out, the caller may fill in stream_buffer_ again. This |
24 // WriteBuffer-Flush-Read cycle is repeated until reaching the end of data | 24 // WriteBuffer-Flush-Read cycle is repeated until reaching the end of data |
25 // stream. | 25 // stream. |
26 // | 26 // |
| 27 // A return of FILTER_OK from ReadData() means that more data is |
| 28 // available to a future ReadData() call and data may not be written |
| 29 // into stream_buffer(). A return of FILTER_NEED_MORE_DATA from ReadData() |
| 30 // indicates that no data will be forthcoming from the filter until |
| 31 // it receives more input data, and that the buffer at |
| 32 // stream_buffer() may be written to. |
| 33 // |
| 34 // The filter being complete (no more data to provide) may be indicated |
| 35 // by either returning FILTER_DONE or by returning FILTER_OK and indicating |
| 36 // zero bytes output; consumers understand both those signals. Consumers |
| 37 // are responsible for not calling ReadData() on a filter after one of these |
| 38 // signals have been returned. Note that some filters may never signal that |
| 39 // they are done (e.g. a pass-through filter will always |
| 40 // say FILTER_NEED_MORE_DATA), so the consumer will also need to |
| 41 // recognize the state of |no_more_input_data_available && |
| 42 // filter->stream_data_len() == 0| as FILTER_DONE. |
| 43 // |
27 // The lifetime of a Filter instance is completely controlled by its caller. | 44 // The lifetime of a Filter instance is completely controlled by its caller. |
28 | 45 |
29 #ifndef NET_FILTER_FILTER_H__ | 46 #ifndef NET_FILTER_FILTER_H__ |
30 #define NET_FILTER_FILTER_H__ | 47 #define NET_FILTER_FILTER_H__ |
31 | 48 |
32 #include <string> | 49 #include <string> |
33 #include <vector> | 50 #include <vector> |
34 | 51 |
35 #include "base/basictypes.h" | 52 #include "base/basictypes.h" |
36 #include "base/gtest_prod_util.h" | 53 #include "base/gtest_prod_util.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // encoding, where various proxies and anti-virus products modify or strip the | 217 // encoding, where various proxies and anti-virus products modify or strip the |
201 // encodings. These fixups require context, which includes whether this | 218 // encodings. These fixups require context, which includes whether this |
202 // response was made to an SDCH request (i.e., an available dictionary was | 219 // response was made to an SDCH request (i.e., an available dictionary was |
203 // advertised in the GET), as well as the mime type of the content. | 220 // advertised in the GET), as well as the mime type of the content. |
204 static void FixupEncodingTypes(const FilterContext& filter_context, | 221 static void FixupEncodingTypes(const FilterContext& filter_context, |
205 std::vector<FilterType>* encoding_types); | 222 std::vector<FilterType>* encoding_types); |
206 | 223 |
207 protected: | 224 protected: |
208 friend class GZipUnitTest; | 225 friend class GZipUnitTest; |
209 friend class SdchFilterChainingTest; | 226 friend class SdchFilterChainingTest; |
| 227 FRIEND_TEST_ALL_PREFIXES(FilterTest, ThreeFilterChain); |
210 | 228 |
211 Filter(); | 229 Filter(); |
212 | 230 |
213 // Filters the data stored in stream_buffer_ and writes the output into the | 231 // Filters the data stored in stream_buffer_ and writes the output into the |
214 // dest_buffer passed in. | 232 // dest_buffer passed in. |
215 // | 233 // |
216 // Upon entry, *dest_len is the total size (in number of chars) of the | 234 // Upon entry, *dest_len is the total size (in number of chars) of the |
217 // destination buffer. Upon exit, *dest_len is the actual number of chars | 235 // destination buffer. Upon exit, *dest_len is the actual number of chars |
218 // written into the destination buffer. | 236 // written into the destination buffer. |
219 // | 237 // |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // Remember what status or local filter last returned so we can better handle | 293 // Remember what status or local filter last returned so we can better handle |
276 // chained filters. | 294 // chained filters. |
277 FilterStatus last_status_; | 295 FilterStatus last_status_; |
278 | 296 |
279 DISALLOW_COPY_AND_ASSIGN(Filter); | 297 DISALLOW_COPY_AND_ASSIGN(Filter); |
280 }; | 298 }; |
281 | 299 |
282 } // namespace net | 300 } // namespace net |
283 | 301 |
284 #endif // NET_FILTER_FILTER_H__ | 302 #endif // NET_FILTER_FILTER_H__ |
OLD | NEW |