OLD | NEW |
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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "net/http/http_pipelined_host_capability.h" | |
15 | 14 |
16 namespace net { | 15 namespace net { |
17 | 16 |
18 namespace { | 17 namespace { |
19 | 18 |
20 // TODO(simonjam): Run experiments with different values of this to see what | |
21 // value is good at avoiding evictions without eating too much memory. Until | |
22 // then, this is just a bad guess. | |
23 const int kDefaultNumHostsToRemember = 200; | |
24 | |
25 const uint64 kBrokenAlternateProtocolDelaySecs = 300; | 19 const uint64 kBrokenAlternateProtocolDelaySecs = 300; |
26 | 20 |
27 } // namespace | 21 } // namespace |
28 | 22 |
29 HttpServerPropertiesImpl::HttpServerPropertiesImpl() | 23 HttpServerPropertiesImpl::HttpServerPropertiesImpl() |
30 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), | 24 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), |
31 alternate_protocol_map_(AlternateProtocolMap::NO_AUTO_EVICT), | 25 alternate_protocol_map_(AlternateProtocolMap::NO_AUTO_EVICT), |
32 alternate_protocol_experiment_( | 26 alternate_protocol_experiment_( |
33 ALTERNATE_PROTOCOL_NOT_PART_OF_EXPERIMENT), | 27 ALTERNATE_PROTOCOL_NOT_PART_OF_EXPERIMENT), |
34 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), | 28 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), |
35 pipeline_capability_map_( | |
36 new CachedPipelineCapabilityMap(kDefaultNumHostsToRemember)), | |
37 weak_ptr_factory_(this) { | 29 weak_ptr_factory_(this) { |
38 canoncial_suffixes_.push_back(".c.youtube.com"); | 30 canoncial_suffixes_.push_back(".c.youtube.com"); |
39 canoncial_suffixes_.push_back(".googlevideo.com"); | 31 canoncial_suffixes_.push_back(".googlevideo.com"); |
40 } | 32 } |
41 | 33 |
42 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { | 34 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { |
43 } | 35 } |
44 | 36 |
45 void HttpServerPropertiesImpl::InitializeSpdyServers( | 37 void HttpServerPropertiesImpl::InitializeSpdyServers( |
46 std::vector<std::string>* spdy_servers, | 38 std::vector<std::string>* spdy_servers, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 94 } |
103 | 95 |
104 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( | 96 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( |
105 SpdySettingsMap* spdy_settings_map) { | 97 SpdySettingsMap* spdy_settings_map) { |
106 for (SpdySettingsMap::reverse_iterator it = spdy_settings_map->rbegin(); | 98 for (SpdySettingsMap::reverse_iterator it = spdy_settings_map->rbegin(); |
107 it != spdy_settings_map->rend(); ++it) { | 99 it != spdy_settings_map->rend(); ++it) { |
108 spdy_settings_map_.Put(it->first, it->second); | 100 spdy_settings_map_.Put(it->first, it->second); |
109 } | 101 } |
110 } | 102 } |
111 | 103 |
112 void HttpServerPropertiesImpl::InitializePipelineCapabilities( | |
113 const PipelineCapabilityMap* pipeline_capability_map) { | |
114 PipelineCapabilityMap::const_iterator it; | |
115 pipeline_capability_map_->Clear(); | |
116 for (it = pipeline_capability_map->begin(); | |
117 it != pipeline_capability_map->end(); ++it) { | |
118 pipeline_capability_map_->Put(it->first, it->second); | |
119 } | |
120 } | |
121 | |
122 void HttpServerPropertiesImpl::SetNumPipelinedHostsToRemember(int max_size) { | |
123 DCHECK(pipeline_capability_map_->empty()); | |
124 pipeline_capability_map_.reset(new CachedPipelineCapabilityMap(max_size)); | |
125 } | |
126 | |
127 void HttpServerPropertiesImpl::GetSpdyServerList( | 104 void HttpServerPropertiesImpl::GetSpdyServerList( |
128 base::ListValue* spdy_server_list, | 105 base::ListValue* spdy_server_list, |
129 size_t max_size) const { | 106 size_t max_size) const { |
130 DCHECK(CalledOnValidThread()); | 107 DCHECK(CalledOnValidThread()); |
131 DCHECK(spdy_server_list); | 108 DCHECK(spdy_server_list); |
132 spdy_server_list->Clear(); | 109 spdy_server_list->Clear(); |
133 size_t count = 0; | 110 size_t count = 0; |
134 // Get the list of servers (host/port) that support SPDY. | 111 // Get the list of servers (host/port) that support SPDY. |
135 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); | 112 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); |
136 it != spdy_servers_map_.end() && count < max_size; ++it) { | 113 it != spdy_servers_map_.end() && count < max_size; ++it) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 148 |
172 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() { | 149 base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() { |
173 return weak_ptr_factory_.GetWeakPtr(); | 150 return weak_ptr_factory_.GetWeakPtr(); |
174 } | 151 } |
175 | 152 |
176 void HttpServerPropertiesImpl::Clear() { | 153 void HttpServerPropertiesImpl::Clear() { |
177 DCHECK(CalledOnValidThread()); | 154 DCHECK(CalledOnValidThread()); |
178 spdy_servers_map_.Clear(); | 155 spdy_servers_map_.Clear(); |
179 alternate_protocol_map_.Clear(); | 156 alternate_protocol_map_.Clear(); |
180 spdy_settings_map_.Clear(); | 157 spdy_settings_map_.Clear(); |
181 pipeline_capability_map_->Clear(); | |
182 } | 158 } |
183 | 159 |
184 bool HttpServerPropertiesImpl::SupportsSpdy( | 160 bool HttpServerPropertiesImpl::SupportsSpdy( |
185 const net::HostPortPair& host_port_pair) { | 161 const net::HostPortPair& host_port_pair) { |
186 DCHECK(CalledOnValidThread()); | 162 DCHECK(CalledOnValidThread()); |
187 if (host_port_pair.host().empty()) | 163 if (host_port_pair.host().empty()) |
188 return false; | 164 return false; |
189 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair); | 165 std::string spdy_server = GetFlattenedSpdyServer(host_port_pair); |
190 | 166 |
191 SpdyServerHostPortMap::iterator spdy_host_port = | 167 SpdyServerHostPortMap::iterator spdy_host_port = |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 HttpServerPropertiesImpl::GetServerNetworkStats( | 399 HttpServerPropertiesImpl::GetServerNetworkStats( |
424 const HostPortPair& host_port_pair) const { | 400 const HostPortPair& host_port_pair) const { |
425 ServerNetworkStatsMap::const_iterator it = | 401 ServerNetworkStatsMap::const_iterator it = |
426 server_network_stats_map_.find(host_port_pair); | 402 server_network_stats_map_.find(host_port_pair); |
427 if (it == server_network_stats_map_.end()) { | 403 if (it == server_network_stats_map_.end()) { |
428 return NULL; | 404 return NULL; |
429 } | 405 } |
430 return &it->second; | 406 return &it->second; |
431 } | 407 } |
432 | 408 |
433 HttpPipelinedHostCapability HttpServerPropertiesImpl::GetPipelineCapability( | |
434 const HostPortPair& origin) { | |
435 HttpPipelinedHostCapability capability = PIPELINE_UNKNOWN; | |
436 CachedPipelineCapabilityMap::const_iterator it = | |
437 pipeline_capability_map_->Get(origin); | |
438 if (it != pipeline_capability_map_->end()) { | |
439 capability = it->second; | |
440 } | |
441 return capability; | |
442 } | |
443 | |
444 void HttpServerPropertiesImpl::SetPipelineCapability( | |
445 const HostPortPair& origin, | |
446 HttpPipelinedHostCapability capability) { | |
447 CachedPipelineCapabilityMap::iterator it = | |
448 pipeline_capability_map_->Peek(origin); | |
449 if (it == pipeline_capability_map_->end() || | |
450 it->second != PIPELINE_INCAPABLE) { | |
451 pipeline_capability_map_->Put(origin, capability); | |
452 } | |
453 } | |
454 | |
455 void HttpServerPropertiesImpl::ClearPipelineCapabilities() { | |
456 pipeline_capability_map_->Clear(); | |
457 } | |
458 | |
459 PipelineCapabilityMap | |
460 HttpServerPropertiesImpl::GetPipelineCapabilityMap() const { | |
461 PipelineCapabilityMap result; | |
462 CachedPipelineCapabilityMap::const_iterator it; | |
463 for (it = pipeline_capability_map_->begin(); | |
464 it != pipeline_capability_map_->end(); ++it) { | |
465 result[it->first] = it->second; | |
466 } | |
467 return result; | |
468 } | |
469 | |
470 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator | 409 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator |
471 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { | 410 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { |
472 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { | 411 for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { |
473 std::string canonical_suffix = canoncial_suffixes_[i]; | 412 std::string canonical_suffix = canoncial_suffixes_[i]; |
474 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { | 413 if (EndsWith(server.host(), canoncial_suffixes_[i], false)) { |
475 HostPortPair canonical_host(canonical_suffix, server.port()); | 414 HostPortPair canonical_host(canonical_suffix, server.port()); |
476 return canonical_host_to_origin_map_.find(canonical_host); | 415 return canonical_host_to_origin_map_.find(canonical_host); |
477 } | 416 } |
478 } | 417 } |
479 | 418 |
(...skipping 25 matching lines...) Expand all Loading... |
505 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 444 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
506 base::MessageLoop::current()->PostDelayedTask( | 445 base::MessageLoop::current()->PostDelayedTask( |
507 FROM_HERE, | 446 FROM_HERE, |
508 base::Bind( | 447 base::Bind( |
509 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 448 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
510 weak_ptr_factory_.GetWeakPtr()), | 449 weak_ptr_factory_.GetWeakPtr()), |
511 delay); | 450 delay); |
512 } | 451 } |
513 | 452 |
514 } // namespace net | 453 } // namespace net |
OLD | NEW |