Chromium Code Reviews| 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/brotli_source_stream.h" | 5 #include "net/filter/brotli_source_stream.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bit_cast.h" | 8 #include "base/bit_cast.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/stringprintf.h" | |
| 14 #include "base/trace_event/memory_allocator_dump.h" | |
| 15 #include "base/trace_event/process_memory_dump.h" | |
| 13 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 14 #include "third_party/brotli/dec/decode.h" | 17 #include "third_party/brotli/dec/decode.h" |
| 15 | 18 |
| 16 namespace net { | 19 namespace net { |
| 17 | 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 const char kBrotli[] = "BROTLI"; | 23 const char kBrotli[] = "BROTLI"; |
| 21 const uint8_t kGzipHeader[] = {0x1f, 0x8b, 0x08}; | 24 const uint8_t kGzipHeader[] = {0x1f, 0x8b, 0x08}; |
| 22 | 25 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 | 69 |
| 67 // All code here is for gathering stats, and can be removed when | 70 // All code here is for gathering stats, and can be removed when |
| 68 // BrotliSourceStream is considered stable. | 71 // BrotliSourceStream is considered stable. |
| 69 const int kBuckets = 48; | 72 const int kBuckets = 48; |
| 70 const int64_t kMaxKb = 1 << (kBuckets / 3); // 64MiB in KiB | 73 const int64_t kMaxKb = 1 << (kBuckets / 3); // 64MiB in KiB |
| 71 UMA_HISTOGRAM_CUSTOM_COUNTS("BrotliFilter.UsedMemoryKB", | 74 UMA_HISTOGRAM_CUSTOM_COUNTS("BrotliFilter.UsedMemoryKB", |
| 72 used_memory_maximum_ / 1024, 1, kMaxKb, | 75 used_memory_maximum_ / 1024, 1, kMaxKb, |
| 73 kBuckets); | 76 kBuckets); |
| 74 } | 77 } |
| 75 | 78 |
| 79 void DumpMemoryStatsImpl( | |
| 80 base::trace_event::MemoryAllocatorDump* dump) const override { | |
| 81 // Log pointer address to avoid duplication though in practice there is | |
| 82 // often only one BrotliSourceStream per URLRequest. | |
| 83 base::trace_event::MemoryAllocatorDump* brotli_dump = | |
| 84 dump->process_memory_dump()->CreateAllocatorDump(base::StringPrintf( | |
| 85 "%s/brotli_%p", dump->absolute_name().c_str(), this)); | |
|
ssid
2016/12/02 21:36:35
Pass the dump name as an extra argument to this fu
| |
| 86 brotli_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
| 87 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 88 used_memory_); | |
| 89 } | |
| 90 | |
| 76 private: | 91 private: |
| 77 // Reported in UMA and must be kept in sync with the histograms.xml file. | 92 // Reported in UMA and must be kept in sync with the histograms.xml file. |
| 78 enum class DecodingStatus : int { | 93 enum class DecodingStatus : int { |
| 79 DECODING_IN_PROGRESS = 0, | 94 DECODING_IN_PROGRESS = 0, |
| 80 DECODING_DONE, | 95 DECODING_DONE, |
| 81 DECODING_ERROR, | 96 DECODING_ERROR, |
| 82 | 97 |
| 83 DECODING_STATUS_COUNT | 98 DECODING_STATUS_COUNT |
| 84 // DECODING_STATUS_COUNT must always be the last element in this enum. | 99 // DECODING_STATUS_COUNT must always be the last element in this enum. |
| 85 }; | 100 }; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 }; | 208 }; |
| 194 | 209 |
| 195 } // namespace | 210 } // namespace |
| 196 | 211 |
| 197 std::unique_ptr<FilterSourceStream> CreateBrotliSourceStream( | 212 std::unique_ptr<FilterSourceStream> CreateBrotliSourceStream( |
| 198 std::unique_ptr<SourceStream> previous) { | 213 std::unique_ptr<SourceStream> previous) { |
| 199 return base::WrapUnique(new BrotliSourceStream(std::move(previous))); | 214 return base::WrapUnique(new BrotliSourceStream(std::move(previous))); |
| 200 } | 215 } |
| 201 | 216 |
| 202 } // namespace net | 217 } // namespace net |
| OLD | NEW |