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 #include "net/filter/filter_source_stream.h" | 5 #include "net/filter/filter_source_stream.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } | 119 } |
120 if (result <= OK) | 120 if (result <= OK) |
121 upstream_end_reached_ = true; | 121 upstream_end_reached_ = true; |
122 return result; | 122 return result; |
123 } | 123 } |
124 | 124 |
125 int FilterSourceStream::DoFilterData() { | 125 int FilterSourceStream::DoFilterData() { |
126 DCHECK(output_buffer_); | 126 DCHECK(output_buffer_); |
127 DCHECK(drainable_input_buffer_); | 127 DCHECK(drainable_input_buffer_); |
128 | 128 |
129 int bytes_output = | 129 int consumed_bytes = 0; |
130 FilterData(output_buffer_.get(), output_buffer_size_, | 130 int bytes_output = FilterData(output_buffer_.get(), output_buffer_size_, |
131 drainable_input_buffer_.get(), upstream_end_reached_); | 131 drainable_input_buffer_.get(), |
| 132 drainable_input_buffer_->BytesRemaining(), |
| 133 &consumed_bytes, upstream_end_reached_); |
| 134 DCHECK_LE(consumed_bytes, drainable_input_buffer_->BytesRemaining()); |
| 135 DCHECK(bytes_output != 0 || |
| 136 consumed_bytes == drainable_input_buffer_->BytesRemaining()); |
| 137 |
132 if (bytes_output == ERR_CONTENT_DECODING_FAILED) { | 138 if (bytes_output == ERR_CONTENT_DECODING_FAILED) { |
133 UMA_HISTOGRAM_ENUMERATION("Net.ContentDecodingFailed.FilterType", type(), | 139 UMA_HISTOGRAM_ENUMERATION("Net.ContentDecodingFailed.FilterType", type(), |
134 TYPE_MAX); | 140 TYPE_MAX); |
135 } | 141 } |
136 // FilterData() is not allowed to return ERR_IO_PENDING. | 142 // FilterData() is not allowed to return ERR_IO_PENDING. |
137 DCHECK_NE(ERR_IO_PENDING, bytes_output); | 143 DCHECK_NE(ERR_IO_PENDING, bytes_output); |
138 | 144 |
| 145 if (consumed_bytes > 0) |
| 146 drainable_input_buffer_->DidConsume(consumed_bytes); |
| 147 |
139 // Received data or encountered an error. | 148 // Received data or encountered an error. |
140 if (bytes_output != 0) | 149 if (bytes_output != 0) |
141 return bytes_output; | 150 return bytes_output; |
142 // If no data is returned, continue reading if |this| needs more input. | 151 // If no data is returned, continue reading if |this| needs more input. |
143 if (NeedMoreData()) { | 152 if (NeedMoreData()) { |
144 DCHECK_EQ(0, drainable_input_buffer_->BytesRemaining()); | 153 DCHECK_EQ(0, drainable_input_buffer_->BytesRemaining()); |
145 next_state_ = STATE_READ_DATA; | 154 next_state_ = STATE_READ_DATA; |
146 } | 155 } |
147 return bytes_output; | 156 return bytes_output; |
148 } | 157 } |
149 | 158 |
150 void FilterSourceStream::OnIOComplete(int result) { | 159 void FilterSourceStream::OnIOComplete(int result) { |
151 DCHECK_EQ(STATE_READ_DATA_COMPLETE, next_state_); | 160 DCHECK_EQ(STATE_READ_DATA_COMPLETE, next_state_); |
152 | 161 |
153 int rv = DoLoop(result); | 162 int rv = DoLoop(result); |
154 if (rv == ERR_IO_PENDING) | 163 if (rv == ERR_IO_PENDING) |
155 return; | 164 return; |
156 | 165 |
157 output_buffer_ = nullptr; | 166 output_buffer_ = nullptr; |
158 output_buffer_size_ = 0; | 167 output_buffer_size_ = 0; |
159 | 168 |
160 base::ResetAndReturn(&callback_).Run(rv); | 169 base::ResetAndReturn(&callback_).Run(rv); |
161 } | 170 } |
162 | 171 |
163 bool FilterSourceStream::NeedMoreData() const { | 172 bool FilterSourceStream::NeedMoreData() const { |
164 return !upstream_end_reached_; | 173 return !upstream_end_reached_; |
165 } | 174 } |
166 | 175 |
167 } // namespace net | 176 } // namespace net |
OLD | NEW |