ServiceWorker: Rename 'current' to 'controller'
[chromium-blink-merge.git] / net / spdy / hpack_huffman_aggregator.h
blob46ba0949c7a6a8edeb5e0d2eb957f2bb1fad2392
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <list>
6 #include <vector>
8 #include "base/macros.h"
9 #include "net/base/net_export.h"
10 #include "net/spdy/spdy_header_block.h"
11 #include "net/spdy/spdy_protocol.h"
12 #include "net/spdy/spdy_session_key.h"
14 namespace net {
16 class HpackEncoder;
17 class HttpRequestHeaders;
18 struct HttpRequestInfo;
19 class HttpResponseHeaders;
20 class ProxyServer;
22 namespace test {
23 class HpackHuffmanAggregatorPeer;
24 } // namespace test
26 class NET_EXPORT_PRIVATE HpackHuffmanAggregator {
27 public:
28 friend class test::HpackHuffmanAggregatorPeer;
30 HpackHuffmanAggregator();
31 ~HpackHuffmanAggregator();
33 // Encodes the request and response headers of the transaction with an
34 // HpackEncoder keyed on the transaction's SpdySessionKey. Literal headers
35 // emitted by that encoder are aggregated into internal character counts,
36 // which are periodically published to a UMA histogram.
37 void AggregateTransactionCharacterCounts(
38 const HttpRequestInfo& request,
39 const HttpRequestHeaders& request_headers,
40 const ProxyServer& proxy,
41 const HttpResponseHeaders& response_headers);
43 // Returns whether the aggregator is enabled for the session by a field trial.
44 static bool UseAggregator();
46 private:
47 typedef std::pair<SpdySessionKey, HpackEncoder*> OriginEncoder;
48 typedef std::list<OriginEncoder> OriginEncoders;
50 // Returns true if the request is considered cross-origin,
51 // and should not be aggregated.
52 static bool IsCrossOrigin(const HttpRequestInfo& request);
54 // Converts |headers| into SPDY headers block |headers_out|.
55 static void CreateSpdyHeadersFromHttpResponse(
56 const HttpResponseHeaders& headers,
57 SpdyHeaderBlock* headers_out);
59 // Creates or returns an encoder for the origin key.
60 HpackEncoder* ObtainEncoder(const SpdySessionKey& key);
62 // Publishes aggregated counts to a UMA histogram.
63 void PublishCounts();
65 std::vector<size_t> counts_;
66 size_t total_counts_;
68 OriginEncoders encoders_;
69 size_t max_encoders_;
71 DISALLOW_COPY_AND_ASSIGN(HpackHuffmanAggregator);
74 } // namespace net