Index: net/http/http_server_properties_impl.cc |
diff --git a/net/http/http_server_properties_impl.cc b/net/http/http_server_properties_impl.cc |
index de94dfed7e38e082f1a3fcc41e03c32e70ec3311..a572a1133fbe1ab5ea65fbd7f68b0962161bec95 100644 |
--- a/net/http/http_server_properties_impl.cc |
+++ b/net/http/http_server_properties_impl.cc |
@@ -19,7 +19,9 @@ namespace net { |
static const int kDefaultNumHostsToRemember = 200; |
HttpServerPropertiesImpl::HttpServerPropertiesImpl() |
- : pipeline_capability_map_( |
+ : alternate_protocol_map_(new CachedAlternateProtocolMap( |
+ CachedAlternateProtocolMap::NO_AUTO_EVICT)), |
ramant (doing other things)
2014/03/05 00:01:30
rch: Should we keep fewer entries in the memory? A
|
+ pipeline_capability_map_( |
new CachedPipelineCapabilityMap(kDefaultNumHostsToRemember)), |
weak_ptr_factory_(this) { |
canoncial_suffixes_.push_back(".c.youtube.com"); |
@@ -44,15 +46,27 @@ void HttpServerPropertiesImpl::InitializeSpdyServers( |
void HttpServerPropertiesImpl::InitializeAlternateProtocolServers( |
AlternateProtocolMap* alternate_protocol_map) { |
- // First swap, and then add back all the ALTERNATE_PROTOCOL_BROKEN ones since |
- // those don't get persisted. |
- alternate_protocol_map_.swap(*alternate_protocol_map); |
+ // Keep all the ALTERNATE_PROTOCOL_BROKEN ones since those don't |
+ // get persisted. |
+ for (CachedAlternateProtocolMap::iterator it = |
+ alternate_protocol_map_->begin(); |
+ it != alternate_protocol_map_->end();) { |
+ if (it->second.protocol != ALTERNATE_PROTOCOL_BROKEN) { |
+ CachedAlternateProtocolMap::iterator old_it = it; |
+ ++it; |
+ alternate_protocol_map_->Erase(old_it); |
+ } else { |
+ ++it; |
+ } |
+ } |
+ |
+ // Add the entries from persisted data. |
for (AlternateProtocolMap::const_iterator it = |
- alternate_protocol_map->begin(); |
+ alternate_protocol_map->begin(); |
it != alternate_protocol_map->end(); ++it) { |
- if (it->second.protocol == ALTERNATE_PROTOCOL_BROKEN) |
- alternate_protocol_map_[it->first] = it->second; |
+ alternate_protocol_map_->Put(it->first, it->second); |
} |
+ |
// Attempt to find canonical servers. |
int canonical_ports[] = { 80, 443 }; |
for (size_t i = 0; i < canoncial_suffixes_.size(); ++i) { |
@@ -61,15 +75,16 @@ void HttpServerPropertiesImpl::InitializeAlternateProtocolServers( |
HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); |
// If we already have a valid canonical server, we're done. |
if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && |
- ContainsKey(alternate_protocol_map_, |
- canonical_host_to_origin_map_[canonical_host])) { |
+ (alternate_protocol_map_->Get( |
+ canonical_host_to_origin_map_[canonical_host]) != |
+ alternate_protocol_map_->end())) { |
continue; |
} |
// Now attempt to find a server which matches this origin and set it as |
// canonical . |
- for (AlternateProtocolMap::const_iterator it = |
- alternate_protocol_map_.begin(); |
- it != alternate_protocol_map_.end(); ++it) { |
+ for (CachedAlternateProtocolMap::const_iterator it = |
+ alternate_protocol_map_->begin(); |
+ it != alternate_protocol_map_->end(); ++it) { |
if (EndsWith(it->first.host(), canoncial_suffixes_[i], false)) { |
canonical_host_to_origin_map_[canonical_host] = it->first; |
break; |
@@ -147,7 +162,7 @@ base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() { |
void HttpServerPropertiesImpl::Clear() { |
DCHECK(CalledOnValidThread()); |
spdy_servers_table_.clear(); |
- alternate_protocol_map_.clear(); |
+ alternate_protocol_map_->Clear(); |
spdy_settings_map_.clear(); |
pipeline_capability_map_->Clear(); |
} |
@@ -186,7 +201,7 @@ void HttpServerPropertiesImpl::SetSupportsSpdy( |
bool HttpServerPropertiesImpl::HasAlternateProtocol( |
const HostPortPair& server) const { |
- if (ContainsKey(alternate_protocol_map_, server) || |
+ if (alternate_protocol_map_->Get(server) != alternate_protocol_map_->end() || |
g_forced_alternate_protocol) |
return true; |
@@ -199,15 +214,15 @@ HttpServerPropertiesImpl::GetAlternateProtocol( |
DCHECK(HasAlternateProtocol(server)); |
// First check the map. |
- AlternateProtocolMap::const_iterator it = |
- alternate_protocol_map_.find(server); |
- if (it != alternate_protocol_map_.end()) |
+ CachedAlternateProtocolMap::const_iterator it = |
+ alternate_protocol_map_->Get(server); |
+ if (it != alternate_protocol_map_->end()) |
return it->second; |
// Next check the canonical host. |
CanonicalHostMap::const_iterator canonical_host = GetCanonicalHost(server); |
if (canonical_host != canonical_host_to_origin_map_.end()) |
- return alternate_protocol_map_.find(canonical_host->second)->second; |
+ return alternate_protocol_map_->Get(canonical_host->second)->second; |
// We must be forcing an alternate. |
DCHECK(g_forced_alternate_protocol); |
@@ -247,7 +262,7 @@ void HttpServerPropertiesImpl::SetAlternateProtocol( |
} |
} |
- alternate_protocol_map_[server] = alternate; |
+ alternate_protocol_map_->Put(server, alternate); |
// If this host ends with a canonical suffix, then set it as the |
// canonical host. |
@@ -263,12 +278,26 @@ void HttpServerPropertiesImpl::SetAlternateProtocol( |
void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( |
const HostPortPair& server) { |
- alternate_protocol_map_[server].protocol = ALTERNATE_PROTOCOL_BROKEN; |
+ CachedAlternateProtocolMap::iterator it = |
+ alternate_protocol_map_->Get(server); |
+ if (it != alternate_protocol_map_->end()) { |
+ it->second.protocol = ALTERNATE_PROTOCOL_BROKEN; |
+ return; |
+ } |
+ PortAlternateProtocolPair alternate; |
+ alternate.protocol = ALTERNATE_PROTOCOL_BROKEN; |
+ alternate_protocol_map_->Put(server, alternate); |
} |
-const AlternateProtocolMap& |
-HttpServerPropertiesImpl::alternate_protocol_map() const { |
- return alternate_protocol_map_; |
+AlternateProtocolMap |
+HttpServerPropertiesImpl::GetAlternateProtocolMap() const { |
+ AlternateProtocolMap result; |
+ CachedAlternateProtocolMap::const_iterator it; |
+ for (it = alternate_protocol_map_->begin(); |
+ it != alternate_protocol_map_->end(); ++it) { |
+ result[it->first] = it->second; |
+ } |
+ return result; |
} |
const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( |