Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: net/spdy/spdy_header_indexing.cc

Issue 2801603003: Add SpdyString alias for std::string in net/spdy. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_header_indexing.h ('k') | net/spdy/spdy_header_indexing_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "net/spdy/spdy_header_indexing.h" 5 #include "net/spdy/spdy_header_indexing.h"
6 6
7 #include "net/spdy/spdy_bug_tracker.h" 7 #include "net/spdy/spdy_bug_tracker.h"
8 8
9 namespace net { 9 namespace net {
10 10
11 int32_t FLAGS_gfe_spdy_indexing_set_bound = 50; 11 int32_t FLAGS_gfe_spdy_indexing_set_bound = 50;
12 int32_t FLAGS_gfe_spdy_tracking_set_bound = 1000; 12 int32_t FLAGS_gfe_spdy_tracking_set_bound = 1000;
13 13
14 HeaderIndexing::HeaderIndexing() 14 HeaderIndexing::HeaderIndexing()
15 : indexing_set_bound_(FLAGS_gfe_spdy_indexing_set_bound), 15 : indexing_set_bound_(FLAGS_gfe_spdy_indexing_set_bound),
16 tracking_set_bound_(FLAGS_gfe_spdy_tracking_set_bound) { 16 tracking_set_bound_(FLAGS_gfe_spdy_tracking_set_bound) {
17 SPDY_BUG_IF(indexing_set_bound_ >= tracking_set_bound_) 17 SPDY_BUG_IF(indexing_set_bound_ >= tracking_set_bound_)
18 << "Tracking set should be larger than indexing set"; 18 << "Tracking set should be larger than indexing set";
19 } 19 }
20 20
21 HeaderIndexing::~HeaderIndexing() {} 21 HeaderIndexing::~HeaderIndexing() {}
22 22
23 void HeaderIndexing::CreateInitIndexingHeaders() { 23 void HeaderIndexing::CreateInitIndexingHeaders() {
24 const std::string initial_fields[] = { 24 const SpdyString initial_fields[] = {
25 // Estimated top 100 fields. 25 // Estimated top 100 fields.
26 "alt-svc", 26 "alt-svc",
27 "date", 27 "date",
28 "cache-control", 28 "cache-control",
29 "content-type", 29 "content-type",
30 "expires", 30 "expires",
31 "location", 31 "location",
32 "x-xss-protection", 32 "x-xss-protection",
33 "p3p", 33 "p3p",
34 "set-cookie", 34 "set-cookie",
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 HeaderSet(initial_fields, initial_fields + arraysize(initial_fields)); 132 HeaderSet(initial_fields, initial_fields + arraysize(initial_fields));
133 } 133 }
134 134
135 bool HeaderIndexing::ShouldIndex(SpdyStringPiece header, 135 bool HeaderIndexing::ShouldIndex(SpdyStringPiece header,
136 SpdyStringPiece /* value */) { 136 SpdyStringPiece /* value */) {
137 total_header_count_++; 137 total_header_count_++;
138 if (header.empty()) { 138 if (header.empty()) {
139 return false; 139 return false;
140 } 140 }
141 // header is in indexing set. 141 // header is in indexing set.
142 std::string header_str(header.data(), header.size()); 142 SpdyString header_str(header.data(), header.size());
143 if (indexing_set_.find(header_str) != indexing_set_.end()) { 143 if (indexing_set_.find(header_str) != indexing_set_.end()) {
144 return true; 144 return true;
145 } 145 }
146 // header not in indexing set. Check tracking set. 146 // header not in indexing set. Check tracking set.
147 if (tracking_set_.find(header_str) != tracking_set_.end()) { 147 if (tracking_set_.find(header_str) != tracking_set_.end()) {
148 // Seen this header before. Add it to indexing set. 148 // Seen this header before. Add it to indexing set.
149 TryInsertHeader(std::move(header_str), &indexing_set_, indexing_set_bound_); 149 TryInsertHeader(std::move(header_str), &indexing_set_, indexing_set_bound_);
150 missed_header_in_tracking_++; 150 missed_header_in_tracking_++;
151 } else { 151 } else {
152 // Add header to tracking set. 152 // Add header to tracking set.
153 TryInsertHeader(std::move(header_str), &tracking_set_, tracking_set_bound_); 153 TryInsertHeader(std::move(header_str), &tracking_set_, tracking_set_bound_);
154 missed_header_in_indexing_++; 154 missed_header_in_indexing_++;
155 } 155 }
156 return false; 156 return false;
157 } 157 }
158 158
159 void HeaderIndexing::TryInsertHeader(std::string&& header, 159 void HeaderIndexing::TryInsertHeader(SpdyString&& header,
160 HeaderSet* set, 160 HeaderSet* set,
161 size_t bound) { 161 size_t bound) {
162 std::pair<HeaderSet::iterator, bool> result = set->insert(std::move(header)); 162 std::pair<HeaderSet::iterator, bool> result = set->insert(std::move(header));
163 if (set->size() > bound) { 163 if (set->size() > bound) {
164 // Reach the size limit. Remove the header next to the newly added header. 164 // Reach the size limit. Remove the header next to the newly added header.
165 // If the new header is at the end, look for the "next" element at the 165 // If the new header is at the end, look for the "next" element at the
166 // beginning. 166 // beginning.
167 HeaderSet::iterator it = std::next(result.first); 167 HeaderSet::iterator it = std::next(result.first);
168 if (it != set->end()) { 168 if (it != set->end()) {
169 set->erase(it); 169 set->erase(it);
170 } else { 170 } else {
171 set->erase(set->begin()); 171 set->erase(set->begin());
172 } 172 }
173 } 173 }
174 } 174 }
175 175
176 } // namespace net 176 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_header_indexing.h ('k') | net/spdy/spdy_header_indexing_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698