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

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

Issue 2753453003: Reject unadvertised encodings (Closed)
Patch Set: Fix histo value comments Created 3 years, 8 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
« no previous file with comments | « net/filter/filter_source_stream.h ('k') | net/filter/source_stream_type_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 15
16 namespace net { 16 namespace net {
17 17
18 namespace { 18 namespace {
19 19
20 const char kDeflate[] = "deflate";
21 const char kGZip[] = "gzip";
22 const char kSdch[] = "sdch";
23 const char kXGZip[] = "x-gzip";
24 const char kBrotli[] = "br";
25
20 const size_t kBufferSize = 32 * 1024; 26 const size_t kBufferSize = 32 * 1024;
21 27
22 } // namespace 28 } // namespace
23 29
24 FilterSourceStream::FilterSourceStream(SourceType type, 30 FilterSourceStream::FilterSourceStream(SourceType type,
25 std::unique_ptr<SourceStream> upstream) 31 std::unique_ptr<SourceStream> upstream)
26 : SourceStream(type), 32 : SourceStream(type),
27 upstream_(std::move(upstream)), 33 upstream_(std::move(upstream)),
28 next_state_(STATE_NONE), 34 next_state_(STATE_NONE),
29 output_buffer_size_(0), 35 output_buffer_size_(0),
(...skipping 30 matching lines...) Expand all
60 return rv; 66 return rv;
61 } 67 }
62 68
63 std::string FilterSourceStream::Description() const { 69 std::string FilterSourceStream::Description() const {
64 std::string next_type_string = upstream_->Description(); 70 std::string next_type_string = upstream_->Description();
65 if (next_type_string.empty()) 71 if (next_type_string.empty())
66 return GetTypeAsString(); 72 return GetTypeAsString();
67 return next_type_string + "," + GetTypeAsString(); 73 return next_type_string + "," + GetTypeAsString();
68 } 74 }
69 75
76 FilterSourceStream::SourceType FilterSourceStream::ParseEncodingType(
77 const std::string& encoding) {
78 if (encoding.empty()) {
79 return TYPE_NONE;
80 } else if (base::LowerCaseEqualsASCII(encoding, kBrotli)) {
81 return TYPE_BROTLI;
82 } else if (base::LowerCaseEqualsASCII(encoding, kDeflate)) {
83 return TYPE_DEFLATE;
84 } else if (base::LowerCaseEqualsASCII(encoding, kGZip) ||
85 base::LowerCaseEqualsASCII(encoding, kXGZip)) {
86 return TYPE_GZIP;
87 } else if (base::LowerCaseEqualsASCII(encoding, kSdch)) {
88 return TYPE_SDCH;
89 } else {
90 return TYPE_UNKNOWN;
91 }
92 }
93
94 void FilterSourceStream::ReportContentDecodingFailed(SourceType type) {
95 UMA_HISTOGRAM_ENUMERATION("Net.ContentDecodingFailed2", type, TYPE_MAX);
96 }
97
70 int FilterSourceStream::DoLoop(int result) { 98 int FilterSourceStream::DoLoop(int result) {
71 DCHECK_NE(STATE_NONE, next_state_); 99 DCHECK_NE(STATE_NONE, next_state_);
72 100
73 int rv = result; 101 int rv = result;
74 do { 102 do {
75 State state = next_state_; 103 State state = next_state_;
76 next_state_ = STATE_NONE; 104 next_state_ = STATE_NONE;
77 switch (state) { 105 switch (state) {
78 case STATE_READ_DATA: 106 case STATE_READ_DATA:
79 rv = DoReadData(); 107 rv = DoReadData();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 int consumed_bytes = 0; 157 int consumed_bytes = 0;
130 int bytes_output = FilterData(output_buffer_.get(), output_buffer_size_, 158 int bytes_output = FilterData(output_buffer_.get(), output_buffer_size_,
131 drainable_input_buffer_.get(), 159 drainable_input_buffer_.get(),
132 drainable_input_buffer_->BytesRemaining(), 160 drainable_input_buffer_->BytesRemaining(),
133 &consumed_bytes, upstream_end_reached_); 161 &consumed_bytes, upstream_end_reached_);
134 DCHECK_LE(consumed_bytes, drainable_input_buffer_->BytesRemaining()); 162 DCHECK_LE(consumed_bytes, drainable_input_buffer_->BytesRemaining());
135 DCHECK(bytes_output != 0 || 163 DCHECK(bytes_output != 0 ||
136 consumed_bytes == drainable_input_buffer_->BytesRemaining()); 164 consumed_bytes == drainable_input_buffer_->BytesRemaining());
137 165
138 if (bytes_output == ERR_CONTENT_DECODING_FAILED) { 166 if (bytes_output == ERR_CONTENT_DECODING_FAILED) {
139 UMA_HISTOGRAM_ENUMERATION("Net.ContentDecodingFailed2.FilterType", type(), 167 ReportContentDecodingFailed(type());
140 TYPE_MAX);
141 } 168 }
142 // FilterData() is not allowed to return ERR_IO_PENDING. 169 // FilterData() is not allowed to return ERR_IO_PENDING.
143 DCHECK_NE(ERR_IO_PENDING, bytes_output); 170 DCHECK_NE(ERR_IO_PENDING, bytes_output);
144 171
145 if (consumed_bytes > 0) 172 if (consumed_bytes > 0)
146 drainable_input_buffer_->DidConsume(consumed_bytes); 173 drainable_input_buffer_->DidConsume(consumed_bytes);
147 174
148 // Received data or encountered an error. 175 // Received data or encountered an error.
149 if (bytes_output != 0) 176 if (bytes_output != 0)
150 return bytes_output; 177 return bytes_output;
(...skipping 16 matching lines...) Expand all
167 output_buffer_size_ = 0; 194 output_buffer_size_ = 0;
168 195
169 base::ResetAndReturn(&callback_).Run(rv); 196 base::ResetAndReturn(&callback_).Run(rv);
170 } 197 }
171 198
172 bool FilterSourceStream::NeedMoreData() const { 199 bool FilterSourceStream::NeedMoreData() const {
173 return !upstream_end_reached_; 200 return !upstream_end_reached_;
174 } 201 }
175 202
176 } // namespace net 203 } // namespace net
OLDNEW
« no previous file with comments | « net/filter/filter_source_stream.h ('k') | net/filter/source_stream_type_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698