Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: net/base/filter.h

Issue 6516025: Remove GetInputStreamBufferSize() method from FilterContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed signed/unsigned error Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/filter.cc » ('j') | net/base/filter.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 20 matching lines...) Expand all
31 #pragma once 31 #pragma once
32 32
33 #include <string> 33 #include <string>
34 #include <vector> 34 #include <vector>
35 35
36 #include "base/basictypes.h" 36 #include "base/basictypes.h"
37 #include "base/gtest_prod_util.h" 37 #include "base/gtest_prod_util.h"
38 #include "base/ref_counted.h" 38 #include "base/ref_counted.h"
39 #include "base/scoped_ptr.h" 39 #include "base/scoped_ptr.h"
40 #include "base/time.h" 40 #include "base/time.h"
41 #include "net/base/io_buffer.h"
41 42
42 class GURL; 43 class GURL;
43 44
44 namespace net {
45 class IOBuffer;
46 }
47
48 //------------------------------------------------------------------------------ 45 //------------------------------------------------------------------------------
49 // Define an interface class that allows access to contextual information 46 // Define an interface class that allows access to contextual information
50 // supplied by the owner of this filter. In the case where there are a chain of 47 // supplied by the owner of this filter. In the case where there are a chain of
51 // filters, there is only one owner of all the chained filters, and that context 48 // filters, there is only one owner of all the chained filters, and that context
52 // is passed to the constructor of all those filters. To be clear, the context 49 // is passed to the constructor of all those filters. To be clear, the context
53 // does NOT reflect the position in a chain, or the fact that there are prior 50 // does NOT reflect the position in a chain, or the fact that there are prior
54 // or later filters in a chain. 51 // or later filters in a chain.
55 class FilterContext { 52 class FilterContext {
56 public: 53 public:
57 // Enum to control what histograms are emitted near end-of-life of this 54 // Enum to control what histograms are emitted near end-of-life of this
(...skipping 29 matching lines...) Expand all
87 virtual bool IsSdchResponse() const = 0; 84 virtual bool IsSdchResponse() const = 0;
88 85
89 // How many bytes were read from the net or cache so far (and potentially 86 // How many bytes were read from the net or cache so far (and potentially
90 // pushed into a filter for processing)? 87 // pushed into a filter for processing)?
91 virtual int64 GetByteReadCount() const = 0; 88 virtual int64 GetByteReadCount() const = 0;
92 89
93 // What response code was received with the associated network transaction? 90 // What response code was received with the associated network transaction?
94 // For example: 200 is ok. 4xx are error codes. etc. 91 // For example: 200 is ok. 4xx are error codes. etc.
95 virtual int GetResponseCode() const = 0; 92 virtual int GetResponseCode() const = 0;
96 93
97 // What is the desirable input buffer size for these filters?
98 // This value is currently supplied by the context, and is constant for all
99 // filters, even when they are part of a chain of filters. (i.e., we currently
100 // don't change the input buffer sizes for a linked chain of filters, and the
101 // buffer size for input to all filters in a chain is this one constant).
102 virtual int GetInputStreamBufferSize() const = 0;
103
104 // The following method forces the context to emit a specific set of 94 // The following method forces the context to emit a specific set of
105 // statistics as selected by the argument. 95 // statistics as selected by the argument.
106 virtual void RecordPacketStats(StatisticSelector statistic) const = 0; 96 virtual void RecordPacketStats(StatisticSelector statistic) const = 0;
107 }; 97 };
108 98
109 //------------------------------------------------------------------------------ 99 //------------------------------------------------------------------------------
110 class Filter { 100 class Filter {
111 public: 101 public:
112 // Return values of function ReadFilteredData. 102 // Return values of function ReadFilteredData.
113 enum FilterStatus { 103 enum FilterStatus {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // start filtering. Then after this function is called, the caller can get 167 // start filtering. Then after this function is called, the caller can get
178 // post-filtered data using ReadFilteredData. The caller must not write to 168 // post-filtered data using ReadFilteredData. The caller must not write to
179 // stream_buffer_ and call this function again before stream_buffer_ is 169 // stream_buffer_ and call this function again before stream_buffer_ is
180 // emptied out by ReadFilteredData. 170 // emptied out by ReadFilteredData.
181 // 171 //
182 // The input stream_data_len is the length (in number of chars) of valid 172 // The input stream_data_len is the length (in number of chars) of valid
183 // data in stream_buffer_. It can not be greater than stream_buffer_size_. 173 // data in stream_buffer_. It can not be greater than stream_buffer_size_.
184 // The function returns true if success, and false otherwise. 174 // The function returns true if success, and false otherwise.
185 bool FlushStreamBuffer(int stream_data_len); 175 bool FlushStreamBuffer(int stream_data_len);
186 176
177 #if defined(UNIT_TEST)
178 // Resets the filter's internal buffer to the given size. Should only
179 // be called in unit tests, and only immediately after filter construction.
180 void ResetInputBufferForTest(int size) {
jar (doing other things) 2011/02/15 06:48:53 This strikes me as a bad or perilous interface for
jar (doing other things) 2011/02/25 18:37:24 I spoke with others on the Chrome team about this
adamk 2011/02/25 20:48:13 I'm happy to get rid of the UNIT_TEST nonsense and
jar (doing other things) 2011/02/26 01:36:52 Perhaps I chose the wrong words.... I was trying
181 stream_buffer_ = new net::IOBuffer(size);
182 stream_buffer_size_ = size;
183 }
184 #endif
185
187 // Translate the text of a filter name (from Content-Encoding header) into a 186 // Translate the text of a filter name (from Content-Encoding header) into a
188 // FilterType. 187 // FilterType.
189 static FilterType ConvertEncodingToType(const std::string& filter_type); 188 static FilterType ConvertEncodingToType(const std::string& filter_type);
190 189
191 // Given a array of encoding_types, try to do some error recovery adjustment 190 // Given a array of encoding_types, try to do some error recovery adjustment
192 // to the list. This includes handling known bugs in the Apache server (where 191 // to the list. This includes handling known bugs in the Apache server (where
193 // redundant gzip encoding is specified), as well as issues regarding SDCH 192 // redundant gzip encoding is specified), as well as issues regarding SDCH
194 // encoding, where various proxies and anti-virus products modify or strip the 193 // encoding, where various proxies and anti-virus products modify or strip the
195 // encodings. These fixups require context, which includes whether this 194 // encodings. These fixups require context, which includes whether this
196 // response was made to an SDCH request (i.e., an available dictionary was 195 // response was made to an SDCH request (i.e., an available dictionary was
(...skipping 20 matching lines...) Expand all
217 virtual FilterStatus ReadFilteredData(char* dest_buffer, int* dest_len); 216 virtual FilterStatus ReadFilteredData(char* dest_buffer, int* dest_len);
218 217
219 // Copy pre-filter data directly to destination buffer without decoding. 218 // Copy pre-filter data directly to destination buffer without decoding.
220 FilterStatus CopyOut(char* dest_buffer, int* dest_len); 219 FilterStatus CopyOut(char* dest_buffer, int* dest_len);
221 220
222 FilterStatus last_status() const { return last_status_; } 221 FilterStatus last_status() const { return last_status_; }
223 222
224 const FilterContext& filter_context() const { return filter_context_; } 223 const FilterContext& filter_context() const { return filter_context_; }
225 224
226 // Buffer to hold the data to be filtered (the input queue). 225 // Buffer to hold the data to be filtered (the input queue).
227 scoped_refptr<net::IOBuffer> stream_buffer_; 226 scoped_refptr<net::IOBuffer> stream_buffer_;
jar (doing other things) 2011/02/25 18:37:24 Please consider whether this can be changed to be
adamk 2011/02/25 20:48:13 Not sure what you mean by "actual stream buffer".
jar (doing other things) 2011/02/26 01:36:52 OK. I hadn't seen places where the ownership was
228 227
229 // Maximum size of stream_buffer_ in number of chars. 228 // Maximum size of stream_buffer_ in number of chars.
230 int stream_buffer_size_; 229 int stream_buffer_size_;
231 230
232 // Pointer to the next data in stream_buffer_ to be filtered. 231 // Pointer to the next data in stream_buffer_ to be filtered.
233 char* next_stream_data_; 232 char* next_stream_data_;
234 233
235 // Total number of remaining chars in stream_buffer_ to be filtered. 234 // Total number of remaining chars in stream_buffer_ to be filtered.
236 int stream_data_len_; 235 int stream_data_len_;
237 236
238 private: 237 private:
239 // A factory helper for creating filters for within a chain of potentially 238 // A factory helper for creating filters for within a chain of potentially
240 // multiple encodings. If a chain of filters is created, then this may be 239 // multiple encodings. If a chain of filters is created, then this may be
241 // called multiple times during the filter creation process. In most simple 240 // called multiple times during the filter creation process. In most simple
242 // cases, this is only called once. Returns NULL and cleans up (deleting 241 // cases, this is only called once. Returns NULL and cleans up (deleting
243 // filter_list) if a new filter can't be constructed. 242 // filter_list) if a new filter can't be constructed.
244 static Filter* PrependNewFilter(FilterType type_id, 243 static Filter* PrependNewFilter(FilterType type_id,
245 const FilterContext& filter_context, 244 const FilterContext& filter_context,
246 Filter* filter_list); 245 Filter* filter_list);
247 246
248 // Allocates and initializes stream_buffer_ based on filter_context_.
249 // Establishes a buffer large enough to handle the amount specified in
250 // filter_context_.GetInputStreamBufferSize().
251 bool InitBuffer();
252
253 // Helper function to empty our output into the next filter's input. 247 // Helper function to empty our output into the next filter's input.
254 void PushDataIntoNextFilter(); 248 void PushDataIntoNextFilter();
255 249
256 // An optional filter to process output from this filter. 250 // An optional filter to process output from this filter.
257 scoped_ptr<Filter> next_filter_; 251 scoped_ptr<Filter> next_filter_;
258 // Remember what status or local filter last returned so we can better handle 252 // Remember what status or local filter last returned so we can better handle
259 // chained filters. 253 // chained filters.
260 FilterStatus last_status_; 254 FilterStatus last_status_;
261 255
262 // Context data from the owner of this filter. Some filters need additional 256 // Context data from the owner of this filter. Some filters need additional
263 // context information (mime type, etc.) to properly function, and they access 257 // context information (mime type, etc.) to properly function, and they access
264 // this data via this reference member. 258 // this data via this reference member.
265 const FilterContext& filter_context_; 259 const FilterContext& filter_context_;
266 260
267 DISALLOW_COPY_AND_ASSIGN(Filter); 261 DISALLOW_COPY_AND_ASSIGN(Filter);
268 }; 262 };
269 263
270 #endif // NET_BASE_FILTER_H__ 264 #endif // NET_BASE_FILTER_H__
OLDNEW
« no previous file with comments | « no previous file | net/base/filter.cc » ('j') | net/base/filter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698