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.
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"
17 class HttpRequestHeaders;
18 struct HttpRequestInfo;
19 class HttpResponseHeaders;
23 class HpackHuffmanAggregatorPeer;
26 class NET_EXPORT_PRIVATE HpackHuffmanAggregator {
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();
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.
65 std::vector<size_t> counts_;
68 OriginEncoders encoders_;
71 DISALLOW_COPY_AND_ASSIGN(HpackHuffmanAggregator);