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

Side by Side Diff: net/filter/filter.cc

Issue 687263002: Improve documentation on Filter and fix pipeline overwrite. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« net/filter/filter.h ('K') | « net/filter/filter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // The basic usage of the Filter interface is described in the comment at
6 // the beginning of filter.h. Filters are designed so that they may be
7 // connected together into an arbitrary chain; in such a case the first filter
8 // in the chain proxies calls to ReadData() so that the input and output signals
9 // apply to the entire chain.
Bence 2014/10/29 20:00:24 Should the part of this paragraph about how to use
Randy Smith (Not in Mondays) 2014/10/30 18:35:42 I'm of two minds on this. The issue is whether th
10 //
11 // In a filter chain, the data flows from first filter (held by the
12 // caller) down the chain. When ReadData() is called on any filter
13 // except for the last filter, it proxies the call down the chain,
14 // filling in the input buffers of subsequent filters if needed (==
15 // that filter's last_status() value is FILTER_NEED_MORE_DATA) and
16 // available (== the current filter has data it can output). The last
17 // Filter will then output data if possible, and return
18 // FILTER_NEED_MORE_DATA if not. Because the indirection pushes
19 // data along the filter chain at each level if it's available and the
20 // next filter needs it, a return value of FILTER_NEED_MORE_DATA from the
21 // final filter will apply to the entire chain.
22
5 #include "net/filter/filter.h" 23 #include "net/filter/filter.h"
6 24
7 #include "base/files/file_path.h" 25 #include "base/files/file_path.h"
8 #include "base/strings/string_util.h" 26 #include "base/strings/string_util.h"
9 #include "net/base/filename_util_unsafe.h" 27 #include "net/base/filename_util_unsafe.h"
10 #include "net/base/io_buffer.h" 28 #include "net/base/io_buffer.h"
11 #include "net/base/mime_util.h" 29 #include "net/base/mime_util.h"
12 #include "net/filter/gzip_filter.h" 30 #include "net/filter/gzip_filter.h"
13 #include "net/filter/sdch_filter.h" 31 #include "net/filter/sdch_filter.h"
14 #include "net/url_request/url_request_context.h" 32 #include "net/url_request/url_request_context.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 98 }
81 return filter_list; 99 return filter_list;
82 } 100 }
83 101
84 Filter::FilterStatus Filter::ReadData(char* dest_buffer, int* dest_len) { 102 Filter::FilterStatus Filter::ReadData(char* dest_buffer, int* dest_len) {
85 const int dest_buffer_capacity = *dest_len; 103 const int dest_buffer_capacity = *dest_len;
86 if (last_status_ == FILTER_ERROR) 104 if (last_status_ == FILTER_ERROR)
87 return last_status_; 105 return last_status_;
88 if (!next_filter_.get()) 106 if (!next_filter_.get())
89 return last_status_ = ReadFilteredData(dest_buffer, dest_len); 107 return last_status_ = ReadFilteredData(dest_buffer, dest_len);
108
109 // This filter needs more data, but it's not clear that the rest of
110 // the chain does; delegate the actual status return to the next filter.
90 if (last_status_ == FILTER_NEED_MORE_DATA && !stream_data_len()) 111 if (last_status_ == FILTER_NEED_MORE_DATA && !stream_data_len())
91 return next_filter_->ReadData(dest_buffer, dest_len); 112 return next_filter_->ReadData(dest_buffer, dest_len);
92 113
93 do { 114 do {
94 if (next_filter_->last_status() == FILTER_NEED_MORE_DATA) { 115 if (next_filter_->last_status() == FILTER_NEED_MORE_DATA) {
95 PushDataIntoNextFilter(); 116 PushDataIntoNextFilter();
96 if (FILTER_ERROR == last_status_) 117 if (FILTER_ERROR == last_status_)
97 return FILTER_ERROR; 118 return FILTER_ERROR;
98 } 119 }
99 *dest_len = dest_buffer_capacity; // Reset the input/output parameter. 120 *dest_len = dest_buffer_capacity; // Reset the input/output parameter.
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 421
401 void Filter::PushDataIntoNextFilter() { 422 void Filter::PushDataIntoNextFilter() {
402 IOBuffer* next_buffer = next_filter_->stream_buffer(); 423 IOBuffer* next_buffer = next_filter_->stream_buffer();
403 int next_size = next_filter_->stream_buffer_size(); 424 int next_size = next_filter_->stream_buffer_size();
404 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); 425 last_status_ = ReadFilteredData(next_buffer->data(), &next_size);
405 if (FILTER_ERROR != last_status_) 426 if (FILTER_ERROR != last_status_)
406 next_filter_->FlushStreamBuffer(next_size); 427 next_filter_->FlushStreamBuffer(next_size);
407 } 428 }
408 429
409 } // namespace net 430 } // namespace net
OLDNEW
« net/filter/filter.h ('K') | « net/filter/filter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698