summaryrefslogtreecommitdiffstats
path: root/net/spdy/hpack_huffman_aggregator.h
blob: 46ba0949c7a6a8edeb5e0d2eb957f2bb1fad2392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <list>
#include <vector>

#include "base/macros.h"
#include "net/base/net_export.h"
#include "net/spdy/spdy_header_block.h"
#include "net/spdy/spdy_protocol.h"
#include "net/spdy/spdy_session_key.h"

namespace net {

class HpackEncoder;
class HttpRequestHeaders;
struct HttpRequestInfo;
class HttpResponseHeaders;
class ProxyServer;

namespace test {
class HpackHuffmanAggregatorPeer;
}  // namespace test

class NET_EXPORT_PRIVATE HpackHuffmanAggregator {
 public:
  friend class test::HpackHuffmanAggregatorPeer;

  HpackHuffmanAggregator();
  ~HpackHuffmanAggregator();

  // Encodes the request and response headers of the transaction with an
  // HpackEncoder keyed on the transaction's SpdySessionKey. Literal headers
  // emitted by that encoder are aggregated into internal character counts,
  // which are periodically published to a UMA histogram.
  void AggregateTransactionCharacterCounts(
    const HttpRequestInfo& request,
    const HttpRequestHeaders& request_headers,
    const ProxyServer& proxy,
    const HttpResponseHeaders& response_headers);

  // Returns whether the aggregator is enabled for the session by a field trial.
  static bool UseAggregator();

 private:
  typedef std::pair<SpdySessionKey, HpackEncoder*> OriginEncoder;
  typedef std::list<OriginEncoder> OriginEncoders;

  // Returns true if the request is considered cross-origin,
  // and should not be aggregated.
  static bool IsCrossOrigin(const HttpRequestInfo& request);

  // Converts |headers| into SPDY headers block |headers_out|.
  static void CreateSpdyHeadersFromHttpResponse(
      const HttpResponseHeaders& headers,
      SpdyHeaderBlock* headers_out);

  // Creates or returns an encoder for the origin key.
  HpackEncoder* ObtainEncoder(const SpdySessionKey& key);

  // Publishes aggregated counts to a UMA histogram.
  void PublishCounts();

  std::vector<size_t> counts_;
  size_t total_counts_;

  OriginEncoders encoders_;
  size_t max_encoders_;

  DISALLOW_COPY_AND_ASSIGN(HpackHuffmanAggregator);
};

}  // namespace net