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

Side by Side Diff: net/http/http_server_properties_impl.cc

Issue 188663002: Revert of HttpServerProperties - Implement MRU for AlternateProtocolMap. Persist (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/http/http_server_properties_impl.h" 5 #include "net/http/http_server_properties_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "net/http/http_pipelined_host_capability.h" 12 #include "net/http/http_pipelined_host_capability.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 // TODO(simonjam): Run experiments with different values of this to see what 16 // TODO(simonjam): Run experiments with different values of this to see what
17 // value is good at avoiding evictions without eating too much memory. Until 17 // value is good at avoiding evictions without eating too much memory. Until
18 // then, this is just a bad guess. 18 // then, this is just a bad guess.
19 static const int kDefaultNumHostsToRemember = 200; 19 static const int kDefaultNumHostsToRemember = 200;
20 20
21 HttpServerPropertiesImpl::HttpServerPropertiesImpl() 21 HttpServerPropertiesImpl::HttpServerPropertiesImpl()
22 : alternate_protocol_map_(AlternateProtocolMap::NO_AUTO_EVICT), 22 : pipeline_capability_map_(
23 pipeline_capability_map_(
24 new CachedPipelineCapabilityMap(kDefaultNumHostsToRemember)), 23 new CachedPipelineCapabilityMap(kDefaultNumHostsToRemember)),
25 weak_ptr_factory_(this) { 24 weak_ptr_factory_(this) {
26 canoncial_suffixes_.push_back(".c.youtube.com"); 25 canoncial_suffixes_.push_back(".c.youtube.com");
27 canoncial_suffixes_.push_back(".googlevideo.com"); 26 canoncial_suffixes_.push_back(".googlevideo.com");
28 } 27 }
29 28
30 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { 29 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() {
31 } 30 }
32 31
33 void HttpServerPropertiesImpl::InitializeSpdyServers( 32 void HttpServerPropertiesImpl::InitializeSpdyServers(
34 std::vector<std::string>* spdy_servers, 33 std::vector<std::string>* spdy_servers,
35 bool support_spdy) { 34 bool support_spdy) {
36 DCHECK(CalledOnValidThread()); 35 DCHECK(CalledOnValidThread());
37 spdy_servers_table_.clear(); 36 spdy_servers_table_.clear();
38 if (!spdy_servers) 37 if (!spdy_servers)
39 return; 38 return;
40 for (std::vector<std::string>::iterator it = spdy_servers->begin(); 39 for (std::vector<std::string>::iterator it = spdy_servers->begin();
41 it != spdy_servers->end(); ++it) { 40 it != spdy_servers->end(); ++it) {
42 spdy_servers_table_[*it] = support_spdy; 41 spdy_servers_table_[*it] = support_spdy;
43 } 42 }
44 } 43 }
45 44
46 void HttpServerPropertiesImpl::InitializeAlternateProtocolServers( 45 void HttpServerPropertiesImpl::InitializeAlternateProtocolServers(
47 AlternateProtocolMap* alternate_protocol_map) { 46 AlternateProtocolMap* alternate_protocol_map) {
48 // Keep all the ALTERNATE_PROTOCOL_BROKEN ones since those don't 47 // First swap, and then add back all the ALTERNATE_PROTOCOL_BROKEN ones since
49 // get persisted. 48 // those don't get persisted.
50 for (AlternateProtocolMap::iterator it = alternate_protocol_map_.begin(); 49 alternate_protocol_map_.swap(*alternate_protocol_map);
51 it != alternate_protocol_map_.end();) { 50 for (AlternateProtocolMap::const_iterator it =
52 AlternateProtocolMap::iterator old_it = it; 51 alternate_protocol_map->begin();
53 ++it; 52 it != alternate_protocol_map->end(); ++it) {
54 if (old_it->second.protocol != ALTERNATE_PROTOCOL_BROKEN) { 53 if (it->second.protocol == ALTERNATE_PROTOCOL_BROKEN)
55 alternate_protocol_map_.Erase(old_it); 54 alternate_protocol_map_[it->first] = it->second;
56 }
57 } 55 }
58
59 // Add the entries from persisted data.
60 for (AlternateProtocolMap::reverse_iterator it =
61 alternate_protocol_map->rbegin();
62 it != alternate_protocol_map->rend(); ++it) {
63 alternate_protocol_map_.Put(it->first, it->second);
64 }
65
66 // Attempt to find canonical servers. 56 // Attempt to find canonical servers.
67 int canonical_ports[] = { 80, 443 }; 57 int canonical_ports[] = { 80, 443 };
68 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { 58 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) {
69 std::string canonical_suffix = canoncial_suffixes_[i]; 59 std::string canonical_suffix = canoncial_suffixes_[i];
70 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { 60 for (size_t j = 0; j < arraysize(canonical_ports); ++j) {
71 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); 61 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]);
72 // If we already have a valid canonical server, we're done. 62 // If we already have a valid canonical server, we're done.
73 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && 63 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) &&
74 (alternate_protocol_map_.Peek(canonical_host_to_origin_map_[ 64 ContainsKey(alternate_protocol_map_,
75 canonical_host]) != alternate_protocol_map_.end())) { 65 canonical_host_to_origin_map_[canonical_host])) {
76 continue; 66 continue;
77 } 67 }
78 // Now attempt to find a server which matches this origin and set it as 68 // Now attempt to find a server which matches this origin and set it as
79 // canonical . 69 // canonical .
80 for (AlternateProtocolMap::const_iterator it = 70 for (AlternateProtocolMap::const_iterator it =
81 alternate_protocol_map_.begin(); 71 alternate_protocol_map_.begin();
82 it != alternate_protocol_map_.end(); ++it) { 72 it != alternate_protocol_map_.end(); ++it) {
83 if (EndsWith(it->first.host(), canoncial_suffixes_[i], false)) { 73 if (EndsWith(it->first.host(), canoncial_suffixes_[i], false)) {
84 canonical_host_to_origin_map_[canonical_host] = it->first; 74 canonical_host_to_origin_map_[canonical_host] = it->first;
85 break; 75 break;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 g_forced_alternate_protocol = NULL; 140 g_forced_alternate_protocol = NULL;
151 } 141 }
152 142
153 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() { 143 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() {
154 return weak_ptr_factory_.GetWeakPtr(); 144 return weak_ptr_factory_.GetWeakPtr();
155 } 145 }
156 146
157 void HttpServerPropertiesImpl::Clear() { 147 void HttpServerPropertiesImpl::Clear() {
158 DCHECK(CalledOnValidThread()); 148 DCHECK(CalledOnValidThread());
159 spdy_servers_table_.clear(); 149 spdy_servers_table_.clear();
160 alternate_protocol_map_.Clear(); 150 alternate_protocol_map_.clear();
161 spdy_settings_map_.clear(); 151 spdy_settings_map_.clear();
162 pipeline_capability_map_->Clear(); 152 pipeline_capability_map_->Clear();
163 } 153 }
164 154
165 bool HttpServerPropertiesImpl::SupportsSpdy( 155 bool HttpServerPropertiesImpl::SupportsSpdy(
166 const net::HostPortPair& host_port_pair) const { 156 const net::HostPortPair& host_port_pair) const {
167 DCHECK(CalledOnValidThread()); 157 DCHECK(CalledOnValidThread());
168 if (host_port_pair.host().empty()) 158 if (host_port_pair.host().empty())
169 return false; 159 return false;
170 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair); 160 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair);
(...skipping 17 matching lines...) Expand all
188 spdy_servers_table_.find(spdy_server); 178 spdy_servers_table_.find(spdy_server);
189 if ((spdy_host_port != spdy_servers_table_.end()) && 179 if ((spdy_host_port != spdy_servers_table_.end()) &&
190 (spdy_host_port->second == support_spdy)) { 180 (spdy_host_port->second == support_spdy)) {
191 return; 181 return;
192 } 182 }
193 // Cache the data. 183 // Cache the data.
194 spdy_servers_table_[spdy_server] = support_spdy; 184 spdy_servers_table_[spdy_server] = support_spdy;
195 } 185 }
196 186
197 bool HttpServerPropertiesImpl::HasAlternateProtocol( 187 bool HttpServerPropertiesImpl::HasAlternateProtocol(
198 const HostPortPair& server) { 188 const HostPortPair& server) const {
199 if (alternate_protocol_map_.Get(server) != alternate_protocol_map_.end() || 189 if (ContainsKey(alternate_protocol_map_, server) ||
200 g_forced_alternate_protocol) 190 g_forced_alternate_protocol)
201 return true; 191 return true;
202 192
203 return GetCanonicalHost(server) != canonical_host_to_origin_map_.end(); 193 return GetCanonicalHost(server) != canonical_host_to_origin_map_.end();
204 } 194 }
205 195
206 PortAlternateProtocolPair 196 PortAlternateProtocolPair
207 HttpServerPropertiesImpl::GetAlternateProtocol( 197 HttpServerPropertiesImpl::GetAlternateProtocol(
208 const HostPortPair& server) { 198 const HostPortPair& server) const {
209 DCHECK(HasAlternateProtocol(server)); 199 DCHECK(HasAlternateProtocol(server));
210 200
211 // First check the map. 201 // First check the map.
212 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); 202 AlternateProtocolMap::const_iterator it =
203 alternate_protocol_map_.find(server);
213 if (it != alternate_protocol_map_.end()) 204 if (it != alternate_protocol_map_.end())
214 return it->second; 205 return it->second;
215 206
216 // Next check the canonical host. 207 // Next check the canonical host.
217 CanonicalHostMap::const_iterator canonical_host = GetCanonicalHost(server); 208 CanonicalHostMap::const_iterator canonical_host = GetCanonicalHost(server);
218 if (canonical_host != canonical_host_to_origin_map_.end()) 209 if (canonical_host != canonical_host_to_origin_map_.end())
219 return alternate_protocol_map_.Get(canonical_host->second)->second; 210 return alternate_protocol_map_.find(canonical_host->second)->second;
220 211
221 // We must be forcing an alternate. 212 // We must be forcing an alternate.
222 DCHECK(g_forced_alternate_protocol); 213 DCHECK(g_forced_alternate_protocol);
223 return *g_forced_alternate_protocol; 214 return *g_forced_alternate_protocol;
224 } 215 }
225 216
226 void HttpServerPropertiesImpl::SetAlternateProtocol( 217 void HttpServerPropertiesImpl::SetAlternateProtocol(
227 const HostPortPair& server, 218 const HostPortPair& server,
228 uint16 alternate_port, 219 uint16 alternate_port,
229 AlternateProtocol alternate_protocol) { 220 AlternateProtocol alternate_protocol) {
(...skipping 19 matching lines...) Expand all
249 LOG(WARNING) << "Changing the alternate protocol for: " 240 LOG(WARNING) << "Changing the alternate protocol for: "
250 << server.ToString() 241 << server.ToString()
251 << " from [Port: " << existing_alternate.port 242 << " from [Port: " << existing_alternate.port
252 << ", Protocol: " << existing_alternate.protocol 243 << ", Protocol: " << existing_alternate.protocol
253 << "] to [Port: " << alternate_port 244 << "] to [Port: " << alternate_port
254 << ", Protocol: " << alternate_protocol 245 << ", Protocol: " << alternate_protocol
255 << "]."; 246 << "].";
256 } 247 }
257 } 248 }
258 249
259 alternate_protocol_map_.Put(server, alternate); 250 alternate_protocol_map_[server] = alternate;
260 251
261 // If this host ends with a canonical suffix, then set it as the 252 // If this host ends with a canonical suffix, then set it as the
262 // canonical host. 253 // canonical host.
263 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { 254 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) {
264 std::string canonical_suffix = canoncial_suffixes_[i]; 255 std::string canonical_suffix = canoncial_suffixes_[i];
265 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { 256 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) {
266 HostPortPair canonical_host(canonical_suffix, server.port()); 257 HostPortPair canonical_host(canonical_suffix, server.port());
267 canonical_host_to_origin_map_[canonical_host] = server; 258 canonical_host_to_origin_map_[canonical_host] = server;
268 break; 259 break;
269 } 260 }
270 } 261 }
271 } 262 }
272 263
273 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( 264 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol(
274 const HostPortPair& server) { 265 const HostPortPair& server) {
275 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); 266 alternate_protocol_map_[server].protocol = ALTERNATE_PROTOCOL_BROKEN;
276 if (it != alternate_protocol_map_.end()) {
277 it->second.protocol = ALTERNATE_PROTOCOL_BROKEN;
278 return;
279 }
280 PortAlternateProtocolPair alternate;
281 alternate.protocol = ALTERNATE_PROTOCOL_BROKEN;
282 alternate_protocol_map_.Put(server, alternate);
283 } 267 }
284 268
285 const AlternateProtocolMap& 269 const AlternateProtocolMap&
286 HttpServerPropertiesImpl::alternate_protocol_map() const { 270 HttpServerPropertiesImpl::alternate_protocol_map() const {
287 return alternate_protocol_map_; 271 return alternate_protocol_map_;
288 } 272 }
289 273
290 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( 274 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings(
291 const HostPortPair& host_port_pair) const { 275 const HostPortPair& host_port_pair) const {
292 SpdySettingsMap::const_iterator it = spdy_settings_map_.find(host_port_pair); 276 SpdySettingsMap::const_iterator it = spdy_settings_map_.find(host_port_pair);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { 370 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) {
387 HostPortPair canonical_host(canonical_suffix, server.port()); 371 HostPortPair canonical_host(canonical_suffix, server.port());
388 return canonical_host_to_origin_map_.find(canonical_host); 372 return canonical_host_to_origin_map_.find(canonical_host);
389 } 373 }
390 } 374 }
391 375
392 return canonical_host_to_origin_map_.end(); 376 return canonical_host_to_origin_map_.end();
393 } 377 }
394 378
395 } // namespace net 379 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_impl.h ('k') | net/http/http_server_properties_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698