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(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 // The URLRequestContext associated with the request. | 122 // The URLRequestContext associated with the request. |
123 virtual const URLRequestContext* GetURLRequestContext() const = 0; | 123 virtual const URLRequestContext* GetURLRequestContext() const = 0; |
124 | 124 |
125 // The following method forces the context to emit a specific set of | 125 // The following method forces the context to emit a specific set of |
126 // statistics as selected by the argument. | 126 // statistics as selected by the argument. |
127 virtual void RecordPacketStats(StatisticSelector statistic) const = 0; | 127 virtual void RecordPacketStats(StatisticSelector statistic) const = 0; |
128 | 128 |
129 // The BoundNetLog of the associated request. | 129 // The BoundNetLog of the associated request. |
130 virtual const BoundNetLog& GetNetLog() const = 0; | 130 virtual const BoundNetLog& GetNetLog() const = 0; |
| 131 |
| 132 virtual bool IsBrotliEnabled() const = 0; |
131 }; | 133 }; |
132 | 134 |
133 //------------------------------------------------------------------------------ | 135 //------------------------------------------------------------------------------ |
134 class NET_EXPORT_PRIVATE Filter { | 136 class NET_EXPORT_PRIVATE Filter { |
135 public: | 137 public: |
136 // Return values of function ReadFilteredData. | 138 // Return values of function ReadFilteredData. |
137 enum FilterStatus { | 139 enum FilterStatus { |
138 // Read filtered data successfully | 140 // Read filtered data successfully |
139 FILTER_OK, | 141 FILTER_OK, |
140 // Read filtered data successfully, and the data in the buffer has been | 142 // Read filtered data successfully, and the data in the buffer has been |
141 // consumed by the filter, but more data is needed in order to continue | 143 // consumed by the filter, but more data is needed in order to continue |
142 // filtering. At this point, the caller is free to reuse the filter | 144 // filtering. At this point, the caller is free to reuse the filter |
143 // buffer to provide more data. | 145 // buffer to provide more data. |
144 FILTER_NEED_MORE_DATA, | 146 FILTER_NEED_MORE_DATA, |
145 // Read filtered data successfully, and filter reaches the end of the data | 147 // Read filtered data successfully, and filter reaches the end of the data |
146 // stream. | 148 // stream. |
147 FILTER_DONE, | 149 FILTER_DONE, |
148 // There is an error during filtering. | 150 // There is an error during filtering. |
149 FILTER_ERROR | 151 FILTER_ERROR |
150 }; | 152 }; |
151 | 153 |
152 // Specifies type of filters that can be created. | 154 // Specifies type of filters that can be created. |
153 enum FilterType { | 155 enum FilterType { |
| 156 FILTER_TYPE_BROTLI, |
154 FILTER_TYPE_DEFLATE, | 157 FILTER_TYPE_DEFLATE, |
155 FILTER_TYPE_GZIP, | 158 FILTER_TYPE_GZIP, |
156 FILTER_TYPE_GZIP_HELPING_SDCH, // Gzip possible, but pass through allowed. | 159 FILTER_TYPE_GZIP_HELPING_SDCH, // Gzip possible, but pass through allowed. |
157 FILTER_TYPE_SDCH, | 160 FILTER_TYPE_SDCH, |
158 FILTER_TYPE_SDCH_POSSIBLE, // Sdch possible, but pass through allowed. | 161 FILTER_TYPE_SDCH_POSSIBLE, // Sdch possible, but pass through allowed. |
159 FILTER_TYPE_UNSUPPORTED, | 162 FILTER_TYPE_UNSUPPORTED, |
160 }; | 163 }; |
161 | 164 |
162 virtual ~Filter(); | 165 virtual ~Filter(); |
163 | 166 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // encodings. These fixups require context, which includes whether this | 227 // encodings. These fixups require context, which includes whether this |
225 // response was made to an SDCH request (i.e., an available dictionary was | 228 // response was made to an SDCH request (i.e., an available dictionary was |
226 // advertised in the GET), as well as the mime type of the content. | 229 // advertised in the GET), as well as the mime type of the content. |
227 static void FixupEncodingTypes(const FilterContext& filter_context, | 230 static void FixupEncodingTypes(const FilterContext& filter_context, |
228 std::vector<FilterType>* encoding_types); | 231 std::vector<FilterType>* encoding_types); |
229 | 232 |
230 // Returns a string describing the FilterTypes implemented by this filter. | 233 // Returns a string describing the FilterTypes implemented by this filter. |
231 std::string OrderedFilterList() const; | 234 std::string OrderedFilterList() const; |
232 | 235 |
233 protected: | 236 protected: |
| 237 friend class BrotliUnitTest; |
234 friend class GZipUnitTest; | 238 friend class GZipUnitTest; |
235 friend class SdchFilterChainingTest; | 239 friend class SdchFilterChainingTest; |
236 FRIEND_TEST_ALL_PREFIXES(FilterTest, ThreeFilterChain); | 240 FRIEND_TEST_ALL_PREFIXES(FilterTest, ThreeFilterChain); |
237 | 241 |
238 explicit Filter(FilterType type_id); | 242 explicit Filter(FilterType type_id); |
239 | 243 |
240 // Filters the data stored in stream_buffer_ and writes the output into the | 244 // Filters the data stored in stream_buffer_ and writes the output into the |
241 // dest_buffer passed in. | 245 // dest_buffer passed in. |
242 // | 246 // |
243 // Upon entry, *dest_len is the total size (in number of chars) of the | 247 // Upon entry, *dest_len is the total size (in number of chars) of the |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // called multiple times during the filter creation process. In most simple | 280 // called multiple times during the filter creation process. In most simple |
277 // cases, this is only called once. Returns NULL and cleans up (deleting | 281 // cases, this is only called once. Returns NULL and cleans up (deleting |
278 // filter_list) if a new filter can't be constructed. | 282 // filter_list) if a new filter can't be constructed. |
279 static Filter* PrependNewFilter(FilterType type_id, | 283 static Filter* PrependNewFilter(FilterType type_id, |
280 const FilterContext& filter_context, | 284 const FilterContext& filter_context, |
281 int buffer_size, | 285 int buffer_size, |
282 Filter* filter_list); | 286 Filter* filter_list); |
283 | 287 |
284 // Helper methods for PrependNewFilter. If initialization is successful, | 288 // Helper methods for PrependNewFilter. If initialization is successful, |
285 // they return a fully initialized Filter. Otherwise, return NULL. | 289 // they return a fully initialized Filter. Otherwise, return NULL. |
| 290 static Filter* InitBrotliFilter(FilterType type_id, int buffer_size); |
286 static Filter* InitGZipFilter(FilterType type_id, int buffer_size); | 291 static Filter* InitGZipFilter(FilterType type_id, int buffer_size); |
287 static Filter* InitSdchFilter(FilterType type_id, | 292 static Filter* InitSdchFilter(FilterType type_id, |
288 const FilterContext& filter_context, | 293 const FilterContext& filter_context, |
289 int buffer_size); | 294 int buffer_size); |
290 | 295 |
291 // Helper function to empty our output into the next filter's input. | 296 // Helper function to empty our output into the next filter's input. |
292 void PushDataIntoNextFilter(); | 297 void PushDataIntoNextFilter(); |
293 | 298 |
294 // Constructs a filter with an internal buffer of the given size. | 299 // Constructs a filter with an internal buffer of the given size. |
295 // Only meant to be called by unit tests that need to control the buffer size. | 300 // Only meant to be called by unit tests that need to control the buffer size. |
(...skipping 10 matching lines...) Expand all Loading... |
306 | 311 |
307 // The filter type this filter was constructed from. | 312 // The filter type this filter was constructed from. |
308 FilterType type_id_; | 313 FilterType type_id_; |
309 | 314 |
310 DISALLOW_COPY_AND_ASSIGN(Filter); | 315 DISALLOW_COPY_AND_ASSIGN(Filter); |
311 }; | 316 }; |
312 | 317 |
313 } // namespace net | 318 } // namespace net |
314 | 319 |
315 #endif // NET_FILTER_FILTER_H__ | 320 #endif // NET_FILTER_FILTER_H__ |
OLD | NEW |