summaryrefslogtreecommitdiff
path: root/chromium/net/spdy/spdy_header_indexing.h
blob: 9dd4bc5a190f9d4099cc929c263409acf9622d10 (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
// Copyright (c) 2016 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.

#ifndef NET_SPDY_SPDY_HEADER_INDEXING_H_
#define NET_SPDY_SPDY_HEADER_INDEXING_H_

#include <stdint.h>
#include <memory>
#include <string>
#include <unordered_set>
#include <utility>

#include "base/strings/string_piece.h"
#include "net/base/net_export.h"

namespace net {

namespace test {
class HeaderIndexingPeer;
}

NET_EXPORT_PRIVATE extern int32_t FLAGS_gfe_spdy_indexing_set_bound;
NET_EXPORT_PRIVATE extern int32_t FLAGS_gfe_spdy_tracking_set_bound;

// Maintain two headers sets: Indexing set and tracking
// set. Call ShouldIndex() for each header to decide if to index it. If for some
// connections, we decide to index all headers, we may still want to call
// UpdateSets to log the headers into both sets.
class NET_EXPORT HeaderIndexing {
 public:
  using HeaderSet = std::unordered_set<std::string>;

  HeaderIndexing();
  ~HeaderIndexing();

  void CreateInitIndexingHeaders();

  // Decide if a header should be indexed. We only use |header|. Add |value| to
  // be consistent with HPACK indexing policy interface.
  bool ShouldIndex(base::StringPiece header, base::StringPiece value);

  // Not to make the indexing decision but to update sets.
  void UpdateSets(base::StringPiece header, base::StringPiece value) {
    update_only_header_count_++;
    ShouldIndex(header, value);
  }

  int64_t total_header_count() { return total_header_count_; }
  int64_t update_only_header_count() { return update_only_header_count_; }
  int64_t missed_headers_in_indexing() { return missed_header_in_indexing_; }
  int64_t missed_headers_in_tracking() { return missed_header_in_tracking_; }

 private:
  friend class test::HeaderIndexingPeer;
  void TryInsertHeader(std::string&& header, HeaderSet* set, size_t bound);
  // Headers to index.
  HeaderSet indexing_set_;
  // Headers seen so far.
  HeaderSet tracking_set_;
  const size_t indexing_set_bound_;
  const size_t tracking_set_bound_;
  int64_t total_header_count_ = 0;
  int64_t update_only_header_count_ = 0;
  int64_t missed_header_in_indexing_ = 0;
  int64_t missed_header_in_tracking_ = 0;
};

}  // namespace net

#endif  // NET_SPDY_SPDY_HEADER_INDEXING_H_