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