| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016 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 #ifndef NET_SPDY_SPDY_HEADER_INDEXING_H_ | |
| 6 #define NET_SPDY_SPDY_HEADER_INDEXING_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 #include <memory> | |
| 10 #include <unordered_set> | |
| 11 #include <utility> | |
| 12 | |
| 13 #include "net/base/net_export.h" | |
| 14 #include "net/spdy/platform/api/spdy_string.h" | |
| 15 #include "net/spdy/platform/api/spdy_string_piece.h" | |
| 16 | |
| 17 namespace net { | |
| 18 | |
| 19 namespace test { | |
| 20 class HeaderIndexingPeer; | |
| 21 } | |
| 22 | |
| 23 NET_EXPORT_PRIVATE extern int32_t FLAGS_gfe_spdy_indexing_set_bound; | |
| 24 NET_EXPORT_PRIVATE extern int32_t FLAGS_gfe_spdy_tracking_set_bound; | |
| 25 | |
| 26 // Maintain two headers sets: Indexing set and tracking | |
| 27 // set. Call ShouldIndex() for each header to decide if to index it. If for some | |
| 28 // connections, we decide to index all headers, we may still want to call | |
| 29 // UpdateSets to log the headers into both sets. | |
| 30 class NET_EXPORT HeaderIndexing { | |
| 31 public: | |
| 32 using HeaderSet = std::unordered_set<SpdyString>; | |
| 33 | |
| 34 HeaderIndexing(); | |
| 35 ~HeaderIndexing(); | |
| 36 | |
| 37 void CreateInitIndexingHeaders(); | |
| 38 | |
| 39 // Decide if a header should be indexed. We only use |header|. Add |value| to | |
| 40 // be consistent with HPACK indexing policy interface. | |
| 41 bool ShouldIndex(SpdyStringPiece header, SpdyStringPiece value); | |
| 42 | |
| 43 // Not to make the indexing decision but to update sets. | |
| 44 void UpdateSets(SpdyStringPiece header, SpdyStringPiece value) { | |
| 45 update_only_header_count_++; | |
| 46 ShouldIndex(header, value); | |
| 47 } | |
| 48 | |
| 49 int64_t total_header_count() { return total_header_count_; } | |
| 50 int64_t update_only_header_count() { return update_only_header_count_; } | |
| 51 int64_t missed_headers_in_indexing() { return missed_header_in_indexing_; } | |
| 52 int64_t missed_headers_in_tracking() { return missed_header_in_tracking_; } | |
| 53 | |
| 54 private: | |
| 55 friend class test::HeaderIndexingPeer; | |
| 56 void TryInsertHeader(SpdyString&& header, HeaderSet* set, size_t bound); | |
| 57 // Headers to index. | |
| 58 HeaderSet indexing_set_; | |
| 59 // Headers seen so far. | |
| 60 HeaderSet tracking_set_; | |
| 61 const size_t indexing_set_bound_; | |
| 62 const size_t tracking_set_bound_; | |
| 63 int64_t total_header_count_ = 0; | |
| 64 int64_t update_only_header_count_ = 0; | |
| 65 int64_t missed_header_in_indexing_ = 0; | |
| 66 int64_t missed_header_in_tracking_ = 0; | |
| 67 }; | |
| 68 | |
| 69 } // namespace net | |
| 70 | |
| 71 #endif // NET_SPDY_SPDY_HEADER_INDEXING_H_ | |
| OLD | NEW |