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

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

Issue 1616863002: Fix division by zero. Test filter with empty output. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | net/filter/brotli_filter_unittest.cc » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/brotli_filter.h" 5 #include "net/filter/brotli_filter.h"
6 6
7 #include "base/bit_cast.h" 7 #include "base/bit_cast.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
(...skipping 23 matching lines...) Expand all
34 34
35 ~BrotliFilter() override { 35 ~BrotliFilter() override {
36 BrotliDestroyState(brotli_state_); 36 BrotliDestroyState(brotli_state_);
37 brotli_state_ = nullptr; 37 brotli_state_ = nullptr;
38 DCHECK(used_memory_ == 0); 38 DCHECK(used_memory_ == 0);
39 39
40 UMA_HISTOGRAM_ENUMERATION( 40 UMA_HISTOGRAM_ENUMERATION(
41 "BrotliFilter.Status", static_cast<int>(decoding_status_), 41 "BrotliFilter.Status", static_cast<int>(decoding_status_),
42 static_cast<int>(DecodingStatus::DECODING_STATUS_COUNT)); 42 static_cast<int>(DecodingStatus::DECODING_STATUS_COUNT));
43 if (decoding_status_ == DecodingStatus::DECODING_DONE) { 43 if (decoding_status_ == DecodingStatus::DECODING_DONE) {
44 UMA_HISTOGRAM_PERCENTAGE( 44 // CompressionPercent is undefined when there is no output produced.
45 "BrotliFilter.CompressionPercent", 45 if (produced_bytes_ != 0) {
46 static_cast<int>((consumed_bytes_ * 100) / produced_bytes_)); 46 UMA_HISTOGRAM_PERCENTAGE(
47 "BrotliFilter.CompressionPercent",
48 static_cast<int>((consumed_bytes_ * 100) / produced_bytes_));
49 }
47 } 50 }
48 51
49 // All code here is for gathering stats, and can be removed when 52 // All code here is for gathering stats, and can be removed when
50 // BrotliFilter is considered stable. 53 // BrotliFilter is considered stable.
51 static const int kBuckets = 48; 54 static const int kBuckets = 48;
52 static const int64_t kMaxKb = 1 << (kBuckets / 3); // 64MiB in KiB 55 static const int64_t kMaxKb = 1 << (kBuckets / 3); // 64MiB in KiB
53 UMA_HISTOGRAM_CUSTOM_COUNTS("BrotliFilter.UsedMemoryKB", 56 UMA_HISTOGRAM_CUSTOM_COUNTS("BrotliFilter.UsedMemoryKB",
54 used_memory_maximum_ / 1024, 1, kMaxKb, 57 used_memory_maximum_ / 1024, 1, kMaxKb,
55 kBuckets); 58 kBuckets);
56 } 59 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 size_t produced_bytes_; 181 size_t produced_bytes_;
179 182
180 DISALLOW_COPY_AND_ASSIGN(BrotliFilter); 183 DISALLOW_COPY_AND_ASSIGN(BrotliFilter);
181 }; 184 };
182 185
183 Filter* CreateBrotliFilter(Filter::FilterType type_id) { 186 Filter* CreateBrotliFilter(Filter::FilterType type_id) {
184 return new BrotliFilter(type_id); 187 return new BrotliFilter(type_id);
185 } 188 }
186 189
187 } // namespace net 190 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/filter/brotli_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698