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

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

Issue 2753453003: Reject unadvertised encodings (Closed)
Patch Set: Extracted code for UMA reporting Created 3 years, 9 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
OLDNEW
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return rv; 60 return rv;
61 } 61 }
62 62
63 std::string FilterSourceStream::Description() const { 63 std::string FilterSourceStream::Description() const {
64 std::string next_type_string = upstream_->Description(); 64 std::string next_type_string = upstream_->Description();
65 if (next_type_string.empty()) 65 if (next_type_string.empty())
66 return GetTypeAsString(); 66 return GetTypeAsString();
67 return next_type_string + "," + GetTypeAsString(); 67 return next_type_string + "," + GetTypeAsString();
68 } 68 }
69 69
70 void FilterSourceStream::ReportContentDecodingFailed(SourceType type) {
71 UMA_HISTOGRAM_ENUMERATION("Net.ContentDecodingFailed2.FilterType", type,
72 TYPE_MAX);
73 }
74
70 int FilterSourceStream::DoLoop(int result) { 75 int FilterSourceStream::DoLoop(int result) {
71 DCHECK_NE(STATE_NONE, next_state_); 76 DCHECK_NE(STATE_NONE, next_state_);
72 77
73 int rv = result; 78 int rv = result;
74 do { 79 do {
75 State state = next_state_; 80 State state = next_state_;
76 next_state_ = STATE_NONE; 81 next_state_ = STATE_NONE;
77 switch (state) { 82 switch (state) {
78 case STATE_READ_DATA: 83 case STATE_READ_DATA:
79 rv = DoReadData(); 84 rv = DoReadData();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 133
129 int consumed_bytes = 0; 134 int consumed_bytes = 0;
130 int bytes_output = FilterData(output_buffer_.get(), output_buffer_size_, 135 int bytes_output = FilterData(output_buffer_.get(), output_buffer_size_,
131 drainable_input_buffer_.get(), 136 drainable_input_buffer_.get(),
132 drainable_input_buffer_->BytesRemaining(), 137 drainable_input_buffer_->BytesRemaining(),
133 &consumed_bytes, upstream_end_reached_); 138 &consumed_bytes, upstream_end_reached_);
134 DCHECK_LE(consumed_bytes, drainable_input_buffer_->BytesRemaining()); 139 DCHECK_LE(consumed_bytes, drainable_input_buffer_->BytesRemaining());
135 DCHECK(bytes_output != 0 || 140 DCHECK(bytes_output != 0 ||
136 consumed_bytes == drainable_input_buffer_->BytesRemaining()); 141 consumed_bytes == drainable_input_buffer_->BytesRemaining());
137 142
138 if (bytes_output == ERR_CONTENT_DECODING_FAILED) { 143 if (bytes_output == ERR_CONTENT_DECODING_FAILED)
139 UMA_HISTOGRAM_ENUMERATION("Net.ContentDecodingFailed2.FilterType", type(), 144 ReportContentDecodingFailed(type());
140 TYPE_MAX);
141 }
142 // FilterData() is not allowed to return ERR_IO_PENDING. 145 // FilterData() is not allowed to return ERR_IO_PENDING.
143 DCHECK_NE(ERR_IO_PENDING, bytes_output); 146 DCHECK_NE(ERR_IO_PENDING, bytes_output);
144 147
145 if (consumed_bytes > 0) 148 if (consumed_bytes > 0)
146 drainable_input_buffer_->DidConsume(consumed_bytes); 149 drainable_input_buffer_->DidConsume(consumed_bytes);
147 150
148 // Received data or encountered an error. 151 // Received data or encountered an error.
149 if (bytes_output != 0) 152 if (bytes_output != 0)
150 return bytes_output; 153 return bytes_output;
151 // If no data is returned, continue reading if |this| needs more input. 154 // If no data is returned, continue reading if |this| needs more input.
(...skipping 15 matching lines...) Expand all
167 output_buffer_size_ = 0; 170 output_buffer_size_ = 0;
168 171
169 base::ResetAndReturn(&callback_).Run(rv); 172 base::ResetAndReturn(&callback_).Run(rv);
170 } 173 }
171 174
172 bool FilterSourceStream::NeedMoreData() const { 175 bool FilterSourceStream::NeedMoreData() const {
173 return !upstream_end_reached_; 176 return !upstream_end_reached_;
174 } 177 }
175 178
176 } // namespace net 179 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698