OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include <list> | |
6 #include <vector> | |
7 | |
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" | |
13 | |
14 namespace net { | |
15 | |
16 class HpackEncoder; | |
17 class HttpRequestHeaders; | |
18 struct HttpRequestInfo; | |
19 class HttpResponseHeaders; | |
20 class ProxyServer; | |
21 | |
22 namespace test { | |
23 class HpackHuffmanAggregatorPeer; | |
24 } // namespace test | |
25 | |
26 class NET_EXPORT_PRIVATE HpackHuffmanAggregator { | |
27 public: | |
28 friend class test::HpackHuffmanAggregatorPeer; | |
29 | |
30 HpackHuffmanAggregator(); | |
31 ~HpackHuffmanAggregator(); | |
32 | |
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); | |
42 | |
43 // Returns whether the aggregator is enabled for the session by a field trial. | |
44 static bool UseAggregator(); | |
45 | |
46 private: | |
47 typedef std::pair<SpdySessionKey, HpackEncoder*> OriginEncoder; | |
48 typedef std::list<OriginEncoder> OriginEncoders; | |
49 | |
50 // Returns true if the request is considered cross-origin, | |
51 // and should not be aggregated. | |
52 static bool IsCrossOrigin(const HttpRequestInfo& request); | |
53 | |
54 // Converts |headers| into SPDY headers block |headers_out|. | |
55 static void CreateSpdyHeadersFromHttpResponse( | |
56 const HttpResponseHeaders& headers, | |
57 SpdyHeaderBlock* headers_out); | |
58 | |
59 // Creates or returns an encoder for the origin key. | |
60 HpackEncoder* ObtainEncoder(const SpdySessionKey& key); | |
61 | |
62 // Publishes aggregated counts to a UMA histogram. | |
63 void PublishCounts(); | |
64 | |
65 std::vector<size_t> counts_; | |
66 size_t total_counts_; | |
67 | |
68 OriginEncoders encoders_; | |
69 size_t max_encoders_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(HpackHuffmanAggregator); | |
72 }; | |
73 | |
74 } // namespace net | |
OLD | NEW |